:root {
  --border: #d8dde3;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --warn-bg: #fff7e6;
  --warn-border: #f0b429;
  --bg: #f7f8fa;
}

* {
  box-sizing: border-box;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: white;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.button {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9rem;
}

.button.secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.charts-grid {
  display: grid;
  /* min(): a chart column never asks for more than the screen has. */
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.chart-card h2 {
  font-size: 1rem;
  margin-top: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--border);
}

th, td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
}

th {
  background: #eef1f5;
  font-weight: 600;
}

tr.outlier-row {
  background: #fff4f4;
}

.icon-cell {
  white-space: nowrap;
  width: 2.5rem;
}

.icon {
  cursor: help;
  margin-right: 0.15rem;
}

form label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

select {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: white;
  color: var(--text);
}

#vehicles-table {
  margin-bottom: 1.5rem;
}

tr.archived-row td {
  color: var(--muted);
}

.row-actions {
  white-space: nowrap;
}

dialog {
  width: min(32rem, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

dialog h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

button.danger {
  background: white;
  color: #b91c1c;
  border-color: #b91c1c;
}

.confirm-actions .spacer {
  flex: 1;
}

button.small,
a.button.small {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  margin-right: 0.3rem;
}

/* Vehicle with no owner row (see the Your role column). */
.warning-text {
  color: var(--warning, #b45309);
}

select.small {
  padding: 0.15rem 0.3rem;
  font-size: 0.85rem;
}

form select,
form input[type="text"],
form input[type="number"],
form input[type="date"],
form input[type="email"],
form input[type="password"],
form input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  color: var(--text);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.checkbox-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  color: var(--text);
}

.checkbox-row input {
  width: auto;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted, #666);
  font-weight: normal;
}

button {
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}

button.secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.confirm-actions {
  display: flex;
  gap: 0.75rem;
}

.status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.status.error {
  color: #b91c1c;
}

.status.success {
  color: #15803d;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: #eef1f5;
}

.badge.ok {
  background: #dcfce7;
  color: #166534;
}

.badge.partial {
  background: #fef3c7;
  color: #92400e;
}

.badge.manual {
  background: #e0e7ff;
  color: #3730a3;
}

.warning {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
}

.required {
  color: #b91c1c;
}

.inline-form {
  display: inline;
  margin: 0;
}

.user-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.link-box input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.9rem;
}

/* "Not the live app" bar, shown on every page outside production. */
.local-notice {
  width: 100%;
  box-sizing: border-box;
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
  text-align: center;
  color: #fff;
  background: #b00020;
  border-bottom: 3px solid #5c0010;
}

.local-notice-copy {
  color: #1a1a1a;
  background: #ffc107;
  border-bottom-color: #8a6500;
}

/* ------------------------------------------------------------------
   Phones: the header stacks, and every table row becomes a card with
   "label: value" lines. app.js copies each column heading into the
   cell's data-label. Desktop layout is untouched.
   ------------------------------------------------------------------ */
@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .header-actions,
  .user-nav {
    flex-wrap: wrap;
  }

  .user-nav {
    width: 100%;
  }

  main {
    padding: 1rem;
  }

  .card,
  .chart-card {
    padding: 0.9rem;
  }

  table,
  table tbody,
  table tr,
  table td {
    display: block;
    width: 100%;
  }

  table {
    border: none;
    background: transparent;
  }

  /* Headings stay readable for screen readers, but take no space. */
  table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  table tr {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
  }

  table tr.outlier-row {
    background: #fff4f4;
  }

  table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid #eef1f5;
    text-align: right;
    overflow-wrap: anywhere;
  }

  table td:last-child {
    border-bottom: none;
  }

  table td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
  }

  /* Cells without a heading: the warning icons and the action buttons. */
  table td:not([data-label]) {
    justify-content: flex-start;
    text-align: left;
  }

  table td.icon-cell {
    width: 100%;
  }

  table td.icon-cell:empty {
    display: none;
  }

  table td.row-actions {
    flex-wrap: wrap;
    gap: 0.4rem;
    padding-top: 0.6rem;
    white-space: normal;
  }
}
