/* Crash 기록 대시보드 — 라이트/다크 자동, 숫자는 고정폭 숫자(tabular-nums) */

:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde2e8;
  --text: #16202b;
  --muted: #5d6b7a;
  --accent: #0d7c8c;
  --accent-ink: #ffffff;
  --pos: #12804a;
  --neg: #c8362f;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --bad-bg: #fde8e6;
  --bad-ink: #8a1f19;
  --ok-bg: #e2f5ea;
  --ok-ink: #14553a;
  /* 결과 배율 구간: 2배 미만 / 2~10 / 10~100 / 100 이상 */
  --t0-bg: #fbe4e2; --t0-ink: #a02a24;
  --t1-bg: #def3e6; --t1-ink: #17633f;
  --t2-bg: #fdecc8; --t2-ink: #7a5300;
  --t3-bg: #ebe2fb; --t3-ink: #5a34a8;
  /* 차트: 강조색 + 무채색 회색(emphasis). validate_palette 로 분리·대비 확인 */
  --viz-hit: #0d7c8c;
  --viz-miss: #8b97a5;
  --viz-grid: #e6eaef;
  --viz-axis: #c9d1da;
  --viz-ink: #16202b;
  --viz-surface: #ffffff;
  --viz-wash: rgba(22, 32, 43, .06);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d24;
    --surface-2: #1e262f;
    --border: #2a343f;
    --text: #e6ebf0;
    --muted: #93a1b0;
    --accent: #3fc1d3;
    --accent-ink: #06222a;
    --pos: #4cd08a;
    --neg: #ff7d73;
    --warn-bg: #3a2f10; --warn-ink: #f2d98a;
    --bad-bg: #3d1a18; --bad-ink: #ffb3ac;
    --ok-bg: #12301f; --ok-ink: #9fe3bd;
    --t0-bg: #3d1d1b; --t0-ink: #ff9d95;
    --t1-bg: #123222; --t1-ink: #7fdcab;
    --t2-bg: #3a2c0c; --t2-ink: #f0c869;
    --t3-bg: #2a2045; --t3-ink: #c3a8ff;
    --shadow: none;
    --viz-hit: #25a0b2;
    --viz-miss: #5a6775;
    --viz-grid: #232c36;
    --viz-axis: #34404c;
    --viz-ink: #e6ebf0;
    --viz-surface: #171d24;
    --viz-wash: rgba(230, 235, 240, .08);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; line-height: 1.25; margin: 1.4rem 0 .3rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0; }
code { background: var(--surface-2); padding: .05em .4em; border-radius: 5px; font-size: .92em; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.strong { font-weight: 650; }
.r { text-align: right; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.lede { color: var(--muted); margin: 0 0 1rem; }
.hint { color: var(--muted); font-size: .86rem; margin: .8rem 0 0; }

/* 상단 바 */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: 54px; }
.brand { font-weight: 750; color: var(--text); letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-link { color: var(--muted); padding: 7px 12px; border-radius: 8px; white-space: nowrap; font-weight: 550; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav-link.active { background: var(--surface-2); color: var(--accent); }
.account { display: flex; gap: 12px; align-items: center; white-space: nowrap; font-size: .9rem; }
.account form { margin: 0; }
.quiet { color: var(--muted); }
.link-button { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }
.link-button:hover { color: var(--text); text-decoration: underline; }

main { padding-bottom: 28px; }
.foot { color: var(--muted); font-size: .82rem; padding-top: 6px; padding-bottom: 36px; }

/* 알림 */
.notice { padding: 10px 14px; border-radius: var(--radius); margin: 14px 0 0; font-size: .93rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.notice.bad { background: var(--bad-bg); color: var(--bad-ink); }
.notice.ok { background: var(--ok-bg); color: var(--ok-ink); }
.notice a { color: inherit; text-decoration: underline; font-weight: 650; }
.field-error { color: var(--neg); margin: .8rem 0 0; font-weight: 550; }

/* 패널 / 카드 */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-top: 16px; box-shadow: var(--shadow); }
.panel.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 16px; }
.cards.tight { margin-top: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.panel .card { background: var(--surface-2); box-shadow: none; border-color: transparent; }
.card.emphasis { border-color: var(--accent); }
.card-label { color: var(--muted); font-size: .82rem; font-weight: 550; }
.card-value { font-size: 1.7rem; font-weight: 700; line-height: 1.25; margin-top: 2px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.card-value.small { font-size: 1.3rem; }
.card-sub { font-size: .86rem; margin-top: 2px; }

.collect-btn { margin-top: 10px; }
.card form { margin: 0; }
.btn:disabled { opacity: .6; cursor: progress; }

/* 폼 */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: .82rem; color: var(--muted); font-weight: 550; }
input[type="text"], input[type="password"], select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 10px; height: 40px; min-width: 0; width: 100%;
}
.filters .field { width: 150px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible, .link-button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.actions { display: flex; gap: 8px; align-items: center; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.btn {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-align: center;
  padding: 0 16px; line-height: 38px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.small { padding: 0 10px; line-height: 28px; font-size: .86rem; font-weight: 550; }
.btn.block { width: 100%; }
.btn.disabled { opacity: .4; pointer-events: none; }

/* 표 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
th.r, td.r { text-align: right; }
th { color: var(--muted); font-size: .8rem; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.bar-cell { width: 18%; min-width: 80px; }
.bar { display: block; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; min-width: 2px; }
.pager { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* 결과 배율 칩 */
.x { display: inline-block; padding: 1px 9px; border-radius: 999px; font-weight: 650; font-size: .9rem; }
.x.t0 { background: var(--t0-bg); color: var(--t0-ink); }
.x.t1 { background: var(--t1-bg); color: var(--t1-ink); }
.x.t2 { background: var(--t2-bg); color: var(--t2-ink); }
.x.t3 { background: var(--t3-bg); color: var(--t3-ink); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }

/* 수집 상태 */
.status { font-weight: 600; font-size: .9rem; }
.status.ok { color: var(--pos); }
.status.error { color: var(--neg); }
.status.running { color: var(--muted); }

/* 출현 간격 */
.gaps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 4px; align-items: baseline; }
.gap-n { font-size: 1.15rem; font-weight: 700; background: var(--surface-2); padding: 2px 10px; border-radius: 8px; }
.gaps li:first-child .gap-n { background: var(--accent); color: var(--accent-ink); }
.gap-sep { color: var(--muted); margin-left: 4px; }

/* 그래프 */
.figure { margin: 18px 0 0; }
.figure figcaption { color: var(--muted); font-size: .84rem; font-weight: 550; margin-bottom: 4px; }
.chart { width: 100%; min-width: 600px; height: auto; display: block; }
.chart-zero { stroke: var(--border); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-line.pos { stroke: var(--pos); }
.chart-line.neg { stroke: var(--neg); }
.chart-label { fill: var(--muted); font-size: 13px; }

/* 로그인 */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 26px 24px; box-shadow: var(--shadow); }
.auth-card .notice { margin: 0 0 14px; }
.auth-title { margin: 0 0 4px; }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 4px 12px; padding-top: 6px; padding-bottom: 4px; }
  .nav { order: 3; flex-basis: 100%; }
  .account { margin-left: auto; }
  .filters .field { width: calc(50% - 6px); }
  .card-value { font-size: 1.45rem; }
  .panel { padding: 14px; }
}


/* ── 대시보드 차트 ─────────────────────────────────────────── */
turbo-frame[aria-busy="true"] { opacity: .55; transition: opacity .15s; }
turbo-frame#charts { display: block; }
.viz .panel-head { margin-bottom: 8px; }
.viz-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.viz-filter-label { color: var(--muted); font-size: .86rem; font-weight: 600; margin-right: 4px; }
.chip-btn { display: inline-block; padding: 0 12px; line-height: 28px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); font-size: .88rem; font-weight: 600; background: var(--surface); }
.chip-btn:hover { background: var(--surface-2); text-decoration: none; }
.chip-btn.selected { background: var(--viz-hit); border-color: var(--viz-hit); color: var(--accent-ink); }
.viz-custom { display: flex; gap: 6px; align-items: center; margin: 0 0 0 8px; }
.viz-custom input[type="text"] { width: 76px; height: 30px; }

.viz-fig { margin: 0; padding: 18px 0 6px; border-bottom: 1px solid var(--border); }
.viz-fig:last-child { border-bottom: 0; }
.viz-fig figcaption h3 { margin: 0; font-size: 1rem; }
.viz-fig figcaption p { margin: 2px 0 0; font-size: .86rem; }
.viz-legend { list-style: none; margin: 10px 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .84rem; color: var(--muted); }
.viz-legend li { display: flex; align-items: center; gap: 6px; }
.viz-legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.hit { background: var(--viz-hit); }
.sw.miss { background: var(--viz-miss); }
.sw.band { background: var(--viz-miss); opacity: .35; }
.line-key { width: 18px; height: 0; border-top: 2px solid var(--viz-hit); display: inline-block; }
.ref-key { width: 18px; height: 0; border-top: 1.5px solid var(--viz-ink); display: inline-block; }
.tick-key { width: 2px; height: 14px; background: var(--viz-ink); display: inline-block; }
.tick-key.h { width: 16px; height: 2px; }

.viz-frame { position: relative; }
.viz-scroll { overflow-x: auto; border-radius: 8px; }
.viz-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.viz-svg { display: block; width: 100%; min-width: 600px; height: auto; user-select: none; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { stroke: var(--viz-axis); stroke-width: 1; }
.viz-tick { fill: var(--muted); font-size: 12px; }
.viz-cat { fill: var(--text); font-size: 12.5px; }
.viz-label { fill: var(--text); font-size: 12.5px; font-weight: 650; }
.viz-mark.hit { fill: var(--viz-hit); }
.viz-mark.miss { fill: var(--viz-miss); }
.viz-line { fill: none; stroke: var(--viz-hit); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-band { fill: var(--viz-miss); opacity: .22; }
.viz-ref { stroke: var(--viz-ink); stroke-width: 1.5; opacity: .75; }
.viz-tick-mark { stroke: var(--viz-ink); stroke-width: 2; stroke-linecap: round; }
.viz-end, .viz-dot { fill: var(--viz-hit); stroke: var(--viz-surface); stroke-width: 2; }
.viz-dot { display: none; pointer-events: none; }
.viz-dot.on { display: block; }
.viz-cross { display: none; stroke: var(--viz-ink); stroke-width: 1; opacity: .5; pointer-events: none; }
.viz-cross.on { display: block; }
.viz-hit { fill: transparent; cursor: crosshair; }
.viz-hit.is-hover { fill: var(--viz-wash); }
.viz-hit.strip.is-hover { fill: transparent; }
.viz-hit.is-hover + .viz-mark { filter: brightness(1.18); }

.viz-tip {
  position: absolute; top: 0; left: 0; z-index: 5; pointer-events: none; opacity: 0; min-width: 130px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, .18); font-size: .84rem; white-space: nowrap;
}
.viz-tip.on { opacity: 1; }
.tip-title { color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tip-row strong { font-size: .95rem; }
.tip-label { color: var(--muted); }
.tip-key { width: 12px; height: 0; border-top: 3px solid transparent; display: inline-block; }
.tip-key.series { border-color: var(--viz-hit); }
.tip-key.miss { border-color: var(--viz-miss); }
.tip-key.ref { border-color: var(--viz-ink); border-top-width: 2px; }
.tip-key.none { display: none; }

.viz-table { margin: 8px 0 2px; font-size: .88rem; }
.viz-table summary { cursor: pointer; color: var(--muted); font-weight: 600; width: fit-content; }
.viz-table summary:hover { color: var(--text); }
.viz-table-wrap { max-height: 320px; overflow: auto; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; }
.viz-table-wrap table th { position: sticky; top: 0; background: var(--surface); }

@media (prefers-reduced-motion: reduce) { turbo-frame[aria-busy="true"] { transition: none; } }
