:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light: #eff6ff;
  --red: #ef4444;
  --green: #22c55e;
  --yellow: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #6b7280;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --nav-h: 64px;
  --header-h: 56px;
  --surface: #ffffff;
  --overlay: rgba(255,255,255,.75);
  --amber-bg: #fef3c7;
  --amber-text: #92400e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100dvh;
  overscroll-behavior: none;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

.screen { display: none; flex-direction: column; flex: 1; padding-bottom: var(--nav-h); }
.screen.active { display: flex; }

.header {
  position: sticky; top: 0; z-index: 10;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: var(--shadow);
}
.header h1 { font-size: 1.1rem; font-weight: 700; }
.header-actions { display: flex; gap: 8px; align-items: center; }

.content { flex: 1; overflow-y: auto; padding: 16px; }

/* ── Bottom nav ─────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--gray-200);
  display: flex;
  box-shadow: 0 -1px 3px rgba(0,0,0,.08);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px;
  cursor: pointer; border: none; background: none;
  color: var(--gray-400); font-size: .7rem; font-weight: 500;
  padding: 8px 0;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
}
.nav-item.active { color: var(--blue); }
.nav-item svg { width: 22px; height: 22px; }
.nav-badge {
  position: absolute; top: 8px;
  background: var(--red); color: white;
  font-size: .6rem; font-weight: 700;
  border-radius: 999px; padding: 1px 5px;
  min-width: 16px; text-align: center;
  display: none;
}
.nav-badge.visible { display: inline-block; }
.nav-item { position: relative; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 8px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.card-row:active { background: var(--gray-50); }
.card-row-info { flex: 1; min-width: 0; }
.card-row-title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-row-sub { font-size: .8rem; color: var(--gray-600); margin-top: 2px; }
.card-row-right { text-align: right; margin-left: 12px; flex-shrink: 0; }
.card-row-amount { font-weight: 700; font-size: 1rem; }
.card-row-currency { font-size: .75rem; color: var(--gray-400); }

/* ── Section header ─────────────────────────────────────────────────────── */
.section-header {
  font-size: .75rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--gray-400);
  padding: 16px 4px 8px;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; font-size: .7rem; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.badge-Taxi    { background: #fef3c7; color: #92400e; }
.badge-Meals   { background: #dcfce7; color: #166534; }
.badge-Hotel   { background: #ede9fe; color: #4c1d95; }
.badge-Travel  { background: #dbeafe; color: #1e40af; }
.badge-Parking { background: #ffedd5; color: #9a3412; }
.badge-Other   { background: var(--gray-100); color: var(--gray-600); }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-reviewed { background: #dcfce7; color: #166534; }

/* ── FAB ────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed; bottom: calc(var(--nav-h) + 16px); right: 20px; z-index: 15;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--blue); color: white; border: none;
  box-shadow: var(--shadow-md); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, transform .1s;
}
.fab:active { background: var(--blue-dark); transform: scale(.95); }
.fab svg { width: 26px; height: 26px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px; border: none;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); }
.btn-danger { background: var(--red); color: white; }
.btn-sm { padding: 6px 14px; font-size: .8rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--gray-600); }
.form-input, .form-select {
  width: 100%; padding: 12px 14px; border-radius: 8px;
  border: 1.5px solid var(--gray-200); background: var(--surface);
  font-size: 1rem; color: var(--gray-800);
  -webkit-appearance: none; appearance: none;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 36px; }

/* ── Login screen ───────────────────────────────────────────────────────── */
#screen-login {
  display: none; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100dvh;
  padding: 32px 24px; background: var(--surface);
}
#screen-login.active { display: flex; }
.login-logo { font-size: 3rem; margin-bottom: 8px; }
.login-title { font-size: 1.6rem; font-weight: 800; color: var(--gray-800); margin-bottom: 4px; }
.login-sub { color: var(--gray-400); font-size: .9rem; margin-bottom: 40px; }
.login-form { width: 100%; max-width: 360px; }
.login-error { color: var(--red); font-size: .85rem; margin-bottom: 12px; min-height: 20px; }

/* ── Receipt detail ─────────────────────────────────────────────────────── */
.receipt-image-wrap {
  width: 100%; aspect-ratio: 3/4; max-height: 320px;
  background: var(--gray-100); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 16px; display: flex;
  align-items: center; justify-content: center;
}
.receipt-image-wrap img { width: 100%; height: 100%; object-fit: contain; }
.receipt-image-wrap object { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.receipt-image-wrap .no-image { color: var(--gray-400); font-size: .9rem; }

.field-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--gray-100);
}
.field-row:last-child { border-bottom: none; }
.field-label { font-size: .8rem; color: var(--gray-400); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; min-width: 90px; }
.field-value { font-size: .95rem; font-weight: 500; flex: 1; text-align: right; }

/* ── Totals bar ─────────────────────────────────────────────────────────── */
.totals-bar {
  background: var(--blue); color: white;
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.totals-bar-label { font-size: .8rem; opacity: .8; }
.totals-bar-amount { font-size: 1.5rem; font-weight: 800; }

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; color: var(--gray-400);
  text-align: center;
}
.empty svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .4; }
.empty p { font-size: .95rem; }

/* ── Toast ──────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 80px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--gray-800); color: white;
  padding: 10px 20px; border-radius: 999px;
  font-size: .85rem; font-weight: 500;
  opacity: 0; transition: opacity .2s, transform .2s;
  z-index: 100; pointer-events: none; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Loading spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--gray-200);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: var(--overlay);
  align-items: center; justify-content: center;
}
.loading-overlay.show { display: flex; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.4); align-items: flex-end;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 32px; width: 100%;
  max-height: 90dvh; overflow-y: auto;
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
}
.modal h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }

/* ── Reports ────────────────────────────────────────────────────────────── */
.report-option {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border: 2px solid var(--gray-200);
  border-radius: var(--radius); margin-bottom: 10px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.report-option.selected { border-color: var(--blue); background: var(--blue-light); }
.report-option-icon { font-size: 1.5rem; }
.report-option-label { font-weight: 600; font-size: .95rem; }
.report-option-sub { font-size: .8rem; color: var(--gray-400); }

/* ── Offline banner ─────────────────────────────────────────────────────── */
#offline-banner {
  display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  background: var(--yellow); color: white;
  padding: 8px 16px; text-align: center; font-size: .85rem; font-weight: 600;
}
#offline-banner.show { display: block; }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--gray-200); margin: 8px 0; }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

input[type="file"] { display: none; }



/* ── Choice buttons (add receipt) ───────────────────────────────────────────── */
.choice-group { display: flex; gap: 8px; }
.choice {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 6px; border: 2px solid var(--gray-200); border-radius: 12px;
  background: var(--surface); font-size: 1.4rem; cursor: pointer; color: var(--gray-800);
}
.choice span { font-size: .8rem; font-weight: 600; }
.choice.selected { border-color: var(--blue); background: var(--blue-light); color: var(--blue-dark); }
.choice-sm { flex-direction: row; justify-content: center; padding: 8px 6px; font-size: .9rem; font-weight: 600; }
.mt-8 { margin-top: 8px; }
.text-muted { color: var(--gray-400); font-weight: 400; }
.field-hint { font-size: .75rem; color: #92400e; margin-top: 4px; }

/* ── Row delete button ──────────────────────────────────────────────────────── */
.row-delete {
  background: none; border: none; color: var(--gray-400); padding: 8px; margin: -8px -8px -8px 4px;
  cursor: pointer; flex-shrink: 0; border-radius: 8px;
}
.row-delete:active { background: #fee2e2; color: var(--red); }
.row-delete svg { width: 20px; height: 20px; display: block; }
.mb-16 { margin-bottom: 16px; }

/* ── Accounts / admin ───────────────────────────────────────────────────────── */
.auth-switch { text-align: center; margin-top: 16px; font-size: .9rem; color: var(--gray-600); }
.link-btn { background: none; border: none; color: var(--blue); font-weight: 600; font-size: inherit; cursor: pointer; padding: 0; }
.admin-only { display: none !important; }
body.is-admin .admin-only { display: flex !important; }
.owner-banner {
  background: #fef3c7; color: #92400e; border-radius: 10px; padding: 8px 12px;
  font-size: .85rem; font-weight: 600; margin-bottom: 12px;
}
.badge-admin    { background: #ede9fe; color: #4c1d95; }
.badge-disabled { background: #fee2e2; color: #991b1b; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.btn-row .btn { flex: 1 1 45%; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* ══ UX/UI review pass ═══════════════════════════════════════════════════════ */

/* Dark mode: remap the gray scale and surfaces */
@media (prefers-color-scheme: dark) {
  :root {
    --gray-50: #0e1116; --gray-100: #1b1f27; --gray-200: #2b303b;
    --gray-400: #9aa3b2; --gray-600: #c3c9d3; --gray-800: #f1f3f6;
    --surface: #161a21; --overlay: rgba(14,17,22,.75);
    --blue: #3b82f6; --blue-dark: #2563eb; --blue-light: #172554;
    --amber-bg: #422006; --amber-text: #fcd34d;
    --shadow: 0 1px 2px rgba(0,0,0,.5); --shadow-md: 0 4px 10px rgba(0,0,0,.5);
  }
  .badge-Taxi, .badge-pending { background: #422006; color: #fcd34d; }
  .badge-Meals, .badge-reviewed { background: #052e16; color: #86efac; }
  .badge-Hotel, .badge-admin { background: #2e1065; color: #c4b5fd; }
  .badge-Travel { background: #172554; color: #93c5fd; }
  .badge-Parking { background: #431407; color: #fdba74; }
  .badge-disabled, .badge-review { background: #450a0a !important; color: #fca5a5 !important; }
  .row-delete:active { background: #450a0a; }
  .choice.selected { color: #bfdbfe; }
}

/* iPhone notch / home bar when installed (viewport-fit=cover) */
.header { height: calc(var(--header-h) + var(--safe-top)); padding-top: var(--safe-top); }
.bottom-nav { height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); }
.screen { padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 72px); }  /* room for the + button */
.fab { bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); }
#toast { bottom: calc(var(--nav-h) + var(--safe-bottom) + 84px); }
.modal { padding-bottom: calc(24px + var(--safe-bottom)); }
#screen-login { padding-top: calc(32px + var(--safe-top)); }
#offline-banner { padding-top: calc(8px + var(--safe-top)); }

/* Comfortable tap targets */
.btn { min-height: 44px; }
.btn-sm { min-height: 36px; }
.nav-item { min-height: var(--nav-h); }

/* Keyboard focus */
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.form-input:focus-visible, .form-select:focus-visible { outline: none; }

/* Desktop / tablet: one centered column for header, content, nav and + */
@media (min-width: 640px) {
  body { background: var(--gray-100); }
  #app { max-width: 560px; margin: 0 auto; background: var(--gray-50); box-shadow: 0 0 0 1px var(--gray-200); }
  .bottom-nav { max-width: 560px; margin: 0 auto; }
  .fab { right: calc(50% - 280px + 20px); }
  .modal-backdrop { align-items: center; justify-content: center; }
  .modal { max-width: 480px; border-radius: var(--radius); }
}

/* Sheet header with close button */
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.modal-head h2 { margin-bottom: 0; }
.modal-close {
  width: 36px; height: 36px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--gray-100); color: var(--gray-600); font-size: 1.1rem; cursor: pointer;
}

/* Receipt rows: type icon + clear "add price" state */
.row-icon {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; margin-right: 12px;
  background: var(--gray-100); display: flex; align-items: center; justify-content: center; font-size: 1.25rem;
}
.amount-missing { color: var(--amber-text); font-weight: 600; font-size: .85rem; }
.badge-review { background: #fee2e2; color: #991b1b; }
.card-row-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; color: var(--gray-400); }
.section-header { display: flex; justify-content: space-between; gap: 12px; color: var(--gray-400); }
.section-header .subtotal { font-weight: 600; text-transform: none; letter-spacing: 0; white-space: nowrap; }

/* Totals card */
.totals-bar { align-items: flex-end; gap: 12px; }
.totals-bar-amount { font-size: 1.35rem; line-height: 1.25; overflow-wrap: anywhere; }
.totals-bar-count { font-size: .8rem; opacity: .85; white-space: nowrap; }

/* Receipt detail */
.receipt-hero { text-align: center; margin-bottom: 16px; }
.receipt-hero-amount { font-size: 2rem; font-weight: 800; letter-spacing: -.01em; }
.receipt-hero-sub { color: var(--gray-400); font-size: .9rem; margin-top: 2px; }
.receipt-image-wrap { cursor: zoom-in; }
.field-value { overflow-wrap: anywhere; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn { flex: 1; }

/* Quiet destructive action */
.btn-danger-ghost { background: transparent; color: var(--red); border: 1.5px solid currentColor; }
.btn-danger-ghost:active { background: rgba(239,68,68,.08); }

/* Loading message under the spinner */
.loading-overlay { flex-direction: column; gap: 14px; }
.loading-text { font-weight: 600; color: var(--gray-800); font-size: .95rem; text-align: center; padding: 0 24px; }

/* Brand mark on login */
.login-logo {
  width: 72px; height: 72px; border-radius: 20px; background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 2.2rem; margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(37,99,235,.35);
}
