/* ALKARA FLEETFMS — Fuel Analysis Ops Stylesheet
 * Strictly conforms to OFALabs UI/UX Guidelines:
 * Minimalist, data-dense, industrial fleet management.
 * Primary background #f8fafc, Surface #ffffff, Borders 1px solid var(--c-border).
 * No gradients, no thick shadows. Full rounded pills (9999px).
 */

.app-shell {
  opacity: 1 !important;
  min-height: 100vh;
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  height: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Design tokens are inherited from the global stylesheet
   /_next/static/chunks/1t4aoiqub9ec4.css; local aliases below map page-level
   names onto the global tokens — do not hardcode hex values here. */
:root {
  --c-bg: var(--c-surface);
  --c-card: var(--c-white);
  --c-border-subtle: var(--c-surface2);
  --c-text-sub: var(--c-sub);
  --c-text-muted: var(--c-muted);
  --c-danger: var(--c-error);
  --radius-card: var(--radius-md);
  --radius-btn: var(--radius-sm);
  --radius-pill: 99px;
}

.p-page {
  background: var(--c-bg);
  min-height: 100%;
  color: var(--c-text);
  font-family: var(--font-sans);
  padding: 20px 28px 60px;
  max-width: 1440px;
  margin: 0 auto;
  box-sizing: border-box;
}

.p-loading-fade {
  opacity: 0.6;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.p-kpi-live-pulse {
  animation: kpiPulse 0.8s ease-out;
}

@keyframes kpiPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.04); color: var(--c-accent); }
  100% { transform: scale(1); }
}

.p-table-scroll::-webkit-scrollbar,
.app-content::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.p-table-scroll::-webkit-scrollbar-track,
.app-content::-webkit-scrollbar-track {
  background: var(--c-surface2);
}
.p-table-scroll::-webkit-scrollbar-thumb,
.app-content::-webkit-scrollbar-thumb {
  background: var(--c-border2);
  border-radius: 3px;
}
.p-table-scroll::-webkit-scrollbar-thumb:hover,
.app-content::-webkit-scrollbar-thumb:hover {
  background: var(--c-muted);
}

/* ── Navigation bar ── */
.p-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.p-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  color: var(--c-text-sub);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.p-back:hover {
  background: var(--c-surface2);
  border-color: var(--c-border2);
  color: var(--c-text);
}

.p-shift-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.p-shift-btn {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  padding: 6px 12px;
  border-radius: var(--radius-btn);
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text-sub);
  cursor: pointer;
  transition: all 0.15s ease;
}
.p-shift-btn:hover {
  color: var(--c-text);
}
.p-shift-btn.active {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-white);
}

/* ── Scope Context Strip ── */
.p-scope-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-btn);
  padding: 10px 16px;
  font-size: 12px;
  color: var(--c-text-sub);
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.p-scope-strip__left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.p-scope-strip strong {
  color: var(--c-text);
  font-weight: 600;
}
.p-scope-strip__badge {
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--c-surface2);
  color: var(--c-sub);
  font-size: 11px;
  font-weight: 600;
}

/* ── Unit Table Card (Directory) ── */
.p-table-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  margin-bottom: 20px;
  overflow: hidden;
}

.p-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  flex-wrap: wrap;
  gap: 10px;
}

.p-table-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.p-table-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.p-table-search {
  width: 220px;
  height: 30px;
  padding: 0 10px 0 30px;
  font-size: 11.5px;
  border: 1px solid var(--c-border2);
  border-radius: 6px;
  background: var(--c-white);
  color: var(--c-text);
  outline: none;
}
.p-table-search:focus {
  border-color: var(--c-accent);
}
.p-table-search-icon {
  position: absolute;
  left: 9px;
  color: var(--c-muted);
  pointer-events: none;
}

.p-table-scroll {
  max-height: 220px;
  overflow-y: auto;
  overflow-x: auto;
}

.p-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

.p-table thead tr {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.p-table th {
  padding: 8px 14px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-text-sub);
  white-space: nowrap;
}

.p-table th.r, .p-table td.r { text-align: right; }
.p-table th.c, .p-table td.c { text-align: center; }

.p-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--c-border-subtle);
  vertical-align: middle;
  white-space: nowrap;
}

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

.unit-table-row {
  cursor: pointer;
  transition: background 0.12s;
}
.unit-table-row:hover {
  background: var(--c-surface);
}
.unit-table-row--selected {
  background: #eff6ff !important;
  border-left: 3px solid var(--c-accent);
}

.td-id {
  font-weight: 700;
  color: var(--c-text);
}

.td-time {
  font-size: 11px;
  color: var(--c-text-sub);
}

.td-num {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--c-text);
}

.td-eff {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--c-surface2);
  color: var(--c-sub);
}
.td-eff--ok {
  background: #dcfce7;
  color: var(--c-loading);
}

/* ── Selected Unit Profile Header ── */
.p-header {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 20px;
}

.p-header__left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.p-unit-icon {
  width: 48px;
  height: 48px;
  background: var(--c-surface2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.p-unit-icon__label {
  font-size: 15px;
  font-weight: 800;
  color: var(--c-accent);
  line-height: 1;
}
.p-unit-icon__sub {
  font-size: 7.5px;
  letter-spacing: 0.1em;
  color: var(--c-text-muted);
  margin-top: 2px;
}

.p-unit-id {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--c-text);
  line-height: 1;
}

.p-unit-model {
  font-size: 12px;
  color: var(--c-text-sub);
  margin: 3px 0 6px;
  display: block;
}

.p-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.p-meta span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--c-text-sub);
}

/* Status Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.p-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.p-pill__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}
.p-pill--above {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid rgba(217, 119, 6, 0.25);
}
.p-pill--above .p-pill__dot { background: #d97706; }

.p-pill--near {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid rgba(37, 99, 235, 0.25);
}
.p-pill--near .p-pill__dot { background: var(--c-accent); }

.p-pill--below {
  background: #dcfce7;
  color: var(--c-loading);
  border: 1px solid rgba(34, 197, 94, 0.25);
}
.p-pill--below .p-pill__dot { background: #16a34a; }

.p-pill--insufficient {
  background: var(--c-surface2);
  color: var(--c-sub);
  border: 1px solid var(--c-border2);
}
.p-pill--insufficient .p-pill__dot { background: var(--c-muted); }

/* ── KPIs ── */
.p-kpis {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.p-kpi {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-btn);
  padding: 10px 14px;
  min-width: 120px;
  text-align: right;
}
.p-kpi__label {
  font-size: 10px;
  color: var(--c-text-sub);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.p-kpi__value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
}
.p-kpi__value--red { color: var(--c-error); }
.p-kpi__value--blue { color: var(--c-accent); }
.p-kpi__unit {
  font-size: 11px;
  font-weight: 500;
  color: var(--c-text-sub);
  margin-left: 3px;
}

/* ── Analytics Grid ── */
.p-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.p-map {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.p-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-text-sub);
  font-weight: 700;
}

.p-map__area {
  position: relative;
  flex: 1;
  min-height: 220px;
  background: var(--c-surface);
  border-radius: var(--radius-btn);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.p-map__unavailable {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 24px;
  text-align: center;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-btn);
  color: var(--c-text-sub);
  gap: 8px;
}

.p-map__unavailable-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text);
}

.p-map__unavailable-desc {
  font-size: 11px;
  color: var(--c-text-muted);
  max-width: 220px;
  line-height: 1.4;
}

.p-map__svg-wrap {
  position: relative;
  width: 100%;
  height: 220px;
  background: var(--c-surface);
  border-radius: var(--radius-btn);
  border: 1px solid var(--c-border);
  overflow: hidden;
}

.p-chart-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.p-chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.p-chart-sub {
  font-size: 11px;
  color: var(--c-text-sub);
  margin-top: 2px;
}

.p-chart-legend {
  display: flex;
  gap: 14px;
}
.p-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--c-text-sub);
  font-weight: 500;
}
.p-legend-line {
  display: inline-block;
  width: 14px;
  height: 2px;
  border-radius: 1px;
}
.p-legend-line--blue { background: var(--c-accent); }
.p-legend-line--red {
  background: #ef4444;
  border-top: 2px dashed #ef4444;
  height: 0;
}

.p-chart-canvas-wrap {
  width: 100%;
  height: 220px;
  position: relative;
}
.p-chart-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Peer Cohort Summary Banner */
.p-peer-banner {
  background: var(--c-white);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-btn);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--c-text);
  line-height: 1.5;
}

/* Header Live Indicator */
.fuel-header-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.fuel-header-live[data-tone="live"] {
  background: #dcfce7;
  color: var(--c-loading);
}
.fuel-header-live[data-tone="live"] .fuel-header-live-dot {
  background: #16a34a;
}
.fuel-header-live[data-tone="degraded"],
.fuel-header-live[data-tone="reconnecting"] {
  background: #fef9c3;
  color: var(--c-dumping);
}
.fuel-header-live[data-tone="degraded"] .fuel-header-live-dot,
.fuel-header-live[data-tone="reconnecting"] .fuel-header-live-dot {
  background: #d97706;
}
.fuel-header-live[data-tone="offline"] {
  background: #fee2e2;
  color: var(--c-error);
}
.fuel-header-live[data-tone="offline"] .fuel-header-live-dot {
  background: #ef4444;
}
.fuel-header-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

/* Category Badge in Directory */
.cat-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--c-surface2);
  color: var(--c-queuing);
}
.cat-pill--haul { background: #eff6ff; color: #1e40af; }
.cat-pill--loader { background: #fef3c7; color: #92400e; }
.cat-pill--support { background: var(--c-surface2); color: var(--c-queuing); }

/* Responsive */
@media (max-width: 1080px) {
  .p-grid { grid-template-columns: 1fr; }
  .p-header { flex-direction: column; align-items: flex-start; }
  .p-kpis { width: 100%; justify-content: flex-start; }
}

@media (max-width: 640px) {
  .p-page { padding: 14px; }
  .p-nav { flex-direction: column; align-items: flex-start; }
}
