:root {
  /* default: dim — light enough that cards read as panels, dark enough for a control room */
  --bg: #242931;
  --panel: #2f353f;
  --panel2: #39404b;
  --line: #4a515e;
  --shadow: 0 1px 3px rgba(0,0,0,.30);
  --text: #eceef1;
  --muted: #a7aeb8;
  --orange: #ff8c1a;
  --orange2: #ffb066;
  --green: #4ad97f;
  --red: #ff6b6b;
  --yellow: #f7d154;
  --pad: 14px;
  --cols: repeat(auto-fill, minmax(430px, 1fr));
  --span: 2;
}
body[data-theme="dark"] {
  --bg: #121417;
  --panel: #1e2228;
  --panel2: #272c34;
  --line: #343b45;
  --shadow: 0 1px 3px rgba(0,0,0,.45);
  --text: #e8e6e1;
  --muted: #9aa0a8;
  --orange: #ff7a00;
  --orange2: #ffa64d;
  --green: #3ccf6e;
  --red: #ff4d4d;
  --yellow: #f5c542;
}
body[data-theme="light"] {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel2: #f4f6f9;
  --line: #d3d9e2;
  --shadow: 0 1px 3px rgba(16,24,40,.10);
  --text: #1c2430;
  --muted: #67707e;
  --orange: #e06a00;
  --orange2: #b95400;
  --green: #1f9d52;
  --red: #d63b3b;
  --yellow: #b7860b;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { width: 100%; overflow-x: hidden; }
h1, h2 { margin: 0; font-weight: 600; }
button { font: inherit; }

/* ---------- header ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px var(--pad); background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; letter-spacing: .3px; white-space: nowrap; }
.brand h1 span { color: var(--orange); font-weight: 500; margin-left: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 10px var(--orange); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 10px; white-space: nowrap; }
.controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.controls label { color: var(--muted); font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.controls label.chk { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 6px; }
select, input[type="search"], .msbtn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 13px; font-family: inherit; }
input[type="search"] { min-width: 160px; }
.controls button, button.linkbtn, button.close, button.expand { cursor: pointer; }
.controls > button { background: var(--orange); color: #111; border: 1px solid var(--orange); border-radius: 6px; padding: 6px 12px; font-weight: 600; }
.controls > button:hover { background: var(--orange2); }
.linkbtn { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 4px 8px; font-size: 12px; }
.linkbtn:hover { color: var(--text); border-color: var(--orange); }

/* ---------- health chips ---------- */
.health { display: flex; gap: 8px; padding: 10px var(--pad) 0; flex-wrap: wrap; }
.chip { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; color: var(--muted); box-shadow: var(--shadow); }
.chip b { color: var(--text); font-weight: 600; }
.chip .led { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.chip.warn .led { background: var(--yellow); }
.chip.bad .led { background: var(--red); }
.chip .err { color: var(--red); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; padding: 10px var(--pad) 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi .delta { font-size: 12px; margin-top: 2px; }
.kpi .delta.up { color: var(--green); }
.kpi .delta.down { color: var(--red); }
.kpi .delta.flat { color: var(--muted); }
.kpi.stream-tx { border-top: 2px solid var(--orange); }
.kpi.stream-wager { border-top: 2px solid #4da3ff; }
.kpi.stream-customer { border-top: 2px solid #b386ff; }

/* ---------- filter bar ---------- */
.filterbar { display: flex; align-items: center; gap: 10px; padding: 10px var(--pad) 0; flex-wrap: wrap; }
.fb-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.fb-hint { color: var(--muted); font-size: 12px; }
.ms { position: relative; }
.msbtn { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.msbtn.active { border-color: var(--orange); color: var(--orange2); }
.msbtn .caret { color: var(--muted); font-size: 10px; }
.mspanel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-width: 280px; max-height: 340px; overflow: auto; box-shadow: 0 12px 32px rgba(0,0,0,.5); }
.mspanel .msactions { display: flex; gap: 6px; margin-bottom: 6px; }
.mspanel label { display: flex; align-items: center; gap: 8px; padding: 3px 2px; font-size: 13px; cursor: pointer; }
.mspanel label:hover { color: var(--orange2); }
.mspanel label .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mspanel label .cnt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }

/* ---------- grid & cards ---------- */
.grid { display: grid; grid-template-columns: var(--cols); grid-auto-flow: row dense; gap: 10px; padding: 10px var(--pad) 20px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 6px; min-width: 0; box-shadow: var(--shadow); }
.card.wide { grid-column: span var(--span, 2); }
.card.full { grid-column: 1 / -1; }
.card > header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.card h2 { font-size: 14px; flex: 1; min-width: 0; }
.card h2 small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.card .expand { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; width: 26px; height: 24px; line-height: 1; }
.card .expand:hover { color: var(--orange); border-color: var(--orange); }
.card[data-widget]:not(#breakdownCard) > header h2 { cursor: pointer; }
.card[data-widget]:not(#breakdownCard) > header h2:hover { color: var(--orange2); }
.cardctl { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chart { width: 100%; height: 250px; }
.card.wide .chart { height: 290px; }

/* ---------- day totals & wallboard ---------- */
.viewsec { padding: 0 var(--pad) 20px; }
.secthead { display: flex; align-items: center; gap: 12px; padding: 14px 0 8px; flex-wrap: wrap; }
.secthead h2 { font-size: 15px; }
.secthead h2 small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.secthint { color: var(--muted); font-size: 12px; margin-left: auto; }
.daycards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.daycard { background: var(--panel); border: 1px solid var(--line); border-top: 2px solid var(--accent, var(--orange)); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.daycard .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.daycard .value { font-size: 30px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.daycard .sub { color: var(--muted); font-size: 12px; }
.daycard .cmp { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.daycard .cmp .up { color: var(--green); } .daycard .cmp .down { color: var(--red); } .daycard .cmp .flat { color: var(--muted); }
.daycard .pace { margin-top: 8px; }
.daycard .pacebar { height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.daycard .pacebar i { display: block; height: 100%; background: var(--accent, var(--orange)); }
.daycard .pacetxt { color: var(--muted); font-size: 11px; margin-top: 3px; }
.daycard .spark { margin-left: auto; }
.prodcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.catcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.catcard { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent, var(--orange)); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.catcard .cname { font-size: 13px; font-weight: 700; letter-spacing: .6px; color: var(--accent, var(--orange)); }
.catcard .cggr { font-size: 26px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.catcard .crow { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.catcard .crow b { color: var(--text); font-weight: 600; }
.catcard .cbar { height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.catcard .cbar i { display: block; height: 100%; background: var(--accent, var(--orange)); }
.badge { display: inline-block; font-size: 10px; letter-spacing: .4px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 1px 6px; margin-left: 6px; }
body[data-view="live"] #t_catsec .catcards { grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); }
body[data-view="live"] #t_catsec .catcard { padding: 9px 11px; }
body[data-view="live"] #t_catsec .cggr { font-size: 20px; }
.prodcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
.prodcard .ptop { display: flex; align-items: baseline; gap: 8px; }
.prodcard .ptop { flex-wrap: wrap; }
.prodcard .pname { font-weight: 600; font-size: 13px; white-space: normal; overflow-wrap: anywhere; line-height: 1.25; }
.prodcard .pshare { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.prodcard .pggr { font-size: 22px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.prodcard .prow { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.prodcard .prow b { color: var(--text); font-weight: 600; }
.prodcard .pbar { height: 4px; background: var(--panel2); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.prodcard .pbar i { display: block; height: 100%; }
.bigtiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; padding-top: 14px; }
.bigtile { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); }
.bigtile .label { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .6px; }
.bigtile .value { font-size: 52px; font-weight: 700; line-height: 1.1; margin: 6px 0; font-variant-numeric: tabular-nums; }
.bigtile .sub { color: var(--muted); font-size: 15px; }
.bigtile .delta { font-size: 16px; margin-top: 6px; }
.bigtile .delta.up { color: var(--green); } .bigtile .delta.down { color: var(--red); } .bigtile .delta.flat { color: var(--muted); }

/* the day cards ride along on the live view, in a denser form */
body[data-view="live"] .daycards { grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); }
body[data-view="live"] .daycard { padding: 9px 11px; }
body[data-view="live"] .daycard .value { font-size: 23px; }
body[data-view="live"] .daycard .pace { display: none; }
body[data-view="live"] .secthead { padding: 12px 0 6px; }

/* view switching */
body[data-view="today"] .grid, body[data-view="today"] .filterbar, body[data-view="today"] .kpis,
body[data-view="compact"] .grid, body[data-view="compact"] .filterbar, body[data-view="compact"] .kpis,
body[data-view="compact"] .foot { display: none; }
body[data-view="tables"] .grid > .card:not(.full) { display: none; }
body[data-view="tables"] .filterbar { display: flex; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; max-height: 520px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
thead th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 500; font-size: 12px; z-index: 1; }
tfoot td { color: var(--muted); font-weight: 600; border-top: 1px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.payout { color: var(--orange2); font-weight: 600; }
td.id { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
td.up { color: var(--green); } td.down { color: var(--red); }
tbody tr:hover { background: rgba(255,255,255,.03); }
.bar { display: inline-block; height: 6px; background: var(--orange); border-radius: 3px; vertical-align: middle; }
.tick { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
#m_table tbody tr { cursor: pointer; }
#m_table tbody tr.off { opacity: .38; }
#m_table tbody tr.off .tick { background: var(--muted) !important; }
.spark { display: block; }

/* ---------- modal ---------- */
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); }
.modal-box { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(1600px, 96vw); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,.6); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.modal-head h2 { font-size: 15px; min-width: 160px; }
.m-range { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; flex: 1; min-width: 220px; }
.m-range b { color: var(--text); font-weight: 600; }
.m-range .zoom { color: var(--orange2); }
.linkbtn.zoomed { border-color: var(--orange); color: var(--orange2); }
.modal-chart { cursor: crosshair; user-select: none; }
.modal-ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.navgrp { display: flex; gap: 4px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 5px; }
.navgrp .linkbtn { border: none; padding: 3px 7px; font-size: 13px; line-height: 1; }
.navgrp select { border: none; background: none; padding: 3px 4px; }
.navgrp #m_reset { color: var(--orange2); }
.navgrp .ms .msbtn { border: none; background: none; padding: 3px 6px; font-size: 12px; }
.mspanel .rowlbl { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 3px 0; }
.mspanel .rowlbl input { flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit; font-size: 12px; color-scheme: dark; }
.mspanel .msactions { flex-wrap: wrap; margin-top: 6px; }
.mspanel .apply { width: 100%; margin-top: 6px; border-color: var(--orange); color: var(--orange2); }
.mspanel .hint { color: var(--muted); font-size: 11px; margin-top: 6px; }
.modal-ctl .chk { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.close { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; width: 28px; height: 26px; }
.close:hover { color: var(--red); border-color: var(--red); }
.modal-body { display: flex; gap: 10px; padding: 10px 14px 0; min-height: 0; }
.chartwrap { flex: 1; min-width: 0; position: relative; }
.modal-chart { width: 100%; height: min(48vh, 460px); }
.zoomsel { position: absolute; top: 0; bottom: 26px; background: rgba(255,122,0,.16);
  border-left: 1px solid var(--orange); border-right: 1px solid var(--orange); pointer-events: none; }
.modal-side { width: 320px; flex: none; display: flex; flex-direction: column; gap: 6px; }
.side-head { display: flex; gap: 6px; }
.side-head input { flex: 1; min-width: 0; }
.side-list { overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; max-height: min(42vh, 400px); }
.side-list label { display: flex; align-items: center; gap: 7px; padding: 3px 2px; font-size: 12px; cursor: pointer; }
.side-list label .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-list label:hover { color: var(--orange2); }
.side-list .cnt { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; flex: none; }
.side-list .swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.modal-table { padding: 10px 14px 14px; max-height: 26vh; }

/* ---------- footer ---------- */
.foot { display: flex; justify-content: space-between; gap: 16px; padding: 8px var(--pad) 20px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
#status.err { color: var(--red); }

@media (max-width: 1100px) {
  :root { --cols: 1fr; --pad: 10px; --span: 1; }
  .modal-body { flex-direction: column; }
  .modal-side { width: auto; }
  .modal-chart { height: 34vh; }
}

.daypick input[type="date"] { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font: inherit; font-size: 12px; color-scheme: dark; }
body[data-theme="light"] .daypick input[type="date"] { color-scheme: light; }
.daypick { padding: 3px 6px; }

/* light theme surface tweaks */
body[data-theme="light"] .top, body[data-theme="light"] thead th { background: var(--panel); }
body[data-theme="light"] .dot { box-shadow: 0 0 8px var(--orange); }
body[data-theme="light"] tbody tr:hover { background: rgba(16,24,40,.04); }
body[data-theme="light"] .controls > button { color: #fff; }
body[data-theme="light"] .zoomsel { background: rgba(224,106,0,.14); }
