:root {
  --ink: #14213d;
  --ink-soft: #3a4a6b;
  --paper: #f7f3ea;
  --card: #fffdf8;
  --accent: #e85d04;
  --accent-2: #0f8b8d;
  --accent-3: #f4a261;
  --ok: #2a9d8f;
  --warn: #e9c46a;
  --bad: #e63946;
  --line: rgba(20, 33, 61, 0.12);
  --shadow: 0 10px 30px rgba(20, 33, 61, 0.08);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(244, 162, 97, 0.35), transparent 35%),
    radial-gradient(circle at 90% 0%, rgba(15, 139, 141, 0.22), transparent 30%),
    linear-gradient(180deg, #fff8ef 0%, var(--paper) 40%, #efe7d8 100%);
  min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 3rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.nav a, .btn, button, .chip {
  border-radius: 999px;
  border: 1px solid transparent;
}

.nav a {
  padding: 0.4rem 0.85rem;
  background: rgba(255,255,255,0.55);
  color: var(--ink);
  border-color: var(--line);
}

.hero, .panel, .card, .auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  background:
    linear-gradient(135deg, rgba(232, 93, 4, 0.12), rgba(15, 139, 141, 0.1)),
    var(--card);
}

.hero h1, h1, h2, h3 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}

.muted { color: var(--ink-soft); }
.cost-link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--ink-soft) 45%, transparent);
  text-underline-offset: 0.18em;
}
.cost-link:hover {
  color: var(--ink);
  text-decoration-color: var(--ink);
}
.cost-breakdown {
  max-height: min(60vh, 28rem);
  overflow: auto;
}
.cost-breakdown table {
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.card { padding: 1rem; overflow: hidden; }
.card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 0.75rem;
  background: #ddd;
}

.panel { padding: 1.1rem 1.25rem; margin-bottom: 1rem; }

.stack { display: grid; gap: 0.75rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.inline-form { display: inline; margin: 0; }

label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.92rem; }

label.check-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

label.check-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex-shrink: 0;
}

label.check-row span {
  white-space: normal;
}

/* Car page: destructive / edit controls only while Edit mode is on */
.edit-only {
  display: none !important;
}

body.car-editing a.edit-only,
body.car-editing button.edit-only {
  display: inline-flex !important;
}

body.car-editing form.edit-only {
  display: block !important;
}

body.car-editing th.edit-only,
body.car-editing td.edit-only {
  display: table-cell !important;
}

body.car-editing td.edit-only .row,
body.car-editing .row.edit-only {
  display: flex !important;
}

body.car-editing #edit-mode-toggle {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.log-toolbar {
  display: grid;
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
}

.log-search {
  display: grid;
  gap: 0.35rem;
  max-width: 22rem;
}

.log-filter.is-active {
  background: rgba(15, 139, 141, 0.18);
  color: #0b5f61;
  box-shadow: inset 0 0 0 1px rgba(15, 139, 141, 0.35);
}

.log-timeline {
  display: grid;
  gap: 0.75rem;
}

.log-year {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.7);
  overflow: hidden;
}

.log-year-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  list-style: none;
  font-family: var(--font-display);
}

.log-year-summary::-webkit-details-marker { display: none; }

.log-year-summary::after {
  content: "▸";
  color: var(--ink-soft);
  margin-left: auto;
}

.log-year[open] .log-year-summary::after {
  content: "▾";
}

.log-year-body {
  display: grid;
  gap: 0.75rem;
  padding: 0 0.85rem 0.95rem;
}

.log-visit {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 0.85rem 0.95rem;
}

.log-visit-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.55rem;
}

.log-visit-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.log-visit-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.log-visit-items li {
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}

.log-visit-items li:first-child {
  border-top: none;
  padding-top: 0;
}

.log-item-main {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.log-empty-filter {
  margin: 0 0 0.75rem;
}
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

textarea { min-height: 120px; resize: vertical; }

.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--ink);
  color: white;
}

.btn.secondary, button.secondary {
  background: white;
  color: var(--ink);
  border-color: var(--line);
}

.btn.accent { background: var(--accent); }
.btn.teal { background: var(--accent-2); }
.btn.danger { background: var(--bad); }

.chip {
  display: inline-flex;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  background: #fff;
  border-color: var(--line);
}

.chip.ok { background: rgba(42,157,143,0.15); color: #136f66; }
.chip.warn { background: rgba(233,196,106,0.35); color: #7a5b00; }
.chip.bad { background: rgba(230,57,70,0.15); color: #9b1521; }
.chip.unknown { background: rgba(58,74,107,0.1); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.defer-details { display: inline-block; }
.defer-toggle {
  cursor: pointer;
  list-style: none;
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
}
.defer-details summary::-webkit-details-marker { display: none; }
.defer-form {
  margin-top: 0.5rem;
  padding: 0.75rem;
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: min(420px, 100%);
  padding: 1.5rem;
}

.chat {
  display: grid;
  align-content: start;
  gap: 0.75rem;
  max-height: 360px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem;
  background: rgba(15,139,141,0.06);
  border-radius: 14px;
}

.bubble {
  max-width: 85%;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  white-space: pre-wrap;
}

.bubble.user {
  justify-self: end;
  background: var(--ink);
  color: white;
}

.bubble.assistant {
  justify-self: start;
  background: white;
  border: 1px solid var(--line);
}

.flash-error {
  background: rgba(230,57,70,0.12);
  color: #9b1521;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
}

.flash-success {
  background: rgba(42, 157, 143, 0.12);
  color: #1d6b62;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
}

.two-col {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
}

.car-main-solo {
  max-width: 920px;
  margin: 0 auto;
  display: grid;
  gap: 0.85rem;
}

.car-hero-identity {
  align-items: flex-start;
  gap: 0.85rem;
  min-width: 0;
}

.car-hero-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.car-photo-thumb {
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 !important;
  margin: 0.15rem 0 0;
  border: 1px solid var(--line);
  border-radius: 10px !important;
  overflow: hidden;
  background: var(--card);
  cursor: zoom-in;
  box-shadow: none;
}

.car-photo-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.car-photo-thumb:hover {
  border-color: var(--accent-2);
}

.due-list {
  display: grid;
  gap: 0.65rem;
}

.due-card {
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}

.due-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.due-card-top strong {
  font-size: 0.98rem;
  line-height: 1.3;
}

.due-card-notes {
  margin: 0.35rem 0 0.55rem;
  font-size: 0.9rem;
}

.due-card .defer-details {
  margin-top: 0.35rem;
}

.log-service-fab {
  position: fixed;
  left: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  padding: 0.85rem 1.25rem;
  box-shadow: 0 12px 28px rgba(232, 93, 4, 0.35);
}

.log-service-fab:hover {
  filter: brightness(1.05);
}

.page-dialog-compact {
  inset: unset;
  top: unset;
  bottom: unset;
  max-width: min(560px, calc(100vw - 1.5rem));
  width: min(560px, calc(100vw - 1.5rem));
  max-height: min(90dvh, 720px);
  height: fit-content;
  overflow-x: hidden;
  overflow-y: auto;
}

.page-dialog-compact[open] {
  display: block;
}

.page-dialog-compact .page-dialog-inner {
  height: auto;
  max-height: none;
  overflow: visible;
}

.insurance-policy-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.insurance-policy-header h2 {
  margin: 0 0 0.25rem;
}

.insurance-premium {
  text-align: right;
}

.insurance-premium strong {
  font-size: 1.25rem;
}

.insurance-facts {
  display: grid;
  gap: 0.55rem;
  margin: 0 0 1rem;
}

.insurance-facts > div {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 0.5rem;
}

.insurance-facts dt {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
}

.insurance-facts dd {
  margin: 0;
}

.insurance-vehicles {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: grid;
  gap: 0.65rem;
}

.insurance-vehicles li {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}

.insurance-card {
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}

.insurance-notes {
  white-space: pre-wrap;
  margin: 0.75rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.photo-dialog {
  inset: unset;
  max-width: min(960px, calc(100vw - 1.5rem));
  width: fit-content;
  max-height: min(90dvh, 900px);
  height: fit-content;
  background: transparent;
  padding: 0;
  overflow: auto;
}

.photo-dialog[open] {
  display: block;
}

.photo-dialog-close {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.photo-dialog img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(80vh, 800px);
  height: auto;
  margin: 0 auto;
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(20, 33, 61, 0.35);
  background: var(--card);
}

.collapsible-panel {
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
}

.collapsible-panel > summary {
  list-style: none;
  cursor: pointer;
}

.collapsible-panel > summary::-webkit-details-marker {
  display: none;
}

.collapsible-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.collapsible-summary h2 {
  margin: 0;
  font-size: 1.15rem;
}

.collapsible-summary::after {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s ease;
}

.collapsible-panel[open] > .collapsible-summary::after {
  transform: rotate(90deg);
}

.collapsible-body {
  margin-top: 0.85rem;
}

.page-dialog {
  border: none;
  padding: 0;
  /* Definite height via top/bottom — required for nested scroll in Safari. */
  inset: 4vh auto;
  width: min(960px, calc(100vw - 1.5rem));
  max-width: min(960px, calc(100vw - 1.5rem));
  max-height: none;
  height: auto;
  margin: auto;
  border-radius: 16px;
  background: transparent;
  overflow: hidden;
  box-sizing: border-box;
}

.page-dialog[open] {
  display: flex;
  flex-direction: column;
}

.page-dialog::backdrop {
  background: rgba(20, 33, 61, 0.45);
}

.page-dialog-inner {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(20, 33, 61, 0.28);
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.page-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex: 0 0 auto;
  padding: 1.25rem 1.35rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.page-dialog-header h2 {
  margin: 0 0 0.35rem;
}

.page-dialog-scroller {
  flex: 1 1 0%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem 1.35rem 1.5rem;
  touch-action: pan-y;
}

.page-dialog-body {
  /* Back-compat alias used by cost modals */
  flex: 1 1 0%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 0 0.25rem;
  touch-action: pan-y;
}

.page-dialog-footer {
  /* Deprecated sticky footer — keep styles harmless if present */
  flex: 0 0 auto;
}

.car-layout {
  grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.1fr);
  align-items: start;
}

.chat-dock {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 2px solid rgba(15, 139, 141, 0.35);
  background:
    linear-gradient(180deg, rgba(15, 139, 141, 0.1), transparent 40%),
    var(--card);
}

.chat-dock #chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.chat-dock .chat {
  flex: 1;
  min-height: 180px;
  max-height: none;
}

.suggest-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.chip.suggest {
  cursor: pointer;
  background: rgba(15, 139, 141, 0.12);
  border-color: rgba(15, 139, 141, 0.28);
  color: #0b5f61;
}

.chip.suggest:hover {
  background: rgba(15, 139, 141, 0.22);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chat-form input {
  flex: 1;
}

.htmx-indicator {
  display: none;
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
}

.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator {
  display: block;
}

.global-chat-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  width: auto;
  min-width: 3.5rem;
  height: 3.5rem;
  padding: 0 1.15rem;
  border-radius: 999px;
  border: none;
  background: var(--accent-2);
  color: white;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(15, 139, 141, 0.35);
}

.global-chat-fab:hover {
  filter: brightness(1.05);
}

.global-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 33, 61, 0.35);
  z-index: 70;
  display: none;
}

body.global-chat-open .global-chat-backdrop {
  display: block;
}

.global-chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 80;
  width: min(420px, 100vw);
  height: 100vh;
  height: 100dvh;
  transform: translateX(105%);
  transition: transform 0.2s ease;
  pointer-events: none;
}

#global-chat-host {
  height: 100%;
}

body.global-chat-open {
  overflow: hidden;
}

body.global-chat-open .global-chat-drawer {
  transform: translateX(0);
  pointer-events: auto;
}

.global-chat-panel {
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1rem 1.25rem;
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(20, 33, 61, 0.18);
  overflow: hidden;
}

.global-chat-header,
.global-car-picker,
.global-chat-panel .suggest-row,
.global-chat-panel .chat-form,
.global-chat-panel .htmx-indicator,
.global-chat-panel .flash-error {
  flex-shrink: 0;
}

.global-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.global-car-picker {
  display: grid;
  gap: 0.35rem;
}

.global-chat-panel .chat {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.app-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 33, 61, 0.45);
  z-index: 90;
  display: none;
}

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: none;
}

body.app-modal-open {
  overflow: hidden;
}

body.app-modal-open .app-modal-backdrop {
  display: block;
}

body.app-modal-open .app-modal {
  display: flex;
  pointer-events: auto;
}

.app-modal-body {
  width: min(1100px, 100%);
  max-height: min(90vh, 900px);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(20, 33, 61, 0.28);
  padding: 1.25rem 1.35rem 1.5rem;
}

.schedule-review-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.schedule-review-header h2 {
  margin: 0 0 0.35rem;
}

.table-scroll {
  overflow-x: auto;
  overscroll-behavior: contain;
}

.review-open {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble .review-open {
  color: inherit;
}

@media (max-width: 820px) {
  .two-col,
  .car-layout { grid-template-columns: 1fr; }
  .chat-dock { position: static; order: -1; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .global-chat-drawer { width: 100vw; }
  .app-modal { padding: 0.5rem; }
  .app-modal-body {
    max-height: 95vh;
    border-radius: 12px;
    padding: 1rem;
  }
  .log-service-fab {
    left: 1rem;
    bottom: 1rem;
    padding: 0.75rem 1.05rem;
  }
  .global-chat-fab {
    right: 1rem;
    bottom: 1rem;
  }
}
