/* C11-D 봇 PWA. 한국 시장 관례: 상승 빨강 · 하락 파랑. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f3; --text: #14171c; --muted: #66707d; --line: #dde1e6;
  --accent: #2f6fe0; --up: #d6303a; --down: #2563d9; --ok: #1f9d55; --warn: #b7791f; --err: #d6303a;
  --mock: #7a4fd6; --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --surface: #1a1e24; --surface-2: #232830; --text: #e8ebef; --muted: #8e98a5; --line: #2c323b;
    --accent: #5b8ff0; --up: #f0555e; --down: #5b8ff0; --ok: #3cc47c; --warn: #e0a440; --err: #f0555e;
    --mock: #a688ef; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --surface: #1a1e24; --surface-2: #232830; --text: #e8ebef; --muted: #8e98a5; --line: #2c323b;
  --accent: #5b8ff0; --up: #f0555e; --down: #5b8ff0; --ok: #3cc47c; --warn: #e0a440; --err: #f0555e;
  --mock: #a688ef; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
b { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--err); }
.pad { padding: 4px 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; }
.badge.mock { background: color-mix(in srgb, var(--mock) 16%, transparent); color: var(--mock); }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.err { background: color-mix(in srgb, var(--err) 16%, transparent); color: var(--err); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }

/* 로그인 */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; font-size: 18px; }
form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
form input:not([type=checkbox]) { display: block; width: 100%; margin-top: 6px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
#login-otp { letter-spacing: .3em; font-variant-numeric: tabular-nums; }
.msg { min-height: 1.4em; color: var(--err); font-size: 13px; margin: 10px 0 0; }

button.primary, button.danger, button.ghost { border: 0; border-radius: 10px; padding: 12px 16px; font-weight: 600; cursor: pointer; }
button.primary { width: 100%; background: var(--accent); color: #fff; }
button.danger { background: var(--err); color: #fff; }
button.ghost { background: var(--surface-2); }
button:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { background: transparent; border: 0; font-size: 20px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; }
.icon-btn:active { background: var(--surface-2); }

/* 셸 */
.app { min-height: 100%; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.title { font-size: 17px; }
.top-actions { display: flex; align-items: center; gap: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.on { background: var(--ok); }
.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--err) 14%, var(--surface)); color: var(--err); font-size: 14px; font-weight: 600; }
.view { padding: 4px 0 16px; max-width: 720px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin: 12px 16px 0; padding: 14px 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
.big { font-size: 24px; font-weight: 700; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-top: 14px; }
.kv-grid > div { display: flex; flex-direction: column; min-width: 0; }
.kv-grid span { font-size: 12px; }
.kv-grid b { font-size: 16px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card.kv-grid { margin-top: 12px; }

.switch { width: 56px; height: 32px; border-radius: 999px; border: 0; background: var(--surface-2); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch span { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"] span { left: 27px; }

.steps, .rank, .events { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.steps li:first-child { border-top: 0; }
.rank { margin-top: 8px; counter-reset: r; }
.rank li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.rank li .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 보유 카드 */
.pos { padding: 14px 16px; }
.pos .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pos .name { font-weight: 600; font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos .ret { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pos .meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; margin: 10px 0; font-size: 13px; }
.pos .meta span { display: block; color: var(--muted); font-size: 11px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.pos .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.pos .foot button { padding: 8px 14px; font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* 표 대신 행 목록 (좁은 화면) */
.list-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.list-row:first-child { border-top: 0; }
.list-row .l { min-width: 0; }
.list-row .r { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.list-row .sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
#ord-date { flex: 1; text-align: center; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); min-width: 0; }

/* 차트 */
.chart svg { display: block; width: 100%; height: auto; }
.chart .ax { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--muted); stroke-dasharray: 3 3; stroke-width: 1; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .ar { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.chart text { fill: var(--muted); font-size: 10px; }

/* 이벤트 */
.events li { margin: 0 16px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13px; }
.events li .t { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.events li.Warn { color: var(--warn); }
.events li.Error { color: var(--err); }

/* 탭 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { background: none; border: 0; padding: 8px 0 10px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabs button span { font-size: 18px; line-height: 1; }
.tabs button.active { color: var(--accent); font-weight: 600; }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; width: min(92vw, 380px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 8px; }
dialog p { margin: 0 0 18px; color: var(--muted); white-space: pre-line; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 10; margin: 0 auto; max-width: 420px; padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; text-align: center; }
