/* ── Login overlay ───────────────────────────────────────── */
#login-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #0f172a;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
#login-overlay.active { display: flex; }

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 4px;
}
.login-sub {
  font-size: .85rem;
  color: #64748b;
  margin-bottom: 28px;
}
.login-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #475569;
  margin-bottom: 6px;
}
.login-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  font-size: .95rem;
  color: #1a1a2e;
  transition: border-color .15s;
  margin-bottom: 10px;
}
.login-input:focus { border-color: #3b82f6; outline: none; }
.login-error {
  min-height: 20px;
  font-size: .82rem;
  color: #dc2626;
  margin-bottom: 12px;
}
.login-btn { width: 100%; justify-content: center; }

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

/* Global keyboard focus ring — never invisible */
:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: #f0f2f5;
  color: #1a1a2e;
}

/* ── Header ──────────────────────────────────────────────── */
header {
  background: #1a1a2e;
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  position: sticky;
  top: 0;
  z-index: 100;
}

@media (max-width: 640px) {
  header { padding: 10px 16px; }
  .header-title { font-size: 1rem; }
  .header-sub { font-size: .78rem; }
}

.header-left { display: flex; align-items: baseline; gap: 12px; }
.header-title { font-size: 1.2rem; font-weight: 700; letter-spacing: .3px; }
.header-sub {
  font-size: .85rem;
  color: #a0aec0;
  font-weight: 400;
}

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  min-width: 260px;
  max-width: 380px;
  padding: 14px 18px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 999;
}
#toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
#toast.success { background: #22c55e; color: #fff; }
#toast.error   { background: #ef4444; color: #fff; }

/* ── Spinner overlay ─────────────────────────────────────── */
#spinner-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.55);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
#spinner-overlay.active { display: flex; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Main layout ─────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 28px auto;
  padding: 0 24px 60px;
}

/* ── Card base ───────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
  padding: 20px 24px;
}

/* ── Mileage card ────────────────────────────────────────── */
#mileage-section {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.mileage-card { flex: 1 1 320px; }

.mileage-stats { display: flex; gap: 32px; flex-wrap: wrap; margin-bottom: 16px; }

.stat-block { display: flex; flex-direction: column; }
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .6px; color: #64748b; font-weight: 600; margin-bottom: 2px; }
.stat-value { font-size: 2rem; font-weight: 700; color: #1a1a2e; line-height: 1.1; }
.stat-value.large { font-size: 2.6rem; }
.stat-value span.unit { font-size: 1rem; font-weight: 500; color: #94a3b8; margin-left: 3px; }

.stat-secondary { font-size: .95rem; color: #334155; }
#stat-last-date { margin-top: 2px; font-size: .82rem; color: #64748b; }

/* inline update form */
#odometer-form-wrapper { margin-top: 14px; }
#odometer-actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#update-odometer-group { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
#photo-mobile-hint { font-size: .7rem; color: #64748b; }
#photo-input { display: none; }
#photo-confirm-panel {
  margin-top: 12px;
  padding: 14px 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}
#photo-confirm-msg { margin: 0 0 12px; font-size: .9rem; color: #1a1a2e; }
#odometer-form {
  display: none;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  margin-top: 10px;
  gap: 10px;
  flex-direction: column;
}
#odometer-form.open { display: flex; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; }
.form-group label { font-size: .78rem; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: .5px; }
.form-group-wide { flex: 2 1 200px; }

input[type="number"],
input[type="date"],
input[type="text"],
textarea {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: .92rem;
  font-family: inherit;
  color: #1a1a2e;
  background: #fff;
  width: 100%;
  transition: border-color .15s;
}
input:focus, textarea:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

.input-with-unit { position: relative; }
.input-with-unit input { padding-right: 36px; }
.input-unit {
  position: absolute;
  right: 10px; top: 50%; transform: translateY(-50%);
  font-size: .78rem; color: #94a3b8; font-weight: 600; pointer-events: none;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 7px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary   { background: #3b82f6; color: #fff; }
.btn-primary:hover:not(:disabled)   { background: #2563eb; }

.btn-success   { background: #22c55e; color: #fff; }
.btn-success:hover:not(:disabled)   { background: #16a34a; }

.btn-amber     { background: #f59e0b; color: #fff; }
.btn-amber:hover:not(:disabled)     { background: #d97706; }

.btn-ghost {
  background: transparent;
  color: #475569;
  border: 1px solid #cbd5e1;
}
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; }

.btn-sm { padding: 7px 14px; font-size: .82rem; min-height: 36px; }

@media (max-width: 640px) {
  .btn-sm { min-height: 44px; padding: 10px 14px; }
}

/* ── Section headers ─────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 32px 0 14px;
}
.section-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1a1a2e;
}
.section-count {
  background: #e2e8f0;
  color: #475569;
  font-size: .75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
}

/* ── Task cards ──────────────────────────────────────────── */
.task-list { display: flex; flex-direction: column; gap: 10px; }

.task-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  border-left: 4px solid transparent;
  padding: 16px 18px;
  transition: box-shadow .15s;
}
.task-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,.11); }

.task-card.status-overdue,
.task-card.status-never_done { background: #fff5f5; border-left-color: #ef4444; }
.task-card.status-due_soon   { background: #fffbf0; border-left-color: #f59e0b; }
.task-card.status-ok         { background: #f0fdf4; border-left-color: #22c55e; }

.task-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.task-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-name { font-size: 1rem; font-weight: 700; color: #1a1a2e; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  background: #e2e8f0;
  color: #475569;
}
.badge-engine    { background: #dbeafe; color: #1d4ed8; }
.badge-oil       { background: #dbeafe; color: #1d4ed8; }
.badge-tires     { background: #fce7f3; color: #be185d; }
.badge-tire      { background: #fce7f3; color: #be185d; }
.badge-brakes    { background: #fee2e2; color: #b91c1c; }
.badge-brake     { background: #fee2e2; color: #b91c1c; }
.badge-fluids    { background: #d1fae5; color: #065f46; }
.badge-fluid     { background: #d1fae5; color: #065f46; }
.badge-cooling   { background: #cffafe; color: #0e7490; }
.badge-filters   { background: #ede9fe; color: #6d28d9; }
.badge-filter    { background: #ede9fe; color: #6d28d9; }
.badge-lighting  { background: #fef9c3; color: #854d0e; }
.badge-electrical{ background: #fef9c3; color: #854d0e; }
.badge-suspension{ background: #ffedd5; color: #9a3412; }
.badge-belts     { background: #e0f2fe; color: #0369a1; }
.badge-belt      { background: #e0f2fe; color: #0369a1; }
.badge-battery   { background: #fefce8; color: #713f12; }
.badge-ac        { background: #f0fdf4; color: #166534; }
.badge-body      { background: #fde8d8; color: #9a3412; }
.badge-exhaust   { background: #f5f5f4; color: #44403c; }
.badge-wipers    { background: #eff6ff; color: #1e40af; }
.badge-wiper     { background: #eff6ff; color: #1e40af; }
.badge-inspection{ background: #fdf4ff; color: #7e22ce; }

.task-meta {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.meta-item { display: flex; flex-direction: column; }
.meta-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .5px; color: #94a3b8; font-weight: 600; }
.meta-value { font-size: .88rem; color: #334155; font-weight: 500; }
.meta-value.highlight-red    { color: #dc2626; font-weight: 700; }
.meta-value.highlight-amber  { color: #d97706; font-weight: 700; }
.meta-value.highlight-green  { color: #16a34a; font-weight: 700; }

.task-notes { margin-top: 8px; font-size: .82rem; font-style: italic; color: #64748b; }

/* inline mark-done form */
.mark-done-form-wrapper { margin-top: 12px; }
.mark-done-form {
  display: none;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px;
  flex-direction: column;
  gap: 10px;
}
.mark-done-form.open { display: flex; }

/* empty state */
.empty-section {
  color: #94a3b8;
  font-size: .9rem;
  padding: 12px 0;
  font-style: italic;
}

/* ── Tabs ───────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 4px;
  margin: 28px 0 16px;
  border-bottom: 2px solid #e2e8f0;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border: none;
  background: transparent;
  font-size: .88rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 6px 6px 0 0;
  transition: color .15s, background .15s;
}
.tab-btn:hover { background: #f1f5f9; color: #1a1a2e; }
.tab-btn.active { color: #1a1a2e; border-bottom-color: #3b82f6; }

.tab-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #475569;
}
.tab-btn.active .tab-badge { background: #3b82f6; color: #fff; }
.tab-btn[data-tab="overdue"].active .tab-badge { background: #ef4444; }
.tab-btn[data-tab="due_soon"].active .tab-badge { background: #f59e0b; }
.tab-btn[data-tab="ok"].active .tab-badge { background: #22c55e; }

/* ── Manual Q&A ──────────────────────────────────────────── */
#manual-qa-section { margin-bottom: 28px; }
#manual-qa-title { font-size: 1.05rem; font-weight: 700; color: #1a1a2e; }
#manual-qa-subtitle { font-size: .8rem; color: #64748b; margin-top: 2px; margin-bottom: 14px; }

#manual-qa-history {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 340px;
  overflow-y: auto;
  margin-bottom: 12px;
}
#manual-qa-history:empty { display: none; margin-bottom: 0; }

.manual-qa-turn { display: flex; flex-direction: column; gap: 6px; }

.manual-qa-question {
  align-self: flex-end;
  max-width: 85%;
  background: #3b82f6;
  color: #fff;
  padding: 8px 14px;
  border-radius: 12px 12px 2px 12px;
  font-size: .88rem;
  white-space: pre-wrap;
}

.manual-qa-answer {
  align-self: flex-start;
  max-width: 90%;
  background: #f1f5f9;
  color: #1a1a2e;
  padding: 10px 14px;
  border-radius: 12px 12px 12px 2px;
  font-size: .88rem;
  white-space: pre-wrap;
}
.manual-qa-answer.manual-qa-pending { color: #94a3b8; font-style: italic; }
.manual-qa-answer.manual-qa-error { background: #fee2e2; color: #991b1b; }

.manual-qa-sources {
  align-self: flex-start;
  font-size: .72rem;
  color: #94a3b8;
}

#manual-qa-form { display: flex; gap: 8px; }
#manual-qa-question { flex: 1 1 auto; }

/* ── Task table ─────────────────────────────────────────── */
.task-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 28px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
  overflow: hidden;
}

/* Visually hidden but readable by screen readers */
.table-caption {
  caption-side: top;
  font-size: .78rem;
  color: #64748b;
  text-align: left;
  padding: 8px 16px 6px;
  background: #fff;
  border-bottom: 1px solid #f1f5f9;
}

.task-table thead tr {
  background: #1a1a2e;
  color: #fff;
}

.task-table th {
  padding: 13px 16px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  text-align: left;
}

.col-task   { width: 52%; }
.col-bucket { width: 16%; text-align: center; }

.col-urgent { border-left: 3px solid #ef4444; }
.col-medium { border-left: 3px solid #f59e0b; }
.col-later  { border-left: 3px solid #22c55e; }

.task-row td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.task-row:last-of-type td { border-bottom: none; }

.task-row:hover td { background: #f8fafc; }

.task-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.task-interval {
  font-size: .75rem;
  color: #94a3b8;
  margin-top: 2px;
}

.collapse-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: #94a3b8;
  font-size: .8rem;
  /* Minimum 44×44px touch target */
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  line-height: 1;
  transition: color .15s, transform .2s, background .15s;
}
.collapse-btn:hover { color: #475569; background: #f1f5f9; }
.collapse-btn:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }
.collapse-btn.open { transform: rotate(180deg); }

.task-detail {
  display: none;
  margin-top: 8px;
}
.task-detail.open { display: block; }

.mark-done-btn { margin-top: 8px; }

/* checkmark in bucket cell */
.checkmark {
  display: block;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: #16a34a;
  line-height: 1;
}

/* mark-done form row */
.mark-done-row { display: none; }
.mark-done-row td {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  padding: 16px;
}

/* ── Getting started banner ─────────────────────────────── */
#getting-started {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 24px;
}
#getting-started h3 {
  font-size: .95rem;
  font-weight: 700;
  color: #1e40af;
  margin-bottom: 10px;
}
#getting-started ol {
  margin: 0 0 14px 18px;
  padding: 0;
  font-size: .88rem;
  color: #1e3a8a;
  line-height: 1.7;
}
#getting-started .gs-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
#getting-started .gs-tip {
  font-size: .8rem;
  color: #3b82f6;
}

/* ── Error banner ────────────────────────────────────────── */
#error-banner {
  display: none;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: .9rem;
}
#error-banner.show { display: block; }

/* ── Mobile responsiveness ───────────────────────────────── */
@media (max-width: 640px) {
  main {
    margin: 16px auto;
    padding: 0 12px 48px;
  }

  /* Mileage stats: stack vertically */
  .mileage-stats {
    gap: 16px;
  }

  .stat-value { font-size: 1.6rem; }
  .stat-value.large { font-size: 2rem; }

  /* Task table: hide the three bucket columns on mobile.
     !important is needed to override the browser's UA stylesheet
     which sets table cells to display:table-cell at high specificity. */
  .task-table th.col-bucket,
  .task-table td.col-bucket { display: none !important; }
  .task-table .col-task { width: 100%; }

  /* Tighter row padding on mobile */
  .task-row td {
    padding: 10px 12px;
  }

  /* Mark-done form: stack fields vertically */
  .mark-done-row td {
    padding: 12px;
  }

  /* Getting started: reduce padding */
  #getting-started {
    padding: 14px 14px;
  }

  /* Odometer form fields stack naturally at flex-wrap */
  .form-group { flex: 1 1 100%; }
}

/* ── Status colour helpers (for inline colour spans in getting-started) */
.status-color-red    { color: #dc2626; font-weight: 600; }
.status-color-amber  { color: #d97706; font-weight: 600; }
.status-color-green  { color: #16a34a; font-weight: 600; }
