:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --line: #e2e1dc;
  --text: #0b0b0b; --text-2: #52514e; --muted: #85847f;
  --accent: #2a78d6; --up: #e34948; --down: #2a78d6;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --ma20: #eb6834; --ma50: #1baf7a; --ma150: #eda100; --ma200: #e87ba4;
  --res: #52514e; --sup: #008300;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #33332f;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8d8c85;
    --accent: #3987e5; --up: #e66767; --down: #3987e5;
    --ma20: #d95926; --ma50: #199e70; --ma150: #c98500; --ma200: #d55181;
    --res: #c3c2b7; --sup: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8d8c85;
  --accent: #3987e5; --up: #e66767; --down: #3987e5;
  --ma20: #d95926; --ma50: #199e70; --ma150: #c98500; --ma200: #d55181;
  --res: #c3c2b7; --sup: #0ca30c;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* 상단 */
header { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1400px; margin: 0 auto; }
.brand { font-weight: 700; white-space: nowrap; }
.bar .grow { flex: 1; }
.bar select, .bar button { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
nav { display: flex; gap: 4px; padding: 0 16px; max-width: 1400px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
nav button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; cursor: pointer; color: var(--text-2); white-space: nowrap; }
nav button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1400px; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.tile .k { color: var(--text-2); font-size: 12px; }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
pre.report { white-space: pre-wrap; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 8px 0 0; color: var(--text-2); }
.state { font-size: 17px; font-weight: 700; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good::before { content: "● "; color: var(--good); }
.badge.serious::before { content: "● "; color: var(--serious); }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* 표 */
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.tools input[type=search] { flex: 1; min-width: 160px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.tools select, .tools label { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.tablewrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; }
th.l, td.l { text-align: left; }
td.theme { max-width: 280px; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.up { color: var(--up); } .down { color: var(--down); }
.ok { color: var(--good); font-weight: 700; } .no { color: var(--muted); }
.count { color: var(--text-2); font-size: 12px; }

/* 차트 창 */
#chartbox { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; z-index: 50; align-items: center; justify-content: center; padding: 16px; }
#chartbox.open { display: flex; }
#chartbox .panel { background: var(--surface); border-radius: 14px; width: min(1100px, 100%); max-height: 100%; overflow: auto; padding: 14px 16px; }
#chartbox .head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
#chartbox .head h3 { margin: 0; font-size: 17px; }
#chartbox .close { margin-left: auto; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; cursor: pointer; }
#chart { height: 460px; margin-top: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-2); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 4px; }
.legend i.dash { background: none !important; border-top: 2px dashed; height: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px 16px; margin-top: 10px; font-size: 13px; }
.facts div span { color: var(--text-2); margin-right: 6px; }
#mkchart-KOSPI, #mkchart-KOSDAQ { height: 220px; margin-top: 8px; }

/* 로그인 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(360px, 100%); }
.login h1 { font-size: 18px; margin: 0 0 16px; }
.login label { display: block; font-size: 12px; color: var(--text-2); margin: 10px 0 4px; }
.login input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.login button { width: 100%; margin-top: 18px; padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login .err { color: var(--critical); font-size: 13px; margin-top: 10px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  #chart { height: 340px; }
  .tablewrap { max-height: calc(100vh - 210px); }
  th, td { padding: 5px 7px; }
}
.grid > *, .tiles > * { min-width: 0; }
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bar { gap: 8px; }
  #who { display: none; }
}
