:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #fdfdfb;
  --text: #17201d;
  --muted: #68716b;
  --line: #dfe4dc;
  --line-strong: #c8d1c8;
  --green: #1e7a4a;
  --green-dark: #145d38;
  --green-soft: #e7f4eb;
  --amber: #c47a21;
  --amber-soft: #fff4df;
  --danger: #b84a3d;
  --shadow: 0 16px 40px rgba(22, 32, 29, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
}

.auth-gate {
  align-items: center;
  background: var(--bg);
  display: none;
  min-height: 100vh;
  padding: 18px;
}

.auth-loading #app,
.auth-locked #app,
.auth-loading .auth-gate,
.auth-unlocked .auth-gate {
  display: none;
}

.auth-locked .auth-gate {
  display: flex;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
  margin: 0 auto;
  max-width: 390px;
  padding: 22px;
  width: 100%;
}

.auth-card h1 {
  margin-bottom: 6px;
}

.auth-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.auth-mark {
  height: 50px;
  width: 50px;
}

.auth-unlocked #app {
  display: block;
}

.topbar {
  align-items: center;
  background: rgba(246, 247, 244, 0.92);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 22px clamp(18px, 4vw, 48px);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(16px);
}

.brand {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  align-items: center;
  background: var(--green);
  border-radius: 8px;
  color: white;
  display: inline-flex;
  height: 44px;
  justify-content: center;
  width: 44px;
  flex: 0 0 auto;
}

.brand-mark svg,
button svg {
  fill: none;
  height: 22px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 760;
  line-height: 1;
}

.brand p,
.muted,
.helper-text {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.tabbar {
  display: flex;
  gap: 8px;
  padding: 16px clamp(18px, 4vw, 48px) 0;
}

.tab-button {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
  min-height: 38px;
  padding: 0 18px;
}

.tab-button.active {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
}

.layout {
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  padding: 26px clamp(18px, 4vw, 48px) 42px;
}

.maintenance-panel {
  display: none;
}

body[data-active-tab="maintenance"] .layout {
  grid-template-columns: 1fr;
}

body[data-active-tab="maintenance"] .side-rail,
body[data-active-tab="maintenance"] .summary-grid,
body[data-active-tab="maintenance"] .entry-panel,
body[data-active-tab="maintenance"] .table-panel {
  display: none;
}

body[data-active-tab="maintenance"] .maintenance-panel {
  display: grid;
}

.side-rail,
.workspace {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.panel,
.summary-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.section-heading {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-heading h2 {
  font-size: 16px;
  font-weight: 740;
  line-height: 1.15;
}

.status-dot {
  background: var(--line-strong);
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.status-dot.active {
  background: var(--green);
}

.station-match {
  background: var(--green-soft);
  border: 1px solid #cfe7d6;
  border-radius: var(--radius);
  display: grid;
  gap: 5px;
  margin: 14px 0;
  padding: 13px;
}

.station-match strong {
  font-size: 15px;
}

.station-match span {
  color: var(--muted);
  font-size: 13px;
}

.nearby-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.nearby-button {
  align-items: flex-start;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  display: grid;
  gap: 4px;
  padding: 10px 11px;
  text-align: left;
  width: 100%;
}

.nearby-button:hover {
  border-color: var(--green);
}

.nearby-button span {
  color: var(--muted);
  font-size: 12px;
}

.primary-button,
.ghost-button,
.full-button,
.text-button,
.file-picker {
  align-items: center;
  border-radius: 7px;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.primary-button {
  background: var(--green);
  border: 1px solid var(--green);
  color: white;
  font-size: 14px;
  font-weight: 720;
}

.primary-button:hover {
  background: var(--green-dark);
  border-color: var(--green-dark);
}

.ghost-button,
.full-button,
.file-picker {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 14px;
  font-weight: 680;
}

.ghost-button:hover,
.full-button:hover,
.file-picker:hover {
  border-color: var(--green);
  color: var(--green-dark);
}

.full-button,
.full-width,
.file-picker {
  width: 100%;
}

.text-button {
  background: transparent;
  border: 0;
  color: var(--green);
  font-size: 13px;
  font-weight: 720;
  min-height: auto;
  padding: 0;
}

.file-picker {
  margin: 14px 0 10px;
  position: relative;
}

.file-picker input {
  inset: 0;
  opacity: 0;
  position: absolute;
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-tile {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.summary-tile span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

.summary-tile strong {
  font-size: clamp(21px, 2.2vw, 30px);
  font-weight: 780;
  line-height: 1;
}

.entry-form {
  display: grid;
  gap: 13px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
  grid-column: span 2;
}

.small-field {
  grid-column: span 1;
}

.entry-form .field:nth-of-type(2) {
  grid-column: span 2;
}

.entry-form .field:nth-of-type(3) {
  grid-column: span 3;
}

.field label {
  color: #3b4640;
  font-size: 12px;
  font-weight: 740;
}

.field input,
.field select,
.table-tools input {
  background: #fbfcfa;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  min-height: 40px;
  outline: none;
  padding: 0 11px;
  width: 100%;
}

.field input:focus,
.field select:focus,
.table-tools input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(30, 122, 74, 0.12);
}

.notes-field {
  grid-column: span 2;
}

.form-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  grid-column: 1 / -1;
}

.form-message {
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 680;
}

.maintenance-panel {
  gap: 18px;
}

.maintenance-panel .section-heading {
  margin-bottom: 0;
}

.maintenance-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.maintenance-stats article {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 7px;
  padding: 13px;
}

.maintenance-stats span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.maintenance-stats strong {
  font-size: 18px;
  line-height: 1.1;
}

.maintenance-form {
  display: grid;
  gap: 13px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.maintenance-form .field:nth-of-type(2),
.maintenance-form .field:nth-of-type(3),
.maintenance-notes-field,
.invoice-field {
  grid-column: span 2;
}

.invoice-field input[type="file"] {
  align-items: center;
  display: flex;
  padding: 8px 11px;
}

.invoice-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
}

.invoice-link {
  background: var(--amber-soft);
  border: 1px solid #ead2a7;
  border-radius: 7px;
  color: #83501d;
  display: inline-flex;
  font-size: 12px;
  font-weight: 720;
  max-width: 180px;
  overflow: hidden;
  padding: 5px 8px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-link:hover {
  border-color: var(--amber);
}

.maintenance-table {
  min-width: 760px;
}

.table-heading {
  align-items: flex-end;
}

.table-heading > div:first-child {
  display: grid;
  gap: 5px;
}

.table-tools {
  min-width: min(260px, 100%);
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 820px;
  width: 100%;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.station-cell {
  display: grid;
  gap: 3px;
}

.station-cell span {
  color: var(--muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.icon-button {
  align-items: center;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  display: inline-flex;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.icon-button:hover {
  border-color: var(--green);
  color: var(--green);
}

.icon-button.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .entry-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .maintenance-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .entry-form .field:nth-of-type(3),
  .maintenance-form .field:nth-of-type(2),
  .maintenance-form .field:nth-of-type(3),
  .maintenance-notes-field,
  .invoice-field,
  .notes-field {
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    gap: 8px;
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .side-rail {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar {
    position: static;
  }

  .layout,
  .topbar,
  .tabbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .tabbar {
    padding-top: 12px;
  }

  .tab-button {
    flex: 1;
    min-height: 44px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand p {
    display: none;
  }

  .layout {
    display: flex;
    flex-direction: column;
  }

  .side-rail,
  .workspace {
    display: contents;
  }

  body[data-active-tab="maintenance"] .side-rail {
    display: none;
  }

  .location-panel {
    order: 1;
  }

  .entry-panel {
    order: 2;
  }

  .summary-grid {
    order: 3;
  }

  .table-panel {
    order: 4;
  }

  .maintenance-panel {
    order: 5;
  }

  .import-panel {
    order: 6;
  }

  .entry-form,
  .maintenance-form {
    display: flex;
    flex-direction: column;
  }

  .invoice-link {
    max-width: 100%;
  }

  .maintenance-stats {
    grid-template-columns: 1fr;
  }

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

  .primary-button,
  .ghost-button,
  .full-button,
  .file-picker {
    font-size: 13px;
    min-height: 44px;
    padding-left: 10px;
    padding-right: 10px;
    white-space: nowrap;
  }

  .empty-row {
    text-align: left;
  }

  .maintenance-table {
    min-width: 0;
  }

  .maintenance-table thead {
    display: none;
  }

  .maintenance-table tr {
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 8px;
    padding: 12px 0;
  }

  .maintenance-table td {
    border: 0;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 0;
  }

  .maintenance-table td::before {
    color: var(--muted);
    content: "";
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 760;
    text-transform: uppercase;
  }

  .maintenance-table td:nth-child(1)::before {
    content: "Date";
  }

  .maintenance-table td:nth-child(2)::before {
    content: "Service";
  }

  .maintenance-table td:nth-child(3)::before {
    content: "Cost";
  }

  .maintenance-table td:nth-child(4)::before {
    content: "Odometer";
  }

  .maintenance-table td:nth-child(5)::before {
    content: "Next due";
  }

  .maintenance-table td:nth-child(6) {
    justify-content: flex-start;
  }

  .maintenance-table td.empty-row {
    border-bottom: 1px solid var(--line);
    display: block;
    padding: 12px 0;
  }

  .maintenance-table td.empty-row::before {
    content: "";
  }

  .table-heading {
    align-items: stretch;
    flex-direction: column;
  }
}
