:root {
  color-scheme: dark;
  --ink: #f4f7fb;
  --muted: #93a1b5;
  --faint: #66758b;
  --canvas: #0b1423;
  --surface: #111f35;
  --surface-2: #172942;
  --line: #263a55;
  --blue: #4c8dff;
  --blue-strong: #2870f0;
  --green: #38c890;
  --red: #ff6b6b;
  --amber: #f6b94b;
  --shadow: 0 18px 60px rgba(0,0,0,.24);
  --radius: 18px;
  --ticket: #f2ead8;
  --ticket-ink: #17202b;
}

[data-theme="light"] {
  color-scheme: light;
  --ink: #172236;
  --muted: #617087;
  --faint: #8a96a7;
  --canvas: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f5f8fb;
  --line: #dce4ee;
  --blue: #236cda;
  --blue-strong: #1558ba;
  --green: #13845f;
  --red: #d84b52;
  --amber: #a96c00;
  --shadow: 0 18px 50px rgba(24,47,78,.11);
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI Variable", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 40%, transparent);
  outline-offset: 2px;
}
.topbar {
  height: 72px;
  padding: 0 max(24px, calc((100vw - 1260px) / 2));
  display: flex;
  align-items: center;
  gap: 38px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--canvas) 91%, transparent);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand { border: 0; background: none; display: flex; align-items: center; gap: 10px; padding: 0; font-weight: 750; font-size: 19px; cursor: pointer; letter-spacing: -.03em; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px 12px 12px 4px; display: grid; place-items: center; background: var(--blue); color: white; letter-spacing: -.08em; }
.desktop-nav { display: flex; height: 100%; gap: 4px; }
.nav-item { border: 0; border-bottom: 2px solid transparent; padding: 2px 14px 0; background: transparent; color: var(--muted); cursor: pointer; }
.nav-item.active { color: var(--ink); border-bottom-color: var(--blue); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.sync-state { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 7px; }
.sync-state i { width: 7px; height: 7px; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 14%, transparent); }
.sync-state.saving i { background: var(--amber); }
.sync-state.error i { background: var(--red); }
.theme-switch { cursor: pointer; }
.theme-switch input { position: absolute; opacity: 0; pointer-events: none; }
.theme-switch span { width: 52px; height: 30px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: space-around; padding: 2px; position: relative; }
.theme-switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; border-radius: 50%; background: var(--blue); transition: transform .22s ease; }
.theme-switch input:checked + span::after { transform: translateX(21px); }
.theme-switch b { z-index: 1; font-size: 11px; font-weight: 500; }
.button { border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); padding: 10px 15px; cursor: pointer; font-weight: 650; }
.button:hover { border-color: color-mix(in srgb, var(--blue) 60%, var(--line)); }
.button.primary { background: var(--blue-strong); border-color: var(--blue-strong); color: white; }
.button.scan { color: var(--blue); background: color-mix(in srgb, var(--blue) 9%, var(--surface)); }
.button.danger { color: var(--red); }
.button.compact { padding: 9px 14px; }
.button.ghost { background: transparent; }
main { width: min(1260px, calc(100% - 48px)); margin: 0 auto; padding: 38px 0 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-head h1 { margin: 0; font-size: clamp(28px, 4vw, 43px); line-height: 1.03; letter-spacing: -.055em; }
.page-head p { color: var(--muted); margin: 8px 0 0; max-width: 620px; }
.eyebrow { color: var(--blue); font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.metrics { display: grid; grid-template-columns: 1.25fr repeat(3, 1fr); gap: 14px; margin-bottom: 22px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-height: 126px; position: relative; overflow: hidden; }
.metric.hero { background: var(--blue-strong); color: white; border-color: transparent; }
.metric.hero::after { content: ""; position: absolute; width: 150px; height: 150px; border: 24px solid rgba(255,255,255,.08); border-radius: 50%; right: -50px; top: -60px; }
.metric-label { color: var(--muted); font-size: 13px; margin-bottom: 13px; }
.metric.hero .metric-label, .metric.hero .metric-foot { color: rgba(255,255,255,.72); }
.metric-value { font-size: 30px; line-height: 1; font-weight: 730; letter-spacing: -.045em; }
.metric-foot { color: var(--muted); font-size: 12px; margin-top: 13px; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .9fr); gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 19px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.text-button { border: 0; color: var(--blue); background: none; cursor: pointer; padding: 0; font-weight: 650; }
.empty { padding: 45px 24px; text-align: center; color: var(--muted); overflow-wrap: anywhere; }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 5px; }
.bet-row { display: grid; grid-template-columns: 56px minmax(150px, 1fr) 90px 104px 28px; gap: 14px; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--line); cursor: pointer; }
.bet-row:last-child { border-bottom: 0; }
.bet-row:hover { background: var(--surface-2); }
.date-tile { width: 46px; height: 48px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: 10px; line-height: 1.05; }
.date-tile b { color: var(--ink); font-size: 18px; }
.bet-name { font-weight: 680; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bet-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.status { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 99px; padding: 5px 9px; font-size: 12px; font-weight: 700; width: max-content; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.won { color: var(--green); background: color-mix(in srgb, var(--green) 12%, transparent); }
.status.lost { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.status.pending { color: var(--amber); background: color-mix(in srgb, var(--amber) 12%, transparent); }
.status.push, .status.void { color: var(--muted); background: color-mix(in srgb, var(--muted) 12%, transparent); }
.member-list { padding: 8px 20px; }
.member-line { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.member-line:last-child { border: 0; }
.avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 12px; color: white; }
.member-line small { color: var(--muted); display: block; }
.member-line .balance { font-weight: 750; }
.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.search { flex: 1; min-width: 210px; position: relative; }
.search input, .field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--ink); padding: 11px 12px; }
.search input { padding-left: 38px; }
.search::before { content: "⌕"; position: absolute; left: 13px; top: 9px; color: var(--muted); font-size: 19px; }
.toolbar select { border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--ink); padding: 10px 34px 10px 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); text-align: left; font-size: 12px; font-weight: 600; padding: 12px 18px; border-bottom: 1px solid var(--line); }
td { padding: 15px 18px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr[data-bet-id] { cursor: pointer; }
tbody tr[data-bet-id]:hover { background: var(--surface-2); }
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart-body { padding: 20px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 62px; gap: 12px; align-items: center; margin-bottom: 14px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bar-track { height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; min-width: 2px; border-radius: inherit; background: var(--blue); }
.bar-fill.green { background: var(--green); }
.bar-stat { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.settle-hero { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.balance-card { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; }
.balance-card span { color: var(--muted); font-size: 12px; }
.balance-card strong { display: block; font-size: 24px; margin-top: 6px; }
.debt-list { padding: 8px 20px; }
.debt { display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 14px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.debt:last-child { border: 0; }
.debt-to { text-align: right; }
.debt-arrow { color: var(--muted); }
.debt strong { font-size: 17px; }
.modal-shell { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
.modal-shell[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,8,17,.74); backdrop-filter: blur(6px); }
.modal-card { position: relative; width: min(900px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.modal-close { position: absolute; z-index: 2; top: 15px; right: 16px; width: 34px; height: 34px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 50%; cursor: pointer; font-size: 22px; line-height: 1; }
.form-head { padding: 27px 28px 20px; border-bottom: 1px solid var(--line); }
.form-head h2 { margin: 0; font-size: 25px; letter-spacing: -.04em; }
.form-head p { margin: 5px 0 0; color: var(--muted); }
.form-section { padding: 21px 28px; border-bottom: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; }
.field { min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field.span-4 { grid-column: span 4; }
.field label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px 2px; }
.field textarea { min-height: 70px; resize: vertical; }
.leg-card { margin-bottom: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-2); }
.leg-card:last-child { margin-bottom: 0; }
.leg-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 700; }
.leg-title .avatar { width: 28px; height: 28px; }
.leg-grid { display: grid; grid-template-columns: 1fr 1fr 1.25fr .72fr .72fr .8fr; gap: 9px; }
.form-actions { display: flex; justify-content: space-between; align-items: center; padding: 18px 28px 26px; gap: 14px; }
.form-actions > div { display: flex; gap: 9px; margin-left: auto; }
.ticket-view { background: var(--ticket); color: var(--ticket-ink); padding: 32px; }
.ticket-view .modal-close { color: var(--ticket-ink); background: rgba(255,255,255,.65); border-color: rgba(0,0,0,.12); }
.ticket-brand { font-weight: 800; font-size: 20px; letter-spacing: -.04em; }
.ticket-match { font-size: 29px; letter-spacing: -.045em; font-weight: 760; margin: 24px 0 5px; }
.ticket-meta { opacity: .62; margin-bottom: 24px; }
.ticket-leg { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; padding: 14px 0; border-top: 1px dashed rgba(0,0,0,.22); }
.ticket-leg:last-of-type { border-bottom: 1px dashed rgba(0,0,0,.22); }
.ticket-leg .avatar { width: 30px; height: 30px; }
.ticket-leg small { display: block; opacity: .62; margin-top: 3px; }
.ticket-total { display: flex; justify-content: space-between; margin-top: 18px; font-size: 18px; }
.rotation-note { display: flex; align-items: center; gap: 11px; margin: 16px 0 4px; padding: 12px 14px; border-radius: 12px; background: rgba(35,108,218,.09); }
.rotation-note span { display: grid; gap: 2px; }
.rotation-note small, .rotation-field small { color: var(--muted); }
.rotation-field { margin-bottom: 15px; padding: 14px; border-radius: 12px; background: var(--surface-2); }
.rotation-field small { display: block; margin-top: 6px; }
.ticket-actions { display: flex; gap: 9px; margin-top: 24px; }
.ticket-actions .button { background: rgba(255,255,255,.55); border-color: rgba(0,0,0,.15); color: var(--ticket-ink); }
.ticket-actions .primary { background: #236cda; color: white; border-color: #236cda; }
.ticket-actions .danger { color: #a52323; border-color: rgba(165,35,35,.35); margin-right: auto; }
.scan-drop { border: 2px dashed var(--line); border-radius: 17px; padding: 32px 20px; text-align: center; background: var(--surface-2); cursor: pointer; display: block; }
.scan-drop:hover { border-color: var(--blue); }
.scan-drop input { position: absolute; opacity: 0; pointer-events: none; }
.scan-icon { width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; margin: 0 auto 13px; background: color-mix(in srgb, var(--blue) 14%, var(--surface)); color: var(--blue); font-size: 25px; }
.scan-drop strong { display: block; font-size: 17px; }
.scan-drop small { color: var(--muted); }
.scan-preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: 14px; background: var(--canvas); margin-bottom: 16px; }
.scan-progress { padding: 32px 18px; text-align: center; }
.scan-progress i { display: block; width: 34px; height: 34px; margin: 0 auto 14px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
.scan-result { padding: 15px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 15px; margin-bottom: 10px; }
.scan-result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.confidence { font-size: 11px; border-radius: 99px; padding: 4px 8px; color: var(--green); background: color-mix(in srgb, var(--green) 12%, transparent); }
.confidence.medium { color: var(--amber); background: color-mix(in srgb, var(--amber) 12%, transparent); }
.confidence.low { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.scan-fields { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: end; }
.scan-summary { font-weight: 650; }
.scan-warnings { color: var(--amber); font-size: 13px; margin: 12px 0 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 150; bottom: 25px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: var(--canvas); padding: 11px 16px; border-radius: 11px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-nav { display: none; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

@media (max-width: 850px) {
  .desktop-nav, .sync-state { display: none; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .dashboard-grid, .analytics-grid { grid-template-columns: 1fr; }
  .settle-hero { grid-template-columns: repeat(2, 1fr); }
  .leg-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field.span-4 { grid-column: span 2; }
}
@media (max-width: 600px) {
  .topbar { height: 62px; padding: 0 16px; }
  .brand > span:last-child, .top-actions .primary { display: none; }
  .top-actions .scan { font-size: 0; padding: 8px 11px; }
  .top-actions .scan::after { content: "▣"; font-size: 18px; }
  .theme-switch { margin-left: auto; }
  main { width: calc(100% - 28px); padding-top: 25px; padding-bottom: 100px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .page-head .button { display: none; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric { padding: 16px; min-height: 112px; }
  .metric.hero { grid-column: span 2; }
  .metric-value { font-size: 25px; }
  .bet-row { grid-template-columns: 48px 1fr auto; padding: 14px; }
  .bet-row > :nth-child(3), .bet-row > :nth-child(5) { display: none; }
  .panel-head { padding: 16px; }
  .member-list { padding: 7px 16px; }
  .mobile-nav { display: grid; grid-template-columns: 1fr 1fr 62px 1fr 1fr; align-items: center; position: fixed; z-index: 50; bottom: 0; left: 0; right: 0; height: 70px; padding: 6px 8px max(6px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 94%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(18px); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; gap: 1px; font-size: 10px; }
  .mobile-nav button span { font-size: 19px; }
  .mobile-nav button.active { color: var(--blue); }
  .mobile-nav .mobile-add { width: 48px; height: 48px; border-radius: 16px; background: var(--blue-strong); color: white; font-size: 25px; margin: -18px auto 0; box-shadow: 0 8px 22px color-mix(in srgb, var(--blue) 35%, transparent); }
  .modal-shell { padding: 0; align-items: end; }
  .modal-card { max-height: 94vh; border-radius: 24px 24px 0 0; }
  .form-head, .form-section { padding-left: 18px; padding-right: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.span-2, .field.span-4 { grid-column: span 1; }
  .scan-fields { grid-template-columns: 1fr; }
  .leg-grid { grid-template-columns: 1fr 1fr; }
  .form-actions { padding: 16px 18px 22px; }
  .form-actions .danger { font-size: 0; }
  .form-actions .danger::after { content: "Delete"; font-size: 14px; }
  .ticket-view { padding: 25px 20px; }
  .ticket-match { font-size: 24px; }
  .settle-hero { grid-template-columns: 1fr 1fr; }
  .debt { grid-template-columns: 1fr 20px 1fr; }
  .debt .button { grid-column: 1 / -1; }
  .bar-row { grid-template-columns: 92px 1fr 54px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
