/* Commodity Desk - trading-floor dark theme.
   Numbers are monospaced and tabular so digits do not jitter as they tick. */

:root {
  --bg: #0b0e13;
  --panel: #12161f;
  --panel-2: #161b26;
  --line: #1e2634;
  --line-soft: #19202c;
  --text: #e6edf3;
  --muted: #8b95a6;
  --dim: #5f6a7a;
  --up: #3fb950;
  --down: #f85149;
  --warn: #e0b64a;
  --info: #58a6ff;
  --accent: #bc8cff;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
button { font-family: inherit; cursor: pointer; }

/* ------------------------------------------------------------------ header */

header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px;
  background: rgba(11, 14, 19, 0.93);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, #e0b64a, #d98555);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800; color: #0b0e13;
}
.brand small { display: block; font-size: 10px; font-weight: 400; color: var(--dim); letter-spacing: 0.02em; }

.header-spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 11px; color: var(--muted);
  white-space: nowrap;
}
.pill.exact { border-color: rgba(63,185,80,0.4); color: var(--up); }
.pill.proxy { border-color: rgba(224,182,74,0.4); color: var(--warn); }
.pill.bad   { border-color: rgba(248,81,73,0.45); color: var(--down); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--up); }
.dot.stale { background: var(--warn); }
.dot.dead  { background: var(--down); }
.dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.icon-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 5px 10px; font-size: 12px;
}
.icon-btn:hover { color: var(--text); border-color: #2b3648; }
.icon-btn.on { color: var(--info); border-color: rgba(88,166,255,0.45); }

/* ------------------------------------------------------------------- board */

main { padding: 16px; max-width: 1560px; margin: 0 auto; }

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px 11px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.12s;
}
.tile:hover { border-color: #2f3b50; transform: translateY(-1px); }
.tile::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--tile-color, var(--info));
  opacity: 0.85;
}

.tile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tile-name { font-weight: 640; font-size: 14px; letter-spacing: -0.01em; }
.tile-sub { font-size: 10.5px; color: var(--dim); margin-top: 1px; }

.tile-price { font-size: 25px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.tile-change { font-size: 11.5px; margin-top: 2px; }

.tile-spark { height: 40px; margin: 9px 0 4px; }
.tile-spark canvas { width: 100%; height: 100%; display: block; }

.contract {
  border-top: 1px solid var(--line-soft);
  margin-top: 8px; padding-top: 9px;
}
.contract-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 10.5px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 5px;
}
.contract-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.contract-label { font-size: 11px; color: var(--muted); }
.contract-value { font-size: 12.5px; font-weight: 550; }

.timebar { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; margin: 7px 0 6px; }
.timebar > div { height: 100%; background: var(--info); transition: width 0.9s linear; }
.timebar.urgent > div { background: var(--down); }

.edge-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 640;
  font-family: var(--mono);
}
.edge-badge.pos { background: rgba(63,185,80,0.14); color: var(--up); border: 1px solid rgba(63,185,80,0.3); }
.edge-badge.neg { background: rgba(248,81,73,0.1); color: var(--down); border: 1px solid rgba(248,81,73,0.22); }
.edge-badge.flat { background: rgba(139,149,166,0.1); color: var(--muted); border: 1px solid var(--line); }

.probbar {
  display: flex; height: 18px; border-radius: 5px; overflow: hidden;
  border: 1px solid var(--line); margin-top: 3px; font-size: 10px; font-family: var(--mono);
}
.probbar > div { display: grid; place-items: center; transition: flex-basis 0.5s ease; overflow: hidden; white-space: nowrap; }
.probbar .p-model  { background: rgba(88,166,255,0.28); color: #cfe4ff; }
.probbar .p-market { background: rgba(139,149,166,0.14); color: var(--muted); }

/* ------------------------------------------------------------- lower panels */

.lower {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px; margin-top: 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
}
.panel h3 {
  margin: 0 0 10px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--dim);
  display: flex; align-items: center; justify-content: space-between;
}

table.matrix { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11px; }
table.matrix th { color: var(--dim); font-weight: 500; padding: 4px 3px; text-align: center; }
table.matrix th.row-head { text-align: left; }
table.matrix td { padding: 4px 3px; text-align: center; border-radius: 4px; }

.ratio-row { display: flex; justify-content: space-between; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.ratio-row:last-child { border-bottom: none; }
.ratio-note { font-size: 10.5px; color: var(--dim); margin-top: 2px; max-width: 34ch; line-height: 1.35; }

.signal { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 12px; line-height: 1.45; }
.signal:last-child { border-bottom: none; }
.signal-mark { width: 3px; border-radius: 2px; flex: none; }
.signal.good   .signal-mark { background: var(--up); }
.signal.warn   .signal-mark { background: var(--warn); }
.signal.danger .signal-mark { background: var(--down); }
.signal.info   .signal-mark { background: var(--info); }
.signal.muted  .signal-mark { background: var(--dim); }
.signal.muted  { color: var(--muted); }
.signal-inst { font-family: var(--mono); font-size: 10px; color: var(--dim); text-transform: uppercase; }

/* ------------------------------------------------------------------ detail */

.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.back-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 7px 12px; font-size: 13px;
}
.back-btn:hover { color: var(--text); }
.detail-title { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.detail-price { font-size: 30px; font-weight: 620; letter-spacing: -0.025em; font-family: var(--mono); }

.range-bar { display: flex; gap: 4px; flex-wrap: wrap; }
.range-bar button {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  padding: 5px 11px; border-radius: 7px; font-size: 11.5px; font-family: var(--mono);
}
.range-bar button.active { background: var(--panel-2); color: var(--text); border-color: #38455c; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 342px; gap: 12px; align-items: start; }
@media (max-width: 1080px) { .detail-grid { grid-template-columns: 1fr; } }

.chart-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.chart-wrap canvas { width: 100%; height: 440px; display: block; border-radius: 6px; }
@media (max-width: 700px) { .chart-wrap canvas { height: 330px; } }

.chart-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 9px; font-size: 11px; }
.toggle { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--info); margin: 0; }

.readout { font-family: var(--mono); font-size: 11px; color: var(--muted); min-height: 15px; }
.readout b { color: var(--text); font-weight: 550; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 1px; background: var(--line-soft); border-radius: 8px; overflow: hidden; }
.stat { background: var(--panel); padding: 9px 10px; }
.stat-label { font-size: 9.5px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 14px; font-weight: 600; font-family: var(--mono); margin-top: 2px; }
.stat-note { font-size: 9.5px; color: var(--dim); margin-top: 1px; }

.trade-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.trade-head { padding: 11px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.trade-head .t { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--dim); }
.trade-body { padding: 12px 14px; }

.kv { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; font-size: 12.5px; }
.kv + .kv { border-top: 1px solid var(--line-soft); }
.kv-label { color: var(--muted); }
.kv-value { font-family: var(--mono); font-weight: 550; }

.side-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line-soft); border-radius: 8px; overflow: hidden; margin: 10px 0; }
.side { background: var(--panel-2); padding: 10px 11px; }
.side-title { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.side.best { background: rgba(63,185,80,0.07); box-shadow: inset 0 0 0 1px rgba(63,185,80,0.28); }
.side-ev { font-size: 16px; font-weight: 650; font-family: var(--mono); margin: 3px 0 1px; }

.book { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-family: var(--mono); font-size: 11px; }
.book-side { display: flex; flex-direction: column; gap: 2px; }
.book-row { display: flex; justify-content: space-between; padding: 2px 5px; border-radius: 3px; position: relative; }
.book-row span { position: relative; z-index: 1; }
.book-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.book-yes .book-fill { background: rgba(63,185,80,0.16); }
.book-no  .book-fill { background: rgba(248,81,73,0.14); }

.imbalance-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; display: flex; margin-top: 8px; }
.imbalance-bar .y { background: var(--up); }
.imbalance-bar .n { background: var(--down); }

.upcoming { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 3px; }
.up-chip { flex: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; font-size: 10.5px; font-family: var(--mono); color: var(--muted); }

.empty { color: var(--dim); font-size: 12px; padding: 14px 0; text-align: center; }

/* ----------------------------------------------------------------- alerts */

.alert-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-bottom: 10px; }
.alert-form select, .alert-form input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 6px 8px; font-size: 12px; font-family: var(--mono); min-width: 0;
}
.alert-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); font-size: 12px; }
.alert-row:last-child { border-bottom: none; }
.alert-row .x { margin-left: auto; background: none; border: none; color: var(--dim); font-size: 15px; line-height: 1; padding: 0 3px; }
.alert-row .x:hover { color: var(--down); }
.alert-row.fired { color: var(--warn); }

.toast-wrap { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: 330px; }
.toast {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  animation: slidein 0.22s ease;
}
.toast.good { border-left-color: var(--up); }
.toast.bad  { border-left-color: var(--down); }
@keyframes slidein { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- settings */

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 300; display: grid; place-items: center; padding: 16px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(460px, 100%); max-height: 86vh; overflow: auto; }
.sheet-head { padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.sheet-body { padding: 14px 16px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .field select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 8px 10px; font-size: 13px; font-family: var(--mono);
}
.field .hint { font-size: 11px; color: var(--dim); margin-top: 4px; line-height: 1.45; }

footer { padding: 22px 16px 34px; text-align: center; color: var(--dim); font-size: 11px; line-height: 1.6; }
footer a { color: var(--muted); }

@media (max-width: 640px) {
  main { padding: 11px; }
  header { padding: 9px 11px; gap: 8px; justify-content: space-between; }
  .brand small { display: none; }
  /* Two rows on a phone: brand and Settings on the first, status pills on the
     second. Keeping them on one line is what pushed the button off the edge. */
  .header-spacer { display: none; }
  #header-status { order: 3; flex: 1 1 100%; justify-content: flex-start !important; }
  .pill { font-size: 10.5px; padding: 3px 8px; }
  .tile-price { font-size: 22px; }
  .detail-grid { gap: 10px; }
}

/* Model-vs-market probability bar: fill is the model, the tick is the market. */
.pb {
  position: relative; height: 17px; margin-top: 4px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; overflow: hidden;
}
.pb-fill { position: absolute; top: 0; bottom: 0; left: 0; background: rgba(88,166,255,0.30); transition: width 0.5s ease; }
.pb-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--warn); transition: left 0.5s ease; }
.pb-txt {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 6px; font-size: 9.5px; font-family: var(--mono); color: var(--muted); letter-spacing: 0.02em;
}
.pb-txt b { color: #cfe4ff; font-weight: 600; }
.pb-txt i { color: var(--warn); font-style: normal; }

/* Reads can run long when several contracts are interesting at once. Cap it so
   one busy panel does not stretch the whole row. */
.scroll-cap { max-height: 340px; overflow-y: auto; }
.scroll-cap::-webkit-scrollbar { width: 6px; }
.scroll-cap::-webkit-scrollbar-thumb { background: #232c3c; border-radius: 3px; }
.lower { align-items: start; }
