:root {
  --app-width: 480px;
  --mobile-gutter: 16px;
  --mobile-nav-height: 68px;
}

html {
  background: #ececef;
}

body {
  min-width: 320px;
  background: #ececef;
  font-size: 16px;
  overscroll-behavior-y: none;
}

.shell {
  width: min(100%, var(--app-width));
  min-height: 100dvh;
  margin-inline: auto;
  background: var(--bg);
  box-shadow: none;
  overflow: clip;
}

.topbar {
  width: 100%;
  height: calc(58px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--mobile-gutter) 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.brand {
  gap: 9px;
  font-size: 16px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
}

.topbar-actions {
  gap: 6px;
}

.connection {
  display: none;
}

.header-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}

.header-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.profile-button {
  width: auto;
  min-width: 44px;
  height: 44px;
  padding-inline: 10px;
  white-space: nowrap;
  background: transparent;
}

.profile-button svg {
  width: 21px;
  height: 21px;
}

.profile-button span {
  display: inline;
  font-size: 13px;
}

.account-button {
  padding-inline: 8px;
}

.logged-out .topbar,
.logged-out .tabbar,
.logged-out .site-footer {
  display: none;
}

.logged-out main {
  min-height: 100dvh;
  padding: max(28px, env(safe-area-inset-top)) var(--mobile-gutter) max(28px, env(safe-area-inset-bottom));
  display: grid;
  align-items: center;
}

.auth-view {
  width: 100%;
  max-width: 390px;
  margin-inline: auto;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-bottom: 20px;
  font-weight: 800;
}

.auth-card {
  display: grid;
  gap: 14px;
}

.auth-card h1 {
  margin: 0;
  font-size: 25px;
}

.auth-card > p {
  margin: -7px 0 3px;
}

.auth-card label,
.mileage-form label,
.password-form label {
  display: grid;
  gap: 6px;
  color: #45454b;
  font-size: 13px;
  font-weight: 650;
}

.auth-card input,
.mileage-form input,
.password-form input,
.picker-search input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #cfcfd4;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 16px;
  outline: none;
}

.auth-card input:focus,
.mileage-form input:focus,
.password-form input:focus,
.picker-search input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(215, 44, 37, 0.12);
}

.account-card {
  display: grid;
  gap: 18px;
}

.password-form {
  display: block;
}

.password-section > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 750;
  cursor: pointer;
}

.password-fields {
  padding-top: 12px;
  display: grid;
  gap: 14px;
}

.ui-icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.account-avatar {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 21px;
  font-weight: 800;
}

.account-details {
  display: grid;
  gap: 5px;
}

.account-details strong + .eyebrow {
  margin-top: 12px;
}

main {
  width: 100%;
  max-width: none;
  min-height: calc(100dvh - 58px);
  margin: 0;
  padding: 16px var(--mobile-gutter)
    calc(var(--mobile-nav-height) + env(safe-area-inset-bottom) + 22px);
}

.tabbar {
  position: fixed;
  inset: auto auto 0 50%;
  width: min(100%, var(--app-width));
  height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
  padding: 5px 8px env(safe-area-inset-bottom);
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  gap: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 0;
  box-shadow: 0 -1px 0 rgba(20, 20, 24, 0.1);
}

.tabbar a {
  width: auto;
  min-width: 56px;
  min-height: 58px;
  padding: 3px 5px;
  border-radius: 10px;
  font-size: 10px;
}

.tabbar a.active::before,
.tabbar a.active:not(.add-tab)::after {
  display: none;
}

.tabbar svg {
  width: 21px;
  height: 21px;
}

.add-tab {
  margin: -16px 0 0;
}

.add-orb {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  box-shadow: 0 3px 7px rgba(180, 30, 25, 0.22);
}

.view {
  animation: none;
}

.page-head,
.home-header,
.wizard-top {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 16px;
}

.page-head h1,
.home-header h1,
.wizard-top h1,
.add-intro h1 {
  margin-bottom: 5px;
  font-size: 24px;
  line-height: 1.18;
  letter-spacing: -0.025em;
}

.page-head p,
.home-header p,
.add-intro p {
  font-size: 14px;
  line-height: 1.42;
}

.home-header .link-button,
.wizard-top .link-button {
  align-self: flex-start;
  margin-left: -8px;
}

.card,
.wizard-card {
  padding: 16px;
  border-radius: 14px;
  box-shadow: none;
}

.card-title {
  margin-bottom: 12px;
}

.card-title h2,
.card-title h3 {
  font-size: 16px;
}

.button,
.filter,
.small-action,
.link-button,
.text-link,
.template-list button,
.starter-prompts button {
  min-height: 44px;
}

input,
select,
textarea,
.form-grid input,
.form-grid select,
.form-grid textarea,
.stack-form input,
.stack-form select,
.stack-form textarea,
.item-grid input,
.item-grid select,
.wizard-form input,
.wizard-form select,
.chat-form input {
  font-size: 16px;
}

.welcome {
  margin: 0;
}

.welcome-layout {
  display: block;
  border-radius: 14px;
  box-shadow: none;
}

.welcome-main {
  padding: 20px 16px 16px;
}

.welcome-main h1 {
  max-width: 18ch;
  margin-bottom: 10px;
  font-size: 27px;
  line-height: 1.12;
}

.welcome-main > p {
  margin-bottom: 0;
  font-size: 15px;
  line-height: 1.42;
}

.welcome-benefits {
  gap: 8px;
  margin: 18px 0;
}

.welcome-benefit {
  grid-template-columns: 28px 1fr;
  gap: 9px;
}

.welcome-benefit span {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 13px;
}

.welcome-benefit strong {
  font-size: 14px;
}

.welcome-benefit small {
  display: block;
  font-size: 12px;
  line-height: 1.35;
}

.welcome-actions {
  display: grid;
  gap: 8px;
}

.welcome-actions .button,
.welcome-actions .link-button {
  width: 100%;
}

.welcome-side {
  display: none;
}

.demo-banner {
  flex-direction: column;
  gap: 10px;
  padding: 13px 14px;
  border-radius: 12px;
}

.demo-banner .vehicle-actions {
  width: 100%;
}

.demo-banner .button,
.demo-banner .link-button {
  flex: 1;
}

.home-layout,
.history-layout,
.plan-grid,
.assistant-layout,
.recent-panel,
.review-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.home-quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.quick-action {
  min-height: 52px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 10px;
  text-align: left;
}

.quick-action .ui-icon {
  width: 23px;
  height: 23px;
}

.quick-action.document {
  background: var(--red);
  color: #fff;
}

.quick-action.assistant {
  background: #202226;
  color: #fff;
}

.more-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.more-row {
  width: 100%;
  min-height: 66px;
  padding: 9px 12px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  text-align: left;
}

.more-row:first-child {
  border-top: 0;
}

.more-row > span:nth-child(2) {
  min-width: 0;
}

.more-row strong,
.more-row small {
  display: block;
}

.more-row small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more-row > b {
  color: var(--subtle);
  font-size: 23px;
  font-weight: 400;
}

.more-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--red);
  font-weight: 800;
}

.vehicle-panel {
  min-height: 184px;
  padding: 16px;
}

.empty-home-vehicle {
  gap: 18px;
}

.empty-home-vehicle .button {
  align-self: flex-start;
}

.vehicle-panel h2 {
  margin: 3px 0 7px;
  font-size: 22px;
}

.vehicle-meta {
  gap: 6px;
  margin-top: 9px;
}

.vehicle-meta span {
  padding: 5px 8px;
  font-size: 12px;
}

.vehicle-bottom {
  margin-top: 18px;
}

.odometer strong {
  font-size: 24px;
}

.vehicle-actions {
  gap: 6px;
}

.vehicle-actions .button {
  min-height: 44px;
}

.summary-panel {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 16px;
  padding-block: 14px;
}

.summary-panel .card-title {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.summary-number strong {
  font-size: 23px;
}

.summary-row {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 0 0 14px;
  border-top: 0;
  border-left: 1px solid var(--line);
}

.next-steps,
.recent-panel {
  grid-column: auto;
}

.next-steps h3 {
  margin-bottom: 4px;
  font-size: 17px;
}

.next-steps > p {
  margin-bottom: 12px;
  font-size: 13px;
}

.action-list {
  display: grid;
  gap: 7px;
}

.action-tile {
  min-height: 62px;
  padding: 11px 13px;
  border-radius: 11px;
}

.action-tile small {
  margin-top: 1px;
}

.recent-panel {
  gap: 16px;
}

.category-summary {
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
  border-left: 0;
}

.list-row {
  gap: 9px;
  padding: 11px 0;
}

.row-main small {
  display: block;
  font-size: 12px;
}

.row-amount {
  font-size: 14px;
}

.row-actions {
  flex-wrap: wrap;
  gap: 2px 4px;
}

.row-main strong {
  white-space: normal;
  overflow-wrap: anywhere;
}

.expense-row .row-actions {
  grid-column: 2 / -1;
  justify-content: flex-start;
  margin-top: 0;
}

.expense-row.has-actions .category-mark {
  grid-row: 1 / 3;
}

.document-row .row-main {
  grid-column: 2 / -1;
}

.document-row .row-actions {
  justify-content: flex-start;
  margin-top: 8px;
}

.duplicate-warning strong {
  display: block;
}

.duplicate-warning .checkline {
  margin-top: 12px;
}

[aria-invalid="true"] {
  border-color: var(--red) !important;
}

.history-filters {
  align-items: stretch;
  flex-direction: column;
  gap: 4px;
}

.filter-row {
  margin-inline: -16px;
  padding: 2px 16px 8px;
  scroll-padding-inline: 16px;
  -webkit-overflow-scrolling: touch;
}

.filter-select {
  justify-content: space-between;
  margin-bottom: 10px;
}

.filter-select select {
  flex: 1;
  max-width: 260px;
  font-size: 16px;
}

.add-intro {
  margin-bottom: 14px;
}

.flow-steps {
  gap: 5px;
  margin-top: 10px;
  font-size: 11px;
}

.flow-steps i {
  width: 14px;
}

.add-choice {
  grid-template-columns: 1fr;
  gap: 10px;
}

.choice-card {
  min-height: 0;
  padding: 15px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
  border-radius: 14px;
  box-shadow: none;
}

.choice-icon {
  grid-row: 1 / 3;
  width: 40px;
  height: 40px;
}

.choice-card h2 {
  margin: 0;
  font-size: 16px;
}

.choice-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
}

.choice-card .link-button {
  grid-column: 3;
  grid-row: 1 / 3;
  width: 38px;
  min-width: 38px;
  padding: 0;
  overflow: hidden;
  color: transparent;
}

.choice-card .link-button .choice-label { display: none; }
.choice-card .link-button .ui-icon { color: var(--red); width: 22px; height: 22px; }

.form-card {
  width: calc(100% + var(--mobile-gutter) + var(--mobile-gutter));
  max-width: none;
  margin-inline: calc(-1 * var(--mobile-gutter));
  border-radius: 0;
}

.form-grid,
.wizard-split,
.item-grid,
.catalog-picker {
  grid-template-columns: 1fr;
  gap: 12px;
}

.span-2 {
  grid-column: auto;
}

.form-grid input,
.form-grid select,
.form-grid textarea,
.stack-form input,
.stack-form select,
.stack-form textarea,
.item-grid input,
.item-grid select,
.wizard-form input,
.wizard-form select,
.chat-form input {
  min-height: 48px;
  border-radius: 10px;
  background: var(--surface-2);
}

.form-actions,
.dialog-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.form-actions .button,
.dialog-actions .button {
  width: 100%;
}

.upload-box {
  padding: 22px 14px;
}

.ai-status,
.warning-box,
.manual-note {
  padding: 11px 12px;
}

.ocr-item {
  padding: 12px;
}

.wizard-shell {
  max-width: none;
}

.wizard-progress {
  margin: 12px 0 16px;
}

.wizard-card {
  margin-inline: calc(-1 * var(--mobile-gutter));
  border-radius: 0;
}

.wizard-form {
  margin-top: 14px;
  gap: 12px;
}

.compact-pickers {
  display: grid;
  gap: 12px;
}

.picker-field {
  display: grid;
  gap: 6px;
}

.picker-field > span {
  color: #45454b;
  font-size: 13px;
  font-weight: 650;
}

.picker-trigger {
  width: 100%;
  min-height: 52px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #cfcfd4;
  border-radius: 10px;
  background: var(--surface-2);
  text-align: left;
  font-size: 16px;
}

.picker-trigger:disabled {
  opacity: .55;
}

.clear-value {
  justify-self: start;
  min-height: 40px;
  margin-top: -4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--red);
  font-weight: 700;
}

.picker-dialog {
  width: min(100%, var(--app-width));
  max-width: none;
  max-height: min(78dvh, 620px);
  margin: auto auto 0;
}

.picker-dialog::backdrop {
  background: rgba(20, 20, 24, .45);
}

.picker-card {
  max-height: min(78dvh, 620px);
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  border-radius: 18px 18px 0 0;
}

.picker-search input {
  background: var(--surface-2);
}

.picker-results {
  min-height: 160px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.picker-results button {
  width: 100%;
  min-height: 50px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  text-align: left;
  font-size: 16px;
}

.picker-results button:first-child {
  border-top: 0;
}

.picker-results button b {
  color: var(--red);
}

.picker-empty {
  padding: 30px 12px;
  color: var(--muted);
  text-align: center;
}

.vehicle-profile {
  display: grid;
  gap: 12px;
}

.vehicle-profile .page-head {
  margin-bottom: 0;
}

.vehicle-profile-card {
  overflow: hidden;
  border-radius: 16px;
  background: #232327;
  color: #fff;
}

.vehicle-profile-head {
  position: relative;
  padding: 22px 18px 20px;
  border-bottom: 1px solid #3a3a40;
}

.vehicle-profile-head h2 {
  margin: 5px 0 0;
  padding-right: 86px;
  font-size: 24px;
  line-height: 1.15;
}

.plate-number {
  position: absolute;
  top: 20px;
  right: 18px;
  padding: 5px 8px;
  border-radius: 5px;
  background: #fff;
  color: #232327;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
}

.vehicle-facts {
  margin: 0;
  padding: 5px 18px;
}

.vehicle-facts div {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid #3a3a40;
}

.vehicle-facts dt {
  color: #b9b9bf;
  font-size: 13px;
}

.vehicle-facts dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.mileage-block {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.mileage-block > div > strong {
  display: block;
  margin-top: 3px;
  font-size: 26px;
}

.mileage-block small {
  display: block;
  color: #b9b9bf;
}

.mileage-form {
  padding-top: 14px;
  border-top: 1px solid #3a3a40;
}

.mileage-form > div:first-child {
  display: grid;
  gap: 10px;
}

.mileage-form label {
  color: #d9d9dd;
}

.mileage-form .form-actions {
  margin-top: 12px;
}

.vehicle-shortcuts {
  display: grid;
  gap: 8px;
}

.empty-vehicle {
  padding-block: 34px;
  text-align: center;
}

.empty-vehicle-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--red-soft);
  color: var(--red);
  font-size: 25px;
}

.review-list {
  margin: 12px 0;
}

.items-editor > summary {
  min-height: 52px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

.items-editor > summary::-webkit-details-marker {
  display: none;
}

.items-editor > summary > .ui-icon { width: 20px; height: 20px; flex-shrink: 0; color: var(--muted); transform: rotate(90deg); }

.items-editor[open] > summary > .ui-icon { transform: rotate(-90deg); }

.items-editor > summary span {
  min-width: 28px;
  min-height: 28px;
  margin-left: auto;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.items-editor-body {
  padding-top: 8px;
}

.items-editor-body .card-title {
  margin-bottom: 8px;
}

.items-editor-body .card-title p {
  margin: 0;
}

.review-line {
  padding: 9px 0;
}

.receipt-preview {
  position: static;
}

.receipt-preview img {
  max-height: 300px;
}

.reminder {
  align-items: center;
  padding: 12px 0;
}

.template-list,
.starter-prompts {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 5px;
  -webkit-overflow-scrolling: touch;
}

.template-list button,
.starter-prompts button {
  flex: none;
}

.assistant-side {
  order: 2;
}

.chat-card {
  min-height: min(520px, calc(100dvh - 180px));
  border-radius: 14px;
}

.chat-log {
  padding: 14px;
}

.message {
  max-width: 88%;
  flex-shrink: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-form {
  position: sticky;
  bottom: 0;
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #fff;
}

.site-footer {
  margin-top: 20px;
  padding: 18px 0 4px;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
}

.toast-stack {
  top: calc(66px + env(safe-area-inset-top));
  right: max(12px, calc((100vw - var(--app-width)) / 2 + 12px));
  left: max(12px, calc((100vw - var(--app-width)) / 2 + 12px));
  max-width: calc(var(--app-width) - 24px);
}

body.keyboard-open main {
  padding-bottom: 16px;
}

body.keyboard-open .tabbar {
  display: none;
}

@media (max-width: 370px) {
  :root {
    --mobile-gutter: 12px;
  }

  .profile-button span {
    display: none;
  }

  .profile-button {
    width: 44px;
    padding: 0;
  }

  .tabbar a {
    min-width: 52px;
  }

  .summary-panel {
    grid-template-columns: 1fr;
  }

  .summary-row {
    padding: 10px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar,
  .tabbar {
    background: #fff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .topbar,
  .tabbar {
    border-color: #555;
  }

  input,
  select,
  textarea {
    border-color: #555 !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .view {
    animation: none;
  }
}

/* Keep the invisible native picker inside its tappable upload area. */
.upload-box { position: relative; }
.upload-box input[type="file"] {
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  min-height: 0;
  opacity: 0;
  cursor: pointer;
  pointer-events: auto;
}
.upload-box:focus-within { outline: 2px solid var(--red); outline-offset: 3px; }
