/* ---- Buttons ---- */
.btn {
  min-height: var(--tap);
  padding: 0 var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger.solid {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--sp-3); font-size: 13px; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.card h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: var(--sp-3);
}
.card-row {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.card-row:last-child { border-bottom: none; }
.card-row .label { color: var(--text-dim); }
.card-row .value { font-weight: 600; }

.bar-track {
  height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 4px;
}
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; }

/* ---- Hero / stat ---- */
.hero-figure { font-size: 28px; font-weight: 700; }
.hero-figure-sm { font-size: 22px; font-weight: 700; }
.hero-figure-md { font-size: 20px; font-weight: 700; }
.state-block-tight { padding: var(--sp-4); }
.state-block-tight h2 { font-size: 15px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-4); }
.stat-card .stat-label { color: var(--text-dim); font-size: 12px; display: flex; align-items: center; gap: 4px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat-value.positive { color: var(--positive); }
.stat-value.danger { color: var(--danger); }
/* 44px tap target wrapping a small visual dot, per UI.md §1.3 / §6 (icon
   targets must be >=44x44 even when the visible glyph is small). */
.info-btn {
  width: var(--tap); height: var(--tap); min-width: var(--tap); min-height: var(--tap);
  background: none; border: none; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle;
}
.info-btn .info-dot {
  width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--text-dim);
  color: var(--text-dim); font-size: 11px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---- Lists ---- */
.list { display: flex; flex-direction: column; gap: var(--sp-2); }
.list-row {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  min-height: var(--tap);
}
.list-row:hover { border-color: var(--accent); }
.list-row-top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-2); }
.list-row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-sub { color: var(--text-dim); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-right { text-align: right; flex-shrink: 0; }
.list-row-value { font-weight: 700; }
.list-row-meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 6px; border-radius: 5px;
  background: var(--surface-2); color: var(--text-dim);
}
.badge-danger { background: rgba(224,84,78,0.15); color: var(--danger); }
.badge-warn { background: rgba(224,163,46,0.15); color: var(--warn); }
.badge-positive { background: rgba(63,178,127,0.15); color: var(--positive); }

.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); min-width: var(--tap);
  padding: 0 var(--sp-3);
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim);
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip-row { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }

/* ---- Skeleton ---- */
.skeleton-row { height: 64px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); margin-bottom: var(--sp-2); overflow: hidden; position: relative; }
.skeleton-bar { height: 10px; border-radius: 4px; background: var(--surface-2); position: relative; overflow: hidden; }
.skeleton-bar::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
  animation: pulse 1.4s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) { .skeleton-bar::after { animation: none; } }
@keyframes pulse { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.skeleton-card { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); justify-content: center; height: 100%; }

/* ---- Empty / error states ---- */
.state-block {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
}
.state-block h2 { font-size: 16px; font-weight: 700; }
.state-block p { color: var(--text-dim); max-width: 320px; }
.state-actions { display: flex; gap: var(--sp-3); flex-wrap: wrap; justify-content: center; }

.error-card {
  border-left: 3px solid var(--danger);
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.error-card p { margin-bottom: var(--sp-3); }
.error-card .request-id { color: var(--text-dim); font-size: 11px; margin-top: var(--sp-2); }

/* ---- Toast ---- */
#toast-region {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom) + var(--sp-3));
  z-index: 60; display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); pointer-events: none;
}
.no-nav #toast-region { bottom: var(--sp-4); }
.toast {
  background: var(--surface); border: 1px solid var(--positive); border-left: 3px solid var(--positive);
  color: var(--text); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  box-shadow: var(--shadow); max-width: 90vw; font-size: 13px; font-weight: 600;
}
.toast.error-toast { border-color: var(--danger); border-left-color: var(--danger); }

/* ---- Sheet / modal ---- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--sp-4); padding-bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto var(--sp-4); }
.sheet h2 { font-size: 17px; font-weight: 700; margin-bottom: var(--sp-2); }
.sheet-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-4); }
.sheet-actions .btn { flex: 1; }

/* full screen viewer sheet */
.viewer-backdrop {
  position: fixed; inset: 0; background: #000; z-index: 55;
  display: flex; flex-direction: column;
}
.viewer-header { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3); }
.viewer-body { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; touch-action: pinch-zoom; }
.viewer-body img { max-height: 90vh; }

/* ---- Forms ---- */
.field { margin-bottom: var(--sp-4); }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: var(--sp-1); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .hint { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.field .live-preview { color: var(--text); font-size: 13px; font-weight: 600; margin-top: 4px; }
.field .field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field-from-receipt { position: relative; }
.receipt-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; color: var(--accent);
  background: rgba(232,132,43,0.14); border-radius: 5px; padding: 2px 6px; margin-top: 4px;
}
.receipt-tag button { background: none; border: none; color: inherit; cursor: pointer; padding: 0; font-size: 13px; line-height: 1; }

.password-field { position: relative; }
.password-toggle {
  position: absolute; right: 4px; top: 24px; width: var(--tap); height: var(--tap);
  background: none; border: none; color: var(--text-dim); cursor: pointer;
}

fieldset { border: none; padding: 0; margin: 0 0 var(--sp-4); }
legend { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); margin-bottom: var(--sp-3); padding: 0; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.segmented button { flex: 1; min-height: var(--tap); border: none; background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap); gap: var(--sp-3); }
.toggle-row .toggle-label { font-weight: 600; }
.toggle-row .toggle-hint { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
/* The visual pill stays a compact 46x26, but the whole label is a 44px-tall
   tap target (UI.md §1.3: every interactive target >=44x44), with the pill
   vertically centered inside it. */
.switch { position: relative; display: inline-flex; align-items: center; width: 46px; height: var(--tap); flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch .track { position: absolute; top: 50%; left: 0; width: 46px; height: 26px; margin-top: -13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; transition: background 0.15s; }
.switch .thumb { position: absolute; top: 50%; left: 2px; width: 20px; height: 20px; margin-top: -10px; border-radius: 50%; background: var(--text-dim); transition: transform 0.15s, background 0.15s; }
.switch input:checked ~ .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked ~ .thumb { transform: translateX(20px); background: var(--accent-ink); }

.sticky-bar {
  position: sticky; bottom: 0; left: 0; right: 0;
  display: flex; gap: var(--sp-3);
  background: var(--surface); border-top: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-4) calc(var(--sp-4) * -1) calc(var(--sp-4) * -1);
}
.sticky-bar .btn { flex: 1; }

.collapsible summary { cursor: pointer; font-weight: 600; padding: var(--sp-2) 0; list-style: none; display: flex; align-items: center; gap: var(--sp-2); }
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary::before { content: "▸"; display: inline-block; transition: transform 0.15s; }
.collapsible[open] summary::before { transform: rotate(90deg); }

/* B12 — opacity:0 alone leaves the tick in the accessibility tree, so a
   screen reader on Settings announced "Saved ✓" on every field before
   anything was touched. visibility:hidden removes it from that tree (unlike
   opacity), and the JS side also toggles aria-hidden for belt-and-suspenders. */
.saved-tick { color: var(--positive); font-size: 12px; font-weight: 700; opacity: 0; visibility: hidden; transition: opacity 0.2s; }
.saved-tick.show { opacity: 1; visibility: visible; }

.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--sp-2); }
.thumb-item { aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); position: relative; cursor: pointer; }
.thumb-item img { width: 100%; height: 100%; object-fit: cover; }
.thumb-item .kind-label { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.6); color: #fff; font-size: 10px; font-weight: 700; text-align: center; padding: 2px 0; }
.file-chip { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }

.progress-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3); background: var(--surface-2); border-radius: var(--radius); margin-bottom: var(--sp-3); }
.progress-track { flex: 1; height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.2s; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { text-align: left; padding: var(--sp-2) var(--sp-2); border-bottom: 1px solid var(--border); }
table.data-table th { color: var(--text-dim); font-weight: 600; }
.table-scroll { overflow-x: auto; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-dow { text-align: center; font-size: 11px; color: var(--text-dim); font-weight: 700; padding-bottom: 4px; }
.calendar-day {
  min-height: 44px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; position: relative; font-weight: 600;
}
.calendar-day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.calendar-day.empty { visibility: hidden; }
.calendar-day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); position: absolute; bottom: 4px; }
.calendar-day[data-status="off_duty"] { background: var(--surface-2); }
.calendar-day[data-status="sleeper"] { background: rgba(63,178,127,0.12); color: var(--positive); }
.calendar-day[data-status="driving"] { background: rgba(232,132,43,0.14); color: var(--accent); }
.calendar-day[data-status="on_duty"] { background: rgba(224,163,46,0.14); color: var(--warn); }
.calendar-day[data-status="home"] { background: rgba(154,168,178,0.14); }

/* M7 — the calendar's four status colors and per-diem dot had no legend. */
.calendar-legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border); background: var(--surface); }
.legend-swatch[data-status="off_duty"] { background: var(--surface-2); }
.legend-swatch[data-status="sleeper"] { background: rgba(63,178,127,0.4); }
.legend-swatch[data-status="driving"] { background: rgba(232,132,43,0.5); }
.legend-swatch[data-status="on_duty"] { background: rgba(224,163,46,0.5); }
.legend-swatch[data-status="home"] { background: rgba(154,168,178,0.5); }
.legend-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); border: none; }

.radio-group { display: flex; flex-direction: column; gap: var(--sp-2); }
.radio-option { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.radio-option input { width: 20px; height: 20px; }
.radio-option.is-checked { border-color: var(--accent); background: rgba(232,132,43,0.08); }

/* ---- Sharing (SHARING.md §8) ---- */
.category-check { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.category-check-row { display: flex; align-items: flex-start; gap: var(--sp-3); min-height: var(--tap); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.category-check-row input { width: 20px; height: 20px; margin-top: 2px; flex-shrink: 0; }
.category-check-row.is-checked { border-color: var(--accent); background: rgba(232,132,43,0.08); }
.category-check-row .cc-label { display: flex; flex-direction: column; }
.category-check-row .cc-hint { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

/* Sibling of .offline-bar, not amber — nothing is wrong, this is just a
   persistent "you're looking at someone else's books" reminder. */
.readonly-bar {
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: var(--sp-2) var(--sp-4);
}

.summary-strip { display: flex; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.summary-strip .item { flex: 1; min-width: 100px; }
.summary-strip .item .n { font-size: 20px; font-weight: 700; }
.summary-strip .item .l { color: var(--text-dim); font-size: 12px; }

.load-more-wrap { text-align: center; padding: var(--sp-4) 0; }

/* ---- Utility classes ----
   CSP is style-src 'self' with no 'unsafe-inline' (SPEC §3.5): HTML `style="..."`
   attributes are blocked, so any per-render styling goes through these classes
   (or, for genuinely per-instance values like a bar-fill width, through JS
   `el.style.setProperty(...)` after insertion — CSP does not restrict that). */
.u-dim { color: var(--text-dim); }
.u-danger { color: var(--danger); }
.u-bold { font-weight: 700; }
.u-bold-text { font-weight: 700; color: var(--text); }
.u-center { text-align: center; }
.u-right { text-align: right; }
.u-flex { display: flex; }
.u-flex-1 { flex: 1; }
.u-flex-gap-2 { display: flex; gap: var(--sp-2); }
.u-flex-gap-3 { display: flex; gap: var(--sp-3); }
.u-flex-between { display: flex; justify-content: space-between; }
.u-flex-center-gap { display: flex; align-items: center; gap: 8px; }
.u-mt-1 { margin-top: 4px; }
.u-mt-2 { margin-top: var(--sp-2); }
/* A bare inline text link (e.g. "View logbook" inside a card caption) is
   otherwise sized to its text alone, well under the 44px tap target UI.md
   §1.3/§6 requires — same fix as .forgot-link in screens.css, generalized. */
.u-tap-link { display: inline-flex; align-items: center; min-height: var(--tap); }
.u-mt-3 { margin-top: var(--sp-3); }
.u-mt-4 { margin-top: var(--sp-4); }
.u-mt-5-block { margin-top: var(--sp-5); }
.u-mt-neg { margin-top: -8px; }
.u-mb-2 { margin-bottom: var(--sp-2); }
.u-mb-3 { margin-bottom: var(--sp-3); }
.u-mb-4 { margin-bottom: var(--sp-4); }
.u-mb-5 { margin-bottom: var(--sp-5); }
.u-fs-12 { font-size: 12px; }
.u-fs-13 { font-size: 13px; }
.u-fs-15 { font-size: 15px; }
.u-fs-20 { font-size: 20px; }
.u-fs-22 { font-size: 22px; }
.u-uppercase { text-transform: uppercase; }
.u-cursor-default { cursor: default; }
.u-cursor-pointer { cursor: pointer; }
.u-w-full { width: 100%; }
.u-pad-3 { padding: var(--sp-3); }
.u-pad-4 { padding: var(--sp-4); }
.u-pad-45 { padding: var(--sp-5) var(--sp-4); }
.list-row.u-inactive { opacity: 0.55; }
.u-thumb-sm { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; margin-top: 6px; }
.u-toggle-row-tight { padding: var(--sp-2) 0; }
.bar-cell { position: relative; }
.bar-cell .bar-track { position: absolute; inset: 6px 4px; z-index: 0; }
.bar-cell .bar-cell-text { position: relative; z-index: 1; }
.progress-fill { width: 0; }
.sk-40 { width: 40%; }
.sk-70 { width: 70%; }
.sk-55 { width: 55%; }
.sk-30 { width: 30%; }
.boot-skeleton-bar { width: 60%; height: 20px; }
.sk-40-mb { width: 40%; margin-bottom: 12px; }
.sk-70-tall { width: 70%; height: 24px; margin-bottom: 8px; }
