/* serve admin panel: a monochrome take on the terminal look.
   Black title bars, grey command line, dense monospace grid, no rounded
   corners. Colour is kept for meaning only: sentiment sign, live state, errors.
   Every token is light-dark(); the page is light unless the THEME button
   chose dark, which the browser remembers. */

:root {
  color-scheme: light;
  --bg: light-dark(#F2F2F0, #0E0E0E);
  --panel: light-dark(#FFFFFF, #161616);
  --stripe: light-dark(#F7F7F5, #1B1B1B);
  --line: light-dark(#DCDCD8, #2A2A2A);
  --line-strong: light-dark(#9C9C97, #5C5C5C);
  --text: light-dark(#111111, #EDEDED);
  --muted: light-dark(#6B6B68, #9B9B9B);
  --title-bg: light-dark(#4A4444, #474747);
  --title-fg: #FFFFFF;
  --cmd-bg: light-dark(#E8E8E5, #1F1F1F);
  --cmd-line: light-dark(#C9C9C4, #3A3A3A);
  --select: light-dark(#D9D9D5, #3A3A3A);
  --hover: light-dark(#EDEDEA, #232323);
  --flash: light-dark(#BDBDB8, #5A5A5A);
  --pos: light-dark(#1B7F3B, #4CC38A);
  --pos-bg: light-dark(#DDF2E3, #1E3A2B);
  --neg: light-dark(#B3261E, #FF7B72);
  --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 12px/1.35 var(--mono);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; border-radius: 0; }
button { cursor: pointer; }
button:disabled { cursor: default; }
.hidden { display: none !important; }
b { font-weight: 700; }
a { color: var(--text); }

/* ---- top bar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 30px; padding: 0 10px;
  background: var(--panel); border-bottom: 2px solid var(--title-bg);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .08em; }
.brand-mark { background: var(--title-bg); color: var(--title-fg); padding: 1px 6px; }
.clocks { display: flex; margin-left: auto; font-variant-numeric: tabular-nums; }
.clock { border: 1px solid var(--line-strong); background: var(--panel); color: var(--muted); padding: 1px 8px; letter-spacing: .04em; }
.clock + .clock { border-left: 0; }
.clock.active { background: var(--title-bg); color: var(--title-fg); font-weight: 700; }
.keybtn { border: 1px solid var(--line-strong); background: var(--panel); padding: 1px 8px; letter-spacing: .06em; }
.keybtn:hover { background: var(--hover); }

/* ---- dataset menu: numbered the way terminal menus are */
.menu { display: flex; gap: 2px; padding: 4px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.menu button { border: 1px solid transparent; background: transparent; padding: 1px 8px; letter-spacing: .04em; }
.menu button b { color: var(--muted); margin-right: 4px; }
.menu button.active { background: var(--title-bg); color: var(--title-fg); font-weight: 700; }
.menu button.active b { color: var(--title-fg); }
.menu button:disabled, .menu button:disabled b { color: var(--muted); }
.menu button:disabled::after { content: " soon"; font-size: 10px; }

/* ---- pages */
.page { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---- command line */
.cmdline {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px;
  padding: 6px 10px;
  background: var(--cmd-bg); border-bottom: 1px solid var(--cmd-line);
}
.cmdline label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.cmdline input, .cmdline select {
  background: var(--panel); border: 1px solid var(--line-strong);
  padding: 1px 6px; height: 22px; min-width: 0; font-weight: 400; color: var(--text);
}
.cmdline input:focus, .cmdline select:focus { outline: 2px solid var(--text); outline-offset: -1px; }
#f-ticker, #mk-ticker { width: 130px; text-transform: uppercase; }
#mk-name { width: 150px; }
#mk-type, #mk-exchange { width: 110px; }
#mk-sector { width: 200px; }
#mk-industry { width: 230px; }
#f-source { width: 150px; }
#f-q { width: 190px; }
.modes { display: flex; }
.modes .mode { border: 1px solid var(--text); background: var(--panel); padding: 1px 10px; font-weight: 700; }
.modes .mode + .mode { border-left: 0; }
.modes .mode.active { background: var(--title-bg); color: var(--title-fg); }
.modes .mode:disabled { color: var(--muted); border-color: var(--line-strong); }
.go { background: var(--title-bg); color: var(--title-fg); border: 1px solid var(--title-bg); padding: 1px 12px; font-weight: 700; letter-spacing: .08em; }
.go:hover { opacity: .85; }
.cancel { background: var(--panel); color: var(--text); border: 1px solid var(--text); padding: 1px 10px; font-weight: 700; letter-spacing: .08em; }
.cancel:hover { background: var(--hover); }
.live { border: 1px solid var(--line-strong); background: var(--panel); padding: 1px 10px; display: flex; align-items: center; gap: 6px; font-weight: 700; letter-spacing: .06em; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); display: inline-block; }
.live.open .dot { background: var(--pos); box-shadow: 0 0 0 2px var(--pos-bg); }
.live.connecting .dot { background: var(--text); }
.live.closed .dot { background: var(--neg); }
.live:disabled { color: var(--muted); }
.export { font-weight: 700; margin-left: auto; letter-spacing: .06em; }
.export.disabled { color: var(--muted); pointer-events: none; text-decoration: none; }
.page:not(.history) .hist { display: none; }
.page.history .live { display: none; }

/* ---- checkbox dropdown (news sources) */
.dropdown { position: relative; }
.dropbtn { border: 1px solid var(--line-strong); background: var(--panel); padding: 1px 8px; height: 22px; font-weight: 700; letter-spacing: .06em; font-size: 11px; color: var(--muted); }
.droppanel {
  position: absolute; top: 24px; left: 0; z-index: 5; min-width: 260px;
  background: var(--panel); border: 1px solid var(--line-strong); box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
}
.dropactions { display: flex; gap: 2px; padding: 4px; border-bottom: 1px solid var(--line); }
.dropactions button { border: 1px solid var(--line-strong); background: var(--panel); padding: 0 8px; font-size: 11px; }
.droplist { max-height: 320px; overflow: auto; padding: 4px 0; }
.droplist label { display: flex; align-items: center; gap: 6px; padding: 1px 8px; cursor: pointer; white-space: nowrap; }
.droplist label:hover { background: var(--hover); }
.droplist label i { margin-left: auto; color: var(--muted); font-style: normal; font-variant-numeric: tabular-nums; padding-left: 12px; }
.droplist input { margin: 0; }

/* ---- locked: the layout stays as a blurred outline behind the key dialog */
body.locked > :not(.keypanel) { filter: blur(6px); pointer-events: none; user-select: none; }
.keypanel {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 45%, transparent);
}
.keypanel .dialog {
  width: min(560px, calc(100% - 32px));
  background: var(--panel); border: 1px solid var(--line-strong);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
}
.keypanel form { display: flex; align-items: center; gap: 10px; padding: 12px; flex-wrap: wrap; }
.keypanel p { margin: 0 0 4px; flex-basis: 100%; color: var(--muted); }
#key-input { flex: 1; min-width: 240px; background: var(--panel); border: 1px solid var(--line-strong); padding: 2px 6px; height: 24px; }
.msg { color: var(--neg); font-weight: 700; flex-basis: 100%; min-height: 1.2em; }

/* ---- work area */
.work {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 8px var(--detail-width, 400px);
  padding: 6px 10px;
}
.splitter { cursor: col-resize; position: relative; touch-action: none; }
.splitter::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; }
.splitter:hover::after, body.resizing .splitter::after { background: var(--line-strong); }
body.resizing { cursor: col-resize; user-select: none; }
.panel { background: var(--panel); border: 1px solid var(--line-strong); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-title {
  background: var(--title-bg); color: var(--title-fg);
  font-weight: 700; letter-spacing: .08em; font-size: 11px; text-transform: uppercase;
  padding: 2px 8px; display: flex; justify-content: space-between;
}
.panel-title .meta { font-weight: 400; text-transform: none; letter-spacing: 0; }

.grid-scroll { flex: 1; overflow: auto; min-height: 0; overflow-anchor: none; }
.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.grid th {
  position: sticky; top: 0; z-index: 1;
  background: var(--stripe); border-bottom: 1px solid var(--line-strong);
  text-align: left; padding: 3px 6px;
  font-size: 10px; letter-spacing: .08em; color: var(--muted);
}
.grid td { padding: 0 6px; height: 22px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid tbody tr.even { background: var(--stripe); }
.grid tbody tr.spacer td { padding: 0; border: 0; }
.grid tbody tr.placeholder td { color: var(--line-strong); }
.newbar { border: 0; border-bottom: 1px solid var(--line-strong); background: var(--cmd-bg); color: var(--text); font-weight: 700; letter-spacing: .08em; padding: 2px 8px; text-align: center; }
.newbar:hover { background: var(--hover); }
.grid tbody tr.spacer:hover { background: transparent; }
.grid tbody tr:hover { background: var(--hover); }
.grid tbody tr.selected { background: var(--select); outline: 1px solid var(--text); outline-offset: -1px; }
.grid tbody tr.flash { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: var(--flash); } to { background: transparent; } }
.grid th.sortable { cursor: pointer; }
.grid th.sortable:hover { color: var(--text); }
.grid th.sorted-asc::after { content: " ▲"; color: var(--text); }
.grid th.sorted-desc::after { content: " ▼"; color: var(--text); }
.c-time { width: 150px; color: var(--muted); font-variant-numeric: tabular-nums; }
.c-ticker { width: 110px; }
.c-source { width: 160px; color: var(--muted); }
.c-period { width: 100px; color: var(--muted); }
.c-no { width: 56px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.c-form { width: 120px; }
.c-company { width: 260px; }
.tag { display: inline-block; border: 1px solid var(--line-strong); padding: 0 5px; font-size: 10px; font-weight: 700; letter-spacing: .06em; line-height: 16px; }
.subhead { margin: 10px 0 2px; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.subtable { width: 100%; border-collapse: collapse; font-size: 11px; }
.subtable th { text-align: left; color: var(--muted); font-size: 10px; letter-spacing: .06em; border-bottom: 1px solid var(--line-strong); padding: 2px 4px; }
.subtable td { padding: 2px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.subtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.subtable .muted, .kv .muted { color: var(--muted); }
#sec-ticker { width: 130px; text-transform: uppercase; }
#sec-company { width: 170px; }
.c-sector { width: 110px; color: var(--muted); }
.c-industry { width: 220px; color: var(--muted); }
.c-mcap, .c-price, .c-chg, .c-vol { text-align: right; font-variant-numeric: tabular-nums; }
.c-mcap { width: 90px; }
.c-price { width: 100px; }
.c-chg { width: 84px; }
.c-vol { width: 120px; }
.grid th.c-no, .grid th.c-mcap, .grid th.c-price, .grid th.c-chg, .grid th.c-vol { text-align: right; }
.tk { font-weight: 700; cursor: pointer; }
.tk:hover { text-decoration: underline; }
.tk-chg { margin-left: 6px; font-variant-numeric: tabular-nums; }
.page[data-page="news"] .c-ticker, .page[data-page="sec"] .c-ticker { width: 130px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero, .na { color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); letter-spacing: .1em; }

.pager { display: flex; align-items: center; gap: 10px; padding: 3px 8px; border-top: 1px solid var(--line-strong); background: var(--stripe); }
.pager button { border: 1px solid var(--line-strong); background: var(--panel); padding: 0 8px; }
.pager button:disabled { color: var(--muted); }
#page-info { display: inline-block; min-width: 38ch; text-align: center; font-variant-numeric: tabular-nums; }
.page:not(.history) .pager { display: none; }

/* ---- detail */
.detail { flex: 1; overflow: auto; padding: 6px 8px; }
.detail .hint { color: var(--muted); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 2px 8px; margin: 0; }
.kv dt { color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; padding-top: 2px; }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; border-bottom: 1px dotted var(--line); padding-bottom: 2px; }
.kv dd.null { color: var(--muted); }
.kv .muted { color: var(--muted); }
.news-list { list-style: none; margin: 0; padding: 0; }
.news-list li { padding: 3px 0; border-bottom: 1px dotted var(--line); }
.news-list a { color: var(--text); text-decoration: none; }
.news-list a:hover { text-decoration: underline; }
.news-list .meta { display: block; color: var(--muted); font-size: 10px; letter-spacing: .04em; }

/* ---- status bar */
.statusbar {
  display: flex; align-items: center;
  height: 24px; padding: 0 10px;
  background: var(--panel); border-top: 2px solid var(--title-bg);
  color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden;
}
.statusbar > span { padding: 0 10px; border-right: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; }
.statusbar > span:first-child { padding-left: 0; }
.statusbar > span:last-child { border-right: 0; margin-left: auto; }
.statusbar b { color: var(--text); }
.statusbar .err { color: var(--neg); }

@media (max-width: 1100px) {
  .work { grid-template-columns: 1fr; grid-template-rows: minmax(0, 2fr) 6px minmax(0, 1fr); }
  .splitter { cursor: default; pointer-events: none; }
}
