*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.42;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* Badges & Buttons (Sentence case wajib, tanpa border-left) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill-info {
  background: var(--status-info-bg);
  color: var(--status-info);
  border-color: var(--status-info-border);
}

.pill-pass {
  background: var(--status-pass-bg);
  color: var(--status-pass);
  border-color: var(--status-pass-border);
}

.pill-warn {
  background: var(--status-warn-bg);
  color: var(--status-warn);
  border-color: var(--status-warn-border);
}

.pill-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger);
  border-color: var(--status-danger-border);
}

.pill-neutral {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border-hairline);
}

.btn-primary {
  height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-mid);
  background: var(--action-primary);
  color: var(--action-primary-fg);
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--duration-fast) var(--ease-out);
}

.btn-primary:hover {
  background: var(--action-primary-hover);
}

.btn-secondary {
  height: 32px;
  padding: 0 11px;
  border-radius: var(--radius-inner);
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
}

/* Gerbang Akses Cepat */
.gate-view {
  min-height: 100vh;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(circle at 50% 22%, rgba(0, 75, 154, 0.18), transparent 56%);
}

.domain-bar {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-mid);
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.gate-card {
  width: 100%;
  max-width: 472px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-mid);
  background: linear-gradient(145deg, var(--brand-anchor), var(--action-primary));
  color: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.gate-head h1 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.gate-head p {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.field-label-row .field-label {
  margin-bottom: 0;
}

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.pin-input {
  width: 100%;
  height: 50px;
  border-radius: var(--radius-mid);
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}

.pin-input:focus {
  border-color: var(--action-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.22);
}

.seg-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-mid);
  padding: 4px;
}

.seg-btn {
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-weight: 600;
  border: 1px solid var(--border-strong);
}

.seg-btn.primary-active {
  background: var(--action-primary);
  color: var(--action-primary-fg);
  font-weight: 600;
}

.token-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-mid);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.token-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
}

.token-btn {
  width: 100%;
  text-align: left;
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 11.5px;
  color: var(--status-info);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-btn:hover {
  border-color: var(--action-primary);
}

.live-token-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-token-input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-inner);
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  font-size: 12px;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out);
}

.live-token-input:focus {
  border-color: var(--action-primary);
}

.gate-error {
  background: var(--status-danger-bg);
  border: 1px solid var(--status-danger-border);
  color: #fca5a5;
  border-radius: var(--radius-inner);
  padding: 8px 11px;
  font-size: 12px;
}

.gate-foot {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Shell Dashboard C2 (Rail kiri ramping 58px + workspace) */
.app-shell {
  display: grid;
  grid-template-columns: 58px 1fr;
  min-height: 100vh;
}

.rail {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px;
  gap: 14px;
}

.rail-logo {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-mid);
  background: linear-gradient(145deg, var(--brand-anchor), var(--action-primary));
  color: #ffffff;
  display: grid;
  place-items: center;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
  margin-top: 4px;
}

.rail-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-mid);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.rail-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.rail-btn.active {
  background: var(--status-info-bg);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.42);
}

.rail-spacer {
  flex: 1;
}

.workspace {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  gap: 10px;
  min-width: 0;
  height: 100vh;
  max-height: 100vh;
}

/* Topbar Tunggal */
.topbar {
  min-height: 48px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-mid);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.title-block {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.title-block h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.title-domain {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.top-tabs {
  display: inline-flex;
  gap: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  border-radius: 9px;
  padding: 3px;
}

.top-tab {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.top-tab.active {
  background: var(--action-primary);
  color: var(--action-primary-fg);
  font-weight: 600;
}

.top-badges {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

/* Strip KPI (Scan order #1) */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  flex-shrink: 0;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-mid);
  padding: 10px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.15;
}

.kpi-value.text-mode {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0;
}

.kpi-unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 3px;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Grid 2x2 Telemetri Sidang */
.grid-2x2 {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.08fr 1fr;
  grid-template-rows: 1.12fr 1fr;
  gap: 10px;
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-outer);
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.panel-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.panel-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.inset-box {
  flex: 1;
  min-height: 0;
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-inner);
  overflow: hidden;
  position: relative;
}

/* Segmented Mini */
.seg-mini {
  display: inline-flex;
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.seg-mini button {
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.seg-mini button.on {
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-weight: 600;
  border: 1px solid var(--border-strong);
}

/* Video Stage */
.video-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.video-stage video,
.video-stage img,
.video-stage svg.mock-cam {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.overlay-tl {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 450;
  background: rgba(11, 13, 18, 0.88);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11.5px;
  color: var(--text-primary);
  pointer-events: none;
}

.overlay-br {
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 450;
  background: rgba(11, 13, 18, 0.88);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--text-secondary);
  pointer-events: none;
}

.cam-fallback-box {
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 340px;
}

.cam-fallback-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.cam-fallback-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Leaflet Dark Theme Overrides */
.leaflet-container {
  width: 100%;
  height: 100%;
  background: var(--bg-inset) !important;
  font-family: var(--font-sans) !important;
}

.leaflet-control-zoom a {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-hairline) !important;
}

.leaflet-control-attribution {
  background: rgba(11, 13, 18, 0.82) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

.campus-poi-tip {
  background: rgba(18, 21, 30, 0.94) !important;
  border: 1px solid var(--border-strong) !important;
  color: var(--text-primary) !important;
  border-radius: 6px !important;
  padding: 3px 7px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  box-shadow: none !important;
}

.campus-poi-tip.target {
  border-color: var(--action-primary) !important;
  color: #dbeafe !important;
}

.campus-poi-tip::before {
  display: none !important;
}

.road-label-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 10.5px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 1px 3px #07090d;
  pointer-events: none;
}

/* Radar + Tabel Deteksi */
.fusion-split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 10px;
}

.radar-box {
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-inner);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.radar-empty {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
}

.table-wrap {
  overflow-y: auto;
  min-height: 0;
}

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

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 4px 8px 7px 8px;
  border-bottom: 1px solid var(--border-hairline);
}

td {
  padding: 8px;
  border-bottom: 1px solid rgba(37, 44, 62, 0.72);
  font-size: 12px;
  color: var(--text-primary);
  vertical-align: middle;
}

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

th.num, td.num {
  text-align: right;
}

/* Kesehatan & Log SSE */
.health-mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex-shrink: 0;
}

.stat-mini {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-inner);
  padding: 8px 10px;
}

.stat-mini-lbl {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.stat-mini-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2px;
}

.sse-log {
  flex: 1;
  min-height: 0;
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-inner);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-secondary);
  overflow-y: auto;
}

.log-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.log-ev {
  color: var(--status-info);
  flex-shrink: 0;
}

/* Mode Pendamping (Seragam C2 Trust Blue + Rail Kiri) */
.pendamping-split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 10px;
}

.trip-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-inner);
  padding: 9px 12px;
  flex-shrink: 0;
}

.trip-dest {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.trip-dist {
  font-size: 18px;
  font-weight: 700;
  color: var(--status-info);
}

.right-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.status-strip-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex-shrink: 0;
}

.mini-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-mid);
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mini-card-lbl {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.mini-card-val {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.mini-card-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  min-height: 0;
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-inner);
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
}

.alert-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.alert-desc {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.privacy-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--border-hairline);
  font-size: 11.5px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.perm-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

html.preview-390,
html.preview-390 body {
  width: 390px;
  max-width: 390px;
  overflow-x: hidden;
}

/* Mobile Responsive (390px) */
@media (max-width: 960px) {
  html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .rail {
    display: none;
  }

  .workspace {
    height: auto;
    max-height: none;
    width: 100%;
    max-width: 100%;
    padding: 10px;
    gap: 10px;
    overflow-x: hidden;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
    min-width: 0;
    width: 100%;
  }

  .title-block {
    flex-wrap: wrap;
    gap: 4px 10px;
    min-width: 0;
  }

  .title-domain {
    font-size: 11px;
    overflow-wrap: anywhere;
  }

  .top-tabs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .top-tab {
    text-align: center;
    padding: 6px 4px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kpi-strip {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .kpi-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 10px;
    min-width: 0;
  }

  .kpi-value {
    font-size: 20px;
  }

  .grid-2x2,
  .pendamping-split {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
  }

  .panel {
    min-width: 0;
    width: 100%;
    padding: 10px;
    overflow: hidden;
  }

  .panel-head {
    flex-wrap: wrap;
    gap: 6px;
  }

  .inset-box {
    min-height: 220px;
    width: 100%;
  }

  .fusion-split {
    grid-template-columns: minmax(0, 1fr);
  }

  .table-wrap {
    overflow-x: auto;
    max-width: 100%;
  }

  .log-line,
  .privacy-bar,
  .alert-item,
  .trip-bar {
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  .status-strip-3 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .mini-card {
    min-width: 0;
  }

  .top-badges {
    flex-wrap: wrap;
    gap: 6px;
  }

  .video-stage {
    width: 100%;
    height: 100%;
  }

  .pill {
    max-width: 100%;
  }

  .overlay-tl, .overlay-br {
    font-size: 10.5px;
    max-width: calc(100% - 16px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
