/* 해도 — 모바일 우선. 폰 폭(360px)에서 설계하고 960px 부터 넓힌다.
   색은 역할 토큰으로만 쓴다. 차트 계열색(매수·매도·평단)과 손익 글자색은 대비·색각 검증을 거친 값이다:
   매수 = 빨강 · 매도 = 파랑(국내 관례, 작업지시서 S2-7), 이익 = 빨강 글자 · 손실 = 파랑 글자(부호와 함께). */

:root {
  color-scheme: light;
  --page: #f3f5f7;
  --surface: #fcfcfd;
  --surface-2: #eef1f4;
  --ink: #0b0f14;
  --ink-2: #4f5661;
  --muted: #6c7480;
  --grid: #e3e7ec;
  --axis: #c5ccd4;
  --border: rgba(11, 15, 20, 0.10);
  --brand: #0f2742;
  --on-brand: #f3f5f7;
  --on-brand-2: #b9c6d6;
  --accent: #1d4f91;
  --accent-soft: #dfe9f6;
  --gain: #c9302c;
  --loss: #1f5fbf;
  --gain-wash: rgba(227, 73, 72, 0.10);
  --loss-wash: rgba(42, 120, 214, 0.10);
  --buy: #e34948;
  --sell: #2a78d6;
  --avg: #008300;
  --price: #898781;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --good-text: #006300;
  --warning-text: #8a5a00;
  --critical-text: #b42323;
  --meter-track: #dfe9f6;
  --meter-fill: #1d4f91;
  --on-accent: #ffffff;
  --radius: 12px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0e12;
    --surface: #161a1f;
    --surface-2: #1d2228;
    --ink: #f3f5f7;
    --ink-2: #c3cad3;
    --muted: #8f98a5;
    --grid: #262c33;
    --axis: #38404a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #7fb0ff;
    --accent-soft: #1b2a3f;
    --gain: #ff7b72;
    --loss: #6aa7ff;
    --gain-wash: rgba(230, 103, 103, 0.14);
    --loss-wash: rgba(57, 135, 229, 0.14);
    --buy: #e66767;
    --sell: #3987e5;
    --good-text: #0ca30c;
    --warning-text: #fab219;
    --critical-text: #ff6b6b;
    --meter-track: #1b2a3f;
    --meter-fill: #7fb0ff;
    --on-accent: #0b0e12;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 var(--font);
  color: var(--ink);
  background: var(--page);
  min-height: 100vh;
}
a { color: inherit; }
button, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.id { word-break: break-all; }

/* ── 상단바 ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: var(--on-brand);
  padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px;
}
.topbar-row { display: flex; align-items: center; gap: 10px; max-width: 1200px; margin: 0 auto; }
.brand { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.brand-mark { width: 26px; height: 26px; color: var(--on-brand); }
.mock-badge {
  background: var(--warning); color: #1f1600; font-weight: 800; font-size: 11px; letter-spacing: .08em;
  padding: 2px 7px; border-radius: 6px;
}
.topnav { display: none; }
.account-filter { margin-left: auto; min-width: 0; }
.account-filter select {
  max-width: 44vw; background: rgba(255, 255, 255, .12); color: var(--on-brand);
  border: 1px solid rgba(255, 255, 255, .22); border-radius: 8px; padding: 5px 8px; font-size: 14px;
}
.account-filter option { color: #0b0f14; background: #fcfcfd; }
.topbar-meta { max-width: 1200px; margin: 2px auto 0; font-size: 12px; color: var(--on-brand-2); display: flex; gap: 10px; }
.link-btn { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; margin-left: auto; }
body.signed-out .tabbar, body.signed-out .topnav, body.signed-out .account-filter, body.signed-out #logout { display: none; }

/* ── 로그인 ─────────────────────────────────────────── */
.login { max-width: 360px; margin: 9vh auto 0; text-align: center; }
.login h1 { font-size: 26px; font-weight: 800; }
.login-lead { color: var(--ink-2); margin-top: 4px; }
.login-form { display: grid; gap: 10px; text-align: left; margin-top: 22px; }
.login-form label { font-size: 13px; color: var(--muted); }
.login-form input[type="password"] {
  font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--ink); width: 100%;
}
.login-form input[type="password"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-button { padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 16px; cursor: pointer; }
.login-button:disabled { opacity: .6; cursor: default; }
.login-message { min-height: 1.5em; color: var(--critical-text); font-size: 14px; }
.login-note { font-size: 12px; color: var(--muted); margin-top: 14px; }
.offline-banner {
  position: sticky; top: 64px; z-index: 19;
  background: var(--warning); color: #1f1600; text-align: center; font-size: 13px; font-weight: 600; padding: 6px var(--gutter);
}

/* ── 하단 탭(모바일) ────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; text-decoration: none; font-size: 12px; color: var(--muted);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }

main {
  display: block; max-width: 1200px; margin: 0 auto;
  padding: 12px var(--gutter) calc(84px + env(safe-area-inset-bottom));
  transition: opacity .15s;
}
main:focus { outline: none; }
main.is-loading { opacity: .5; }
.loading, .empty { color: var(--muted); padding: 24px 0; text-align: center; }
.error-box { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--critical); border-radius: var(--radius); padding: 14px 16px; }
.error-box p + p { margin-top: 6px; color: var(--muted); font-size: 13px; }

/* ── 카드·섹션 ─────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 12px; min-width: 0;
}
.card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.card-title small { font-weight: 400; font-size: 12px; color: var(--muted); }
.section-note { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* 지표 타일 — 값이 먼저, 이름은 작게 */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 10px; padding: 9px 11px; min-width: 0; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 17px; font-weight: 650; overflow-wrap: break-word; }
.tile-sub { font-size: 12px; color: var(--ink-2); }

/* 이름-값 격자 */
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
.kv > div { display: flex; flex-direction: column; border-bottom: 1px solid var(--grid); padding: 6px 0; min-width: 0; }
.kv > .wide { grid-column: 1 / -1; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: break-word; }

/* 배지 — 상태는 언제나 아이콘 + 글자 */
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; background: var(--surface); white-space: nowrap;
}
.badge svg { width: 13px; height: 13px; flex: none; }
.badge.ok { color: var(--good-text); }
.badge.warn { color: var(--warning-text); }
.badge.crit { color: var(--critical-text); }
.badge.pending { color: var(--ink-2); }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── 홈 ─────────────────────────────────────────────── */
.account-rows { margin-top: 12px; border-top: 1px solid var(--grid); }
.account-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.account-row .name { font-weight: 650; font-size: 14px; }
.account-row .right { text-align: right; font-variant-numeric: tabular-nums; }
.cards { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.cycle-card { display: block; text-decoration: none; margin: 0; }
.cycle-card:hover { border-color: var(--accent); }
.cycle-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cycle-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.cycle-name { min-width: 0; }
.ticker { font-size: 20px; font-weight: 800; letter-spacing: .01em; }
.ticker small { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-left: 4px; }
.cycle-sub { font-size: 12px; color: var(--muted); }
.cycle-head { margin-bottom: 6px; }
.card-badges { margin-bottom: 12px; }
.stats4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin-top: 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: break-word; }

/* 진행 바(T값·투입률) — 채움은 같은 색 계열의 옅은 트랙 위에 */
.meter-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 5px; }
.meter-head b { font-size: 15px; }
.meter { position: relative; height: 10px; border-radius: 5px; background: var(--meter-track); }
.meter-fill { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--meter-fill); }
.meter.warn { background: color-mix(in srgb, var(--warning) 22%, var(--surface)); }
.meter.warn .meter-fill { background: var(--warning); }
.meter.crit { background: color-mix(in srgb, var(--critical) 18%, var(--surface)); }
.meter.crit .meter-fill { background: var(--critical); }
.meter-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.meter-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 3px; position: relative; }

/* ── 사이클 리포트 ─────────────────────────────────── */
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--accent); text-decoration: none; margin-bottom: 8px; }
.report-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 12px; }
.report-head h1 { font-size: 22px; font-weight: 800; }
.report-head .sub { width: 100%; font-size: 13px; color: var(--ink-2); }
.hero { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 2px 0 12px; }
.hero-value { font-size: clamp(34px, 10vw, 48px); font-weight: 750; line-height: 1.1; letter-spacing: -.01em; }
.hero-sub { font-size: 14px; color: var(--ink-2); }
.hero-label { width: 100%; font-size: 12px; color: var(--muted); }
.warn-line { margin-top: 10px; font-size: 13px; color: var(--warning-text); display: flex; gap: 6px; align-items: flex-start; }
.warn-line svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }

/* 가격 위치 바 — 한 줄 위의 점들 */
.priceline { position: relative; height: 64px; margin: 6px 6px 0; }
.priceline-axis { position: absolute; left: 0; right: 0; top: 30px; height: 2px; background: var(--axis); border-radius: 1px; }
.pl-dot { position: absolute; top: 31px; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); }
.pl-dot.buy { background: var(--buy); }
.pl-dot.target { background: var(--surface); border: 2px solid var(--sell); }
.pl-dot.avg { width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 2px; transform: rotate(45deg); background: var(--ink); z-index: 2; }
.pl-dot.now { width: 14px; height: 14px; margin: -7px 0 0 -7px; background: var(--accent); z-index: 3; }
.pl-label { position: absolute; font-size: 11px; white-space: nowrap; transform: translateX(-50%); font-variant-numeric: tabular-nums; }
.pl-label.top { top: 0; }
.pl-label.bottom { top: 44px; }
.pl-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin: 0 0 2px; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.key { display: inline-block; flex: none; }
.key.dot { width: 9px; height: 9px; border-radius: 50%; }
.key.ring { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--sell); }
.key.diamond { width: 9px; height: 9px; transform: rotate(45deg); background: var(--ink); }
.key.line { width: 18px; height: 0; border-top: 2px solid var(--price); }
.key.dash { width: 18px; height: 0; border-top: 2px dashed var(--avg); }
.key.up { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 9px solid var(--buy); }
.key.down { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 9px solid var(--sell); }

/* 목록형 표 — 폰에서 가로 스크롤 없이 두 줄로 */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 12px; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.rows li:last-child { border-bottom: 0; }
.rows .main { font-weight: 600; font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.rows .side { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .detail { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.rows .detail-r { color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.side-chip { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.more { margin-top: 8px; width: 100%; background: var(--surface-2); border: 0; border-radius: 8px; padding: 8px; font-size: 13px; color: var(--accent); cursor: pointer; }
details.fold > summary { cursor: pointer; font-size: 13px; color: var(--accent); padding: 6px 0; list-style-position: inside; }
details.fold[open] > summary { margin-bottom: 4px; }

/* 작은 표(표로 보기) */
.mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.mini-table th, .mini-table td { padding: 5px 4px; border-bottom: 1px solid var(--grid); text-align: right; }
.mini-table th:first-child, .mini-table td:first-child { text-align: left; }
.mini-table th { color: var(--muted); font-weight: 600; }

.chart-box { position: relative; height: 240px; }
.chart-box.short { height: 200px; }
.chart-fallback { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }

/* ── 완료(캘린더) ──────────────────────────────────── */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.month-nav h2 { font-size: 17px; font-weight: 750; }
.nav-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 18px; line-height: 1; }
.nav-btn:disabled { opacity: .35; cursor: default; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-dow { font-size: 11px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.cal-dow.sun { color: var(--gain); }
.cal-cell {
  min-height: 54px; border-radius: 8px; padding: 3px 2px 4px; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; border: 0; font: inherit; color: inherit;
}
.cal-cell.blank { background: transparent; }
.cal-cell .d { font-size: 12px; color: var(--ink-2); line-height: 1.2; }
.cal-cell .p { font-size: 11px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; max-width: 100%; overflow-wrap: anywhere; }
.cal-cell .h { font-size: 10px; color: var(--muted); line-height: 1.2; }
.cal-cell.holiday { background: transparent; border: 1px dashed var(--axis); }
.cal-cell.has-gain { background: var(--gain-wash); }
.cal-cell.has-loss { background: var(--loss-wash); }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
button.cal-cell { cursor: pointer; }
.cal-cell .flag { width: 12px; height: 12px; color: var(--accent); }
.grad-list li .main a { text-decoration: none; }

dialog.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; border: 0; padding: 0;
  border-radius: 16px 16px 0 0; background: var(--surface); color: var(--ink); max-height: 80vh;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
dialog.sheet:focus { outline: none; }
.sheet-body { padding: 16px var(--gutter) calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 80vh; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { font-size: 16px; }
.close-btn { border: 0; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; cursor: pointer; }

/* ── 점검 ───────────────────────────────────────────── */
.check-list { list-style: none; margin: 0; padding: 0; }
.check-list > li { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 2px 8px; padding: 9px 0; border-bottom: 1px solid var(--grid); }
.check-list > li:last-child { border-bottom: 0; }
.check-list .ic { width: 18px; height: 18px; margin-top: 2px; }
.check-list .ic.ok { color: var(--good-text); }
.check-list .ic.warn { color: var(--critical-text); }
.check-list .ic.pending { color: var(--ink-2); }
.check-list .t { font-weight: 650; font-size: 14px; }
.check-list .s { grid-column: 2; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ── PC: 상단 메뉴, 2단 배치 ───────────────────────── */
@media (min-width: 600px) {
  .tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stats4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .cal-cell { min-height: 64px; }
  .cal-cell .p { font-size: 12px; }
}
@media (min-width: 960px) {
  :root { --gutter: 24px; }
  .tabbar { display: none; }
  main { padding-bottom: 32px; }
  .topnav { display: flex; gap: 4px; margin-left: 18px; }
  .topnav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--on-brand-2); font-weight: 600; }
  .topnav a[aria-current="page"] { background: rgba(255, 255, 255, .14); color: var(--on-brand); }
  .offline-banner { top: 70px; }
  .report { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 0 16px; align-items: start; }
  .chart-box { height: 320px; }
  .done-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 0 16px; align-items: start; }
  dialog.sheet { margin: auto; border-radius: 16px; }
}
@media (prefers-reduced-motion: reduce) { main { transition: none; } }
