/* MWO 운영 콘솔 — 색 토큰은 앱 Theme.kt(LightMwoColors·DarkMwoColors) 값을 그대로 쓴다(D39 AA 4.5:1).
   danger-soft는 콘솔 전용(라이트 #FEF2F2 위 #D92323 ≈ 4.56:1). 외부 글꼴·CDN 없음. 인라인 style 없음(CSP). */

:root {
  --canvas: #FAFAFA;
  --surface: #FFFFFF;
  --surface-muted: #F4F4F5;
  --border: #E7E7EA;
  --border-strong: #D4D4D8;
  --ink: #18181B;
  --ink-muted: #52525B;
  --ink-faint: #6D6D76;
  --accent: #0A64F1;
  --accent-soft: #EAF2FE;
  --success: #15803D;
  --success-soft: #EAF7EE;
  --warning: #B45309;
  --warning-soft: #FDF4E7;
  --danger: #D92323;
  --danger-soft: #FEF2F2;
  --action: #27272A;
  --on-action: #FFFFFF;
  --backdrop: rgba(24, 24, 27, 0.45);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #111113;
    --surface: #18181B;
    --surface-muted: #232327;
    --border: #2E2E33;
    --border-strong: #3F3F46;
    --ink: #F4F4F5;
    --ink-muted: #B4B4BB;
    --ink-faint: #8A8A93;
    --accent: #5B9BFF;
    --accent-soft: #1B2A44;
    --success: #4ADE80;
    --success-soft: #16291D;
    --warning: #FBBF24;
    --warning-soft: #2E2414;
    --danger: #F87171;
    --danger-soft: #2E1616;
    --action: #F4F4F5;
    --on-action: #18181B;
    --backdrop: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --canvas: #111113;
  --surface: #18181B;
  --surface-muted: #232327;
  --border: #2E2E33;
  --border-strong: #3F3F46;
  --ink: #F4F4F5;
  --ink-muted: #B4B4BB;
  --ink-faint: #8A8A93;
  --accent: #5B9BFF;
  --accent-soft: #1B2A44;
  --success: #4ADE80;
  --success-soft: #16291D;
  --warning: #FBBF24;
  --warning-soft: #2E2414;
  --danger: #F87171;
  --danger-soft: #2E1616;
  --action: #F4F4F5;
  --on-action: #18181B;
  --backdrop: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ── 기본 ───────────────────────────────────────── */
* { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  overflow-x: hidden;
}
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.75rem; }
code { background: var(--surface-muted); border-radius: 6px; padding: 0.0625rem 0.375rem; word-break: break-all; }
.num, .metric-value, td.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.small { font-size: 0.75rem; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.125rem; height: 1.125rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round; }
.fill { fill: currentColor; }
.boot { padding: 2rem; color: var(--ink-muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 버튼·입력 ──────────────────────────────────── */
button, .btn {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; min-height: 2.5rem; padding: 0.375rem 0.875rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem; text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-muted); }
button.primary, .btn.primary { background: var(--action); border-color: var(--action); color: var(--on-action); font-weight: 600; }
button.primary:hover { filter: brightness(1.15); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-muted); }
button.icon-btn { padding: 0.375rem; min-width: 2.5rem; }
button:disabled, input:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; min-height: 2.5rem; padding: 0.375rem 0.625rem; min-width: 0; max-width: 100%;
}
input[type="radio"], input[type="checkbox"] { min-height: auto; width: 1rem; height: 1rem; accent-color: var(--accent); }
label { color: var(--ink); }
.field { display: grid; gap: 0.25rem; min-width: 0; }
.field > span { font-weight: 600; font-size: 0.8125rem; }
.field .help { color: var(--ink-muted); font-size: 0.75rem; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; min-width: 0; }
ul.stack, ol.stack { list-style: none; padding: 0; margin: 0; }
.stack { display: grid; gap: 0.75rem; min-width: 0; }
.grow { flex: 1 1 14rem; min-width: 0; }
.switch { display: inline-flex; align-items: center; gap: 0.375rem; cursor: pointer; min-height: 2.5rem;
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 0.625rem; background: var(--surface); }
.switch input { margin: 0; }

/* ── 배지 ───────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 0.25rem; border-radius: 6px; padding: 0.0625rem 0.5rem;
  font-size: 0.75rem; font-weight: 600; line-height: 1.5; max-width: 100%; overflow-wrap: anywhere; }
td .badge, .tab .badge { white-space: nowrap; }
.mode-link { text-decoration: none; display: inline-flex; border-radius: 6px; }
.badge .dot { font-size: 0.625rem; }
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-critical { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.badge-neutral { background: var(--surface-muted); color: var(--ink-muted); }
.count { display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem; border-radius: 999px;
  padding: 0 0.375rem; background: var(--warning-soft); color: var(--warning); font-size: 0.6875rem; font-weight: 700; }

/* ── 레이아웃 ───────────────────────────────────── */
.layout { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 0.875rem 0.625rem;
  display: flex; flex-direction: column; gap: 0.25rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; padding: 0.25rem 0.5rem 0.75rem; }
.brand .mark { width: 1.75rem; height: 1.75rem; border-radius: 8px; background: var(--action); color: var(--on-action);
  display: grid; place-items: center; font-size: 0.875rem; }
.brand small { display: block; font-weight: 400; color: var(--ink-muted); font-size: 0.6875rem; }
.nav-group { color: var(--ink-faint); font-size: 0.75rem; font-weight: 600; padding: 0.75rem 0.625rem 0.25rem; }
.nav-link { display: flex; align-items: center; gap: 0.625rem; min-height: 2.5rem; padding: 0.375rem 0.625rem;
  border-radius: 8px; color: var(--ink); text-decoration: none; }
.nav-link:hover { background: var(--surface-muted); }
.nav-link[aria-current="page"] { background: var(--surface-muted); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-link .count { margin-left: auto; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 0.75rem 0.375rem 0; display: grid; gap: 0.5rem; }
.sidebar-foot .row { gap: 0.375rem; }
.drawer-close, .menu-btn, .backdrop { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.5rem 0.75rem; padding: 0.5rem 1.5rem; flex-wrap: wrap; min-height: 3.5rem;
}
.topbar .title { font-size: 1rem; font-weight: 600; margin-right: auto; display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.topbar .refresh-meta { color: var(--ink-muted); font-size: 0.75rem; white-space: nowrap; }
.topbar .meta { display: flex; align-items: center; gap: 0.375rem; flex-wrap: wrap; }
.content { padding: 1.5rem; width: 100%; max-width: 82rem; min-width: 0; }
.page-head { display: grid; gap: 0.25rem; margin-bottom: 1rem; }
.page-head h1 { font-size: 1.25rem; font-weight: 600; }
.page-head h1:focus { outline: none; }
.page-head p { color: var(--ink-muted); }
.stale-note { margin-bottom: 1rem; }
.view.stale { opacity: 0.72; }

/* ── 카드·격자 ──────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: 0.875rem; font-weight: 600; }
.card-body { padding: 0.875rem 1rem; min-width: 0; display: grid; gap: 0.75rem; }
/* 열 수는 화면 폭이 아니라 '글자 크기 기준 최소폭'으로 정한다(R1-QA W1). 1280·기본 글꼴이면 대시보드 4열,
   글꼴을 키우거나 창이 좁으면 3·2·1열로 저절로 줄어 카드 내용이 넘치지 않는다. */
.grid { display: grid; gap: 0.875rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13.5rem), 1fr)); margin-bottom: 0.875rem; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); }
.section { margin-bottom: 0.875rem; }

.metric-card { padding: 0.875rem 1rem; display: grid; gap: 0.375rem; align-content: start; }
.metric-card .head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.metric-card h3 { font-size: 0.875rem; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.metric-card .go { overflow-wrap: anywhere; }
.metric-value { font-size: 1.75rem; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.metric-value .unit { font-size: 0.875rem; font-weight: 500; color: var(--ink-muted); margin-left: 0.125rem; }
.metric-value.text { font-size: 1.125rem; }
.metric-card .sub { color: var(--ink-muted); font-size: 0.8125rem; overflow-wrap: anywhere; }
.metric-card .go { font-size: 0.8125rem; font-weight: 600; text-decoration: none; }
.metric-card .go:hover { text-decoration: underline; }
.metric-card .judged { color: var(--ink-faint); font-size: 0.6875rem; }

.stat { border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 0.875rem; background: var(--surface); min-width: 0; }
.stat b { display: block; font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { color: var(--ink-muted); font-size: 0.75rem; }

/* ── 상태 띠·안내 ───────────────────────────────── */
.band { border-radius: 10px; padding: 0.875rem 1rem; margin-bottom: 0.875rem; display: grid; gap: 0.375rem;
  border: 1px solid var(--border); }
.band h2 { font-size: 1rem; font-weight: 600; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.band ul { margin: 0; padding-left: 1.25rem; display: grid; gap: 0.25rem; }
.band-ok { background: var(--success-soft); }
.band-ok h2 { color: var(--success); }
.band-warning { background: var(--warning-soft); }
.band-warning h2 { color: var(--warning); }
.band-critical { background: var(--danger-soft); }
.band-critical h2 { color: var(--danger); }
.band li { color: var(--ink); }
.notice { border-radius: 8px; padding: 0.625rem 0.75rem; font-size: 0.8125rem; background: var(--surface-muted);
  color: var(--ink); display: flex; gap: 0.5rem; align-items: flex-start; }
.notice.warning { background: var(--warning-soft); color: var(--warning); }
.notice.critical { background: var(--danger-soft); color: var(--danger); }
.notice.info { background: var(--accent-soft); color: var(--ink); }
.notice .icon { margin-top: 0.0625rem; }
.notice ul.notes { margin: 0; padding-left: 1.125rem; display: grid; gap: 0.25rem; }

/* ── 표 ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; max-width: 100%; container-type: inline-size; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--ink-muted); font-weight: 500; font-size: 0.75rem; padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td .row { flex-wrap: nowrap; }
.chart th, .chart td { white-space: nowrap; } /* [표로 보기] 숫자 표는 가로 스크롤(버튼 없음) */

/* 좁은 칸(표를 감싼 칸이 50rem 미만 — 800px 창·휴대폰, 글꼴을 키운 넓은 창)에서는 행을 카드로 쌓는다.
   칸마다 머리글을 라벨로(ui.js labelTables가 data-label을 단다), 머리글 없는 버튼 칸은 아래 한 줄. R1-QA W2. */
@container (max-width: 50rem) {
  .stack-table, .stack-table tbody, .stack-table tr { display: block; width: 100%; }
  .stack-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stack-table tr { border: 1px solid var(--border); border-radius: 8px; padding: 0.25rem 0.75rem; margin-bottom: 0.5rem; }
  .stack-table tr td { display: grid; grid-template-columns: minmax(4.5rem, 30%) minmax(0, 1fr); gap: 0.75rem;
    padding: 0.4375rem 0; border-bottom: 1px solid var(--border); text-align: left; overflow-wrap: anywhere; }
  .stack-table tr td:last-child { border-bottom: 0; }
  .stack-table td::before { content: attr(data-label); color: var(--ink-muted); font-size: 0.75rem; padding-top: 0.125rem; }
  .stack-table tr td[data-label=""] { display: block; }
  .stack-table td[data-label=""]::before { content: none; }
  .stack-table td .row { flex-wrap: wrap; }
}

details summary { cursor: pointer; color: var(--accent); }
details pre { white-space: pre-wrap; word-break: break-all; margin: 0.375rem 0 0; font-size: 0.75rem; }

/* ── 탭·칩 ──────────────────────────────────────── */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tab { padding: 0.5rem 0.875rem; color: var(--ink-muted); text-decoration: none; border-bottom: 2px solid transparent;
  white-space: nowrap; min-height: 2.5rem; display: inline-flex; align-items: center; }
.tab[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.chips { display: flex; gap: 0.375rem; flex-wrap: wrap; }
.chip { border-radius: 999px; min-height: 2.25rem; padding: 0.25rem 0.75rem; font-size: 0.8125rem; }
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; min-height: 2.25rem; }
.segmented button[aria-pressed="true"] { background: var(--surface-muted); font-weight: 600; }

/* ── 키 카드 ────────────────────────────────────── */
.checklist { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); gap: 0.5rem; padding: 0; margin: 0; list-style: none; }
.checklist li { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.625rem; display: grid; gap: 0.25rem; font-size: 0.8125rem; }
.checklist li.done { border-color: var(--success); }
.checklist .state { font-weight: 600; }
.checklist li.done .state { color: var(--success); }
.key-card .card-head { align-items: flex-start; }
.key-title { display: grid; gap: 0.25rem; min-width: 0; }
.key-title h3 { font-size: 0.9375rem; }
.key-meta { display: flex; gap: 0.375rem; align-items: center; flex-wrap: wrap; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.875rem; }
.step { display: grid; grid-template-columns: 1.75rem minmax(0, 1fr); gap: 0.625rem; }
.step-no { width: 1.75rem; height: 1.75rem; border-radius: 999px; border: 1.5px solid var(--border-strong);
  display: grid; place-items: center; font-size: 0.75rem; font-weight: 700; color: var(--ink-muted); }
.step.done .step-no { border-color: var(--success); color: var(--success); }
.step h4 { margin: 0 0 0.25rem; font-size: 0.8125rem; font-weight: 600; }
.step p { color: var(--ink-muted); font-size: 0.8125rem; }
.key-input-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.key-input-row input { flex: 1 1 14rem; }
.key-msg { font-size: 0.8125rem; min-height: 1.25rem; }
.key-msg.ok { color: var(--success); }
.key-msg.bad { color: var(--danger); }
.key-msg.info { color: var(--accent); }
.copy-line { display: flex; gap: 0.375rem; align-items: center; flex-wrap: wrap; margin-top: 0.25rem; }
.mode-options { display: grid; gap: 0.5rem; }
.mode-opt { display: flex; gap: 0.625rem; align-items: flex-start; padding: 0.75rem; border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer; }
.mode-opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.mode-opt.disabled { color: var(--ink-faint); cursor: not-allowed; }
.mode-opt input { margin-top: 0.1875rem; }

/* ── 가중치 ─────────────────────────────────────── */
.weights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem 1.25rem; }
.weights label { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; min-width: 0; }
.weights input { width: 6rem; text-align: right; }
.sum-bar { display: grid; gap: 0.25rem; }
.sum-bar svg { width: 100%; height: 0.5rem; }
.sum-bar .track { fill: var(--surface-muted); }
.sum-bar .fill-ok { fill: var(--success); }
.sum-bar .fill-bad { fill: var(--warning); }

/* ── 차트 ───────────────────────────────────────── */
.chart { display: grid; gap: 0.375rem; }
.chart svg { width: 100%; height: 10rem; display: block; }
.chart.small svg { height: 6rem; }
.chart .legend { display: flex; gap: 0.75rem; flex-wrap: wrap; font-size: 0.75rem; color: var(--ink-muted); }
.chart .axis { display: flex; justify-content: space-between; font-size: 0.6875rem; color: var(--ink-faint); gap: 0.5rem; }
.sw { display: inline-block; width: 0.625rem; height: 0.625rem; border-radius: 2px; margin-right: 0.25rem; vertical-align: -1px; }
.sw-ok, .c-ok { background: var(--accent); fill: var(--accent); }
.sw-4xx, .c-4xx { background: var(--warning); fill: var(--warning); }
.sw-5xx, .c-5xx { background: var(--danger); fill: var(--danger); }
.sw-p50 { background: var(--ink-muted); }
.sw-p95 { background: var(--accent); }
.sw-new { background: var(--accent); }
.sw-del { background: var(--ink-faint); }
.c-new { fill: var(--accent); }
.c-del { fill: var(--ink-faint); }
.c-zero { fill: var(--warning); }
.c-grid { stroke: var(--border); stroke-width: 1; }
.c-p50 { stroke: var(--ink-muted); fill: none; stroke-width: 2; }
.c-p95 { stroke: var(--accent); fill: none; stroke-width: 2; stroke-dasharray: 5 4; }
.c-dot { stroke-width: 7; stroke-linecap: round; stroke-dasharray: none; }
.c-limit { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 2 4; }
.c-before { fill: url(#hatch); }
.hatch-line { stroke: var(--border-strong); stroke-width: 1; }
.spark svg { width: 100%; height: 2rem; display: block; }

/* ── 상태 상자·스켈레톤 ─────────────────────────── */
.state-box { display: grid; justify-items: center; text-align: center; gap: 0.5rem; padding: 2rem 1rem; color: var(--ink-muted); }
.state-box .icon { width: 2rem; height: 2rem; color: var(--ink-faint); }
.state-box h3 { color: var(--ink); font-size: 0.9375rem; }
.skeleton { border-radius: 10px; background: var(--surface-muted); height: 6.5rem; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ── 연결 화면 ──────────────────────────────────── */
.connect { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.connect .card { width: 100%; max-width: 28rem; }
.connect form { display: grid; gap: 0.75rem; }
.connect .brand { padding: 0; }
.form-error { color: var(--danger); font-size: 0.8125rem; }

/* ── 확인창·토스트 ──────────────────────────────── */
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 0;
  width: min(26rem, calc(100vw - 2rem)); }
dialog::backdrop { background: var(--backdrop); }
dialog form { display: grid; gap: 0.75rem; padding: 1.125rem; }
dialog h2 { font-size: 1rem; }
dialog .actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }
.toast { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 50; max-width: min(28rem, calc(100vw - 2rem));
  background: var(--action); color: var(--on-action); padding: 0.625rem 0.875rem; border-radius: 8px;
  opacity: 0; transform: translateY(0.5rem); transition: opacity 0.2s, transform 0.2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }

/* ── 반응형 ─────────────────────────────────────── */
/* 기준은 em(= 브라우저 기본 글꼴 크기, 16px일 때 1023px·640px)이라 글꼴을 키우면 좁은 배치로 같이 바뀐다(R1-QA W1).
   카드 열 수는 위 .grid의 rem 최소폭이 정하므로 여기서 다시 고정하지 않는다. */

/* 63.9375em(1023px) 이하: 사이드바는 왼쪽 서랍(숨기지 않고 화면 밖으로). [☰]로 연다. */
@media (max-width: 63.9375em) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; bottom: 0; width: min(18rem, 86vw);
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: none; visibility: hidden; }
  body.drawer-open .sidebar { transform: none; visibility: visible; }
  body.drawer-open .backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: var(--backdrop);
    border: 0; border-radius: 0; width: 100%; height: 100%; }
  .menu-btn, .drawer-close { display: inline-flex; }
  .drawer-close { position: absolute; right: 0.5rem; top: 0.625rem; }
  .topbar { padding: 0.5rem 1rem; }
  .content { padding: 1rem; }
  .weights { grid-template-columns: minmax(0, 1fr); }
}

/* 40em(640px) 이하: 상단 바 2줄. 역할·환경·테마·연결 해제는 서랍 아래(sidebar-foot)에서. 카드는 최소폭 때문에 1열. */
@media (max-width: 40em) {
  .topbar .meta.wide-only { display: none; }
  .topbar .title { flex: 1 1 100%; order: 1; }
  .topbar .menu-btn { order: 0; }
  .topbar .refresh-meta { order: 2; margin-right: auto; }
  .topbar .refresh-actions { order: 3; }
  button, .btn, input, select, .nav-link, .tab, .switch { min-height: 2.75rem; }
  .content { padding: 1rem; }
  .toast { left: 50%; right: auto; transform: translate(-50%, 0.5rem); }
  .toast.show { transform: translate(-50%, 0); }
  .page-head h1 { font-size: 1.125rem; }
  .metric-value { font-size: 1.5rem; }
}

@media (min-width: 40.0625em) {
  .sidebar-foot .narrow-only { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .toast { transition: none; }
  .skeleton { animation: none; }
}
