:root {
  --bg: #08110f;
  --panel: #0e1b18;
  --panel-2: #12231f;
  --line: #223832;
  --line-soft: #192c27;
  --ink: #edf3ef;
  --muted: #91a59e;
  --mint: #75dfb1;
  --mint-deep: #173c31;
  --amber: #f3c56f;
  --red: #ff8c86;
  --shadow: 0 18px 55px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 82% -10%, rgba(55, 132, 104, .2), transparent 32rem),
    var(--bg);
  color: var(--ink);
  font: 14px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.topbar {
  min-height: 82px;
  padding: 16px max(22px, 4vw);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--mint);
  color: #06100d;
  font: 700 21px/1 Georgia, serif;
}

.brand b, .brand small { display: block; }
.brand b { font-size: 16px; }
.brand small { color: var(--muted); font-size: 11px; margin-top: 1px; }

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.refresh-state {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.dataset-picker, .portfolio-picker, .day-picker {
  display: flex;
  align-items: center;
  gap: 9px;
}

.dataset-picker > span, .portfolio-picker > span, .day-picker > span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

select, input {
  min-height: 39px;
  padding: 8px 11px;
  color: var(--ink);
  border: 1px solid #2c4840;
  border-radius: 8px;
  outline: none;
  background: #10211d;
}

select:focus, input:focus { border-color: var(--mint); }

.button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid #2c4840;
  border-radius: 8px;
  color: var(--ink);
  background: #10211d;
}

.button.ghost { background: transparent; }
.button.primary { margin-left: 14px; color: #06100d; background: var(--mint); border-color: var(--mint); font-weight: 700; }
.button:disabled { opacity: .4; cursor: default; }

.main-nav {
  height: 54px;
  padding: 0 max(22px, 4vw);
  display: flex;
  align-items: stretch;
  gap: 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 17, 15, .72);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
}

.nav-item {
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 2px;
  color: var(--muted);
  background: transparent;
}

.nav-item:hover, .nav-item.active { color: var(--ink); }
.nav-item.active { border-bottom-color: var(--mint); }

main { max-width: 1480px; margin: 0 auto; padding: 30px max(22px, 4vw) 90px; }
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

.context-strip {
  min-height: 48px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(17, 34, 30, .66);
}

.context-strip > div { display: flex; align-items: center; gap: 9px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 5px rgba(117, 223, 177, .09); }
.context-facts { color: var(--muted); font-size: 12px; flex-wrap: wrap; justify-content: flex-end; }
.context-facts span + span::before { content: "·"; margin-right: 9px; color: #47645b; }

.page-heading {
  margin: 34px 0 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}

.page-heading.compact { align-items: start; margin-top: 10px; }
.eyebrow { display: block; margin-bottom: 6px; color: var(--mint); font: 700 10px/1.4 ui-monospace, monospace; letter-spacing: .15em; text-transform: uppercase; }
.page-heading h1 { font: 600 clamp(27px, 3.3vw, 42px)/1.12 Georgia, "Noto Serif SC", serif; letter-spacing: -.035em; }
.page-heading p { max-width: 720px; margin-top: 9px; color: var(--muted); }
.portfolio-picker { min-width: min(100%, 360px); flex-direction: column; align-items: stretch; }
.portfolio-picker select { min-width: 310px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 11px;
  margin-bottom: 20px;
}

.metric {
  min-height: 106px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(145deg, #11231f, #0c1816);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
}

.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric b { display: block; margin-top: 9px; font: 600 25px/1.1 Georgia, serif; }
.metric small { display: block; margin-top: 6px; color: #6f877f; font-size: 10px; }
.positive { color: var(--mint) !important; }
.negative { color: var(--red) !important; }
.muted { color: var(--muted); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, .75fr);
  gap: 16px;
  margin-bottom: 28px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(150deg, rgba(18, 35, 31, .96), rgba(10, 23, 20, .96));
  box-shadow: var(--shadow);
}

.panel-head {
  min-height: 68px;
  padding: 17px 19px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-head h2, .section-head h2 { font-size: 17px; }
.panel-head .eyebrow, .section-head .eyebrow { margin-bottom: 3px; }

.equity-chart { min-height: 268px; padding: 16px 18px 12px; }
.equity-chart svg { width: 100%; height: 220px; overflow: visible; }
.chart-grid { stroke: #264039; stroke-width: 1; }
.chart-zero { stroke: #6f877f; stroke-dasharray: 4 5; }
.chart-line { fill: none; stroke: var(--mint); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: url("#area-fill"); }
.chart-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.empty-state { min-height: 180px; display: grid; place-items: center; color: var(--muted); }

.rule-list { list-style: none; margin: 0; padding: 8px 19px 2px; }
.rule-list li { padding: 14px 0; display: grid; grid-template-columns: 80px 1fr; gap: 12px; border-bottom: 1px solid var(--line-soft); }
.rule-list span { color: var(--muted); }
.rule-note { margin: 14px 19px 18px; padding: 11px 12px; border-radius: 7px; color: #b8cbc4; background: var(--mint-deep); font-size: 12px; }

.section-head {
  margin: 0 0 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.ledger-tools { display: flex; gap: 9px; }
.ledger-tools input { width: 220px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #0b1815; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; color: var(--muted); background: #13241f; font-size: 11px; font-weight: 600; letter-spacing: .03em; }
tbody tr { transition: background .15s ease; }
tbody tr[data-bet-id] { cursor: pointer; }
tbody tr:hover { background: #10231e; }
tbody tr:last-child td { border-bottom: 0; }
.cell-main, .cell-sub { display: block; }
.cell-sub { margin-top: 2px; color: var(--muted); font-size: 11px; }
.pill { display: inline-flex; padding: 3px 7px; border-radius: 5px; color: var(--mint); background: var(--mint-deep); font-size: 11px; }
.pill.warn { color: var(--amber); background: #352c18; }
.pager { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 12px; }
.pager > div { display: flex; align-items: center; gap: 12px; }

.daily-toolbar {
  margin-bottom: 18px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.segmented { display: flex; gap: 5px; }
.segmented button, .research-tab {
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
}
.segmented button:hover, .segmented button.active, .research-tab:hover, .research-tab.active { color: var(--ink); background: var(--mint-deep); border-color: #2b5246; }
.daily-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(320px, .55fr); gap: 16px; }
.day-detail { min-height: 300px; align-self: start; position: sticky; top: 76px; }
.day-bets { max-height: 620px; overflow: auto; padding: 5px 17px 15px; }
.day-bet { padding: 13px 2px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.day-bet:last-child { border-bottom: 0; }
.day-bet > div { display: flex; justify-content: space-between; gap: 12px; }
.day-bet small { display: block; margin-top: 3px; color: var(--muted); }

.research-nav { display: flex; gap: 7px; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); overflow: auto; }
.research-panel { display: none; }
.research-panel.active { display: block; }
.funnel-row { padding: 12px 19px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-soft); }
.funnel-row:last-child { border-bottom: 0; }
.funnel-row small { display: block; color: var(--muted); }
.compact-list { max-height: 410px; overflow: auto; }
.compact-item { padding: 11px 19px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line-soft); }
.compact-item small { display: block; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 13px; }
.card { padding: 19px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.card h3 { margin-bottom: 15px; }
.card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card-stats span { display: block; color: var(--muted); font-size: 11px; }
.card-stats b { font-size: 18px; }
.notice { padding: 14px 16px; border: 1px solid var(--line); border-radius: 9px; color: #b7c9c2; background: #10211d; }
.notice.error { margin-bottom: 18px; color: #ffd0cd; border-color: #673532; background: #281614; }
#matrix-table, #runs-table { margin-top: 16px; }

.drawer-mask { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .58); }
.drawer {
  width: min(540px, 94vw);
  height: 100vh;
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  transform: translateX(102%);
  transition: transform .22s ease;
  border-left: 1px solid var(--line);
  background: #0b1714;
  box-shadow: -24px 0 70px rgba(0, 0, 0, .5);
}
.drawer.open { transform: translateX(0); }
.drawer-head { min-height: 82px; padding: 19px 21px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 18px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: transparent; font-size: 25px; line-height: 1; }
.drawer-content { height: calc(100vh - 82px); padding: 20px; overflow: auto; }
.detail-hero { padding: 18px; border-radius: 10px; background: linear-gradient(145deg, #173229, #10201c); }
.detail-hero h3 { font-size: 20px; }
.detail-hero p { margin-top: 5px; color: var(--muted); }
.detail-grid { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-item { padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.detail-item span { display: block; color: var(--muted); font-size: 11px; }
.detail-item b { display: block; margin-top: 4px; font-size: 16px; }
.detail-section { margin-top: 22px; }
.detail-section h3 { margin-bottom: 10px; font-size: 14px; }
.change-line { padding: 17px; border: 1px solid var(--line); border-radius: 9px; background: #0e1e1a; }
.change-line strong { font-size: 25px; }
.change-line small { display: block; margin-top: 5px; color: var(--muted); }

.login-body { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: min(390px, calc(100vw - 34px)); padding: 34px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); box-shadow: var(--shadow); }
.login-card .mark { width: 43px; height: 43px; margin-bottom: 20px; display: grid; place-items: center; border-radius: 9px; color: #06100d; background: var(--mint); font: 700 22px Georgia, serif; }
.login-card p { margin: 7px 0 22px; color: var(--muted); }
.login-card label { display: block; margin: 12px 0; color: var(--muted); }
.login-card input { width: 100%; display: block; margin-top: 6px; }
.login-card button { width: 100%; min-height: 42px; margin-top: 12px; border: 0; border-radius: 8px; color: #06100d; background: var(--mint); font-weight: 700; }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid, .daily-layout { grid-template-columns: 1fr; }
  .day-detail { position: static; }
}

@media (max-width: 760px) {
  .topbar, .top-actions, .page-heading, .daily-toolbar, .section-head { align-items: stretch; flex-direction: column; }
  .top-actions { width: 100%; gap: 8px; }
  .dataset-picker { justify-content: space-between; }
  .dataset-picker select { flex: 1; }
  .refresh-state { order: 3; }
  .portfolio-picker, .portfolio-picker select { width: 100%; min-width: 0; }
  .context-strip { align-items: flex-start; flex-direction: column; }
  .context-facts { justify-content: flex-start; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .ledger-tools { width: 100%; }
  .ledger-tools input { min-width: 0; flex: 1; }
  .day-picker { justify-content: space-between; }
  .segmented { overflow: auto; }
}

@media (max-width: 480px) {
  main { padding-inline: 14px; }
  .topbar, .main-nav { padding-inline: 14px; }
  .main-nav { gap: 22px; }
  .metrics { gap: 8px; }
  .metric { min-height: 94px; padding: 14px; }
  .metric b { font-size: 21px; }
  .rule-list li { grid-template-columns: 1fr; gap: 3px; }
  .ledger-tools { flex-direction: column; }
  .pager { align-items: flex-start; flex-direction: column; }
  .button.primary { display: block; margin: 12px 0 0; }
}
