:root {
  color-scheme: dark;
  --page: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #32322f;
  --grid: #2b2b28;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8d8c83;
  --series-1: #3987e5; /* 주문 성공 / 결제 대기 */
  --series-2: #d95926; /* 품절 / 결제 확인 중 */
  --series-3: #199e70; /* 거절 / 결제 완료 */
  --neutral-1: #6b6a63;
  --neutral-2: #45443f;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --font: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text-primary); font-family: var(--font); font-size: 14px; line-height: 1.45; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--text-secondary); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

.bar { display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: center; justify-content: space-between; padding: 16px clamp(14px, 2.5vw, 28px); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(17, 17, 16, .92); backdrop-filter: blur(8px); z-index: 5; }
.bar-title { display: flex; align-items: center; gap: 14px; }
.bar h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.bar-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--text-muted); align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-1); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.pill[data-state="open"]::before { background: var(--good); box-shadow: 0 0 0 3px rgba(12, 163, 12, .25); }
.pill[data-state="wait"]::before { background: var(--warning); }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: clamp(14px, 2.5vw, 28px); max-width: 1500px; margin: 0 auto; }
.span2 { grid-column: span 2; }
.span3, .kpis { grid-column: 1 / -1; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 18px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card-head p { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.sub-head { margin: 20px 0 8px; font-size: 12px; font-weight: 700; color: var(--text-secondary); }

/* ---------- 지표 ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; min-width: 0; }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.kpi-value { margin-top: 4px; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; display: flex; align-items: baseline; gap: 8px; }
.kpi-value small { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.kpi-sub { margin-top: 6px; font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.kpi-meter { margin-top: 10px; height: 6px; border-radius: 3px; background: #1f3654; overflow: hidden; }
.kpi-meter i { display: block; height: 100%; background: var(--series-1); border-radius: 3px; transition: width .3s ease; }
.state-icon { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px; font-weight: 900; color: #111; align-self: center; }
.kpi[data-state="good"] .state-icon { background: var(--good); }
.kpi[data-state="critical"] .state-icon { background: var(--critical); color: #fff; }
.kpi[data-state="critical"] { border-color: var(--critical); }
.kpi[data-state] .kpi-value { font-size: 23px; align-items: center; min-height: 35px; }

/* ---------- 차트 ---------- */
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--text-secondary); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; }
.chart { position: relative; height: 230px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.table-view { margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.table-view summary { cursor: pointer; width: fit-content; }
.table-view table { margin-top: 8px; border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
.table-view th:first-child, .table-view td:first-child { text-align: left; }

.tooltip { position: fixed; z-index: 30; pointer-events: none; background: #0b0b0b; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; font-size: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); min-width: 130px; }
.tooltip b { display: block; margin-bottom: 4px; color: var(--text-secondary); font-weight: 600; }
.tooltip div { display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; }
.tooltip i { width: 8px; height: 8px; border-radius: 50%; }
.tooltip span { margin-left: auto; padding-left: 14px; font-weight: 700; }

/* ---------- 주문 상태 ---------- */
.seg { display: flex; gap: 2px; height: 26px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.seg i { display: block; min-width: 3px; transition: flex-grow .3s ease; }
.state-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 7px; }
.state-list li { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--text-secondary); }
.state-list i { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.state-list b { margin-left: auto; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.state-list small { color: var(--text-muted); }
.paying { list-style: none; margin: 0; padding: 0; font-size: 13px; display: grid; gap: 5px; max-height: 120px; overflow: auto; }
.paying li { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 8px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.paying .none { background: transparent; padding: 0; color: var(--text-muted); }

/* ---------- SKU 표 ---------- */
.table-wrap { overflow-x: auto; }
.sku { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 560px; }
.sku th { text-align: right; font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 0 10px 8px; white-space: nowrap; }
.sku td { text-align: right; padding: 7px 10px; border-top: 1px solid var(--grid); white-space: nowrap; }
.sku th:first-child, .sku td:first-child { text-align: left; padding-left: 0; }
.sku th:nth-child(2), .sku td:nth-child(2) { text-align: left; width: 34%; }
.meter { display: flex; align-items: center; gap: 10px; }
.meter-track { flex: 1; height: 8px; border-radius: 4px; background: #1f3654; overflow: hidden; }
.meter-track i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; transition: width .3s ease; }
.meter span { flex: 0 0 52px; text-align: right; color: var(--text-secondary); }
.check-cell { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.check-cell::before { content: "✓"; width: 16px; height: 16px; border-radius: 50%; background: var(--good); color: #111; font-size: 11px; font-weight: 900; display: inline-grid; place-items: center; }
.check-cell[data-bad]::before { content: "!"; background: var(--critical); color: #fff; }
tr[data-bad] td { background: rgba(208, 59, 59, .09); }

/* ---------- 조작 ---------- */
.controls fieldset { border: 0; border-top: 1px solid var(--grid); margin: 0; padding: 14px 0 12px; display: grid; gap: 8px; }
.controls legend { padding: 0; font-size: 12px; font-weight: 700; color: var(--text-secondary); float: left; width: 100%; margin-bottom: 8px; }
.controls label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--text-secondary); clear: both; }
.controls input[type="number"] { width: 92px; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--page); text-align: right; font-variant-numeric: tabular-nums; }
.controls .check { justify-content: flex-start; }
.controls .check input { accent-color: var(--series-1); width: 16px; height: 16px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.btns button, .chips button { padding: 8px 13px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; font-weight: 600; }
.btns button:hover, .chips button:hover { border-color: var(--text-muted); }
.btns button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btns button.primary:hover { filter: brightness(1.1); }
.btns button:disabled { opacity: .5; cursor: not-allowed; }
.note { margin: 0; min-height: 18px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- 사건 기록 ---------- */
.chips { display: flex; gap: 6px; }
.chips button { padding: 5px 11px; border-radius: 999px; font-size: 12px; }
.chips button[aria-pressed="true"] { background: var(--text-primary); color: #111; border-color: var(--text-primary); }
.log { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; font-size: 13px; }
.log li { display: grid; grid-template-columns: 96px 20px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--grid); align-items: baseline; }
.log time { white-space: nowrap; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.log .lv { width: 16px; height: 16px; border-radius: 50%; font-size: 10px; font-weight: 900; display: inline-grid; place-items: center; background: var(--neutral-2); color: var(--text-secondary); align-self: center; }
.log [data-level="ok"] .lv { background: var(--good); color: #111; }
.log [data-level="warn"] .lv { background: var(--warning); color: #111; }
.log [data-level="bad"] .lv { background: var(--critical); color: #fff; }
.log .none { display: block; color: var(--text-muted); border: 0; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 40; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--text-primary); color: #111; padding: 11px 14px; border-radius: 10px; font-size: 13px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid > .card { grid-column: 1 / -1; }
  .controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; align-items: start; }
  .controls .card-head { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .controls { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
