/* ====================================================================
   Mekong app — layout, components, modules
   ==================================================================== */

/* ============ TOPBAR ============ */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-3) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(12px);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-primary);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; color: var(--color-text); }
.brand-sub { font-size: var(--text-xs); color: var(--color-text-muted); }

.primary-nav {
  display: flex;
  gap: 2px;
  background: var(--color-surface-offset);
  padding: 3px;
  border-radius: var(--radius-full);
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}
.primary-nav::-webkit-scrollbar { display: none; }

.nav-tab {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-radius: var(--radius-full);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: all var(--transition);
}
.nav-tab:hover { color: var(--color-text); }
.nav-tab.active {
  background: var(--color-surface-2);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}
.nav-tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-success); box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-success) 25%, transparent); }

.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.role-switch { display: flex; align-items: center; gap: var(--space-2); }
.role-switch label { font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.role-switch select { width: auto; padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
  position: relative;
}
.icon-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.icon-btn .badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  font-size: 10px; font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--color-error); color: white;
  display: inline-flex; align-items: center; justify-content: center;
}

.user-chip { display: flex; align-items: center; gap: var(--space-2); padding-left: var(--space-3); border-left: 1px solid var(--color-divider); }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-blue));
  color: white; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-name { font-size: var(--text-sm); font-weight: 600; }
.user-role { font-size: var(--text-xs); color: var(--color-text-muted); }

/* ============ TICKER ============ */
.ticker {
  display: flex;
  align-items: center;
  background: linear-gradient(90deg, color-mix(in oklab, var(--color-warning) 16%, transparent), transparent);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-2) 0 var(--space-2) var(--space-6);
  font-size: var(--text-sm);
  gap: 0;
  overflow: hidden;
  position: relative;
}
.ticker-label {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em;
  color: var(--color-error);
  flex-shrink: 0;
  padding-right: var(--space-4);
  background: var(--color-bg);
  z-index: 2;
  box-shadow: 8px 0 12px -6px var(--color-bg);
}
.ticker-wrap { flex: 1; overflow: hidden; mask-image: linear-gradient(90deg, transparent 0, #000 24px, #000 calc(100% - 80px), transparent 100%); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--color-error); animation: pulse 1.6s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-error) 60%, transparent); }
  70% { box-shadow: 0 0 0 10px color-mix(in oklab, var(--color-error) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.ticker-track {
  display: flex; gap: var(--space-8);
  animation: scroll 60s linear infinite;
  white-space: nowrap;
  padding-left: var(--space-4);
  will-change: transform;
}
@keyframes scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.ticker-track span { color: var(--color-text); }
.ticker-track .sev-high { color: var(--color-error); font-weight: 600; }
.ticker-track .sev-med  { color: var(--color-warning); font-weight: 600; }

/* ============ VIEW SYSTEM ============ */
.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-5) var(--space-6) var(--space-3);
  flex-wrap: wrap;
}
.page-title { font-size: var(--text-xl); margin-right: auto; }

.seg {
  display: inline-flex;
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.seg-btn:hover { color: var(--color-text); }
.seg-btn.active { background: var(--color-surface-2); color: var(--color-text); box-shadow: var(--shadow-sm); }

.time-range { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.time-range label { color: var(--color-text-muted); }
.time-range select { width: auto; }

/* ============ DASHBOARD ============ */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  height: calc(100dvh - 120px);
}

.map-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-divider);
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
}
#map, #routeMap { width: 100%; height: 100%; background: var(--color-surface-offset); }

.map-legend {
  position: absolute; top: var(--space-3); right: var(--space-3);
  background: color-mix(in oklab, var(--color-surface-2) 92%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  z-index: 500;
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  min-width: 200px;
  max-width: min(280px, calc(100% - var(--space-6)));
  overflow: hidden;
  display: flex; flex-direction: column;
}
.map-legend__toggle {
  all: unset;
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  user-select: none;
  width: 100%;
  box-sizing: border-box;
}
.map-legend__toggle:hover { background: color-mix(in oklab, var(--color-surface-2) 60%, transparent); }
.map-legend__title { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-muted); flex: 1; }
.map-legend__hint {
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--color-primary);
  background: color-mix(in oklab, var(--color-primary) 14%, transparent);
  padding: 2px 7px; border-radius: var(--radius-full);
}
.map-legend__chev { color: var(--color-text-muted); transition: transform var(--transition); }
.map-legend:not(.is-collapsed) .map-legend__chev { transform: rotate(180deg); }
.map-legend__body {
  padding: 0 var(--space-3) var(--space-3);
  max-height: min(60vh, 420px);
  overflow-y: auto;
  border-top: 1px solid var(--color-divider);
  margin-top: 0;
}
.map-legend.is-collapsed .map-legend__body { display: none; }
.map-legend label { display: flex; align-items: center; gap: var(--space-2); padding: 4px 0; cursor: pointer; }
.map-legend input { width: auto; margin: 0; }
.sw { width: 14px; height: 14px; border-radius: 3px; }
.sw.vessel { background: var(--color-primary); }
.sw.hazard { background: var(--color-warning); }
.sw.depth { background: linear-gradient(90deg, var(--color-error), var(--color-warning), var(--color-success)); }
.sw.port { background: var(--color-blue); border-radius: 50%; }
.sw.sensor { background: var(--color-purple); }
.sw.dwt { background: #f5b400; border-radius: 4px; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
.sw.mrcport { background: #c8893c; border-radius: 2px; }
.sw.rapid { background: #e85a3c; border-radius: 50%; }
.sw.deeppool { background: #4fb3c4; border-radius: 50%; box-shadow: inset 0 0 0 2px #1d6e8a; }
.sw.bridge { background: #d8d8d8; border-radius: 2px; box-shadow: inset 0 0 0 2px #555; }
.sw.dam { background: #6e54c8; border-radius: 2px; }
.sw.hydromet { background: #3f7c3a; border-radius: 50%; }

.legend-group { margin-bottom: var(--space-3); }
.legend-group:last-child { margin-bottom: 0; }
.legend-group-title {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--color-text-muted);
  padding: var(--space-2) 0 4px;
  border-top: 1px dashed var(--color-divider);
  margin-top: var(--space-2);
}
.legend-group:first-of-type .legend-group-title { border-top: 0; margin-top: 0; padding-top: 0; }
.legend-badge {
  display: inline-block; min-width: 28px; text-align: center;
  padding: 1px 6px; border-radius: 10px;
  background: color-mix(in oklab, var(--color-primary) 18%, transparent);
  color: var(--color-primary);
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
}

/* ---- MRC markers ---- */
.mrc-dwt-pill {
  display: inline-block;
  background: #f5b400;
  color: #1a1a1a;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 3px 7px;
  border-radius: 11px;
  border: 1.5px solid #1a1a1a;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  white-space: nowrap;
  line-height: 1;
}
.mrc-dwt-pill[data-water="Low"] { background: #f48a2c; }
.mrc-dot {
  display: block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.3);
}
.mrc-dot-bridge { background: #d8d8d8; border-color: #2a2a2a; }
.mrc-dot-rapid  { background: #e85a3c; }
.mrc-dot-met    { background: #3f7c3a; }
.mrc-sq {
  display: block; width: 11px; height: 11px;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
  transform: rotate(45deg);
}
.mrc-sq-port    { background: #c8893c; }
.mrc-sq-dam-op  { background: #6e54c8; }
.mrc-sq-dam-co  { background: #b9a3ff; }
.mrc-sq-dam-pl  { background: #d8d8d8; border-color: #555; }
.mrc-sq-dam-ot  { background: #888; }

.popup-sub { color: var(--color-text-muted); font-size: 12px; }
.leaflet-popup-content small { color: var(--color-text-muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; }

.report-fab {
  position: absolute;
  bottom: var(--space-5);
  right: var(--space-5);
  background: var(--color-error);
  color: white;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: var(--text-sm);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  transition: transform var(--transition);
}
.report-fab:hover { transform: translateY(-2px); }

.map-stats {
  position: absolute; bottom: var(--space-5); left: var(--space-5);
  display: flex; gap: var(--space-2);
  z-index: 500;
}
.map-stats > div {
  background: color-mix(in oklab, var(--color-surface-2) 92%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-sm);
}
.map-stats .num { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; line-height: 1; color: var(--color-primary); }
.map-stats .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); margin-top: 4px; }

/* Side rail */
.rail { display: flex; flex-direction: column; gap: var(--space-4); overflow-y: auto; min-height: 0; }

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel > header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}
.panel h3 { font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); }
.count {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.alert-list, .vessel-list {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.alert-list::-webkit-scrollbar,
.vessel-list::-webkit-scrollbar { width: 6px; }
.alert-list::-webkit-scrollbar-thumb,
.vessel-list::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--color-text-muted) 30%, transparent);
  border-radius: 3px;
}
.alert-list li, .vessel-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.alert-list li:last-child, .vessel-list li:last-child { border-bottom: none; }
.alert-list li:hover, .vessel-list li:hover { background: var(--color-surface-offset); }

.alert-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.alert-icon.high { background: var(--color-error-highlight); color: var(--color-error); }
.alert-icon.med  { background: var(--color-warning-highlight); color: var(--color-warning); }
.alert-icon.low  { background: var(--color-primary-highlight); color: var(--color-primary); }

.alert-body { display: flex; flex-direction: column; min-width: 0; }
.alert-body strong { font-size: var(--text-sm); font-weight: 600; }
.alert-body small { font-size: var(--text-xs); color: var(--color-text-muted); }
.alert-time { font-size: var(--text-xs); color: var(--color-text-faint); }

.vessel-list li .v-icon {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.v-meta { display: flex; flex-direction: column; min-width: 0; }
.v-meta strong { font-size: var(--text-sm); font-weight: 600; }
.v-meta small { font-size: var(--text-xs); color: var(--color-text-muted); }
.v-speed { font-size: var(--text-xs); font-weight: 600; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; }
.kpi {
  padding: var(--space-3) var(--space-4);
  border-right: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
}
.kpi:nth-child(2n) { border-right: none; }
.kpi:nth-last-child(-n+2) { border-bottom: none; }
.k-lbl { display: block; font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.k-val {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  margin-top: 2px;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.k-val small { font-size: 0.55em; color: var(--color-text-muted); margin-left: 2px; font-weight: 500; }
.k-trend { font-size: var(--text-xs); color: var(--color-text-muted); }
.k-trend.up { color: var(--color-warning); }

/* ============ ROUTE PLANNER ============ */
.planner-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  height: calc(100dvh - 120px);
}
.planner-form {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-3);
}
.muted { color: var(--color-text-muted); font-size: var(--text-sm); }
.muted.small { font-size: var(--text-xs); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.planner-form label { display: flex; flex-direction: column; gap: 4px; font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.planner-form input, .planner-form select { text-transform: none; letter-spacing: 0; }

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-weight: 600;
  font-size: var(--text-sm);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  transition: background var(--transition), transform var(--transition);
}
.btn-primary:hover { background: var(--color-primary-hover); transform: translateY(-1px); }

.btn-ghost {
  background: var(--color-surface-offset);
  color: var(--color-text);
  font-weight: 500;
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-divider);
}
.btn-ghost:hover { background: var(--color-surface-offset-2); }

.planner-h { font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-muted); margin-top: var(--space-3); }

.route-options { list-style: none; display: flex; flex-direction: column; gap: var(--space-2); }
.route-options li {
  padding: var(--space-3);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
}
.route-options li:hover { border-color: var(--color-primary); background: var(--color-surface-offset); }
.route-options li.selected {
  border-color: var(--color-primary);
  background: color-mix(in oklab, var(--color-primary) 8%, transparent);
}
.route-options .ro-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-1); }
.route-options .ro-name { font-weight: 600; font-size: var(--text-sm); }
.route-options .ro-tag { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; padding: 2px 6px; border-radius: var(--radius-sm); }
.ro-tag.safe { background: var(--color-success-highlight); color: var(--color-success); }
.ro-tag.fast { background: var(--color-warning-highlight); color: var(--color-warning); }
.ro-tag.eco  { background: var(--color-primary-highlight); color: var(--color-primary); }
.ro-stats { display: flex; gap: var(--space-3); font-size: var(--text-xs); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.ro-stats strong { color: var(--color-text); font-weight: 600; font-size: var(--text-sm); }

.export-row { display: flex; gap: var(--space-2); margin-top: var(--space-3); }

.planner-map-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-divider);
}
.route-summary {
  position: absolute; bottom: var(--space-4); left: var(--space-4); right: var(--space-4);
  background: color-mix(in oklab, var(--color-surface-2) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  z-index: 500;
}
.route-summary em { color: var(--color-text-muted); font-style: normal; }

/* ============ CARD GRID (twin / env) ============ */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  padding: 0 var(--space-6) var(--space-8);
}
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.card.span-2 { grid-column: span 2; }
.card > header {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}
.card h3 { font-size: var(--text-sm); font-weight: 600; }
.tag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 2px 8px; border-radius: var(--radius-full);
  background: var(--color-primary-highlight); color: var(--color-primary);
}
.chart-wrap { padding: var(--space-4); height: 240px; position: relative; }
.card.span-2 .chart-wrap { height: 260px; }

.hot-list { list-style: none; padding: var(--space-2) 0; }
.hot-list li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-divider); font-size: var(--text-sm); }
.hot-list li:last-child { border-bottom: none; }
.hot-list .val { font-size: var(--text-xs); font-weight: 600; color: var(--color-text-muted); }
.dot.risk-h { width: 10px; height: 10px; border-radius: 50%; background: var(--color-error); }
.dot.risk-m { width: 10px; height: 10px; border-radius: 50%; background: var(--color-warning); }
.dot.risk-l { width: 10px; height: 10px; border-radius: 50%; background: var(--color-success); }

/* ============ PORTS ============ */
.ports-pane { padding: 0 var(--space-6) var(--space-8); }
.ports-pane.hidden { display: none; }

.filter-row { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.filter-row select, .filter-row input { width: auto; }
.queue-pill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

.table-card { background: var(--color-surface); border: 1px solid var(--color-divider); border-radius: var(--radius-lg); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table thead th {
  text-align: left;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-offset);
  font-weight: 600;
}
.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-surface-offset); }

.pill {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px; font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pill.ok { background: var(--color-success-highlight); color: var(--color-success); }
.pill.warn { background: var(--color-warning-highlight); color: var(--color-warning); }
.pill.err { background: var(--color-error-highlight); color: var(--color-error); }
.pill.info { background: var(--color-primary-highlight); color: var(--color-primary); }

.insp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }

.checklist { list-style: none; padding: var(--space-2); }
.checklist li {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}
.checklist li:hover { background: var(--color-surface-offset); }
.checklist input { width: auto; margin: 0; }

.insp-actions { padding: var(--space-3) var(--space-4); display: flex; gap: var(--space-3); align-items: center; border-top: 1px solid var(--color-divider); flex-wrap: wrap; }
.upload {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); color: var(--color-text-muted);
  cursor: pointer;
}
.upload input { display: none; }

.dg-list { list-style: none; padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.dg-list li { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-3); background: var(--color-surface-offset); border-radius: var(--radius-md); font-size: var(--text-sm); }
.dg-list strong { color: var(--color-primary); font-family: var(--font-mono); font-size: var(--text-xs); }

.lmtlis { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-3); padding: var(--space-4); }
.lmtlis-node {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.lmtlis-node .flag { font-size: 20px; }
.lmtlis-node .ok, .lmtlis-node .warn { margin-left: auto; font-size: var(--text-xs); font-weight: 600; }
.lmtlis-node .ok { color: var(--color-success); }
.lmtlis-node .warn { color: var(--color-warning); }

/* ============ ENVIRONMENT ============ */
.env-pane { padding: 0 var(--space-6) var(--space-8); }
.env-pane.hidden { display: none; }

.station-list { list-style: none; padding: var(--space-2); }
.station-list li { display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3); align-items: center; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); font-size: var(--text-sm); }
.station-list li > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.station-list li strong { font-size: var(--text-sm); font-weight: 600; }
.station-list .pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-success); }
.station-list .pulse-dot.warn { background: var(--color-warning); }
.station-list .pulse-dot.err { background: var(--color-error); }
.station-list small { font-size: var(--text-xs); color: var(--color-text-muted); }

.incidents { display: flex; flex-direction: column; gap: var(--space-3); }
.incident-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-left: 3px solid var(--color-warning);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-4);
  align-items: center;
}
.incident-card.high { border-left-color: var(--color-error); }
.incident-card.low { border-left-color: var(--color-success); }
.inc-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-warning-highlight); color: var(--color-warning);
  font-size: 18px;
}
.incident-card.high .inc-icon { background: var(--color-error-highlight); color: var(--color-error); }
.incident-card.low .inc-icon { background: var(--color-success-highlight); color: var(--color-success); }
.inc-body strong { display: block; font-size: var(--text-sm); font-weight: 600; }
.inc-body small { font-size: var(--text-xs); color: var(--color-text-muted); display: block; margin-top: 2px; }

/* ============ COMMUNITY ============ */
.community-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6) var(--space-8);
}
.hero-card { grid-column: span 3; }
.bulletin { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); }

.training-list { list-style: none; padding: var(--space-2); display: flex; flex-direction: column; gap: var(--space-1); }
.training-list li { display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3); align-items: center; padding: var(--space-3); border-radius: var(--radius-sm); font-size: var(--text-sm); }
.t-icon { font-size: 20px; }
.training-list small { display: block; color: var(--color-text-muted); font-size: var(--text-xs); }
.progress { width: 80px; height: 6px; background: var(--color-surface-offset); border-radius: var(--radius-full); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--color-primary); border-radius: var(--radius-full); }

.cs-form { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.cs-form label { display: flex; flex-direction: column; gap: 4px; font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.forum, .kb { list-style: none; padding: var(--space-2); }
.forum li, .kb li { padding: var(--space-3); border-bottom: 1px solid var(--color-divider); font-size: var(--text-sm); cursor: pointer; }
.forum li:last-child, .kb li:last-child { border-bottom: none; }
.forum li:hover, .kb li:hover { background: var(--color-surface-offset); }
.forum small { display: block; color: var(--color-text-muted); font-size: var(--text-xs); margin-top: 2px; }

/* ============ ACCOUNT ============ */
.account-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6) var(--space-8);
}
.prof-form { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.prof-form label, .pref { display: flex; flex-direction: column; gap: 4px; font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; padding: var(--space-3) var(--space-4); }
.pref-set { border: none; padding: var(--space-3) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.pref-set legend { font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: var(--space-2); }
.pref-set label { padding: 0; flex-direction: row; align-items: center; gap: var(--space-2); text-transform: none; letter-spacing: 0; font-size: var(--text-sm); color: var(--color-text); }
.pref-set input { width: auto; }
.sec-list { list-style: none; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); }
.code { background: var(--color-surface-offset); padding: var(--space-3); margin: 0 var(--space-4) var(--space-3); border-radius: var(--radius-md); font-family: var(--font-mono); font-size: var(--text-xs); white-space: pre-wrap; }

/* ============ DRAWER ============ */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 380px; max-width: 100vw;
  background: var(--color-surface);
  border-left: 1px solid var(--color-divider);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  transform: translateX(100%);
  transition: transform var(--transition);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer > header { display: flex; justify-content: space-between; align-items: center; padding: var(--space-4); border-bottom: 1px solid var(--color-divider); }
.drawer ul { list-style: none; overflow-y: auto; }
.drawer li { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-divider); font-size: var(--text-sm); }
.drawer li strong { display: block; font-size: var(--text-sm); }
.drawer li small { display: block; color: var(--color-text-muted); font-size: var(--text-xs); margin-top: 2px; }

/* ============ MODAL ============ */
.modal {
  border: none;
  padding: 0;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
  width: min(440px, 100vw);
}
.modal::backdrop { background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.modal form { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); }
.modal h3 { font-size: var(--text-lg); }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.modal-actions { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-3); }

/* ============ LEAFLET TWEAKS ============ */
.leaflet-container { background: var(--color-surface-offset); font-family: var(--font-body); }
.leaflet-popup-content-wrapper {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-divider);
}
.leaflet-popup-content { margin: var(--space-3) var(--space-4); font-size: var(--text-sm); }
.leaflet-popup-content strong { font-family: var(--font-display); }
.leaflet-popup-tip { background: var(--color-surface-2); }
.leaflet-control-zoom a { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-divider); }
.leaflet-control-attribution { background: color-mix(in oklab, var(--color-surface-2) 80%, transparent); color: var(--color-text-muted); font-size: 10px; }
[data-theme="dark"] .leaflet-tile { filter: brightness(0.7) hue-rotate(15deg) saturate(0.85); }

/* Custom vessel marker */
.vessel-marker {
  width: 14px; height: 14px;
  background: var(--color-primary);
  border: 2px solid var(--color-surface-2);
  border-radius: 50%;
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--color-primary) 40%, transparent);
}
.vessel-marker.cargo { background: var(--color-blue); }
.vessel-marker.passenger { background: var(--color-purple); }
.vessel-marker.tanker { background: var(--color-warning); }
.hazard-marker {
  width: 24px; height: 24px;
  background: var(--color-warning);
  border: 2px solid white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow-md);
}
.hazard-marker.high { background: var(--color-error); }
.port-marker {
  width: 16px; height: 16px;
  background: var(--color-blue);
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}
.sensor-marker {
  width: 10px; height: 10px;
  background: var(--color-purple);
  border: 2px solid white;
  border-radius: 2px;
  transform: rotate(45deg);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1600px) {
  .topbar { gap: var(--space-3); padding: var(--space-3) var(--space-4); }
  .nav-tab { padding: var(--space-2) 9px; font-size: 13px; }
  .role-switch label { display: none; }
  .brand-sub { display: none; }
  .user-meta { display: none; }
}
@media (max-width: 1200px) {
  .primary-nav { order: 3; grid-column: 1 / -1; margin-top: var(--space-2); }
  .topbar { grid-template-columns: auto 1fr; }
}
@media (max-width: 1280px) {
  .dash-grid { grid-template-columns: 1fr 340px; }
  .card-grid, .community-grid { grid-template-columns: repeat(2, 1fr); }
  .hero-card { grid-column: span 2; }
  .card.span-2 { grid-column: span 2; }
}
@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; padding: var(--space-3) var(--space-4); }
  .primary-nav { grid-column: 1 / -1; order: 3; }
  .user-meta { display: none; }
  .role-switch label { display: none; }
  .dash-grid { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 60vh; }
  .planner-grid { grid-template-columns: 1fr; height: auto; }
  .planner-map-wrap { height: 50vh; }
  .card-grid, .community-grid, .account-grid { grid-template-columns: 1fr; }
  .card.span-2, .hero-card { grid-column: span 1; }
  .insp-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .map-stats { flex-direction: column; }
  .view-header { padding: var(--space-4); }
  .map-legend { top: auto; bottom: var(--space-3); right: var(--space-3); }
}
