:root {
  --navy: #101b36;
  --navy-2: #172848;
  --ink: #172033;
  --muted: #6f7a90;
  --line: #e4e9f2;
  --canvas: #f3f6fb;
  --panel: #ffffff;
  --gold: #d8a84b;
  --gold-soft: #fff5df;
  --blue: #315be8;
  --blue-soft: #ebf0ff;
  --green: #15866c;
  --green-soft: #e8f7f2;
  --red: #d1495b;
  --red-soft: #fff0f2;
  --shadow: 0 12px 30px rgba(28, 43, 76, 0.07);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #dfe9ff, transparent 42%), var(--canvas); }
.auth-card { width: min(100%, 430px); padding: 28px; border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: 0 22px 60px rgba(31,47,80,.14); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand strong, .auth-brand span { display: block; }
.auth-brand span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.auth-card h1 { margin-top: 5px; font-size: 23px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 236px;
  padding: 26px 18px 22px;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 12% 90%, rgba(216,168,75,.13), transparent 34%),
    linear-gradient(165deg, var(--navy), #0d1730 68%);
  color: #fff;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 25px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  font-size: 21px; font-weight: 800; color: var(--navy); background: linear-gradient(145deg, #f5d994, var(--gold));
  box-shadow: 0 8px 22px rgba(216,168,75,.2);
}
.brand-logo { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 13px; object-fit: cover; box-shadow: 0 8px 22px rgba(16,27,54,.18); }
.admin-main { max-width: 1500px; margin: 0 auto; padding: 0 34px 46px; }
.admin-main .topbar { position: sticky; top: 0; z-index: 10; background: rgba(243,246,251,.96); backdrop-filter: blur(12px); }
.brand strong { display: block; font-size: 15px; letter-spacing: .02em; }
.brand span { display: block; margin-top: 3px; color: #98a5c0; font-size: 11px; }
.nav-list { display: grid; gap: 7px; margin-top: 22px; }
.nav-item {
  border: 0; border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 12px;
  color: #aeb9d0; background: transparent; text-align: left; transition: .2s ease;
}
.nav-item span { width: 20px; text-align: center; font-weight: 800; color: #7485a9; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: linear-gradient(90deg, rgba(216,168,75,.23), rgba(216,168,75,.07)); box-shadow: inset 3px 0 0 var(--gold); }
.nav-item.active span { color: #f0c66e; }
.sidebar-note {
  margin-top: auto; padding: 15px; border: 1px solid rgba(255,255,255,.08); border-radius: 14px;
  color: #cad2e3; font-size: 12px; background: rgba(255,255,255,.035);
}
.sidebar-note small { display: block; margin: 5px 0 0 14px; color: #7787a7; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #46d6a8; box-shadow: 0 0 0 4px rgba(70,214,168,.1); }

.main { min-height: 100vh; margin-left: 236px; padding: 0 34px 46px; }
.topbar {
  min-height: 94px; display: flex; align-items: center; justify-content: space-between; gap: 20px;
  border-bottom: 1px solid var(--line); margin-bottom: 28px;
}
h1, h2, p { margin: 0; }
h1 { margin-top: 2px; font-size: 24px; letter-spacing: -.02em; }
h2 { font-size: 18px; letter-spacing: -.015em; }
.eyebrow { color: #8a94a8; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.user-menu { display: flex; align-items: center; gap: 8px; padding-left: 8px; border-left: 1px solid var(--line); font-size: 11px; }
.user-menu #connectionStatus { padding: 3px 7px; border-radius: 999px; color: #248663; background: #e7f8f1; }
.user-menu #connectionStatus.offline { color: #a46b12; background: #fff3d8; }
.market-switch, .segmented {
  display: inline-flex; gap: 3px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.market-switch button, .segmented button {
  border: 0; border-radius: 8px; padding: 8px 12px; color: var(--muted); background: transparent; font-size: 13px;
}
.market-switch button.active, .segmented button.active { color: #fff; background: var(--navy-2); box-shadow: 0 5px 12px rgba(16,27,54,.15); }

.button {
  min-height: 42px; border: 1px solid transparent; border-radius: 10px; padding: 10px 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; font-size: 13px; transition: transform .15s, box-shadow .15s, opacity .15s;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button.primary { color: #fff; background: var(--blue); box-shadow: 0 8px 18px rgba(49,91,232,.18); }
.button.secondary { color: var(--navy); background: #eef2fa; border-color: #dce4f2; }
.button.ghost { color: var(--ink); background: #fff; border-color: var(--line); }
.button.danger { color: #fff; background: var(--red); }
.button.compact { min-height: 36px; padding: 8px 13px; }
.text-button { border: 0; padding: 5px; color: var(--blue); background: transparent; font-size: 12px; font-weight: 700; }

.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .45; transform: translateY(4px); } }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-card {
  position: relative; min-height: 124px; padding: 20px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow);
}
.metric-card::after { content: ""; position: absolute; right: -20px; bottom: -34px; width: 94px; height: 94px; border-radius: 50%; background: #f3f6fc; }
.metric-card.accent { border-color: #ead9b6; background: linear-gradient(145deg, #fff, var(--gold-soft)); }
.metric-card.profit { border-color: #cde8df; background: linear-gradient(145deg, #fff, var(--green-soft)); }
.metric-card span, .metric-card small { display: block; position: relative; z-index: 1; color: var(--muted); font-size: 12px; }
.metric-card strong { display: block; position: relative; z-index: 1; margin: 10px 0 5px; font-size: 27px; letter-spacing: -.04em; }
.dashboard-grid, .entry-layout, .draw-layout, .settings-grid, .report-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(310px, .65fr); gap: 20px; }
.panel { border: 1px solid var(--line); border-radius: 16px; padding: 20px; background: var(--panel); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.panel-head .eyebrow { margin-bottom: 5px; }
.period-list { display: grid; gap: 10px; }
.period-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 13px;
  padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcff;
}
.market-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; background: var(--blue-soft); color: var(--blue); }
.market-icon.mc { color: #9a6515; background: var(--gold-soft); }
.period-card strong, .period-card span, .period-card small { display: block; }
.period-card span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.period-card small { color: var(--muted); text-align: right; }
.status-pill { border-radius: 999px; padding: 6px 9px; font-size: 11px; font-weight: 800; }
.status-pill.open, .status-pill.pending { color: var(--blue); background: var(--blue-soft); }
.status-pill.closed { color: #a16b1a; background: var(--gold-soft); }
.status-pill.settled, .status-pill.win { color: var(--green); background: var(--green-soft); }
.status-pill.lose { color: var(--red); background: var(--red-soft); }
.status-pill.push { color: #8a681b; background: #fff6d9; }

label { display: grid; gap: 7px; color: #4f5a70; font-size: 12px; font-weight: 700; }
input, select, textarea {
  width: 100%; min-height: 42px; border: 1px solid #dce3ee; border-radius: 10px; padding: 10px 12px;
  color: var(--ink); background: #fff; outline: 0; font-weight: 500; transition: border .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.65; }
input:focus, select:focus, textarea:focus { border-color: #8fa6f2; box-shadow: 0 0 0 3px rgba(49,91,232,.1); }
input:disabled { color: #8b94a5; background: #f6f8fc; }
.stack-form, .order-form { display: grid; gap: 14px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-row .grow { grid-column: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 3px; }
.rule-note, .rule-callout {
  margin-top: 18px; padding: 13px 14px; border-left: 3px solid var(--gold); border-radius: 8px;
  color: #80642a; background: var(--gold-soft); font-size: 12px; line-height: 1.55;
}
.rule-note strong, .rule-note span { display: block; }
.rule-note span { margin-top: 2px; color: #816f4d; }
.section-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.section-toolbar .eyebrow { margin-bottom: 5px; }
.inline-field { min-width: 250px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.toolbar-fields { display: flex; align-items: center; gap: 9px; }
.toolbar-fields select, .toolbar-fields input { min-width: 150px; }
.entry-layout { grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); margin-bottom: 20px; }
.segmented { margin-bottom: 18px; }
.entry-tab { display: none; }
.entry-tab.active { display: block; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.choice-chip {
  min-width: 38px; border: 1px solid #dce3ee; border-radius: 9px; padding: 8px 10px;
  color: #59657b; background: #fff; font-size: 12px; font-weight: 700;
}
.choice-chip.selected { color: var(--blue); border-color: #9cb0f4; background: var(--blue-soft); }
.field-help { color: var(--muted); font-size: 11px; line-height: 1.55; }
.recent-list { display: grid; gap: 9px; }
.recent-item { padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcff; }
.recent-item > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.recent-item strong { font-size: 13px; }
.recent-item span { color: var(--blue); font-weight: 800; font-size: 13px; }
.recent-item small { display: block; margin-top: 5px; color: var(--muted); }
.error-list { margin-top: 13px; padding: 12px; border-radius: 10px; background: var(--red-soft); color: #9f3042; font-size: 12px; line-height: 1.6; }

.table-panel { padding: 5px 0 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 12px 14px; color: #8a94a8; background: #f7f9fc; text-align: left; white-space: nowrap; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
td { padding: 13px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #fbfcff; }
.cell-primary { font-weight: 800; }
.cell-sub { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.money-positive { color: var(--green); font-weight: 800; }
.money-negative { color: var(--red); font-weight: 800; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.member-actions { display: flex; flex-wrap: wrap; gap: 5px; min-width: 280px; }
.icon-button { border: 0; border-radius: 7px; padding: 6px 8px; color: var(--muted); background: #f1f4f9; font-size: 11px; }
.icon-button.delete { color: var(--red); background: var(--red-soft); }
.empty-state { min-height: 90px; display: grid; place-items: center; color: #9aa4b7; font-size: 12px; }

.draw-layout { grid-template-columns: minmax(0, 1.45fr) minmax(280px, .55fr); }
.draw-panel { min-height: 350px; }
.draw-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; padding-bottom: 20px; border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.market-badge { display: inline-block; margin-bottom: 7px; padding: 5px 8px; border-radius: 7px; color: #9a6515; background: var(--gold-soft); font-size: 10px; font-weight: 800; }
.draw-head h2 { font-size: 24px; }
.draw-head p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.field-title { margin-bottom: 12px; color: #4f5a70; font-size: 12px; font-weight: 700; }
.draw-inputs { display: grid; grid-template-columns: repeat(6, minmax(42px, 1fr)) auto minmax(48px, 1fr); gap: 8px; align-items: center; }
.draw-inputs input { height: 58px; padding: 8px; text-align: center; font-size: 21px; font-weight: 800; }
.draw-inputs .special { color: #fff; border-color: var(--red); background: var(--red); box-shadow: 0 7px 15px rgba(209,73,91,.18); }
.plus { color: var(--muted); font-size: 18px; font-weight: 800; }
.draw-legend { display: flex; justify-content: space-between; margin-top: 9px; color: var(--muted); font-size: 10px; }
.special-text { color: var(--red); }
.draw-actions { margin-top: 28px; }
.settle-summary { display: grid; gap: 0; }
.settle-summary > div { display: flex; align-items: center; justify-content: space-between; padding: 15px 0; border-bottom: 1px solid var(--line); }
.settle-summary span { color: var(--muted); font-size: 12px; }
.settle-summary strong { font-size: 17px; }
.rule-callout { border-left-color: var(--blue); color: #496194; background: var(--blue-soft); }
.report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.report-grid .panel { padding: 0; overflow: hidden; }
.report-grid .panel-head { padding: 18px 18px 0; }

.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 20px; }
.backup-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.danger-zone { margin-top: 22px; padding-top: 18px; border-top: 1px solid #f0d6da; }
.danger-zone strong { color: var(--red); }
.danger-zone p { margin: 5px 0 12px; color: var(--muted); font-size: 11px; }
.bulk-rate-box { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)) auto; gap: 10px; align-items: end; margin-bottom: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #f8faff; }
.bulk-rate-box label, .rate-field { color: var(--muted); font-size: 10px; font-weight: 700; }
.bulk-rate-box input, .bulk-rate-box select { margin-top: 5px; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; color: #4f5a70; font-size: 12px; }
.check-row input { width: 16px; min-height: 16px; }
.odds-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.odds-item { display: grid; grid-template-columns: minmax(150px, 1.2fr) repeat(4, minmax(85px, .65fr)) minmax(120px, .8fr); align-items: end; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; }
.rate-name { align-self: center; }
.odds-item strong { display: block; font-size: 12px; }
.odds-item small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.odds-item input, .odds-item select { min-height: 36px; margin-top: 4px; padding: 7px; font-size: 12px; }
.odds-item .empty-odds { visibility: hidden; }
.mobile-nav { display: none; }
.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 100; transform: translate(-50%, 18px);
  max-width: min(90vw, 480px); padding: 11px 16px; border-radius: 10px;
  color: #fff; background: var(--navy); box-shadow: 0 12px 30px rgba(16,27,54,.28);
  font-size: 12px; opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }
.hidden { display: none !important; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bulk-rate-box { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .odds-item { grid-template-columns: minmax(140px, 1fr) repeat(2, minmax(90px, .7fr)); }
}

@media (max-width: 860px) {
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 0 16px 28px; }
  .admin-main { padding: 0 16px 28px; }
  .topbar { min-height: 76px; margin-bottom: 18px; }
  .topbar h1 { font-size: 21px; }
  .top-actions .button { display: none; }
  .admin-main .top-actions .admin-front-link { display: inline-flex; }
  .user-menu { gap: 5px; padding-left: 0; border-left: 0; }
  .user-menu strong { display: none; }
  .market-switch button { padding: 7px 9px; }
  .dashboard-grid, .entry-layout, .draw-layout, .settings-grid, .report-grid { grid-template-columns: 1fr; }
  .entry-layout { gap: 14px; }
  .section-toolbar { align-items: stretch; flex-direction: column; gap: 12px; }
  .inline-field { min-width: 0; }
  .toolbar-fields { flex-wrap: wrap; }
  .toolbar-fields select, .toolbar-fields input { flex: 1; min-width: 130px; }
  .mobile-nav {
    position: fixed; inset: auto 0 0; z-index: 50; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding: 7px 7px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.96);
    box-shadow: 0 -8px 24px rgba(31,47,80,.08); backdrop-filter: blur(12px);
  }
  .mobile-nav button { border: 0; padding: 5px 2px; display: grid; gap: 3px; place-items: center; color: #8d97aa; background: transparent; font-size: 9px; }
  .mobile-nav button span { font-size: 17px; line-height: 1; }
  .mobile-nav button.active { color: var(--blue); font-weight: 800; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

@media (max-width: 600px) {
  .metric-grid { gap: 10px; margin-bottom: 14px; }
  .metric-card { min-height: 104px; padding: 15px; border-radius: 14px; }
  .metric-card strong { margin: 8px 0 3px; font-size: 22px; }
  .panel { padding: 16px; border-radius: 14px; }
  .field-row, .field-row.three { grid-template-columns: 1fr; }
  .section-toolbar h2 { font-size: 18px; }
  .topbar .eyebrow { display: none; }
  .draw-inputs { grid-template-columns: repeat(6, minmax(35px, 1fr)); gap: 5px; }
  .draw-inputs .plus { display: none; }
  .draw-inputs .special { grid-column: span 2; width: 64px; justify-self: end; }
  .draw-inputs input { height: 50px; font-size: 17px; }
  .draw-legend { flex-direction: column; gap: 3px; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .button { flex: 1; }
  .preview-panel { display: none; }
  .bulk-rate-box { grid-template-columns: 1fr; }
  .odds-item { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rate-name { grid-column: 1 / -1; }
  .backup-actions { flex-direction: column; }
  th, td { padding: 11px 10px; }
}

@media print {
  .sidebar, .topbar, .mobile-nav, .section-toolbar, .button, #view-dashboard, #view-entry, #view-orders, #view-draw, #view-settings { display: none !important; }
  body, .main { margin: 0; padding: 0; background: #fff; }
  #view-reports { display: block !important; }
  .panel, .metric-card { box-shadow: none; break-inside: avoid; }
}
