:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --ink: #111827;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #c8102e;
  --brand-dark: #8f1025;
  --nav: #171a1f;
  --nav-soft: #242a32;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --info: #0369a1;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 10px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

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

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  background: #f8fafc;
  border-right: 1px solid var(--line);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-stack {
  background: transparent;
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 6px 4px 12px;
}

.brand-stack img {
  display: block;
  height: auto;
  max-width: 100%;
  min-width: 0;
  object-fit: contain;
  width: 100%;
}

.logo-shenton { max-height: 52px; }
.logo-mansfield { max-height: 58px; }
.brand-divider {
  background: var(--line);
  display: block;
  height: 1px;
  width: 100%;
}

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

.sidebar-nav button {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #475569;
  display: flex;
  font-weight: 500;
  min-height: 44px;
  padding: 0 12px;
  text-align: left;
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease;
}

.sidebar-nav button::before {
  content: none;
}

.sidebar-nav button:hover {
  background: #ffffff;
  border-color: #e5e7eb;
  color: var(--ink);
}

.sidebar-nav button.active {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: inset 3px 0 0 var(--brand), 0 8px 18px rgba(15, 23, 42, 0.05);
  color: var(--ink);
}

.sidebar-nav button.active::before {
  content: none;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  display: grid;
  gap: 6px;
  margin-top: auto;
  padding-top: 18px;
}

.sidebar-footer strong {
  font-weight: 500;
}

.workspace {
  min-width: 0;
}

.topbar {
  align-items: center;
  background: rgba(245, 246, 248, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 24px 32px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1, h2, h3 {
  letter-spacing: -0.01em;
  margin: 0;
  font-weight: 600;
}

h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }

main {
  display: grid;
  gap: 24px;
  padding: 28px 32px 40px;
}

.tab { display: none; }
.tab.active { display: grid; gap: 22px; min-width: 0; }

.section-heading {
  align-items: end;
  display: flex;
  justify-content: space-between;
}

.grid {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.grid.two {
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.75fr);
}

.dashboard-live-grid {
  align-items: stretch;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
}

.grid.side {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

.stack {
  display: grid;
  gap: 20px;
  align-content: start;
}

.metrics {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  min-width: 0;
}

.stat-card,
.panel {
  background: var(--surface);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  min-width: 0;
}

.stat-card {
  min-height: 118px;
  overflow: hidden;
  padding: 18px;
  position: relative;
}

.stat-card::after {
  background: linear-gradient(135deg, rgba(200, 16, 46, 0.16), rgba(17, 24, 39, 0));
  border-radius: 999px;
  content: "";
  height: 86px;
  position: absolute;
  right: -28px;
  top: -34px;
  width: 86px;
}

.stat-card span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 500;
}

.stat-card strong {
  display: block;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-top: 12px;
}

.panel {
  padding: 20px;
}

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

.table-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.status-pill {
  align-items: center;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 13px;
  font-weight: 500;
  min-height: 34px;
  padding: 0 14px;
}

.status-pill.ready {
  background: #ecfdf3;
  border-color: #bbf7d0;
  color: var(--success);
}

.status-pill.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 0;
  overflow: auto;
}

.data-table {
  border-collapse: collapse;
  min-width: 780px;
  width: 100%;
}

.data-table th {
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 13px 14px;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table th button {
  background: transparent;
  border: 0;
  color: inherit;
  font-weight: inherit;
  padding: 0;
  text-transform: inherit;
}

.data-table td {
  border-bottom: 1px solid #edf2f7;
  font-size: 14px;
  font-weight: 400;
  padding: 14px;
  vertical-align: top;
}

.data-table td strong {
  font-weight: 500;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: #fbfcfd;
}

.compact-table .data-table {
  min-width: 560px;
}

.compact-table .data-table th,
.compact-table .data-table td {
  padding: 11px 12px;
}

.jobs-map {
  border: 1px solid var(--line);
  border-radius: 12px;
  height: 350px;
  min-height: 350px;
  overflow: hidden;
}

.map-panel {
  display: grid;
  grid-template-rows: auto 1fr;
}

.leaflet-container {
  color: var(--ink);
  font-family: inherit;
}

.map-legend {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
}

.map-legend span {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  gap: 6px;
}

.map-legend i {
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 0 0 1px var(--line);
  display: inline-block;
  height: 10px;
  width: 10px;
}

.legend-live { background: #c8102e; }
.legend-generator { background: #2563eb; }
.legend-contract { background: #14b8a6; opacity: 0.45; }
.legend-month { background: #64748b; opacity: 0.65; }

form {
  display: grid;
  gap: 14px;
}

label {
  color: #334155;
  display: grid;
  font-size: 13px;
  font-weight: 500;
  gap: 7px;
}

input, select, textarea {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  color: var(--ink);
  min-height: 42px;
  outline: none;
  padding: 10px 12px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(200, 16, 46, 0.12);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.file-drop {
  align-items: center;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 86px;
  padding: 16px;
  text-align: center;
}

.file-drop input {
  display: none;
}

.helper-text,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.btn,
button {
  align-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: #334155;
  display: inline-flex;
  font-weight: 500;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  padding: 9px 13px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.btn:hover,
button:hover {
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.btn.primary,
button.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  border-color: var(--brand);
  color: #ffffff;
  width: 100%;
}

.btn.compact,
button.compact {
  width: auto;
}

button.danger {
  border-color: #fecaca;
  color: var(--danger);
}

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

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  padding: 7px 10px;
}

.badge.live,
.badge.completed,
.badge.arrived,
.badge.sent {
  background: #ecfdf3;
  color: var(--success);
}

.badge.archived,
.badge.cancelled {
  background: #f1f5f9;
  color: #475569;
}

.badge.failed {
  background: #fef2f2;
  color: var(--danger);
}

.badge.dispatched,
.badge.emergency {
  background: #fff7ed;
  color: var(--warning);
}

.badge.planned {
  background: #eff6ff;
  color: var(--info);
}

.card {
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 12px;
  padding: 16px;
}

.card-head {
  align-items: start;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

.card-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 12px;
  margin-top: 10px;
}

.bar-row {
  margin-bottom: 16px;
}

.bar-label {
  color: #334155;
  display: flex;
  font-size: 14px;
  font-weight: 500;
  justify-content: space-between;
  margin-bottom: 8px;
}

.bar {
  background: #eef2f7;
  border-radius: 999px;
  height: 9px;
  overflow: hidden;
}

.bar > span {
  background: linear-gradient(90deg, var(--brand), #111827);
  border-radius: inherit;
  display: block;
  height: 100%;
}

.volume-chart {
  min-height: 160px;
  padding-top: 4px;
}

.volume-line-chart {
  display: block;
  height: auto;
  max-height: 160px;
  width: 100%;
}

.chart-axis {
  stroke: #cbd5e1;
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: var(--brand);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.chart-line.previous {
  stroke: #94a3b8;
  stroke-dasharray: 7 7;
  stroke-width: 3;
}

.chart-point {
  fill: #ffffff;
  stroke: var(--brand);
  stroke-width: 3;
}

.chart-point.previous {
  fill: #ffffff;
  stroke: #94a3b8;
  stroke-width: 2;
}

.volume-line-chart text {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.empty-state {
  align-items: center;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  color: var(--muted);
  display: grid;
  min-height: 132px;
  padding: 22px;
  place-items: center;
  text-align: center;
}

.empty-state strong {
  font-weight: 500;
}

.modal {
  align-items: center;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 50;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
  max-height: min(760px, calc(100vh - 48px));
  max-width: 720px;
  overflow: auto;
  padding: 22px;
  width: 100%;
}

.modal-header {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.icon-btn {
  border-radius: 999px;
  font-size: 22px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  width: 36px;
}

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

  .sidebar {
    height: auto;
    position: static;
  }

  .brand-stack {
    align-items: center;
    grid-template-columns: 1fr auto 1fr;
  }

  .brand-divider {
    height: 44px;
    width: 1px;
  }

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

  .sidebar-footer {
    display: none;
  }

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

@media (max-width: 760px) {
  .sidebar {
    padding: 16px;
  }

  .brand-stack,
  .sidebar-nav,
  .grid.two,
  .grid.side,
  .metrics {
    grid-template-columns: 1fr;
  }

  .brand-divider {
    height: 1px;
    width: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    padding: 20px;
  }

  main {
    padding: 20px;
  }

  h1 { font-size: 24px; }
  h2 { font-size: 22px; }

  .panel-header,
  .section-heading,
  .card-head {
    align-items: stretch;
    flex-direction: column;
  }

  .table-tools {
    justify-content: stretch;
  }

  .table-tools input,
  .table-tools select {
    min-width: 100%;
  }
}
