/* Signal Desk — quiet, monochrome surfaces; colour only where it carries meaning. */

:root {
  --bg: #0b0b0c;
  --surface: #0b0b0c;
  --raised: #161618;
  --line: rgba(255, 255, 255, 0.07);
  --line-soft: rgba(255, 255, 255, 0.04);
  --text: #f2f2f3;
  --muted: #9a9aa2;
  --faint: #5c5c64;
  --accent: #9db4ff;
  --accent-soft: rgba(157, 180, 255, 0.10);
  --up: #4cc38a;
  --up-soft: rgba(76, 195, 138, 0.12);
  --down: #ef6b73;
  --down-soft: rgba(239, 107, 115, 0.12);
  --warn: #e0b45e;
  --warn-soft: rgba(224, 180, 94, 0.12);
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --raised: #f4f4f3;
    --line: rgba(0, 0, 0, 0.08);
    --line-soft: rgba(0, 0, 0, 0.045);
    --text: #111113;
    --muted: #6c6c73;
    --faint: #a5a5ac;
    --accent: #3461d9;
    --accent-soft: rgba(52, 97, 217, 0.07);
    --up: #13804c;
    --up-soft: rgba(19, 128, 76, 0.08);
    --down: #cc3b45;
    --down-soft: rgba(204, 59, 69, 0.08);
    --warn: #a26a0e;
    --warn-soft: rgba(162, 106, 14, 0.09);
    --shadow: 0 24px 64px rgba(0, 0, 0, 0.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* layout rules (flex/grid) must not un-hide elements */
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-rows: 60px auto 1fr;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
small { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- header ---------- */
.bar {
  display: flex; align-items: center; gap: 22px;
  padding: 0 32px;
  white-space: nowrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand .mark { width: 8px; height: 8px; border-radius: 50%; background: var(--text); }
.chip {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--warn); background: var(--warn-soft); padding: 4px 10px; border-radius: 999px;
  overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.chip.quiet, .chip.quiet.demo { color: var(--muted); background: none; padding: 0; font-weight: 400; letter-spacing: 0; text-transform: none; font-size: 12px; flex: 0 1 auto; }
.badge { font-size: 12px; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.status.up i { background: var(--up); }
.status.idle i { background: var(--accent); }
.status.down i, .status.off i { background: var(--down); }
.status.starting i { background: var(--warn); }
.status.ws span { display: none; }  /* dot only; colour says connected / reconnecting */
.clock { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.window-btn {
  background: none; border: 0; border-radius: 8px;
  padding: 6px 10px; margin: 0 -10px; color: var(--muted); cursor: pointer; font-size: 12px;
  transition: background 0.15s, color 0.15s;
}
.window-btn b { color: var(--text); font-weight: 500; font-family: var(--mono); margin-left: 6px; }
.window-btn:hover:not(:disabled) { background: var(--raised); color: var(--text); }
.window-btn:disabled { cursor: default; }
.link { color: var(--muted); text-decoration: none; font-size: 13px; transition: color 0.15s; }
.link:hover { color: var(--text); }
.spacer { flex: 1; }
.badge.kill {
  color: var(--down); font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
}
.badge.kill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--down); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.badge.attn {
  color: var(--warn); font-size: 12px; font-weight: 500; text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge.attn::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.attn.critical { color: var(--down); }
.badge.attn.critical::before { animation: pulse 1.6s ease-in-out infinite; }
.badge.attn[hidden] { display: none; }
.kill-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 6px 16px; cursor: pointer; font-size: 12px; font-weight: 500;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.kill-btn:hover { color: var(--down); border-color: color-mix(in srgb, var(--down) 50%, transparent); }
.kill-btn.on { background: var(--down); border-color: var(--down); color: #fff; }
.user { color: var(--faint); font-size: 12px; }

/* ---------- summary: the four numbers that matter ---------- */
.summary {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 32px;
  padding: 18px 32px 26px; border-bottom: 1px solid var(--line);
}
.summary div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.summary small { color: var(--faint); font-size: 12px; }
.summary b {
  font-family: var(--sans); font-weight: 500; font-size: 26px; letter-spacing: -0.025em; line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.summary b.small { font-size: 14px; white-space: normal; letter-spacing: 0; }

/* ---------- layout ---------- */
.grid {
  display: grid;
  grid-template-columns: 470px minmax(0, 1fr);
  min-height: 0;
}
.watch { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.detail { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
.count { color: var(--faint); font-weight: 400; margin-left: 4px; }

/* segmented controls read as quiet text tabs */
.seg { display: inline-flex; gap: 2px; flex-wrap: wrap; }
.seg button {
  background: none; border: 0; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; color: var(--faint); cursor: pointer; transition: color 0.15s, background 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { color: var(--text); background: var(--raised); }

/* ---------- watchlist ---------- */
.watch-head { display: flex; flex-direction: column; gap: 12px; padding: 20px 24px 12px; }
.watch-head .seg { margin-left: -10px; }
.search {
  width: 100%; padding: 10px 14px; border: 0; border-radius: var(--radius);
  background: var(--raised); color: var(--text); outline: none; font: inherit; font-size: 13px;
}
.search::placeholder { color: var(--faint); }
.search:focus { box-shadow: 0 0 0 1px var(--line); }

.table-wrap { overflow: auto; min-height: 0; flex: 1; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface); color: var(--faint); font-weight: 400; font-size: 11px;
  text-align: right; padding: 8px 10px; white-space: nowrap;
}
.table td {
  text-align: right; padding: 11px 10px; border-top: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 12px; white-space: nowrap;
}
.table th:first-child, .table td:first-child { padding-left: 24px; }
.table th:last-child, .table td:last-child { padding-right: 24px; }
.table td.two small { display: block; font-size: 10px; line-height: 1.2; }
.table .l { text-align: left; }
.table td.l { font-family: var(--sans); }
.table tbody tr { cursor: pointer; transition: background 0.12s; }
.table tbody tr:hover { background: var(--raised); }
.table tbody tr.sel { background: var(--raised); }
.table tbody tr.sel td:first-child { box-shadow: inset 2px 0 0 var(--text); }
.table tr.dim td { color: var(--faint); }
/* the contracts list: symbol, NSE bid, META ask, gap, state; all four prices are under Details */
#watch-table td:nth-child(4) { font-variant-numeric: tabular-nums; }
.sym { font-weight: 500; font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.sym small { margin-left: 6px; color: var(--faint); font-size: 10px; font-weight: 400; }
td.flash-up { animation: flashUp 0.8s ease-out; }
td.flash-down { animation: flashDown 0.8s ease-out; }
@keyframes flashUp { from { color: var(--up); } }
@keyframes flashDown { from { color: var(--down); } }
#watch-table td.hot { color: var(--accent); font-weight: 600; }
.empty { color: var(--faint); font-size: 13px; padding: 40px 24px; text-align: center; }

/* ---------- state: a coloured dot and a word ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--sans); font-size: 12px; color: var(--faint);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.FLAT { color: var(--muted); }
.pill.OPEN { color: var(--up); }
.pill.PENDING { color: var(--warn); }

/* ---------- selected instrument ---------- */
.instrument {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
  padding: 28px 36px 6px;
}
.inst-id h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.inst-id .muted { font-size: 12px; color: var(--faint); }
.inst-price { text-align: right; white-space: nowrap; }
.inst-price .last { font-family: var(--sans); font-size: 40px; font-weight: 500; letter-spacing: -0.035em; line-height: 1; }
.inst-price .chg { font-family: var(--mono); margin-left: 12px; font-size: 14px; }
.story { display: flex; align-items: baseline; gap: 14px; padding: 12px 36px 4px; font-size: 14px; color: var(--muted); }
.story .pill { font-size: 13px; font-weight: 500; flex: none; }

.chart { flex: 1; min-height: 220px; position: relative; margin: 8px 20px 0 24px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 4px 24px 8px; font-size: 11px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 14px; }
.chart-legend .k { display: inline-block; width: 16px; height: 0; border-top: 2px solid; margin-right: 5px; }
.chart-legend .k.ltp { border-color: var(--accent); }
.chart-legend .k.nbid { border-color: color-mix(in srgb, var(--up) 60%, transparent); }
.chart-legend .k.nask { border-color: color-mix(in srgb, var(--down) 60%, transparent); }
.chart-legend .k.mbid { border-top: 2px dashed #8b5cf6; }
.chart-legend .k.mask { border-top: 2px dashed #f59e0b; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 26px; padding: 0 36px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.tabs button {
  background: none; border: 0; padding: 14px 0 12px; margin-bottom: -1px; cursor: pointer;
  font-size: 13px; color: var(--faint); border-bottom: 2px solid transparent; transition: color 0.15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--text); }
.tab-panel { height: 240px; display: flex; flex-direction: column; min-height: 0; }
.tab-panel .table th:first-child, .tab-panel .table td:first-child { padding-left: 36px; }
.tab-panel .table th:last-child, .tab-panel .table td:last-child { padding-right: 36px; }
.panel-tools { padding: 12px 26px 6px; }

/* ---------- details ---------- */
.calc { overflow: auto; padding: 18px 36px 20px; }
.book { display: flex; gap: 48px; margin-bottom: 18px; white-space: nowrap; }
.book div { display: flex; flex-direction: column; gap: 2px; }
.book small { color: var(--faint); }
.book b { font-family: var(--mono); font-weight: 400; font-size: 14px; }
.book .qty { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.calc-grid {
  display: grid; grid-template-columns: max-content max-content 1fr max-content; gap: 6px 24px;
  font-size: 13px; align-items: baseline;
}
.calc-grid .label { color: var(--muted); }
.calc-grid .formula { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.calc-grid .value { font-family: var(--mono); text-align: right; }
.calc-grid .verdict { font-size: 12px; text-align: left; }
.calc-grid .verdict.ok { color: var(--up); }
.calc-grid .verdict.no { color: var(--faint); }
.calc-grid .verdict.hit { color: var(--accent); font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 16px; }
.check { font-size: 12px; color: var(--faint); }
.check::before { content: "✓ "; color: var(--up); }
.check.bad { color: var(--down); }
.check.bad::before { content: "✕ "; color: var(--down); }
#calc-note { margin: 14px 0 0; color: var(--faint); }
#calc-note a { color: inherit; }

/* ---------- orders ---------- */
.orders { overflow: auto; flex: 1; min-height: 0; padding: 0 0 12px; }
.order { padding: 12px 36px; border-top: 1px solid var(--line-soft); }
.order .row1 { display: flex; gap: 12px; align-items: baseline; white-space: nowrap; min-width: 0; }
.order .row1 > * { flex: none; }
.order .row1 > .why, .order .row1 > .s { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.order .row1 > .why { flex-shrink: 8; }
.order .t { font-family: var(--mono); color: var(--faint); font-size: 11px; }
.order .s { font-weight: 500; }
.order .side { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }
.order .side.BUY { color: var(--up); }
.order .side.SELL { color: var(--down); }
.order .why { color: var(--faint); font-size: 12px; }
.order .px { margin-left: auto; font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.order .row2 { margin-top: 4px; font-size: 11px; color: var(--muted); font-family: var(--mono); overflow-wrap: anywhere; }
.order .row2 .ok { color: var(--up); }
.order .row2 .rej { color: var(--down); }
.order.new { animation: arrive 1.4s ease-out; }
@keyframes arrive { from { background: var(--accent-soft); } }

/* ---------- activity ---------- */
.log-lines { overflow: auto; flex: 1; min-height: 0; padding: 4px 36px 12px; font-family: var(--mono); font-size: 11px; }
.log-line { display: grid; grid-template-columns: 90px 60px 150px 1fr; gap: 14px; padding: 4px 0; color: var(--muted); }
.log-line .tag { font-size: 10px; letter-spacing: 0.04em; color: var(--faint); }
.log-line.signal .tag { color: var(--accent); }
.log-line.fill .tag { color: var(--up); }
.log-line.blocked .tag, .log-line.risk.rej .tag, .log-line.warning .tag { color: var(--warn); }
.log-line.exec .tag, .log-line.kill .tag { color: var(--down); }
.log-line.alert .tag { color: var(--warn); }
.log-line .who { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- popover ---------- */
.popover {
  position: fixed; top: 68px; left: 50%; transform: translateX(-50%); z-index: 20;
  width: 380px; padding: 26px 28px; border-radius: 16px;
  background: var(--bg); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, -4px); } }
.popover h3 { font-size: 16px; margin-bottom: 8px; }
.popover h4 { font-size: 12px; font-weight: 500; color: var(--faint); margin: 22px 0 6px; }
.popover p { margin: 0; line-height: 1.6; }
.times { display: flex; gap: 14px; margin: 20px 0 6px; }
.times label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); flex: 1; }
.times input {
  font: 16px var(--mono); padding: 10px 12px; border-radius: var(--radius); border: 0;
  background: var(--raised); color: var(--text); outline: none;
}
.error { color: var(--down); font-size: 12px; min-height: 18px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.actions button { border-radius: 999px; padding: 8px 18px; cursor: pointer; border: 1px solid var(--line); background: none; font-size: 13px; }
.actions button:hover { border-color: var(--muted); }
.actions .primary { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 500; }
.actions .primary:hover { opacity: 0.88; border-color: var(--text); }
.audit { list-style: none; margin: 0; padding: 0; font-size: 11px; color: var(--faint); font-family: var(--mono); max-height: 120px; overflow: auto; }
.audit li { padding: 2px 0; }

/* ---------- smaller screens: one column, natural heights ---------- */
@media (max-width: 1100px) {
  .user, .clock { display: none; }
}
@media (max-width: 900px) {
  body { display: block; overflow: auto; height: auto; }
  .bar { flex-wrap: wrap; padding: 14px 18px; gap: 10px 16px; }
  .chip.quiet { order: 9; width: 100%; }
  .summary { grid-template-columns: 1fr 1fr; gap: 18px; padding: 10px 18px 20px; }
  .summary b { font-size: 20px; }
  .grid { display: flex; flex-direction: column-reverse; }
  .watch { border-right: 0; border-top: 1px solid var(--line); }
  .watch .table-wrap { max-height: 480px; }
  .watch-head, .table th:first-child, .table td:first-child { padding-left: 18px; }
  .watch-head { padding-right: 18px; }
  .table th:last-child, .table td:last-child { padding-right: 18px; }
  .instrument { padding: 22px 18px 4px; flex-wrap: wrap; }
  .inst-price { text-align: left; }
  .inst-price .last { font-size: 32px; }
  .story { padding: 10px 18px 0; flex-wrap: wrap; gap: 6px 12px; }
  .chart { height: 300px; flex: none; margin: 8px 8px 0; }
  .tabs { padding: 0 18px; gap: 20px; overflow-x: auto; }
  .tab-panel { height: auto; max-height: 460px; }
  .tab-panel .table th:first-child, .tab-panel .table td:first-child { padding-left: 18px; }
  .tab-panel .table th:last-child, .tab-panel .table td:last-child { padding-right: 18px; }
  .order, .calc { padding-left: 18px; padding-right: 18px; }
  .log-lines { padding: 4px 18px 12px; }
  .log-line { grid-template-columns: 76px 1fr; }
  .log-line .tag, .log-line .who { display: none; }
  .calc-grid { grid-template-columns: max-content max-content 1fr; }
  .calc-grid .formula { display: none; }
  .book { gap: 28px; flex-wrap: wrap; }
  .popover { width: calc(100% - 32px); }
}

/* Close button on our open positions (operators) */
.close-btn {
  font: inherit; font-size: 12px; padding: 2px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line, rgba(127,127,127,.35)); background: transparent; color: var(--down);
}
.close-btn:hover:not(:disabled) { background: var(--down); color: #fff; }
.close-btn:disabled { opacity: .55; cursor: default; }
#watch-table td.up { color: var(--up); }

/* ---------- trade notifications: bell and pop-ups (notify.js); the log is notifications.html ---------- */
.notif-btn {
  position: relative; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; margin: 0 -8px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); cursor: pointer; transition: background 0.15s, color 0.15s;
}
.notif-btn:hover { background: var(--raised); color: var(--text); }
.notif-count {
  position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 999px;
  background: var(--up); color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
}
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 40; display: flex; flex-direction: column; gap: 8px; width: 360px; max-width: calc(100% - 32px); }
.toast {
  text-align: left; cursor: pointer; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  border-left: 3px solid var(--up); background: var(--bg); box-shadow: var(--shadow); color: var(--text);
  animation: toastin 0.2s ease-out; transition: opacity 0.4s, transform 0.4s;
}
.toast.close { border-left-color: var(--accent); }
.toast.close.win { border-left-color: var(--up); }
.toast.close.loss { border-left-color: var(--down); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }
.toast-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.toast-head span { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.toast-line { font-size: 12px; color: var(--muted); margin-top: 2px; }
@media (max-width: 900px) {
  .toasts { right: 16px; bottom: 16px; }
}
}
