:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --border: #eee;
  --accent: #c2185b;
  --text: #222;
  --muted: #777;
  --pick1-bg: #fff4da;
  --pick-bg: #f5f1ea;
  --odds-bg: #e8f0ff;
  --odds-color: #1e3a8a;
  --match-bg: #dcfce7;
  --match-color: #166534;
  --contra-bg: #fde2e2;
  --contra-color: #991b1b;
  --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font: 16px/1.5 -apple-system, system-ui, sans-serif;
  margin: 0;
  padding: 24px 16px;
  max-width: 820px;
  margin-inline: auto;
  background: var(--bg);
  color: var(--text);
}

/* ── Header ─────────────────────────────────────────── */
.app-header { margin-bottom: 24px; }
.app-header h1 { margin: 0 0 4px; font-size: 26px; }
.app-header .sub { color: var(--muted); font-size: 14px; }

/* ── Date picker bar ─────────────────────────────────── */
.date-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.date-bar select {
  font: inherit;
  font-size: 15px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  border: 1px solid #ddd;
  color: var(--text);
}

/* ── Status bar ─────────────────────────────────────── */
.status-bar {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  min-height: 18px;
}
.status-bar.error { color: var(--contra-color); }

/* ── Loading skeleton ───────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
  height: 18px;
  margin: 6px 0;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Day overview ───────────────────────────────────── */
.day-overview {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.day-overview h2 { margin: 0 0 8px; font-size: 18px; }

/* ── Track facts strip ──────────────────────────────── */
.track-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  padding: 6px 0 12px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.tf-item   { white-space: nowrap; }
.tf-curve  { font-variant-numeric: tabular-nums; }
.tf-region { font-style: italic; }
.tf-link   {
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
  margin-left: auto;
}
.tf-link:hover { text-decoration: underline; }
.betting-forms { width: 100%; border-collapse: collapse; font-size: 13px; }
.betting-forms th, .betting-forms td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.betting-forms th { color: var(--muted); font-weight: 600; }
.betting-forms td:first-child { white-space: nowrap; font-weight: 600; }

/* ── Race cards ─────────────────────────────────────── */
.race {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.race header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.lopp-badge {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}
.race h2 { margin: 0; font-size: 17px; font-weight: 600; }
.race-meta { font-size: 12px; color: var(--muted); margin-left: auto; white-space: nowrap; }

/* ── Pick list ─────────────────────────────────────── */
ol.picks { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.pick {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--pick-bg);
}
.pick-1 { background: var(--pick1-bg); }
.pick .rank {
  font-weight: 800;
  font-size: 22px;
  color: var(--accent);
  grid-row: 1 / span 3;
  align-self: center;
  text-align: center;
}
.pick .nr  { font-size: 12px; color: #999; }
.pick .name { font-weight: 700; font-size: 16px; }
.pick .meta { font-size: 12px; color: #666; }
.pick .why  { grid-column: 2; font-size: 14px; color: #333; margin-top: 4px; }
.pick .tags { grid-column: 2; margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.pick .tags span {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.odds-tag  { background: var(--odds-bg);   color: var(--odds-color); }
.odds-na   { background: #eee; color: #888; }
.match-tag { background: var(--match-bg);  color: var(--match-color); }
.contra-tag{ background: var(--contra-bg); color: var(--contra-color); }
.result-tag{ background: #f3e8ff; color: #6b21a8; }

.market-line {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--muted);
}
.market-line b { color: var(--text); }

/* ── Expert race tips (spetsanalys / speltips) ──────── */
.race-tip {
  background: #f0f4ff;
  border-left: 3px solid #6366f1;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.race-tip.speltips { background: #fff7ed; border-color: #f97316; }
.race-tip .tip-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #6366f1;
  margin-bottom: 4px;
}
.race-tip.speltips .tip-label { color: #f97316; }
.race-tip p { margin: 4px 0 0; }
.race-tip strong { color: var(--text); }

/* ── Horse expert annotations ───────────────────────── */
.stat-comment {
  grid-column: 2;
  font-size: 12px;
  color: #555;
  font-style: italic;
  margin-top: 3px;
  line-height: 1.4;
}
.expert-comment {
  grid-column: 2;
  font-size: 13px;
  color: #333;
  background: #f9fafb;
  border-radius: 4px;
  padding: 4px 8px;
  margin-top: 4px;
  line-height: 1.4;
}

/* Expert rank badges */
.expert-a { background: #dcfce7; color: #166534; }
.expert-b { background: #fef9c3; color: #854d0e; }
.expert-c { background: #f3f4f6; color: #6b7280; }

/* ── Methodology box ────────────────────────────────── */
.info {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.info summary { cursor: pointer; font-weight: 700; font-size: 15px; color: var(--accent); }
.info p { margin: 10px 0; font-size: 14px; }
.info table { width: 100%; border-collapse: collapse; font-size: 13px; }
.info th, .info td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.info th { color: var(--muted); font-weight: 600; }
.info td:last-child { font-family: ui-monospace, monospace; color: var(--accent); }
.caveat { color: var(--muted); font-size: 12px; font-style: italic; }

/* ── Tabs ───────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  transition: color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Voucher tab ────────────────────────────────────── */
.voucher-input-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.voucher-input-bar input {
  flex: 1;
  min-width: 200px;
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: var(--surface);
}

/* ── Voucher card ───────────────────────────────────── */
.voucher-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  transition: opacity .2s;
}
.voucher-card.loading { opacity: .6; pointer-events: none; }
.voucher-loading { color: var(--muted); font-size: 14px; padding: 8px 0; }
.voucher-empty { color: var(--muted); font-size: 14px; }

.voucher-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.voucher-id {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: #555;
}
.voucher-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.btn-sm { font-size: 12px; padding: 4px 10px; }

.voucher-meta { font-size: 12px; color: var(--muted); margin-bottom: 12px; }

/* Status badges */
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-done { background: var(--match-bg); color: var(--match-color); }
.badge-live { background: #fff3cd; color: #856404; }
.badge-err  { background: var(--contra-bg); color: var(--contra-color); }

/* ── Division summary table ─────────────────────────── */
.div-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 10px;
}
.div-table th {
  text-align: left;
  padding: 6px 8px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.div-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.div-table td:nth-child(4), .div-table td:nth-child(5) { text-align: right; }
.div-done-row td { background: #fafafa; }
.div-row-hit  td { background: #dcfce7 !important; }   /* green — winner was in your selections */
.div-row-miss td { background: #fef9c3 !important; }   /* yellow — winner not in your selections */
.div-won  { color: var(--match-color); font-weight: 600; }
.div-pending { color: var(--muted); }
.scratched-note { font-size: 11px; color: var(--muted); font-weight: 400; }

/* Selection outcome dots in compact view */
.sel-dot { margin-right: 6px; font-size: 14px; }
.sel-hit  { color: #16a34a; }
.sel-miss { color: #ca8a04; }

/* Hint below compact table */
.sel-hint { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── Payouts ────────────────────────────────────────── */
.payouts-bar {
  font-size: 13px;
  color: #444;
  background: #f8f8f0;
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 8px;
}

/* ── Detailed runner tables ─────────────────────────── */
.detail-race {
  margin-bottom: 20px;
}
.detail-race h4 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}
.runner-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.runner-table th {
  text-align: left;
  padding: 5px 8px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.runner-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.runner-table tbody tr:not(.runner-scratched) { cursor: pointer; }
.runner-table tbody tr:not(.runner-scratched):hover { opacity: .85; }

/* Runner coloring — result states */
.runner-hit       { background: #dcfce7; font-weight: 600; } /* selected + won = green */
.runner-hit td:first-child { color: #16a34a; }
.runner-miss      { background: #fee2e2; }                   /* selected + race done + lost = red */
.runner-miss td:first-child { color: #b91c1c; }
.runner-won-unsel { background: #fff3cd; font-weight: 600; } /* won but not selected = amber */
.runner-won-unsel td:first-child { color: #92400e; }
/* Pending rows coloured by ABC type */
.runner-selected  { background: #eff6ff; }                   /* selected, no type set = blue */
.runner-type-a    { background: #f0fdf4; }                   /* A-horse pending = green tint */
.runner-type-a td:first-child { color: #166534; }
.runner-type-b    { background: #fefce8; }                   /* B-horse pending = yellow tint */
.runner-type-b td:first-child { color: #854d0e; }
.runner-type-c    { background: #fdf4ff; }                   /* C-horse pending = purple tint */
.runner-type-c td:first-child { color: #7e22ce; }
.runner-won { background: #f0fdf4; font-weight: 600; }       /* won (no selections set) */
.runner-won td:first-child { color: var(--match-color); }
.runner-scratched { opacity: .4; text-decoration: line-through; cursor: default; }

/* ABC type badges shown inline with horse name */
.type-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  vertical-align: middle;
  margin-left: 4px;
  letter-spacing: .04em;
}
.type-a { background: #bbf7d0; color: #14532d; }
.type-b { background: #fef08a; color: #713f12; }
.type-c { background: #e9d5ff; color: #581c87; }

/* ABC constraint tracker — always visible in voucher header area */
.abc-tracker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.abc-track-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 8px;
  font-size: 0.8rem;
  border: 1px solid transparent;
}
.abc-track-item.abc-met  { background: #f0fdf4; border-color: #86efac; }
.abc-track-item.abc-pend { background: #fefce8; border-color: #fde047; }
.abc-track-item.abc-warn { background: #fff7ed; border-color: #fdba74; }
.abc-track-item.abc-dead { background: #fef2f2; border-color: #fca5a5; }
.abc-limit { font-weight: 600; color: #555; font-size: 0.75rem; }
.abc-pips  { letter-spacing: 1px; color: #888; font-size: 0.85rem; }
.abc-note  { color: #444; font-size: 0.8rem; }
.abc-dead .abc-note { color: #b91c1c; font-weight: 700; }
.abc-warn .abc-note { color: #c2410c; font-weight: 600; }
.abc-met  .abc-note { color: #15803d; }
.pips-over { color: #b91c1c; }

/* ── Footer + version ───────────────────────────────── */
footer { color: var(--muted); font-size: 12px; margin-top: 32px; text-align: center; }
.version-info { font-family: ui-monospace, monospace; opacity: .7; }

/* ── App header with user bar ───────────────────────── */
.app-header-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding-top: 4px;
}
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.user-name {
  font-size: 13px;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-login { font-size: 12px; }

/* ── Maintenance tab ────────────────────────────────── */
.maintenance-container { max-width: 640px; }
.maint-heading { font-size: 20px; margin: 0 0 20px; }
.maint-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.maint-section h3 { margin: 0 0 6px; font-size: 15px; }
.maint-desc { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.maint-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.maint-result {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  background: #f8fafc;
  border: 1px solid var(--border);
  line-height: 1.6;
}
.maint-result.error { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.maint-ok  { color: #15803d; }
.maint-err { color: #b91c1c; }
.maint-info-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.maint-info-table th {
  text-align: left;
  padding: 5px 10px 5px 0;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  width: 160px;
}
.maint-info-table td { padding: 5px 0; }

/* ── Claude routine cards ───────────────────────────── */
.routines-list { display: flex; flex-direction: column; gap: 10px; }
.routine-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}
.routine-info { flex: 1; min-width: 180px; }
.routine-info strong { font-size: 14px; }
.routine-schedule {
  margin-left: 8px;
  font-size: 11px;
  color: var(--muted);
  background: #eee;
  padding: 1px 6px;
  border-radius: 999px;
}
.routine-desc { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.routine-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.routine-unconfigured { font-size: 12px; color: #c2410c; }

/* ── Empty / error states ───────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state h3 { margin: 0 0 8px; font-size: 18px; color: var(--text); }
