/* ---------- Design tokens ---------- */
:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --ink: #211d18;
  --muted: #6e675c;
  --line: #e2dcd2;
  --accent: #b4541e;
  --accent-strong: #96440f;
  --on-accent: #ffffff;
  --good: #176e3c;
  --good-bg: #e3f2e8;
  --bad: #aa2828;
  --bad-bg: #f9e4e4;
  --warn: #8a5a00;
  --warn-bg: #fdf0d3;
  --focus: #1a6fb5;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(33, 29, 24, 0.08);
  --nav-height: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191e;
    --surface: #20232a;
    --surface-2: #2a2d35;
    --ink: #ebe7df;
    --muted: #a39c8f;
    --line: #383b43;
    --accent: #e0813f;
    --accent-strong: #ef955a;
    --on-accent: #20140b;
    --good: #65c08a;
    --good-bg: #1d3327;
    --bad: #e08484;
    --bad-bg: #3c2425;
    --warn: #e0b25c;
    --warn-bg: #3a3021;
    --focus: #6fb3e8;
    --shadow: none;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }

a { color: var(--accent); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

button, input, select, textarea { font: inherit; color: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  padding-top: calc(14px + env(safe-area-inset-top));
  max-width: 720px;
  margin: 0 auto;
}

.topbar-title { font-size: 22px; font-weight: 700; }

.topbar-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.topbar-logout { margin-left: auto; }

.btn-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted, #777);
  cursor: pointer;
}

.btn-logout svg { width: 20px; height: 20px; }

/* ---------- Layout ---------- */
.content {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-height) + env(safe-area-inset-bottom) + 24px);
}

.section { margin-bottom: 28px; }

.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.section-hint { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title { font-size: 17px; font-weight: 700; margin-bottom: 12px; }

/* ---------- Gig cards ---------- */
.gig-list { display: flex; flex-direction: column; gap: 10px; }

.gig-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  min-height: 72px;
  text-decoration: none;
  color: inherit;
  transition: background-color 150ms ease;
}

.gig-card:active { background: var(--surface-2); }

.gig-date {
  flex: 0 0 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 6px 4px;
}

.gig-date-day { font-size: 20px; font-weight: 700; line-height: 1.1; }
.gig-date-month { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.gig-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.gig-band { font-weight: 700; }
.gig-venue { font-size: 14px; }
.gig-band, .gig-venue { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gig-meta { font-size: 13px; color: var(--muted); }

.gig-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.gig-pay { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Chips ---------- */
.chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.chip-paid, .chip-good, .chip-completed { background: var(--good-bg); color: var(--good); }
.chip-bad { background: var(--bad-bg); color: var(--bad); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-status { text-transform: capitalize; }
.chip-upcoming { background: var(--surface-2); color: var(--muted); }
.chip-archived { background: var(--surface-2); color: var(--muted); }

/* ---------- Forms ---------- */
.form .field { margin-bottom: 14px; }

.field label, .field legend {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.req { color: var(--bad); }

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px; /* prevents iOS zoom-on-focus */
}

.field textarea { min-height: 72px; resize: vertical; }

.field-hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

fieldset.field { border: 0; padding: 0; margin: 0 0 14px; }

.radio-row { display: flex; gap: 10px; }

.radio-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.radio-pill input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }

.radio-pill:has(input:checked) {
  border-color: var(--accent);
  background: var(--surface-2);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}

.check-row input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: filter 150ms ease;
  touch-action: manipulation;
}

.btn:active { filter: brightness(0.92); }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-secondary { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn-block { width: 100%; }
.btn-icon { width: 20px; height: 20px; }

.btn[disabled] { opacity: 0.5; cursor: default; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:active { background: var(--surface-2); color: var(--bad); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Gig detail ---------- */
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-band { font-size: 20px; font-weight: 700; }
.detail-venue { margin: 2px 0 0; color: var(--muted); }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-grid dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.detail-grid dd { margin: 2px 0 0; font-weight: 600; font-size: 15px; }

.detail-notes {
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 15px;
}

/* ---------- Money summary ---------- */
.money-list { list-style: none; margin: 0; padding: 0; }

.money-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  font-size: 15px;
}

.money-list strong { font-variant-numeric: tabular-nums; font-size: 16px; }

.money-divider { border-top: 1px solid var(--line); }
.money-list .neg, .money-list .neg strong { color: var(--bad); }
.money-list .pos, .money-list .pos strong { color: var(--good); }

.money-note {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 12px !important;
  font-size: 14px !important;
}

/* ---------- Expenses ---------- */
.expense-list { list-style: none; margin: 0 0 16px; padding: 0; }

.expense-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.expense-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.expense-cat { font-weight: 600; text-transform: capitalize; }
.expense-desc { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-amount { font-variant-numeric: tabular-nums; font-weight: 600; }

.expense-total {
  font-weight: 700;
  justify-content: space-between;
  border-bottom: 0 !important;
  padding-top: 10px !important;
}

.form-inline-block { padding-top: 4px; }

/* ---------- Danger zone ---------- */
.danger-zone { display: flex; gap: 10px; flex-wrap: wrap; }
.danger-zone form { flex: 1; min-width: 140px; }
.danger-zone .btn { width: 100%; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

.empty-state .btn { margin-top: 8px; }

/* ---------- Flash messages ---------- */
.flashes {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

.flash {
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 500;
}

.flash-success { background: var(--good-bg); color: var(--good); }
.flash-error { background: var(--bad-bg); color: var(--bad); }

/* ---------- Bottom navigation ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-height);
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}

.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--accent); }
.nav-item:active { background: var(--surface-2); }

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  text-align: center;
}

.login-box h1 { font-size: 22px; margin-bottom: 20px; }
.login-box .form { text-align: left; }
.login-logo { width: 40px; height: 40px; color: var(--accent); margin-bottom: 8px; }
.login-alt { margin-top: 18px; font-size: 14px; color: var(--muted, #777); }
.login-alt a { color: var(--accent); font-weight: 600; }

/* ---------- Import / export ---------- */
.export-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.export-actions .btn { flex: 1 1 140px; }

.map-grid { display: grid; gap: 12px; }
.map-row { display: grid; grid-template-columns: 1fr; gap: 4px; }
.map-row label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.map-row select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
}

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.data-table th, .data-table td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}
.data-table th { background: var(--surface-2); font-weight: 700; }

.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.result-list li:last-child { border-bottom: 0; }
.result-subhead { font-size: 15px; font-weight: 700; margin: 18px 0 4px; }

@media (min-width: 560px) {
  .map-row { grid-template-columns: 220px 1fr; align-items: center; }
  .map-row label { text-align: right; }
}

/* ---------- Wider screens ---------- */
@media (min-width: 768px) {
  .topbar { padding-top: 24px; }
  .gig-list { gap: 12px; }
  .content { padding-bottom: calc(var(--nav-height) + 48px); }
}
