:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel2: #1c222b;
  --line: #2a313c;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --up: #f04452;      /* 한국식: 상승 빨강 */
  --down: #3182f6;    /* 하락 파랑 */
  --good: #22c55e;
  --bad: #f04452;
  --accent: #4c8dff;
  --warn: #f5a524;
  --zone-bull: rgba(34, 197, 94, 0.16);
  --zone-bear: rgba(240, 68, 82, 0.15);
  --radius: 10px;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.hidden { display: none !important; }

/* 상단 */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: rgba(14, 17, 22, 0.95); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--panel2); white-space: nowrap;
}
.badge.demo { color: #c4b5fd; border-color: #5b4b9a; }
.badge.paper { color: #7dd3fc; border-color: #1f5f7f; }
.badge.live { color: #fff; background: #b4232f; border-color: #e5484d; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.on .dot { background: var(--good); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
.badge.halt { color: var(--warn); border-color: #7a5410; }
.spacer { flex: 1; }
.clock { color: var(--muted); font-size: 13px; }

.btn {
  border: 1px solid var(--line); background: var(--panel2); padding: 7px 12px; border-radius: 8px;
  cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap;
}
.btn:hover { border-color: #3a4352; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: #3a1418; border-color: #7d2630; color: #ff8a93; }
.btn.danger:hover { background: #5a1a21; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { padding: 4px 9px; font-size: 12px; }

nav.tabs { display: flex; gap: 4px; padding: 8px 16px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
nav.tabs button {
  background: none; border: none; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 16px; max-width: 1480px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; letter-spacing: -0.01em; }
.grid { display: grid; gap: 12px; }

/* 경고 띠 */
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.banner.err { background: #2b1216; border: 1px solid #6b2029; color: #ffb4bb; }
.banner.warn { background: #2a2010; border: 1px solid #6b4f12; color: #ffd27a; }
.banner.info { background: #121c2b; border: 1px solid #22406b; color: #a9c8ff; }

/* 종목 줄 */
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.sym {
  min-width: 150px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; text-align: left;
}
.sym.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sym .code { font-size: 12px; color: var(--muted); }
.sym .px { font-size: 16px; font-weight: 700; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-top: 4px; background: var(--panel2); border: 1px solid var(--line); }
.chip.hold { color: #ffd27a; border-color: #6b4f12; }
.chip.plan { color: #a9c8ff; border-color: #22406b; }

/* 대시보드 */
.dash { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; align-items: start; }
@media (max-width: 1050px) { .dash { grid-template-columns: 1fr; } }
.chart-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head .name { font-size: 18px; font-weight: 700; }
.chart-head .bigpx { font-size: 22px; font-weight: 800; }
.tfs { display: flex; gap: 4px; margin-left: auto; }
.tfs button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; cursor: pointer; font-size: 12px; color: var(--muted); }
.tfs button.active { color: #fff; border-color: var(--accent); background: #1d3460; }
.chart-wrap { position: relative; height: 520px; }
@media (max-width: 700px) { .chart-wrap { height: 380px; } }
.chart-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: pan-y; }
.tooltip { position: absolute; top: 6px; left: 8px; font-size: 12px; color: var(--muted); pointer-events: none; background: rgba(14, 17, 22, 0.75); padding: 2px 6px; border-radius: 4px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.stats4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--panel2); border-radius: 8px; padding: 8px 10px; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.plan { border: 1px solid #22406b; background: #101a29; border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.plan.pos { border-color: #6b4f12; background: #1d170c; }
.plan .title { font-weight: 700; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
.plan .lines { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; text-align: center; }
.plan .lines div { background: rgba(255, 255, 255, 0.03); border-radius: 6px; padding: 6px 4px; }
.plan .lines .l { font-size: 11px; color: var(--muted); }
.plan .lines .v { font-weight: 700; font-variant-numeric: tabular-nums; }
ul.reasons { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: #c9d1dc; }
ul.reasons li { margin: 2px 0; }
.hist { font-size: 12.5px; border-top: 1px solid var(--line); padding: 7px 0; }
.hist:first-child { border-top: none; }
.hist .st { font-weight: 700; margin-right: 6px; }

/* 기록 */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
select, input[type=text], input[type=password], input[type=number], input[type=time] {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.trade { margin-bottom: 12px; }
.trade .top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.trade .pnl { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
@media (max-width: 700px) { .cols2 { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ev { display: grid; grid-template-columns: 64px 70px 70px 1fr; gap: 8px; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 700px) { .ev { grid-template-columns: 56px 1fr; } .ev .k, .ev .s { display: none; } }
.ev .k { font-weight: 700; font-size: 12px; }
.k-PLAN { color: #a9c8ff; } .k-ORDER { color: #c4b5fd; } .k-FILL { color: #ffd27a; } .k-CLOSE { color: var(--good); }
.k-SKIP { color: var(--muted); } .k-ERROR, .k-HALT { color: var(--bad); } .k-STOP { color: #fb923c; } .k-WARN { color: var(--warn); }

/* 설정 */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .settings { grid-template-columns: 1fr; } }
.field { display: grid; grid-template-columns: 1fr 160px; gap: 4px 12px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; }
.field:last-child { border-bottom: none; }
.field label { font-weight: 600; font-size: 13px; }
.field .help { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.field input, .field select { width: 100%; }
.switch { position: relative; width: 42px; height: 24px; justify-self: end; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #39414d; border-radius: 999px; cursor: pointer; transition: 0.15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.formrow { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 600px) { .formrow { grid-template-columns: 1fr; } }

/* 로그인 */
.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }
.login .card { padding: 22px; }
.login input { width: 100%; margin: 8px 0 12px; }
.login .btn { width: 100%; padding: 10px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #222a35; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; font-size: 13px; max-width: 90vw; }
.toast.err { border-color: #7d2630; color: #ffb4bb; }
.progress { height: 6px; background: var(--panel2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.3s; }

/* ── 탭 아이콘 · 휴대폰 하단 탭 ── */
nav.tabs button { display: inline-flex; align-items: center; gap: 6px; }
nav.tabs svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hdr-actions { display: flex; gap: 6px; }

/* ── 맡긴 돈 카드 ── */
.money { margin-bottom: 12px; }
.money-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.money-eq { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.money-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.gauge { position: relative; height: 8px; background: var(--panel2); border-radius: 999px; margin: 12px 0 4px; overflow: hidden; }
.gauge-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--good); border-radius: 999px; transition: width .4s; }
.gauge-cap { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #e6e9ee; }
.gauge-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.money-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.money-grid > div { background: var(--panel2); border-radius: 8px; padding: 8px 10px; }
.money-grid .l { font-size: 11px; color: var(--muted); }
.money-grid .v { font-weight: 700; font-size: 14px; }
.money.stopped { border-color: #7d2630; }

@media (max-width: 760px) {
  :root { font-size: 15px; }
  header { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 8px; }
  .brand { font-size: 15px; }
  .clock { width: 100%; order: 5; font-size: 12px; }
  .hdr-actions { width: 100%; order: 6; }
  .hdr-actions .btn { flex: 1; padding: 9px 6px; }
  nav.tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    background: rgba(14, 17, 22, 0.97); border-top: 1px solid var(--line); border-bottom: none; justify-content: space-around;
  }
  nav.tabs button { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; border-bottom: none; flex: 1; }
  nav.tabs button.active { color: var(--accent); }
  nav.tabs svg { width: 22px; height: 22px; }
  main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }
  .money-grid { grid-template-columns: repeat(2, 1fr); }
  .money-eq { font-size: 24px; }
  .savebar { bottom: calc(62px + env(safe-area-inset-bottom)); }
  .field { grid-template-columns: 1fr 120px; }
  .card { padding: 12px; }
  .sym { min-width: 128px; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .chart-head .tfs { margin-left: 0; width: 100%; }
  .chart-head .tfs button { flex: 1; padding: 6px 0; }
}
