/* AI Trader console: a quiet operator screen. Cool slate neutrals, one cobalt accent,
   semantic green/red only for money moving up or down. */
:root {
  --bg: #F2F4F7; --surface: #FFFFFF; --sunk: #EEF1F5; --fg: #121A24; --muted: #5B6778; --line: #DCE1E8;
  --accent: #2A52D6; --accent-soft: #E6ECFB; --up: #11784A; --up-soft: #E1F2E9; --down: #B4302B; --down-soft: #FAE6E5;
  --warn: #9A6200; --warn-soft: #FAEFD8; --bench: #8794A6; --quant: #7A5AC8;
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C1219; --surface: #141C26; --sunk: #0F161F; --fg: #E4E9F0; --muted: #94A1B3; --line: #243042;
    --accent: #86A1FF; --accent-soft: #1B2847; --up: #4DC48B; --up-soft: #113222; --down: #F27C75; --down-soft: #3A1715;
    --warn: #E2A83C; --warn-soft: #342712; --bench: #6E7A8C; --quant: #A48CF0;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.6 var(--font); -webkit-text-size-adjust: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.05rem; font-weight: 600; } h3 { font-size: .95rem; margin-top: 8px; }
p { margin: 0; }
pre { margin: 0; font-family: var(--mono); font-size: .82rem; white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--muted); } .small { font-size: .82rem; }
.error { color: var(--down); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 16px; }
.login { width: min(400px, 100%); gap: 14px; }
.login label, .cfg label { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--fg); background: var(--sunk); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
textarea { min-height: 90px; resize: vertical; font-family: var(--mono); font-size: .85rem; }
input[type=checkbox] { width: auto; }

.btn { font: inherit; font-size: .9rem; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.danger { color: var(--down); border-color: var(--down); background: var(--surface); }
.btn.danger:hover { background: var(--down-soft); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
  padding: max(10px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
  display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand strong { font-size: 1.05rem; }
.status-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end; }
.tabs { grid-column: 1 / -1; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; font-size: .92rem; }
.tabs a.on { color: var(--fg); border-bottom-color: var(--accent); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; color: var(--muted); }
.pill.up { color: var(--up); border-color: currentColor; } .pill.bad { color: var(--down); border-color: currentColor; background: var(--down-soft); }
.pill.warn { color: var(--warn); border-color: currentColor; background: var(--warn-soft); }
.pill.buy { color: var(--up); border-color: currentColor; } .pill.sell { color: var(--down); border-color: currentColor; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--bench); }
.conn.live i { background: var(--up); box-shadow: 0 0 0 3px var(--up-soft); }
.conn.down i { background: var(--down); }
@media (max-width: 640px) { .top { grid-template-columns: 1fr; } .status-row { justify-content: flex-start; } }

.wrap { max-width: 1180px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 16px; }
.tab { display: grid; gap: 16px; }
.banner { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: .9rem; }
.banner.bad { border-color: var(--down); background: var(--down-soft); color: var(--down); }
.lede { color: var(--muted); }
.lede b { color: var(--fg); font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 2px; min-width: 0; }
.tile .lab { font-size: .8rem; color: var(--muted); }
.tile .big { font-size: 1.55rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .small { color: var(--muted); font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }

.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.legend .s::before { background: var(--accent); } .legend .q::before { background: var(--bench); } .legend .t::before { background: var(--quant); }
.chart { position: relative; min-height: 240px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font: 11px var(--mono); }
.chart .grid { stroke: var(--line); } .chart .zero { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .ls { stroke: var(--accent); stroke-width: 2.2; fill: none; } .chart .lq { stroke: var(--bench); stroke-width: 1.6; fill: none; }
.chart .lt { stroke: var(--quant); stroke-width: 1.6; stroke-dasharray: 5 4; fill: none; } .chart .lab-t { fill: var(--quant); }
.chart .dot { fill: var(--accent); } .chart .lab-s { fill: var(--accent); font-weight: 600; }
.tip { position: absolute; top: 6px; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; font-size: .8rem; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-variant-numeric: tabular-nums; white-space: nowrap; }

.tbl { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 8px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: .74rem; color: var(--muted); font-weight: 500; white-space: nowrap; background: var(--sunk); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.sym { font-weight: 600; white-space: nowrap; }
td.why { min-width: 260px; color: var(--muted); }
.empty { color: var(--muted); padding: 6px 0; }
.view { line-height: 1.75; max-width: 80ch; }
.list { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; }
.list .forced, .list .halt { color: var(--down); }
.list .urgent { color: var(--warn, var(--down)); font-weight: 600; }
.list .lock { color: var(--muted); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.two.wide-left { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
@media (max-width: 800px) { .two, .two.wide-left { grid-template-columns: minmax(0, 1fr); } }
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(0, 12em) minmax(0, 1fr) 4.5em; gap: 10px; align-items: center; font-size: .85rem; }
.track { position: relative; height: 10px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.fill { height: 100%; background: var(--accent); border-radius: 3px; }
.fill.over { background: var(--down); }
.bar .v { text-align: right; font-variant-numeric: tabular-nums; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.notify-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 6px 0 4px; }
.notify-form label { flex: 1 1 280px; display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.row.end { justify-content: flex-end; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.req { border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 4px; }
.req pre { max-height: 220px; overflow: auto; background: var(--sunk); padding: 8px; border-radius: 6px; }
.danger-zone { border-color: color-mix(in srgb, var(--down) 45%, var(--line)); }

.cfg { display: grid; gap: 16px; }
.cfg fieldset { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 14px 16px 16px; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; min-width: 0; }
.cfg legend { font-weight: 600; padding: 0 6px; }
.cfg .full { grid-column: 1 / -1; }
.cfg .hint { font-size: .76rem; color: var(--muted); }
.cfg .days { display: flex; flex-wrap: wrap; gap: 10px; color: var(--fg); }
.cfg .days label { display: inline-flex; align-items: center; gap: 4px; color: var(--fg); }
.cfg .changed input, .cfg .changed select, .cfg .changed textarea { border-color: var(--accent); background: var(--accent-soft); }
.sticky-save { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); padding: 10px 0 max(10px, env(safe-area-inset-bottom, 0px)); }

.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 520px; overflow: auto; }
.files button { width: 100%; text-align: left; font: inherit; font-size: .88rem; background: none; border: 0; padding: 6px 8px; border-radius: 6px; color: var(--fg); cursor: pointer; }
.files button:hover, .files button.on { background: var(--accent-soft); }
.doc { max-height: 620px; overflow: auto; font-size: .84rem; line-height: 1.6; }
.log { max-height: 420px; overflow: auto; background: var(--sunk); padding: 10px; border-radius: 8px; font-size: .78rem; }

dialog { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--fg); padding: 20px; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 15, 22, .55); }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: .9rem; z-index: 20; max-width: calc(100vw - 32px); }

/* account */
.form { display: grid; gap: 12px; align-content: start; }
.form label { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
.qr { display: block; width: 240px; height: 240px; max-width: 100%; border-radius: 8px; background: #fff; padding: 4px; image-rendering: pixelated; }
.steps { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; font-size: .9rem; }
.form code { font-size: .85rem; word-break: break-all; user-select: all; }
details summary { cursor: pointer; color: var(--muted); }

/* skeleton loading: placeholders in the shape of the content until the first data arrives */
@keyframes sk-shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.sk {
  color: transparent !important; border-color: transparent !important; user-select: none; pointer-events: none;
  background: linear-gradient(90deg, var(--sunk) 25%, var(--line) 50%, var(--sunk) 75%) !important;
  background-size: 200% 100% !important; animation: sk-shimmer 1.4s ease-in-out infinite; border-radius: 6px;
}
.sk * { visibility: hidden; }
.sk-line { display: block; height: .8em; width: 100%; margin: .25em 0; }
.sk-line.short { width: 55%; }
.sk-line.title { width: 35%; height: 1.1em; margin-bottom: 14px; }
.sk-item { padding: 3px 0; list-style: none; }
.sk-block { display: block; width: 100%; }
.sk-chart { height: 240px; }
.sk-row td { padding-top: 12px; padding-bottom: 12px; }
.sk-field { display: grid; gap: 6px; margin: 12px 0; }
.sk-input { display: block; height: 36px; border-radius: 8px; }
.sk-card { margin-bottom: 16px; }
.tile .big.sk { width: 70%; min-height: 1.2em; }
.tile .small .sk, .tile .small span.sk { display: inline-block; min-width: 5ch; }
#takeaway.sk { width: min(640px, 90%); min-height: 1.2em; }
#dec-view.sk { min-height: 4.5em; }
.pill.sk { min-width: 9ch; }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; background: var(--line) !important; } }
.warn-text { color: var(--warn); font-weight: 600; }
