/* ── Custom Properties ─────────────────────────────────────────────────── */
:root {
  --bg:          #1a1a1a;
  --surface:     #252525;
  --surface-2:   #2e2e2e;
  --surface-3:   #383838;
  --accent:      #f97316;
  --accent-hover:#ea6800;
  --text:        #f5f5f5;
  --text-muted:  #b0b0b0;  /* boosted from #a3a3a3 for better senior contrast */
  --border:      #444;     /* lightened slightly */
  --success:     #4ade80;  /* brighter green for better contrast */
  --warning:     #facc15;
  --danger:      #f87171;  /* brighter red */
  --info:        #60a5fa;
  --radius:      8px;
  --nav-w:       240px;
  --bottom-nav-h:72px;
  --font:        'Inter', system-ui, -apple-system, sans-serif;

  /* Senior-friendly sizing */
  --touch-min:   48px;     /* WCAG 2.5.5 minimum touch target */
  --input-pad:   0.75rem 1rem;
  --btn-pad:     0.7rem 1.25rem;
}

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

html {
  font-size: 18px;         /* seniors: larger base */
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
  /* space for fixed bottom nav on mobile */
  padding-bottom: var(--bottom-nav-h);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

img { max-width: 100%; }
input, select, textarea, button { font: inherit; }

/* ── Skip to content (accessibility) ───────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-weight: 700;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

/* ── App Shell ──────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar Nav — desktop only ─────────────────────────────────────────── */
.sidebar {
  display: none; /* hidden on mobile */
  width: var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
}
.sidebar-logo .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-nav { padding: 0.5rem 0; flex: 1; }

.nav-section {
  padding: 0.75rem 1rem 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 1rem;
  min-height: var(--touch-min);
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.1s, color 0.1s;
  border-left: 3px solid transparent;
  text-decoration: none;
}
.nav-link:hover  { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--surface-2); color: var(--accent); border-left-color: var(--accent); }
.nav-link:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.nav-icon { width: 20px; text-align: center; flex-shrink: 0; font-size: 1rem; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Bottom Nav — mobile only ───────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 2px solid var(--border);
  z-index: 200;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0.4rem 0.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-height: var(--bottom-nav-h);
  transition: color 0.15s, background 0.15s;
  border-top: 3px solid transparent;
}
.bottom-nav-item:hover  { color: var(--text); text-decoration: none; background: var(--surface-2); }
.bottom-nav-item.active { color: var(--accent); border-top-color: var(--accent); }
.bottom-nav-item:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.bottom-nav-icon { font-size: 1.4rem; line-height: 1; }

/* ── Main Content ───────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* no sidebar on mobile */
  width: 100%;
}

/* ── Upgrade Banner ─────────────────────────────────────────────────────── */
.upgrade-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  font-size: 0.9rem;
}

/* ── Page Header ────────────────────────────────────────────────────────── */
.page-header {
  padding: 1.25rem 1rem 0.85rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.page-body { padding: 1rem; flex: 1; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

/* ── KPI Cards ──────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.kpi-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.kpi-value       { font-size: 2rem; font-weight: 700; color: var(--text); }
.kpi-accent      { color: var(--accent); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
  background: var(--surface-2);
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover      { background: var(--surface-2); }
td {
  padding: 0.85rem 1rem;
  vertical-align: middle;
}
tfoot td {
  padding: 0.75rem 1rem;
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: var(--surface-2);
}
.td-right  { text-align: right; }
.col-num   { width: 100px; text-align: right; }
.col-actions { width: 72px; text-align: center; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group  { margin-bottom: 1.1rem; }
.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: var(--input-pad);
  font-size: 1rem;           /* seniors: readable input text */
  min-height: var(--touch-min);
  transition: border-color 0.15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25);
}
select option   { background: var(--surface-2); }
textarea        { resize: vertical; min-height: 90px; }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: var(--btn-pad);
  min-height: var(--touch-min);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-success { background: transparent; color: var(--success); border-color: var(--success); }
.btn-success:hover { background: var(--success); color: #fff; }

/* Slightly smaller variants — still meet 44px minimum */
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.9rem; min-height: 44px; }
.btn-xs { padding: 0.35rem 0.7rem; font-size: 0.82rem; min-height: 44px; }

.btn-group { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

/* ── Status Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge-draft    { background: #3a3a3a; color: #d4d4d4; }   /* contrast 5.8:1 */
.badge-sent     { background: #1e3a5f; color: #93c5fd; }   /* contrast 5.1:1 */
.badge-approved { background: #14532d; color: #86efac; }   /* contrast 6.4:1 */
.badge-declined { background: #500e0e; color: #fca5a5; }   /* contrast 5.6:1 */
.badge-paid     { background: #14532d; color: #86efac; }

/* ── Filter Tabs ────────────────────────────────────────────────────────── */
.filter-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.filter-tab {
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
}
.filter-tab:hover  { color: var(--text); text-decoration: none; }
.filter-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Toast ──────────────────────────────────────────────────────────────── */
#toast-anchor {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 1rem);
  right: 1rem;
  left: 1rem;
  z-index: 9999;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  font-size: 1rem;
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  animation: slideUp 0.25s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Line Items ─────────────────────────────────────────────────────────── */
.line-items-section    { margin-top: 1.5rem; }
.line-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.add-item-wrap {
  container-type: inline-size;
  container-name: add-item;
}
.add-item-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.85rem;
}
.add-item-row .form-group { margin-bottom: 0; }
.add-item-row label { font-size: 0.72rem; }

/* ── Detail Header ──────────────────────────────────────────────────────── */
.detail-header-wrap {
  container-type: inline-size;
  container-name: detail-header;
  margin-bottom: 1.25rem;
}
.detail-header {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

/* ── Status Bar ─────────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.share-link-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.share-link-box code {
  background: var(--surface-2);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  word-break: break-all;
}

/* ── Dashboard Cols ─────────────────────────────────────────────────────── */
.dashboard-cols-wrap {
  container-type: inline-size;
  container-name: dashboard-cols;
}
.dashboard-cols {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

/* ── Public Doc ─────────────────────────────────────────────────────────── */
.public-wrap    { max-width: 820px; margin: 1.5rem auto; padding: 0 1rem; }
.public-doc     { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.public-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 1rem;
}
.doc-shop-info h2 { font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.doc-shop-info p  { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.2rem; }
.doc-number h3    { font-size: 1.1rem; font-weight: 700; }
.doc-number p     { font-size: 0.9rem; color: var(--text-muted); text-align: right; }

.doc-customer-vehicle-wrap {
  container-type: inline-size;
  container-name: doc-cv;
}
.doc-customer-vehicle {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.doc-section-label {
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.doc-section-value { font-size: 0.95rem; }

/* ── Login Page ─────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .logo-icon {
  width: 56px;
  height: 56px;
  background: var(--accent);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  margin-bottom: 0.85rem;
}
.login-logo h1 { font-size: 1.5rem; font-weight: 700; }
.login-logo p  { font-size: 0.95rem; color: var(--text-muted); margin-top: 0.3rem; }
.error-msg {
  background: #500e0e;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: #fca5a5;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

/* ── Misc Utilities ─────────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); font-size: 0.9rem; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state p { margin-bottom: 1rem; font-size: 1rem; }

/* ── Tablet / Desktop (>= 768px) ────────────────────────────────────────── */
@media (min-width: 768px) {
  body { padding-bottom: 0; }

  .sidebar      { display: flex; }
  .bottom-nav   { display: none; }

  .main-content { margin-left: var(--nav-w); width: auto; }

  .page-header  { padding: 1.5rem 2rem 1rem; }
  .page-body    { padding: 1.5rem 2rem; }

  #toast-anchor { left: auto; right: 1.5rem; bottom: 1.5rem; max-width: 360px; }

  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .form-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

/* ── Large Desktop (>= 1024px) ──────────────────────────────────────────── */
@media (min-width: 1024px) {
  .detail-header     { grid-template-columns: 1fr 1fr; }
  .dashboard-cols    { grid-template-columns: 1fr 1fr; }
  .doc-customer-vehicle { grid-template-columns: 1fr 1fr; }
}

/* ── Container Queries ──────────────────────────────────────────────────── */
@container detail-header (min-width: 600px) {
  .detail-header { grid-template-columns: 1fr 1fr; }
}
@container dashboard-cols (min-width: 600px) {
  .dashboard-cols { grid-template-columns: 1fr 1fr; }
}
@container doc-cv (min-width: 500px) {
  .doc-customer-vehicle { grid-template-columns: 1fr 1fr; }
}

/* ── Print ──────────────────────────────────────────────────────────────── */
@media print {
  :root {
    --bg: #fff; --surface: #fff; --surface-2: #f5f5f5;
    --text: #111; --text-muted: #555; --border: #ccc;
  }
  .sidebar, .bottom-nav, .btn-group, .add-item-row, .add-item-wrap,
  .status-bar, #toast-anchor, .filter-tabs, .no-print { display: none !important; }

  body          { padding-bottom: 0; font-size: 12pt; }
  .main-content { margin-left: 0 !important; }
  .app-shell    { display: block; }
  .public-wrap  { max-width: 100%; margin: 0; padding: 0; }
  .public-doc   { border: none; padding: 0; }

  table         { font-size: 11pt; }
  thead th      { background: #f0f0f0 !important; color: #333 !important; }
  .badge        { border: 1px solid #999; color: #333 !important; background: #f5f5f5 !important; }

  @page { margin: 1.5cm; }
}
