/* =====================================================================
   Vehicle Expense Tracker — base styles, design tokens, shared components
   ===================================================================== */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f0;
  --text: #0f172a;          /* dark navy */
  --text-2: #334155;
  --muted: #64748b;
  --blue: #2563eb;
  --blue-soft: #e8f0fe;
  --green: #16a34a;
  --green-soft: #e7f6ec;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fde8e8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.18);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.35);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

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

/* The hidden attribute must win over any display rule below */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0 0 0.5rem; }
a { color: var(--blue); }
img { max-width: 100%; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.pre-wrap { white-space: pre-wrap; }
.center { text-align: center; }
.text-danger { color: var(--red); }
.text-warning { color: var(--amber); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 260px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack { display: grid; gap: 16px; align-content: start; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.noscript { padding: 24px; text-align: center; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--text); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

/* Lucide icons */
.icon, [data-lucide], svg.lucide { width: 18px; height: 18px; flex-shrink: 0; stroke-width: 2; }

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 0.9rem; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: #cbd5e1; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost-danger { background: transparent; color: var(--red); border-color: #f5c2c2; }
.btn-ghost-danger:hover:not(:disabled) { background: var(--red-soft); }
.btn-sm { padding: 6px 11px; font-size: 0.82rem; }
.btn-sm .icon, .btn-sm svg.lucide { width: 16px; height: 16px; }
.btn-lg { padding: 13px 22px; font-size: 1rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid transparent; border-radius: 9px; background: transparent;
  color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: var(--red-soft); }

.link { color: var(--blue); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link-btn {
  display: inline-flex; align-items: center; gap: 4px; margin-left: 8px;
  background: none; border: 0; padding: 0; color: var(--blue); font: inherit; font-size: 0.8rem; cursor: pointer;
}
.link-btn .icon, .link-btn svg.lucide { width: 14px; height: 14px; }

/* ---------------------------------------------------------------------
   Cards, badges, chips, alerts
   --------------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card-header { margin-bottom: 14px; }
.card-header h2 + p { margin-top: 4px; margin-bottom: 0; }

.badge {
  display: inline-block; margin-left: 6px; padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; line-height: 1.5; vertical-align: middle; white-space: nowrap;
}
.badge-grey { background: #eef2f7; color: #475569; }
.badge-green { background: var(--green-soft); color: #15803d; }
.badge-blue { background: var(--blue-soft); color: #1d4ed8; }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: #b91c1c; }

.chip {
  --chip: #94a3b8;
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 500; white-space: nowrap;
}
.chip::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--chip); }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid; margin-bottom: 12px; font-size: 0.88rem;
}
.alert > svg, .alert > .icon { margin-top: 1px; }
.alert-info { background: var(--blue-soft); border-color: #c7d7fb; color: #1e3a8a; }
.alert-success { background: var(--green-soft); border-color: #bbe5c8; color: #14532d; }
.alert-warning { background: var(--amber-soft); border-color: #f8dc8c; color: #78350f; }
.alert-error { background: var(--red-soft); border-color: #f5c2c2; color: #7f1d1d; }
.alert .btn { margin-top: 8px; }

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--muted);
  font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}
.table tbody tr:hover { background: #fafbfd; }
.table tfoot th, .table tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { white-space: nowrap; text-align: right; }
.table tbody th { font-weight: 600; }
.row-muted td, .row-muted th { color: #94a3b8; }

.table-summary { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; margin-bottom: 12px; }
.table-summary .btn { margin-left: auto; }

.pagination { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 0.85rem; }
.pagination-buttons { display: flex; align-items: center; gap: 8px; }
.page-indicator { color: var(--muted); }

/* ---------------------------------------------------------------------
   Feedback: loading, empty states, toasts
   --------------------------------------------------------------------- */
.spinner {
  width: 22px; height: 22px; border: 3px solid #dbe3ef; border-top-color: var(--blue);
  border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block;
}
.spinner-sm { width: 14px; height: 14px; border-width: 2px; border-color: rgba(255, 255, 255, 0.45); border-top-color: #fff; }
.btn-secondary .spinner-sm { border-color: #dbe3ef; border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 60px 20px; color: var(--muted); }

.empty-state { text-align: center; padding: 36px 16px; }
.empty-state h3 { font-size: 1.05rem; margin-bottom: 6px; }
.empty-state p { color: var(--muted); max-width: 420px; margin: 0 auto 16px; }
.empty-icon { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--blue-soft); color: var(--blue); margin-bottom: 12px; }
.empty-icon svg { width: 26px; height: 26px; }

.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: grid; gap: 10px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: #fff; box-shadow: var(--shadow-lg); font-size: 0.9rem; animation: toast-in 0.2s ease-out;
}
.toast-success svg { color: #4ade80; }
.toast-error { background: #7f1d1d; }
.toast-warning svg { color: #fbbf24; }
.toast-close { margin-left: auto; background: none; border: 0; color: #cbd5e1; font-size: 1.2rem; cursor: pointer; line-height: 1; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------------------------------------------------------------------
   Brand
   --------------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.container { width: min(1160px, 100% - 32px); margin-inline: auto; }

/* ---------------------------------------------------------------------
   Landing page
   --------------------------------------------------------------------- */
.landing-body { background: var(--surface); }
.landing-header { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.landing-nav { display: flex; align-items: center; justify-content: space-between; height: 68px; }
.landing-links { display: flex; align-items: center; gap: 22px; }
.landing-links > a:not(.btn) { color: var(--text-2); text-decoration: none; font-weight: 500; }
.landing-links > a:not(.btn):hover { color: var(--blue); }
.landing-menu-btn { display: none; }

.hero { padding: 72px 0 64px; background: radial-gradient(1000px 400px at 85% 0%, #e8f0fe 0%, transparent 60%), radial-gradient(600px 300px at 0% 100%, #e7f6ec 0%, transparent 60%); }
.hero-grid { display: grid; grid-template-columns: 1.05fr 1fr; gap: 56px; align-items: center; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--green-soft); color: #15803d; font-weight: 600; font-size: 0.82rem; }
.hero h1 { font-size: clamp(2rem, 4vw, 3.1rem); letter-spacing: -0.02em; margin: 18px 0 16px; }
.lead { font-size: 1.1rem; color: var(--text-2); max-width: 560px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 28px 0 24px; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; color: var(--text-2); }
.hero-points li { display: flex; align-items: center; gap: 10px; }
.hero-points svg { color: var(--green); }

.preview { margin: 0; }
.preview-window { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden; }
.preview-bar { display: flex; gap: 6px; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.preview-bar span { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; }
.preview-body { padding: 18px; display: grid; gap: 16px; background: var(--bg); }
.preview-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.preview-stat { background: var(--surface); border-radius: 12px; padding: 12px 14px; border-left: 4px solid var(--blue); }
.preview-stat.green { border-left-color: var(--green); }
.preview-stat small { display: block; color: var(--muted); font-size: 0.72rem; }
.preview-stat strong { font-size: 1.05rem; }
.preview-chart { display: flex; align-items: flex-end; gap: 8px; height: 110px; background: var(--surface); border-radius: 12px; padding: 14px; }
.preview-chart span { flex: 1; background: linear-gradient(180deg, #60a5fa, var(--blue)); border-radius: 6px 6px 2px 2px; }
.preview-rows { background: var(--surface); border-radius: 12px; padding: 6px 14px; font-size: 0.82rem; }
.preview-rows div { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.preview-rows div:last-child { border-bottom: 0; }
.preview-rows span:nth-child(2) { color: var(--muted); }
.preview figcaption { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 12px; }

.section { padding: 72px 0; }
.section-alt { background: var(--bg); }
.section-title { text-align: center; font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: 36px; }
.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.feature { border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; background: var(--surface); }
.feature > svg { width: 40px; height: 40px; padding: 9px; border-radius: 12px; background: var(--blue-soft); color: var(--blue); margin-bottom: 14px; }
.feature:nth-child(odd) > svg { background: var(--green-soft); color: var(--green); }
.feature h3 { font-size: 1.05rem; margin-bottom: 6px; }
.feature p { color: var(--text-2); margin: 0; }
.steps { list-style: none; padding: 0; margin: 0 0 32px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.steps li { background: var(--surface); border-radius: var(--radius); padding: 22px; border: 1px solid var(--border); }
.steps span { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--text); color: #fff; font-weight: 700; margin-bottom: 12px; }
.steps h3 { margin-bottom: 6px; }
.steps p { color: var(--text-2); margin: 0; font-size: 0.92rem; }
.landing-footer { border-top: 1px solid var(--border); padding: 28px 0; }
.footer-grid { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; }
.footer-grid nav { display: flex; gap: 18px; }
.footer-grid nav a { color: var(--text-2); text-decoration: none; }

/* ---------------------------------------------------------------------
   Auth pages
   --------------------------------------------------------------------- */
.auth-body { min-height: 100vh; background: radial-gradient(800px 400px at 100% 0%, #e8f0fe, transparent 60%), var(--bg); }
.auth-layout { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 22px; padding: 32px 16px; }
.auth-brand { font-size: 1.1rem; }
.auth-card { width: min(420px, 100vw - 32px); padding: 32px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card form { margin-top: 20px; display: grid; gap: 14px; }
.auth-row { display: flex; justify-content: flex-end; font-size: 0.88rem; margin-top: -4px; }
.auth-switch { margin: 20px 0 0; text-align: center; font-size: 0.9rem; color: var(--muted); }

/* Setup screen shown when js/config.js is missing */
.setup-screen { max-width: 560px; margin: 12vh auto; padding: 0 16px; display: grid; gap: 16px; justify-items: start; }
