:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #64748b;
  --line: #d8dee6;
  --accent: #e86122;
  --accent-dark: #b84412;
  --green: #138a45;
  --red: #bd2b2b;
  --amber: #b7791f;
  --blue: #2563eb;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(232, 97, 34, 0.12), rgba(19, 138, 69, 0.1)),
    var(--bg);
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-brand {
  padding-bottom: 6px;
}

.login-card h2 {
  margin: 0;
  font-size: 28px;
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111827;
  color: white;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.brand p,
.sync-status p,
.panel-header p,
.metric-card p {
  margin: 0;
  color: var(--muted);
}

.brand p,
.sync-status p {
  color: #9ca3af;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: transparent;
  color: #d1d5db;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.sync-status {
  margin-top: auto;
  display: flex;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: #22c55e;
}

.main {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h2 {
  margin: 0;
  font-size: 30px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: end;
}

.session-user {
  display: grid;
  gap: 5px;
  min-width: 170px;
  color: var(--muted);
  font-size: 12px;
}

.session-user strong {
  color: var(--ink);
  font-size: 13px;
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.search input,
.dialog-card input,
.dialog-card select {
  width: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
}

.primary-button,
.secondary-button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: white;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

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

.metric-card {
  padding: 18px;
}

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

.metric-card strong {
  display: block;
  margin: 6px 0;
  font-size: 30px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.wide {
  min-width: 0;
}

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

.panel-header h3 {
  margin: 0 0 3px;
}

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

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

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

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

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #e5e7eb;
}

.badge.green {
  color: var(--green);
  background: #dff5e9;
}

.badge.red {
  color: var(--red);
  background: #fee2e2;
}

.badge.amber {
  color: var(--amber);
  background: #fef3c7;
}

.badge.blue {
  color: var(--blue);
  background: #dbeafe;
}

.activity-feed,
.log-list,
.tracking-list,
.collection-list,
.driver-grid {
  display: grid;
  gap: 10px;
}

.activity-item,
.log-item,
.tracking-item,
.collection-item,
.driver-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.activity-item strong,
.log-item strong,
.tracking-item strong,
.driver-card strong {
  display: block;
  margin-bottom: 3px;
}

.activity-item p,
.log-item p,
.tracking-item p,
.driver-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.driver-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.driver-card {
  display: grid;
  gap: 10px;
}

.driver-card footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.collection-item {
  width: 100%;
  text-align: left;
  background: white;
}

.collection-item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.record-preview {
  min-height: 260px;
  margin: 0;
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  font-size: 12px;
  line-height: 1.5;
}

.map-canvas {
  position: relative;
  min-height: 420px;
  border-radius: 8px;
  overflow: hidden;
  background: #e8edf1;
  isolation: isolate;
}

.map-canvas::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
}

.map-canvas::after {
  z-index: 1;
  box-shadow: inset 0 0 0 1px rgba(100, 116, 139, 0.24);
  background: linear-gradient(rgba(255, 255, 255, 0.04), rgba(15, 23, 42, 0.08));
}

.map-tile {
  position: absolute;
  z-index: 0;
  width: 256px;
  height: 256px;
  user-select: none;
}

.map-attribution {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 3;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.truck-pin {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid white;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
  transform: translate(-50%, -50%);
}

.truck-pin::before {
  content: "▣";
  font-size: 17px;
}

.truck-pin.stale {
  background: var(--amber);
}

.truck-pin.offline {
  background: var(--red);
}

.pin-label {
  position: absolute;
  left: 50%;
  top: 38px;
  transform: translateX(-50%);
  padding: 4px 7px;
  white-space: nowrap;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}

.sync-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.sync-grid article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.sync-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}

.checklist {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.checklist li {
  margin-bottom: 10px;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

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

.dialog-card {
  display: grid;
  gap: 12px;
  width: min(460px, 92vw);
  padding: 20px;
}

.dialog-card h3 {
  margin: 0;
}

.dialog-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.dialog-card input,
.dialog-card select {
  width: 100%;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 8px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .metric-grid,
  .content-grid,
  .sync-grid {
    grid-template-columns: 1fr;
  }

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

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search input,
  .session-user {
    width: 100%;
  }
}
