/* =========================================================================
   관리자 대시보드 — 본 화면(web/styles.css)의 색·모서리·그림자 토큰을 그대로 따른다.
   차트 색: 단일 계열은 브랜드 녹색, 언어 3색은 색각 이상 구분 검증을 통과한 조합.
   ========================================================================= */
:root {
  --bg: #fbf7ee; --bg-elev: #fffdf8; --bg-subtle: #f3ecdc; --surface-2: #f7f1e3;
  --border: #e6dcc6; --border-strong: #d2c4a6;
  --text: #1f2a24; --text-2: #4d5a52; --text-3: #5f6d63;
  --brand: #2f8f5b; --brand-strong: #24734a; --brand-soft: #e3f2e9; --brand-contrast: #ffffff;
  --accent: #f2a33a; --accent-soft: #fdeed6; --accent-ink: #8a5a12;
  --relevant: #e4572e; --relevant-ink: #a83616; --relevant-soft: #fde9e2;
  --sensitized: #6b7a8f; --sensitized-soft: #eef1f5;
  --indet: #d9860a; --indet-ink: #8a5405; --indet-soft: #fdf3e3;
  --ok-ink: #24734a;
  --series: #2f8f5b; --series-hover: #24734a; --grid: #e6dcc6;
  --lang-ko: #2a78d6; --lang-en: #eb6834; --lang-zh: #1baf7a;
  --shadow-sm: 0 1px 2px rgba(60,48,20,.06), 0 1px 3px rgba(60,48,20,.05);
  --shadow-lg: 0 18px 44px rgba(60,48,20,.16);
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 999px;
  --font: 'Pretendard', 'Pretendard Variable', -apple-system, BlinkMacSystemFont,
          'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --maxw: 1240px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1a16; --bg-elev: #16231e; --bg-subtle: #1c2b25; --surface-2: #1a2822;
  --border: #27392f; --border-strong: #35493e;
  --text: #ecf1ea; --text-2: #b6c3b8; --text-3: #8f9e93;
  --brand: #4fb87f; --brand-strong: #4fb87f; --brand-soft: #173124; --brand-contrast: #08150f;
  --accent: #f5b25a; --accent-soft: #3a2a12; --accent-ink: #f5d39a;
  --relevant: #ff7a54; --relevant-ink: #ff7a54; --relevant-soft: #3a1f16;
  --sensitized: #9aa9bd; --sensitized-soft: #1f2732;
  --indet: #f0a33a; --indet-ink: #f0a33a; --indet-soft: #3a2a12;
  --ok-ink: #4fb87f;
  --series: #4fb87f; --series-hover: #7fd0a3; --grid: #27392f;
  --lang-ko: #3987e5; --lang-en: #d95926; --lang-zh: #199e70;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 18px 44px rgba(0,0,0,.6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1a16; --bg-elev: #16231e; --bg-subtle: #1c2b25; --surface-2: #1a2822;
    --border: #27392f; --border-strong: #35493e;
    --text: #ecf1ea; --text-2: #b6c3b8; --text-3: #8f9e93;
    --brand: #4fb87f; --brand-strong: #4fb87f; --brand-soft: #173124; --brand-contrast: #08150f;
    --accent: #f5b25a; --accent-soft: #3a2a12; --accent-ink: #f5d39a;
    --relevant: #ff7a54; --relevant-ink: #ff7a54; --relevant-soft: #3a1f16;
    --sensitized: #9aa9bd; --sensitized-soft: #1f2732;
    --indet: #f0a33a; --indet-ink: #f0a33a; --indet-soft: #3a2a12;
    --ok-ink: #4fb87f;
    --series: #4fb87f; --series-hover: #7fd0a3; --grid: #27392f;
    --lang-ko: #3987e5; --lang-en: #d95926; --lang-zh: #199e70;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 18px 44px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--text); background: var(--bg); font-size: 14.5px;
  line-height: 1.55; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:where(button, a, input, [tabindex]):focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
code { font-family: var(--mono); font-size: .92em; background: var(--bg-subtle); padding: 1px 5px; border-radius: 5px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sub { color: var(--text-3); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-3); }

/* ---------- 버튼·세그먼트 ---------- */
.btn { border: 1px solid var(--border-strong); background: var(--bg-elev); border-radius: var(--r-sm);
  padding: 7px 12px; min-height: 36px; font-weight: 600; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.btn:hover { background: var(--bg-subtle); color: var(--text); }
.btn.primary { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--brand-contrast); }
.btn.primary:hover { filter: brightness(1.06); background: var(--brand-strong); color: var(--brand-contrast); }
.btn.icon { width: 36px; padding: 0; font-size: 15px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg-subtle); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.btn.danger { color: var(--relevant-ink); border-color: color-mix(in srgb, var(--relevant) 45%, var(--border)); }
.btn.danger:hover { background: var(--relevant-soft); color: var(--relevant-ink); }
.btn:disabled { opacity: .55; cursor: default; }
.seg { display: inline-flex; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 6px; padding: 5px 12px; min-height: 30px;
  font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- 로그인 ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: min(380px, 100%); background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 30px 26px 22px; box-shadow: var(--shadow-sm); }
.gate-mark { width: 46px; height: 46px; display: grid; place-items: center; font-size: 22px; border-radius: 12px;
  background: var(--brand-soft); border: 1.5px dashed var(--brand); margin-bottom: 14px; }
.gate-card h1 { font-size: 20px; letter-spacing: -.2px; }
.gate-sub { color: var(--text-3); font-size: 13px; margin-bottom: 20px; }
.gate-card form { display: grid; gap: 12px; }
.gate-card label { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.gate-card input { border: 1px solid var(--border-strong); background: var(--bg); border-radius: var(--r-sm);
  padding: 10px 12px; font-size: 15px; min-height: 42px; }
.gate-card .btn.primary { min-height: 42px; font-size: 14.5px; margin-top: 4px; }
.form-error { color: var(--relevant-ink); font-size: 13px; min-height: 1.2em; }
.note { background: var(--indet-soft); border: 1px solid color-mix(in srgb, var(--indet) 35%, var(--border));
  border-radius: var(--r-md); padding: 12px 14px; font-size: 13.5px; }
.note p { margin-top: 6px; color: var(--text-2); }
.gate-back { display: inline-block; margin-top: 18px; font-size: 13px; color: var(--text-3); text-decoration: none; }
.gate-back:hover { color: var(--text); }

/* ---------- 상단 바 ---------- */
.topbar { position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg-elev) 90%, transparent); border-bottom: 1px solid var(--border); }
.topbar-in { max-width: var(--maxw); margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; font-size: 18px;
  background: var(--brand-soft); border: 1.5px dashed var(--brand); flex: none; }
.brand b { display: block; font-size: 15px; line-height: 1.2; }
.brand small { color: var(--text-3); font-size: 11.5px; }

main { max-width: var(--maxw); margin: 0 auto; padding: 18px 20px 56px; display: grid; gap: 14px; }
.banner { background: var(--relevant-soft); color: var(--relevant-ink); border-radius: var(--r-md); padding: 10px 14px; font-size: 13.5px; }

/* ---------- 카드·KPI ---------- */
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 16px 18px; box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head.wrap { flex-wrap: wrap; align-items: center; }
.card-head.sub-head { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.card h2 { font-size: 14.5px; font-weight: 700; letter-spacing: -.1px; }
.grid.two { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 14px 16px; box-shadow: var(--shadow-sm); min-width: 0; }
.kpi-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.kpi-value { font-size: 30px; font-weight: 750; letter-spacing: -.8px; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12px; color: var(--text-3); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--ok-ink); }
.delta.down { color: var(--relevant-ink); }
.skeleton { color: transparent !important; background: var(--bg-subtle); border-radius: 6px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- 차트 ---------- */
.card.fill { display: flex; flex-direction: column; }
.chart { position: relative; height: 230px; }
.card.fill .chart { flex: 1 1 230px; height: auto; min-height: 230px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .bar, .chart .bar.on { fill: var(--series-hover); }
.empty { color: var(--text-3); font-size: 13px; padding: 26px 0; text-align: center; }

.stack { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; background: var(--bg-subtle); }
.stack i { display: block; min-width: 3px; }
.legend { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 7px; }
.legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; font-size: 13px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.legend .p { color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; font-size: 12.5px; }

.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(96px, 34%) minmax(0, 1fr) 34px; gap: 10px; align-items: center; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .name small { color: var(--text-3); margin-left: 4px; }
.hbar .track { height: 12px; }
.hbar .fill { height: 100%; background: var(--series); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- 표 ---------- */
.search input { border: 1px solid var(--border-strong); background: var(--bg); border-radius: var(--r-sm);
  padding: 7px 12px; min-height: 36px; width: min(280px, 60vw); font-size: 13.5px; }
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td .primary-cell { font-weight: 600; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; font-size: 12.5px; color: var(--text-3); }
.pager div { display: flex; gap: 6px; }

.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: var(--r-pill); padding: 1px 8px; font-size: 11.5px;
  font-weight: 700; border: 1px solid var(--border); background: var(--bg-subtle); color: var(--text-2); white-space: nowrap; }
.pill.ready { background: var(--brand-soft); color: var(--ok-ink); border-color: transparent; }
.pill.failed { background: var(--relevant-soft); color: var(--relevant-ink); border-color: transparent; }
.pill.pending, .pill.running { background: var(--indet-soft); color: var(--indet-ink); border-color: transparent; }
.pills { display: inline-flex; gap: 4px; flex: none; }
#listTable td { white-space: nowrap; }

/* ---------- 서랍 ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 26, 22, .45); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); z-index: 50; background: var(--bg);
  border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(102%); transition: transform .28s cubic-bezier(.2,.8,.2,1); visibility: hidden; }
.drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 16px 20px;
  border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.drawer-title { min-width: 0; }
.drawer-title h2 { font-size: 17px; overflow-wrap: anywhere; }
.drawer-body { overflow-y: auto; padding: 16px 20px 40px; display: grid; gap: 14px; align-content: start; flex: 1; }
.session-list { display: grid; gap: 6px; }
.session-item { display: flex; gap: 10px; align-items: center; justify-content: space-between; text-align: left; width: 100%;
  border: 1px solid var(--border); background: var(--bg-elev); border-radius: var(--r-md); padding: 9px 12px; }
.session-item:hover { border-color: var(--border-strong); }
.session-item.on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.session-item b { font-size: 13.5px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: transparent; padding: 9px 14px; font-weight: 600; font-size: 13.5px; color: var(--text-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--brand); }
.panel { display: grid; gap: 14px; }
.panel h3 { font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 6px; }
.box { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px; min-width: 0; }
.box .table-wrap { margin: 0 -14px; padding: 0 14px; }
.kv { display: grid; grid-template-columns: minmax(110px, 30%) minmax(0, 1fr); gap: 6px 12px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.frame { width: 100%; height: 62vh; min-height: 380px; border: 1px solid var(--border); border-radius: var(--r-md); background: #fff; }
pre.md { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  max-height: 62vh; overflow: auto; }
.chat { display: grid; gap: 10px; }
.msg { max-width: 86%; border-radius: 14px; padding: 9px 13px; font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg small { display: block; margin-top: 4px; font-size: 11px; color: var(--text-3); }
.msg.user { justify-self: end; background: var(--brand-soft); border-bottom-right-radius: 4px; }
.msg.assistant { justify-self: start; background: var(--bg-elev); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.rel { font-weight: 700; font-size: 12px; }
.rel.clinically_relevant { color: var(--relevant-ink); }
.rel.indeterminate { color: var(--indet-ink); }
.rel.sensitized_only { color: var(--text-2); }

.tooltip { position: fixed; z-index: 60; pointer-events: none; background: var(--text); color: var(--bg);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px; line-height: 1.4; box-shadow: var(--shadow-lg); white-space: nowrap; }
.tooltip b { font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .grid.two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .card.fill .chart { flex-basis: 190px; min-height: 190px; }
  main { padding: 12px 12px 48px; gap: 12px; }
  .topbar-in { padding: 8px 12px; }
  .brand small { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 24px; }
  .card { padding: 14px; border-radius: var(--r-md); }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .chart { height: 190px; }
  .drawer-head, .drawer-body { padding-left: 14px; padding-right: 14px; }
  .search, .search input { width: 100%; }
  .msg { max-width: 94%; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer { transition: none; }
  .skeleton { animation: none; }
}
