:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #d9dee7;
  --muted: #5f6876;
  --text: #17202e;
  --accent: #0f766e;
  --accent-soft: #d9f3ef;
  --warn: #a15c07;
  --shadow: 0 10px 24px rgba(30, 42, 62, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width, 300px) 6px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 0 minmax(0, 1fr);
}

.sidebar {
  grid-column: 1;
  grid-row: 1;
  border-right: 1px solid var(--line);
  background: #eef2f5;
  padding: 18px;
  overflow: auto;
}

#sidebarResizer {
  grid-column: 2;
  grid-row: 1;
}

.sidebar-collapsed .sidebar {
  display: none;
}

.sidebar-collapsed #sidebarResizer {
  display: none;
}

.sidebar-reopen {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  min-height: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 800;
  line-height: 1;
}

.resize-handle {
  background: transparent;
  position: relative;
  z-index: 5;
}

.resize-handle.vertical {
  cursor: col-resize;
}

.resize-handle.vertical::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 2px;
  width: 2px;
  background: var(--line);
}

.resize-handle:hover::after,
body.resizing .resize-handle::after {
  background: var(--accent);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.panel {
  margin-bottom: 18px;
}

.panel-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.file-list {
  display: grid;
  gap: 8px;
}

.file-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.file-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count-badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: #e7ebf0;
  color: var(--muted);
  font-size: 12px;
}

select,
input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  min-height: 40px;
  padding: 0 12px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #07534d;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.tag:hover,
.tag.selected {
  border-color: var(--accent);
  background: #d6f7ef;
}

.main {
  grid-column: 3;
  grid-row: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  padding: 16px 18px 10px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.load-status {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 18px 12px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.summary-card b {
  display: block;
  font-size: 22px;
  margin-bottom: 3px;
}

.summary-card span {
  color: var(--muted);
  font-size: 12px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6px var(--detail-width, 390px);
  min-height: 0;
  padding: 0 18px 18px;
}

.content-grid.detail-collapsed {
  grid-template-columns: minmax(0, 1fr) 0 0;
}

.content-grid.detail-collapsed #detailResizer,
.content-grid.detail-collapsed .detail-panel {
  display: none;
}

.table-panel,
.detail-panel {
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.table-meta strong {
  color: var(--text);
}

.table-wrap {
  overflow: auto;
}

.column-menu {
  position: relative;
}

.column-menu-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.column-menu-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  display: grid;
  gap: 4px;
  min-width: 150px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.column-menu-popover label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 6px;
  border-radius: 6px;
}

.column-menu-popover label:hover {
  background: #eefaf7;
}

.column-menu-popover input {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th.hidden-column,
td.hidden-column {
  display: none;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0f3f6;
  color: #394251;
  font-size: 12px;
  cursor: pointer;
  padding-right: 16px;
}

.column-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  bottom: 0;
  z-index: 2;
  width: 8px;
  cursor: col-resize;
  touch-action: none;
}

.column-resize-handle::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  width: 1px;
  background: transparent;
}

th:hover .column-resize-handle::after,
body.resizing-column .column-resize-handle::after {
  background: var(--accent);
}

body.resizing-column {
  cursor: col-resize;
  user-select: none;
}

td {
  line-height: 1.45;
}

tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #eefaf7;
}

th:nth-child(1),
td:nth-child(1) {
  width: 170px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 110px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 145px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 220px;
}

th:nth-child(5),
td:nth-child(5) {
  min-width: 260px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 150px;
}

th:nth-child(7),
td:nth-child(7) {
  width: 150px;
}

.cell-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.detail-panel {
  overflow: auto;
  padding: 16px;
}

.detail-actions {
  display: flex;
  gap: 6px;
}

.detail-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none;
}

.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.detail-id {
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
}

.detail-heading h2 {
  margin: 4px 0 0;
  font-size: 19px;
  line-height: 1.3;
}

.detail-list {
  margin: 16px 0;
}

.detail-list dt {
  font-weight: 800;
  margin-top: 14px;
}

.detail-list dd {
  margin: 6px 0 0;
  white-space: pre-wrap;
  color: #2c3543;
}

.structured-list,
.structured-list ul,
.structured-list ol {
  margin: 0;
  padding-left: 20px;
  white-space: normal;
}

.structured-list li {
  margin: 6px 0;
  line-height: 1.5;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 8px 0;
  background: #fbfcfd;
}

.detail-item-title {
  font-weight: 800;
  margin-bottom: 8px;
}

.empty-value {
  color: var(--muted);
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f4f6f8;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  max-height: 420px;
  overflow: auto;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: auto;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #sidebarResizer,
  #detailResizer {
    display: none;
  }

  .content-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .toolbar,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .load-status {
    flex-basis: 100%;
  }

  .toolbar-actions button {
    flex: 1;
  }
}
