:root {
  --bg: #F4F6FA; --card: #FFFFFF; --ink: #172B4D; --text: #253858; --muted: #6B778C; --line: #E6EAF0;
  --brand: #172B4D; --accent: #2F6FB2; --pos: #1E7F43; --neg: #0277BD; --neg-bg: rgba(2,119,189,.10); --danger: #C0392B; --warn: #B7791F;
  --equity: #2F6FB2; --bond: #B7791F; --fund: #6B46C1; --chip: #EEF2F7; --input: #FFFFFF;
  --shadow: 0 1px 2px rgba(23,43,77,.06), 0 4px 16px rgba(23,43,77,.06); --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0F1623; --card: #172133; --ink: #E8EEF7; --text: #CFD8E6; --muted: #8C9AB0; --line: #26324A;
    --brand: #7FA7E0; --accent: #7FA7E0; --pos: #4CC38A; --neg: #7DD3FC; --neg-bg: rgba(125,211,252,.13); --danger: #FF7A6B; --chip: #1F2B41; --input: #101826;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 26px; margin: 0; color: var(--ink); letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--ink); }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

#app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 16px; background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); font-size: 18px; }
.brand img { width: 32px; height: 32px; }
#side-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text); }
#side-nav a.active { background: var(--chip); color: var(--ink); font-weight: 600; }
#side-nav a:hover { background: var(--chip); }
.side-foot { margin-top: auto; font-size: 12px; color: var(--muted); }
main { padding: 28px clamp(16px, 4vw, 40px) 40px; max-width: 1240px; width: 100%; min-width: 0; outline: none; }
.tabbar { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--chip); font-size: 12px; color: var(--muted); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.live .dot { background: var(--pos); box-shadow: 0 0 0 3px rgba(30,127,67,.18); }
.pill.off .dot { background: var(--danger); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, 1fr); margin-bottom: 14px; }
.kpi .label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 700; color: var(--ink); margin: 6px 0 2px; }
.kpi .value.pos { color: var(--pos); } .kpi .value.neg { color: var(--neg); }
.two { grid-template-columns: 1.1fr 1fr; align-items: start; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: right; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { text-align: right; padding: 11px 10px; border-bottom: 1px solid var(--line); }
.table th:first-child, .table td:first-child, .table .left { text-align: left; }
.table td:first-child { white-space: nowrap; }
.table tr.click { cursor: pointer; } .table tr.click:hover td { background: var(--chip); }
.table tr.total td { font-weight: 700; border-bottom: none; }
.table-wrap { overflow-x: auto; }
.name { font-weight: 600; color: var(--ink); } .code { font-size: 12px; color: var(--muted); }
.sym { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 6px; background: var(--chip); color: var(--text);
  font-size: 11px; font-weight: 700; letter-spacing: .02em; line-height: 1.5; vertical-align: 1px; white-space: nowrap; }
.table td.left .name-row { white-space: nowrap; }
.table td.left .name-row .name { display: inline-block; max-width: 190px; vertical-align: bottom; }
.table td.left .name-row + .code { max-width: 250px; }
.table td.left .name, .table td.left .code { white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
body.setup-mode #app { grid-template-columns: 1fr; }
body.setup-mode .sidebar, body.setup-mode .tabbar { display: none; }
.bar { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; border-radius: 4px; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0F1623; } }
.btn.danger { color: var(--danger); } .btn.block { width: 100%; } .btn.small { padding: 6px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.seg { display: inline-flex; background: var(--chip); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.badge.buy { color: var(--pos); } .badge.sell { color: var(--neg); } .badge.price { color: var(--warn); } .badge.auto { color: var(--accent); }
.status { font-size: 12px; color: var(--muted); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

.list .item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list .item:last-child { border-bottom: 0; }
.list .item .right { text-align: right; }
.list .item .right .btn { white-space: nowrap; }
.group-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 4px 4px; }

label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, input.search { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--input); color: var(--ink); font-weight: 500; }
.field input:focus, input.search:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form { display: grid; gap: 14px; }
.form .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); font-weight: 500; }
.results { border: 1px solid var(--line); border-radius: 10px; max-height: 220px; overflow: auto; }
.results button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line); background: var(--card); cursor: pointer; }
.results button:hover { background: var(--chip); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.error { color: var(--danger); font-size: 13px; }
.chart-box { position: relative; height: 280px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.qr img, .qr canvas { display: block; width: 200px; height: 200px; image-rendering: pixelated; }
code.key { word-break: break-all; background: var(--chip); padding: 8px 10px; border-radius: 8px; display: block; font-size: 13px; }
.setup { max-width: 520px; margin: 8vh auto; }
.setup .card { padding: 28px; }

#sheet-backdrop { position: fixed; inset: 0; background: rgba(9,16,30,.45); z-index: 40; }
#sheet { position: fixed; z-index: 50; background: var(--card); box-shadow: 0 20px 60px rgba(0,0,0,.25);
  top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  overflow: auto; border-radius: 20px; padding: 22px; }
#sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
#sheet .close { border: 0; background: var(--chip); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 18px; color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 60; font-size: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.actionable { pointer-events: auto; display: flex; align-items: center; gap: 14px; bottom: calc(90px + env(safe-area-inset-bottom)); }
.toast-btn { border: 0; background: transparent; color: #7FB3FF; font-weight: 700; cursor: pointer; padding: 2px 4px; }
details summary::-webkit-details-marker { display: none; }
@media (min-width: 861px) { #toast.actionable { bottom: 24px; } }

/* ---------- intraday ---------- */
.tabs-scroll { overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
.tabs-scroll::-webkit-scrollbar { display: none; }
.tabs-scroll .seg { white-space: nowrap; }
.idx { grid-template-columns: repeat(4, 1fr); margin-bottom: 14px; }
.idx-card { padding: 12px 14px; }
.idx-card .name { font-size: 18px; margin: 2px 0; }
.guard { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; padding: 12px 18px; font-size: 14px; }
.guard a { margin-left: auto; }
.badge.pos { color: var(--pos); } .badge.neg { color: var(--neg); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.watch-table td:first-child { white-space: normal; }
.watch-table td.left .name { white-space: normal; }
.watch-table td.left .name-row { white-space: normal; } .watch-table td.left .name-row .name { display: inline; max-width: none; }
.tags .badge { text-transform: none; letter-spacing: 0; font-weight: 600; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.spark { width: 120px; height: 34px; display: block; }
.spark path, .spark line { vector-effect: non-scaling-stroke; fill: none; }
.spark-line { stroke-width: 1.6; } .spark-line.up { stroke: var(--pos); } .spark-line.down { stroke: var(--neg); }
.spark-vwap { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 3 2; }
.spark-prev { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 1 3; opacity: .7; }
.icon-btn { border: 0; background: transparent; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 18px; line-height: 1; }
.icon-btn:hover { background: var(--chip); color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; font-weight: 500; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on { color: #0F1623; } }
.chip-check { border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
.big-qty { font-size: 15px; color: var(--muted); margin: 4px 0 14px; display: flex; align-items: baseline; gap: 8px; }
.big-qty .num { font-size: 34px; font-weight: 700; color: var(--ink); }
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 10px 0 0; border-left: 3px solid var(--muted); background: var(--chip); color: var(--text); }
.alert.warn { border-left-color: var(--warn); background: rgba(183,121,31,.10); }
.alert.neg { border-left-color: var(--danger); background: rgba(192,57,43,.09); }
.ticket { background: var(--chip); border-radius: 12px; padding: 14px; font: 14px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; margin: 0 0 12px; color: var(--ink); }
.steps { padding-left: 20px; margin: 0 0 14px; } .steps li { margin-bottom: 6px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .d { background: var(--chip); border-radius: 8px; min-height: 46px; padding: 5px 6px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; justify-content: space-between; }
.cal .d b { font-size: 11px; color: var(--ink); }
.cal .d.pos { background: rgba(30,127,67,.16); } .cal .d.pos b { color: var(--pos); }
.cal .d.neg { background: var(--neg-bg); } .cal .d.neg b { color: var(--neg); }
details.learn { border-bottom: 1px solid var(--line); padding: 10px 0; }
details.learn:last-child { border-bottom: 0; }
details.learn summary { cursor: pointer; font-weight: 600; color: var(--ink); list-style: none; }
details.learn summary::after { content: '+'; float: right; color: var(--muted); }
details.learn[open] summary::after { content: '−'; }
details.learn p { margin: 8px 0 2px; }

/* ---------- AI analyst ---------- */
.ai-grid { grid-template-columns: minmax(280px, 380px) 1fr; align-items: start; }
.task-list { display: grid; gap: 8px; padding: 12px; }
.task { display: grid; gap: 2px; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.task:hover { border-color: var(--accent); }
.task.on { border-color: var(--accent); background: var(--chip); }
.ai-status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }
.md { color: var(--text); line-height: 1.6; overflow-wrap: anywhere; }
.md h2, .md h3, .md h4 { color: var(--ink); margin: 18px 0 6px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; } .md h4 { font-size: 15px; }
.md > :first-child { margin-top: 0; }
.md p { margin: 8px 0; } .md ul, .md ol { margin: 6px 0; padding-left: 22px; } .md li { margin: 3px 0; }
.md code { background: var(--chip); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md pre { background: var(--chip); padding: 10px; border-radius: 10px; overflow-x: auto; }
.md blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md-table td, .md-table th { text-align: left !important; white-space: normal !important; }
.sources { padding-left: 18px; margin: 8px 0 0; } .sources li { margin: 4px 0; }
.field textarea { resize: vertical; min-height: 70px; }

.desktop-only { display: revert; } .mobile-only { display: none; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } .two, .ai-grid { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  main { padding: calc(18px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .kpi .value { font-size: 21px; }
  .card { padding: 16px; }
  .desktop-only { display: none; } .mobile-only { display: revert; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--ink); font-weight: 600; }
  .tabbar a.add span.plus { width: 44px; height: 44px; border-radius: 14px; background: var(--brand); color: #fff; display: grid; place-items: center;
    font-size: 26px; line-height: 1; margin-top: -14px; box-shadow: var(--shadow); }
  #sheet { top: auto; bottom: 0; left: 0; transform: none; width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .form .cols { grid-template-columns: 1fr 1fr; }
  .chart-box { height: 230px; }
  .table th, .table td { padding: 10px 5px; }
  .table td { font-size: 14px; }
  .idx { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .guard a { margin-left: 0; }
  .big-qty .num { font-size: 28px; }
  .task-list { grid-template-columns: 1fr 1fr; padding: 10px; }
  .task { padding: 9px 10px; } .task .code { display: none; }
}
