:root {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --online: #16a34a;
  --offline: #dc2626;
  --stale: #ea580c;
  --accent: #2563eb;
  --border: #e5e7eb;
}

* {
  box-sizing: border-box;
}

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

.header {
  background: var(--accent);
  color: white;
  padding: 24px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

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

.logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

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

.subtitle {
  margin: 4px 0 0;
  opacity: 0.85;
  font-size: 0.9rem;
}

.last-refreshed {
  font-size: 0.85rem;
  opacity: 0.85;
}

main {
  padding: 24px 32px;
  max-width: 1100px;
  margin: 0 auto;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 4px solid var(--accent);
}

.card-online {
  border-left-color: var(--online);
}

.card-offline {
  border-left-color: var(--offline);
}

.card-stale {
  border-left-color: var(--stale);
}

.card-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.card-value {
  font-size: 1.8rem;
  font-weight: 600;
}

.controls {
  margin-bottom: 16px;
}

#search-input {
  width: 100%;
  max-width: 360px;
  padding: 10px 14px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
}

#search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.table-section {
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  color: var(--accent);
}

.sort-indicator {
  display: inline-block;
  width: 0.8em;
}

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
}

.status-online {
  background: var(--online);
}

.status-offline {
  background: var(--offline);
}

.status-stale {
  background: var(--stale);
}

.status-unknown {
  background: var(--muted);
}

.map-link {
  color: var(--accent);
  text-decoration: none;
}

.map-link:hover {
  text-decoration: underline;
}

.error-message {
  color: var(--offline);
  margin-top: 16px;
  font-size: 0.9rem;
}

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

main h2 {
  font-size: 1.1rem;
  margin: 28px 0 12px;
}

.section-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -8px 0 12px;
}

.action-btn {
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  color: white;
  margin-right: 6px;
}

.action-btn:hover {
  opacity: 0.85;
}

.action-immobilize {
  background: var(--offline);
}

.action-restore {
  background: var(--online);
}

.action-unavailable {
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* ============ HEADER: user info / logout (Stage 2) ============ */

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.user-info {
  font-size: 0.85rem;
  opacity: 0.9;
}

.logout-button {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.25);
}

.logout-button:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}


/* ============ LOGIN PAGE (Stage 2) ============ */

.login-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.login-page {
  width: 100%;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.login-brand .logo {
  background: var(--accent);
  color: white;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--text);
}

.login-brand .subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  opacity: 1;
  font-size: 0.85rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.login-field input {
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
}

.login-field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--offline);
  font-size: 0.85rem;
}

.login-submit {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.login-submit:hover:not(:disabled) {
  opacity: 0.92;
}

.login-submit:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.login-submit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.login-support {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 480px) {
  .login-card {
    padding: 24px 20px;
  }
}

/* ============ FLEET HEALTH (Phase 3) — additive only, nothing above this
   line was changed to build it. ============ */

/* A fourth summary-card colour, for "Unknown" — the three online/offline/
   stale variants above already match healthy/critical/attention exactly. */
.card-unknown {
  border-left-color: var(--muted);
}

/* Header navigation links (Fleet Health <-> Dashboard) — styled to sit
   naturally among the existing white-on-accent header content. */
.nav-link {
  color: white;
  text-decoration: none;
  font-size: 0.85rem;
  opacity: 0.9;
}

.nav-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.nav-link:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* The Fleet Health status filter <select>, styled to match #search-input's
   existing look without altering the shared .controls rule (which the main
   dashboard's search box also uses). */
#status-filter {
  margin-top: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
}

#status-filter:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Multiple issues / recommended actions per vehicle render as a compact
   list inside one table cell, rather than one row per issue. */
.issue-list {
  margin: 0;
  padding-left: 18px;
}

.issue-list li + li {
  margin-top: 4px;
}

/* ============ REPORTING (Phase 3) — additive only, nothing above this
   line was changed to build it. ============ */

/* Manual-refresh button (Daily Summary / Vehicle Report have no live
   polling) — same visual language as the existing header buttons, its own
   accent-colored fill so it reads as an action distinct from "Log out". */
.refresh-button {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}

.refresh-button:hover {
  background: rgba(255, 255, 255, 0.25);
}

.refresh-button:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* A "View report" link sitting inside a normal table cell (dark text on a
   light card background) rather than the header (white text on the accent
   background) — .nav-link alone assumes the header's white-on-accent
   context, so this narrows just the color for this one context. */
.nav-link-inline {
  color: var(--accent);
}

.nav-link-inline:hover,
.nav-link-inline:focus-visible {
  text-decoration: underline;
}

/* Non-table report sections (Assessment, Driver Score, Maintenance Notes,
   GPS Reliability) — the same card look .table-section already gives
   tables, reused here for prose/definition-list content instead. */
.report-panel {
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.report-panel h3 {
  margin: 16px 0 8px;
  font-size: 0.95rem;
}

.report-panel h3:first-child {
  margin-top: 0;
}

/* Label/value pairs (distance, trips, moving time, etc.) laid out as a
   simple two-column grid that collapses to one column on narrow screens. */
.report-fact-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0;
}

.report-fact-list dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.report-fact-list dd {
  margin: 0;
  font-weight: 600;
}

@media (max-width: 480px) {
  .report-fact-list {
    grid-template-columns: 1fr;
  }

  .report-fact-list dd {
    margin-bottom: 6px;
  }
}

/* ============ ORGANISATION PICKER (Super Admin UX fix) — additive only,
   nothing above this line was changed to build it. Reuses the existing
   .login-body/.login-page/.login-card shell (same centered-card shape) —
   only this list styling is new. ============ */
.org-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.org-list a {
  display: block;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}

.org-list a:hover,
.org-list a:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

/* ============ ORGANISATION ADMINISTRATION (Phase 4.4) — additive only,
   nothing above this line was changed to build it. Deliberately reuses
   .report-panel for the create-organisation form, .login-submit's exact
   recipe for its primary (accent-filled) buttons, and .status-badge/
   .status-online/.status-offline for the active/inactive distinction —
   no new color rules needed for any of that. ============ */

.admin-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 360px;
}

.admin-form-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.admin-form-field input,
.admin-form-field select,
.admin-form-field textarea {
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
}

.admin-form-field input:focus-visible,
.admin-form-field select:focus-visible,
.admin-form-field textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Shared by the create-organisation form and the inline rename form below. */
.field-error {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--offline);
  font-size: 0.85rem;
}

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

/* Secondary, neutral row actions (Rename, Cancel, Enable) inside a table
   cell — bordered rather than solid-filled, so they read as lower-emphasis
   than the accent-filled .login-submit-style primary buttons. */
.table-action-btn {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-right: 6px;
}

.table-action-btn:hover:not(:disabled) {
  background: var(--bg);
}

.table-action-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.table-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* "Disable" specifically — a visual warning cue, same red as
   .status-offline, inverting to a solid fill on hover/focus. */
.table-action-btn.danger {
  border-color: var(--offline);
  color: var(--offline);
}

.table-action-btn.danger:hover:not(:disabled) {
  background: var(--offline);
  color: white;
}

/* The inline rename input, sitting directly in a table cell rather than a
   form layout — same visual recipe as .admin-form-field input, just without
   the flex/label wrapper. */
.inline-edit-input {
  padding: 6px 10px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  margin-right: 6px;
  max-width: 220px;
}

.inline-edit-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The inline rename "Save" button reuses .login-submit's accent-filled
   look but needs .table-action-btn's compact table-cell sizing instead of
   .login-submit's full-width block layout. */
.table-action-btn-inline {
  display: inline-block;
  width: auto;
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 6px;
  margin-right: 6px;
}

/* Screen-reader-only accessible name for the inline rename input (a visible
   <label> would repeat the organisation name unnecessarily inside a table
   row that already shows it) — visually hidden without removing it from
   the accessibility tree. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .admin-form-field {
    max-width: 100%;
  }

  .inline-edit-input {
    max-width: 140px;
  }
}

/* ============ VEHICLE ADMINISTRATION (Phase 5.1.3) — additive only,
   nothing above this line was changed to build it. The search/filter row
   is the only genuinely new layout this page needed; everything else
   (.report-panel, .admin-form-field, .table-action-btn, .status-badge,
   .inline-edit-input, .table-action-btn-inline, .visually-hidden) is
   reused exactly as Organisation/User Administration already established
   it. ============ */

.vehicle-toolbar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* ============ MAINTENANCE MANAGEMENT (Phase 5.2.3) — additive only.
   Reuses .report-panel/.report-fact-list/.admin-form-field/.table-action-btn/
   .status-badge/.inline-edit-input/.table-action-btn-inline/.visually-hidden
   exactly as Vehicle Administration already established them. The single
   new element this page needs is a label-wrapped checkbox ("Show voided
   records") that .admin-form-field's column layout doesn't fit. */
.checkbox-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text);
}

/* ============ CUSTOMER PORTAL (Stage B) — additive only, nothing above
   this line was changed to build it. Deliberately its own card layout
   rather than reusing .table-section/table: this view targets a phone
   first, and a dense admin table is exactly what a customer-facing
   "which vehicle needs attention" screen must not look like. Reuses
   .header/.brand/.logo/.header-right/.user-info/.logout-button/
   .refresh-button/.status-badge (and its four colour variants)/
   .error-message/.section-hint/.report-panel/.admin-form-field exactly as
   every earlier page already established them. ============ */

.portal-nav {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 32px;
  display: flex;
  gap: 20px;
}

.portal-nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding-bottom: 4px;
  border-bottom: 2px solid transparent;
}

.portal-nav-link[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.portal-nav-link:hover,
.portal-nav-link:focus-visible {
  color: var(--accent);
}

.portal-main {
  padding: 24px 32px;
  max-width: 1100px;
  margin: 0 auto;
}

.vehicle-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.vehicle-card {
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 18px 20px;
  border-left: 4px solid var(--muted);
  min-width: 0;
}

/* The card is a real <a> (Stage C: whole card navigates to vehicle detail)
   -- undo anchor defaults so it still reads as a card, not a link, with a
   clear but not gimmicky hover/focus affordance since the entire card is
   now the tap target. */
.vehicle-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.vehicle-card-link:hover {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.vehicle-card-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.vehicle-card-healthy {
  border-left-color: var(--online);
}

.vehicle-card-attention {
  border-left-color: var(--stale);
}

.vehicle-card-critical {
  border-left-color: var(--offline);
}

.vehicle-card-unknown {
  border-left-color: var(--muted);
}

.vehicle-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.vehicle-card-name {
  margin: 0;
  font-size: 1.1rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

.vehicle-card-alert-badge {
  flex-shrink: 0;
}

.vehicle-card-registration {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

.vehicle-card-body {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vehicle-fact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.vehicle-fact-label {
  color: var(--muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.vehicle-fact-value {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: right;
  overflow-wrap: break-word;
  word-break: break-word;
}

@media (max-width: 600px) {
  .header.portal-header {
    padding: 16px 20px;
  }

  .portal-nav {
    padding: 8px 20px;
  }

  .portal-main {
    padding: 16px 16px;
  }

  .vehicle-card-grid {
    grid-template-columns: 1fr;
  }
}

/* ============ CUSTOMER PORTAL VEHICLE DETAIL (Stage C) — additive only,
   nothing above this line was changed to build it, aside from
   .vehicle-card-link (the whole My Vehicles card becoming a tap target).
   Reuses .vehicle-card/.vehicle-card-header/.vehicle-card-name/
   .vehicle-card-registration/.vehicle-card-body/.vehicle-fact/
   .report-panel exactly as Stage B already established them -- the detail
   view is deliberately the same visual language as a My Vehicles card, not
   a new one. ============ */

.vehicle-detail-card {
  max-width: 480px;
  margin-bottom: 20px;
}

/* The map/provider boundary. Never a real map yet -- see portal-vehicle.js
   -- so this is a plain, clearly-a-placeholder box, not something styled
   to look like a finished map. */
.map-placeholder {
  min-height: 220px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 20px;
}

.map-placeholder-message {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.map-placeholder-note {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.map-placeholder-unavailable {
  background: var(--bg);
}

.map-placeholder-unavailable .map-placeholder-message {
  color: var(--muted);
  font-weight: 500;
}

.map-placeholder-pending {
  background: var(--bg);
}

/* Stage D: the live Google map container. Google Maps requires an explicit
   height on its container to render into (unlike the placeholder above,
   which only needs min-height since it's just centered text) -- same
   border-radius as the placeholder so replacing one with the other never
   visually jumps. */
.map-container-live {
  height: 300px;
  border-radius: 8px;
  overflow: hidden;
}

@media (max-width: 600px) {
  .vehicle-detail-card {
    max-width: 100%;
  }

  .map-placeholder {
    min-height: 180px;
  }

  .map-container-live {
    height: 240px;
  }
}
