/* Milemark — tidy logbook styling */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1c2430;
  --ink-soft: #5b6675;
  --ink-faint: #8b95a3;
  --line: #e3e7ec;
  --accent: #2563eb;
  --accent-ink: #1d4ed8;
  --accent-soft: #e8effd;
  --warn: #b45309;
  --warn-bg: #fef3e2;
  --warn-line: #f3d9ae;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 60;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

.hidden { display: none !important; }

/* ---------- Header ---------- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.header-inner {
  max-width: 1060px; margin: 0 auto; padding: .7rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .65rem; }
.brand-mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand-name { font-size: 1.15rem; margin: 0; letter-spacing: -.01em; }
.brand-tag { margin: 0; font-size: .78rem; color: var(--ink-soft); }

.vehicle-switcher { display: flex; align-items: center; gap: .5rem; }
.vehicle-switcher select {
  font: inherit; padding: .45rem .6rem; border: 1px solid var(--line);
  border-radius: 9px; background: var(--surface); color: var(--ink);
  max-width: 200px; min-height: 40px;
}

/* ---------- Layout ---------- */
.app-main {
  max-width: 1060px; margin: 0 auto; padding: 1.25rem 1rem 3rem;
  display: grid; gap: 1.25rem;
}

/* ---------- Summary ---------- */
.summary {
  display: grid; gap: .8rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.summary-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .15rem; min-width: 0;
}
.summary-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-faint); font-weight: 600;
}
.summary-value {
  font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.summary-business .summary-value { color: var(--accent-ink); }
.summary-sub { font-size: .78rem; color: var(--ink-soft); }
.cat-list, .month-list {
  list-style: none; margin: .25rem 0 0; padding: 0;
  display: flex; flex-direction: column; gap: .2rem;
  font-size: .82rem; max-height: 7.5em; overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
}
.cat-list li, .month-list li {
  display: flex; justify-content: space-between; gap: .75rem;
  font-variant-numeric: tabular-nums;
}
.cat-list .cat-name, .month-list .month-name { color: var(--ink-soft); }
.cat-list .empty-note, .month-list .empty-note { color: var(--ink-faint); font-style: italic; }
.cat-dot { display: inline-block; width: .55em; height: .55em; border-radius: 50%; margin-right: .4em; }

/* ---------- Quick add ---------- */
.quick-add {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.quick-add h2, .log-section h2 { font-size: 1rem; margin: 0 0 .8rem; }
#entry-form {
  display: grid; gap: .8rem; align-items: end;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-notes { grid-column: 1 / -1; }
.field label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.optional { font-weight: 400; color: var(--ink-faint); }
.field input, .field select {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 9px; background: #fbfcfd; color: var(--ink);
  min-height: 42px; width: 100%;
}
.field input:focus, .field select:focus, .vehicle-switcher select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
.form-actions { display: flex; gap: .5rem; align-items: center; }
.form-hint { grid-column: 1 / -1; margin: 0; font-size: .8rem; color: var(--ink-soft); min-height: 1.1em; }
.form-hint.warn { color: var(--warn); }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 9px; border: 1px solid transparent;
  padding: .5rem .9rem; min-height: 40px;
  display: inline-flex; align-items: center; gap: .45rem;
  transition: background .15s, border-color .15s, color .15s;
}
.btn svg { width: 15px; height: 15px; flex: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-ink); }
.btn-secondary:hover { background: #d8e5fc; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: #f0f2f5; color: var(--ink); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-small { padding: .3rem .55rem; min-height: 36px; font-size: .8rem; }

/* ---------- Log table ---------- */
.log-section {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.log-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; padding: 1rem 1.1rem .6rem; flex-wrap: wrap;
}
.log-toolbar h2 { margin: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.vehicle-name-chip {
  font-size: .75rem; font-weight: 600; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 999px; padding: .15rem .6rem;
}
.log-actions { display: flex; gap: .5rem; }

.table-wrap { overflow-x: auto; }
.log-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.log-table th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-faint); font-weight: 600;
  padding: .55rem .8rem; border-bottom: 1px solid var(--line);
  background: #fafbfc; position: sticky; top: 0;
}
.log-table th.num, .log-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.log-table td { padding: .55rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.log-table tbody tr:last-child td { border-bottom: none; }
.log-table tbody tr:hover { background: #f7f9fc; }

.date-cell { white-space: nowrap; }
.date-rel { display: block; font-size: .74rem; color: var(--ink-faint); }
.odo-cell { font-family: var(--mono); font-size: .85rem; }
.miles-cell { font-weight: 650; }
.miles-none { color: var(--ink-faint); font-weight: 400; }
.purpose-pill {
  display: inline-block; font-size: .74rem; font-weight: 600;
  border-radius: 999px; padding: .12rem .55rem; white-space: nowrap;
}
.purpose-none { color: var(--ink-faint); font-size: .8rem; }
.purpose-business   { background: #e3edfd; color: #1d4ed8; }
.purpose-commute    { background: #e6f4ec; color: #15803d; }
.purpose-personal   { background: #f1f2f4; color: #5b6675; }
.purpose-medical    { background: #fde8e8; color: #b91c1c; }
.purpose-charitable { background: #f3eafd; color: #7c3aed; }
.notes-cell { color: var(--ink-soft); max-width: 260px; overflow-wrap: anywhere; }

.row-actions { white-space: nowrap; text-align: right; }
.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--ink-faint);
  padding: .35rem; border-radius: 7px; min-width: 36px; min-height: 36px;
}
.icon-btn:hover { background: #eef1f5; color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn svg { width: 15px; height: 15px; vertical-align: middle; }

tr.row-warning { background: var(--warn-bg); }
tr.row-warning:hover { background: #fdeed3; }
tr.row-warning td { border-bottom-color: var(--warn-line); }
.flag-list { list-style: none; margin: .3rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .2rem; }
.flag-item {
  font-size: .74rem; color: var(--warn); display: flex; gap: .35rem; align-items: baseline;
}
.flag-item::before { content: "⚠"; font-size: .8em; }
.flag-actions { margin-top: .3rem; display: flex; gap: .4rem; flex-wrap: wrap; }
.flag-btn {
  font: inherit; font-size: .72rem; font-weight: 600; cursor: pointer;
  background: #fff; border: 1px solid var(--warn-line); color: var(--warn);
  border-radius: 7px; padding: .25rem .55rem; min-height: 32px;
}
.flag-btn:hover { background: #fdf6e7; }
.flag-ack {
  font-size: .72rem; color: var(--ink-faint); font-style: italic; margin-top: .25rem;
}

/* ---------- Empty state ---------- */
.empty-state {
  padding: 2.5rem 1.5rem 3rem; text-align: center; color: var(--ink-soft);
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
}
.empty-art { width: 120px; height: 80px; color: var(--accent); margin-bottom: .4rem; }
.empty-state h3 { margin: 0; color: var(--ink); font-size: 1.05rem; }
.empty-state p { margin: 0 0 .8rem; max-width: 42ch; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 22, 34, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: 14px; padding: 1.4rem 1.5rem;
  max-width: 420px; width: 100%; box-shadow: 0 12px 40px rgba(15, 22, 34, .25);
}
.modal h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
.modal p { margin: 0 0 1rem; color: var(--ink-soft); font-size: .9rem; }
.modal-field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.modal-field label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.modal-field input {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 9px; min-height: 42px;
}
.modal-field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .5rem; z-index: 70; width: min(92vw, 420px);
}
.toast {
  background: #1c2430; color: #f2f5f9; border-radius: 10px;
  padding: .7rem 1rem; font-size: .86rem; box-shadow: 0 6px 24px rgba(15,22,34,.3);
  display: flex; gap: .5rem; align-items: baseline;
  animation: toast-in .22s ease-out;
}
.toast.toast-ok::before { content: "✓"; color: #4ade80; font-weight: 700; }
.toast.toast-warn::before { content: "⚠"; color: #fbbf24; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ---------- Footer ---------- */
.app-footer { text-align: center; color: var(--ink-faint); font-size: .78rem; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .header-inner { padding: .6rem .8rem; }
  .brand-tag { display: none; }
  .app-main { padding: 1rem .7rem 2.5rem; gap: 1rem; }
  #entry-form { grid-template-columns: 1fr 1fr; }
  .field-notes, .form-actions, .form-hint { grid-column: 1 / -1; }
  .form-actions .btn-primary { flex: 1; justify-content: center; }
  .summary { grid-template-columns: 1fr 1fr; }
  .summary-value { font-size: 1.35rem; }
  .notes-cell { max-width: 140px; }
  .log-table { font-size: .84rem; }
  .log-table th, .log-table td { padding: .5rem .55rem; }
}
@media (max-width: 400px) {
  #entry-form { grid-template-columns: 1fr; }
  .summary { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .btn { transition: none; }
}
