:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2024;
  --muted: #60646c;
  --border: #e0e1e6;
  --accent: #3e63dd;
  --accent-soft: #edf2fe;
  --up: #e5484d;
  --down: #3e63dd;
  --ok: #30a46c;
  --warn: #f76b15;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --panel: #18191b;
    --text: #edeef0;
    --muted: #9ea0a8;
    --border: #2e3135;
    --accent: #7b9cff;
    --accent-soft: #1d2340;
    --up: #ff6369;
    --down: #6e8dff;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: flex; min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }

/* 레이아웃 */
.sidebar {
  width: 200px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 700; font-size: 17px; padding: 0 10px 14px; display: flex; align-items: center; gap: 8px; }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 10px; }
main { flex: 1; min-width: 0; padding: 20px 28px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; }
.status-pills { display: flex; gap: 6px; flex-wrap: wrap; }

/* 공통 요소 */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card + .card, .section + .section { margin-top: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 12px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.pill.bad { color: var(--up); border-color: color-mix(in srgb, var(--up) 35%, transparent); background: color-mix(in srgb, var(--up) 10%, transparent); }
.pill.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; max-height: 560px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

button, .btn {
  font: inherit; font-weight: 600; font-size: 13px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
}
button:hover { background: var(--bg); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--up); }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

input, select {
  font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: -1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.field input, label.field select { color: var(--text); font-weight: 400; font-size: 14px; }
.field .help { font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }

/* 스위치 */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { left: 19px; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 종목 검색 */
.search { position: relative; }
.search input { width: 100%; }
.search .results {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 320px; overflow-y: auto;
}
.search .results div { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.search .results div.sel, .search .results div:hover { background: var(--accent-soft); }
.search .results .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.chip button { border: 0; background: none; color: inherit; padding: 0 6px; font-size: 14px; line-height: 1; }
.chip.static { padding-right: 10px; }

/* 차트 */
.quote { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.quote .name { font-size: 20px; font-weight: 700; }
.quote .price { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-box { height: 520px; margin-top: 12px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.legend .sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: space-between; }

/* 전략 */
.strategy-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.strategy-head h3 { margin: 0; font-size: 16px; }
.kv { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; margin: 10px 0; }
.kv span b { color: var(--muted); font-weight: 600; margin-right: 4px; }
.panel { border-top: 1px dashed var(--border); margin-top: 14px; padding-top: 14px; }
.hidden { display: none !important; }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; border: 1px solid; }
.banner.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.banner.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); }

#toast { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
#toast div { background: var(--text); color: var(--panel); padding: 10px 14px; border-radius: 8px; font-size: 13px; max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.err { background: var(--up); color: #fff; }

@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 16px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; gap: 2px; }
  .sidebar .foot { display: none; }
  main { padding: 16px; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .chart-box { height: 400px; }
}
.table-wrap td { white-space: nowrap; }

/* 팝업 (전략 편집) */
dialog#editor {
  padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); color: var(--text);
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog#editor::backdrop { background: rgba(10, 12, 16, .55); }
.modal { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 20px 24px; overflow-y: auto; flex: 1; }
.modal-section { font-size: 14px; margin: 22px 0 10px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--bg); }
.modal-error { flex: 1; font-size: 13px; }
.icon-btn { border: 0; background: none; font-size: 22px; line-height: 1; padding: 2px 8px; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--bg); }
@media (max-width: 900px) {
  dialog#editor { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .modal { height: 100%; max-height: 100dvh; }
}
