:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #4338ca;
  --primary-hover: #3730a3;
  --primary-soft: #eef2ff;
  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-soft: #fef3c7;
  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.hidden {
  display: none !important;
}

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-6 { margin-bottom: 6px; }
.spacer { flex: 1; }

/* TOPBAR */
.topbar {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 55%, #3730a3 100%);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 60;
  box-shadow: 0 4px 18px rgba(30, 27, 75, 0.25);
}

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

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  display: grid;
  place-items: center;
  font-size: 24px;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.78);
}

.topbar-party-bar,
.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.party-select,
.role-select {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.party-select option,
.role-select option {
  color: var(--text);
  background: #fff;
}

.role-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
}

.role-label {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.82);
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn-lg { padding: 12px 18px; font-size: 1.02rem; font-weight: 800; border-radius: 11px; }
.btn-md { padding: 8px 14px; font-size: 0.88rem; font-weight: 700; }
.btn-sm { padding: 6px 11px; font-size: 0.82rem; }
.btn-xs { padding: 4px 8px; font-size: 0.76rem; }
.btn-icon { padding: 6px 9px; font-size: 1rem; }
.btn-block { width: 100%; display: flex; text-align: center; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-accent {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 3px 12px rgba(217, 119, 6, 0.35);
}
.btn-accent:hover { background: var(--accent-hover); }

.btn-warning {
  background: #d97706;
  color: #fff;
}
.btn-warning:hover { background: #b45309; }

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover { background: #047857; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}
.btn-secondary:hover { background: #cbd5e1; }

.btn-ghost {
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  border: 1px solid rgba(148, 163, 184, 0.3);
}
.panel .btn-ghost,
.modal .btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: rgba(148, 163, 184, 0.2);
}

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
}
.sync-dot.cloud {
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
}

/* KPI STRIP */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 12px;
  padding: 14px 20px 6px;
  max-width: 1520px;
  margin: 0 auto;
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.kpi-icon {
  font-size: 1.55rem;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--surface-alt);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.kpi-info {
  display: flex;
  flex-direction: column;
}

.kpi-value {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-late.has-late {
  background: #fef2f2;
  border-color: #fca5a5;
  animation: pulseBorder 1.8s infinite;
}
.kpi-late.has-late .kpi-value {
  color: var(--danger);
}

@keyframes pulseBorder {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.25); }
  50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.08); }
}

/* TABS */
.main-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 20px 0;
  max-width: 1520px;
  margin: 0 auto;
  overflow-x: auto;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--primary);
  background: #fff;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.04);
}

/* MAIN CONTAINER */
.main-container {
  max-width: 1520px;
  margin: 0 auto;
  padding: 0 20px 36px;
}

.tab-panel {
  display: none;
  background: transparent;
  padding-top: 14px;
}

.tab-panel.active {
  display: block;
}

/* PANELS */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px;
}

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

.panel-header h2,
.panel-header-bar h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.panel-hint {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.panel-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.header-bar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

/* DASHBOARD SPLIT */
.dashboard-split {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 16px;
  align-items: stretch;
}

@media (max-width: 1080px) {
  .dashboard-split {
    grid-template-columns: 1fr;
  }
}

/* 3D MAP VIEWPORT */
.map-panel {
  display: flex;
  flex-direction: column;
}

.map-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.map-viewport {
  position: relative;
  width: 100%;
  height: 470px;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, #dbeafe 0%, #eff6ff 45%, #ecfdf5 100%);
  border: 1px solid #cbd5e1;
  user-select: none;
  touch-action: none;
  cursor: grab;
}

.map-viewport:active {
  cursor: grabbing;
}

.map-viewport.picking-mode {
  cursor: crosshair;
  box-shadow: inset 0 0 0 3px var(--accent);
}

#map3dCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.map-pins-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.map-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.14s ease;
}

.map-pin:hover {
  transform: translate(-50%, -104%) scale(1.06);
  z-index: 999 !important;
}

.pin-card {
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  border-radius: 11px;
  padding: 5px 9px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
  border: 2px solid #94a3b8;
  min-width: 122px;
  max-width: 175px;
  text-align: center;
}

.map-pin.status-active .pin-card {
  border-color: var(--success);
  background: #ecfdf5;
}

.map-pin.status-waiting .pin-card {
  border-color: #f59e0b;
  background: #fffbeb;
}

.map-pin.status-overtime .pin-card {
  border-color: var(--danger);
  background: #fef2f2;
  animation: pinBounce 1s infinite;
}

@keyframes pinBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.pin-title {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 700;
}

.pin-timer {
  padding: 1px 6px;
  border-radius: 99px;
  background: #0f172a;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.map-pin.status-active .pin-timer {
  background: var(--success);
}
.map-pin.status-overtime .pin-timer {
  background: var(--danger);
}

.pin-group-tag {
  margin-top: 2px;
  font-size: 0.68rem;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  padding: 1px 6px;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-stem {
  width: 3px;
  height: 14px;
  background: #334155;
}

.pin-beacon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #64748b;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.map-pin.status-active .pin-beacon {
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(5, 150, 105, 0.28);
}
.map-pin.status-waiting .pin-beacon {
  background: #f59e0b;
}
.map-pin.status-overtime .pin-beacon {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.32);
}

.map-legend {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  padding: 6px 11px;
  border-radius: 99px;
  display: flex;
  gap: 12px;
  font-size: 0.74rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.dot-active { background: var(--success); }
.dot-waiting { background: #f59e0b; }
.dot-overtime { background: var(--danger); }

.map-pick-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e1b4b;
  color: #fff;
  padding: 8px 14px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  z-index: 30;
}

/* LIVE FEED LIST */
.filter-pills {
  display: flex;
  gap: 5px;
}

.pill {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  border-radius: 99px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* DASHBOARD ROLE & VIEW SELECTOR */
.dash-view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.view-pill-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.view-pill-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text-muted);
}

.dash-view-pill {
  border: 1px solid #cbd5e1;
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 99px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dash-view-pill:hover {
  border-color: var(--primary);
  background: #fff;
}

.dash-view-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 3px 10px rgba(67, 56, 202, 0.28);
}

.dash-view-pill.pill-station.active {
  background: #059669;
  border-color: #059669;
  box-shadow: 0 3px 10px rgba(5, 150, 105, 0.28);
}

.dash-view-pill.pill-group.active {
  background: #d97706;
  border-color: #d97706;
  box-shadow: 0 3px 10px rgba(217, 119, 6, 0.28);
}

/* Section visibility based on view pills */
body.dash-view-stations #dashGroupsSection { display: none !important; }
body.dash-view-groups #dashStationsSection { display: none !important; }

/* HERO HEADERS IN DASHBOARD SECTIONS */
.section-hero-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.hero-header-text h2 {
  font-size: 1.15rem;
  color: #1e1b4b;
  font-weight: 900;
  margin: 0;
}

/* SECTION 1: STATIONS LEADER CARDS */
.dash-stations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.dash-station-card {
  background: #ffffff;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.dash-station-card:hover {
  border-color: #94a3b8;
}

.dash-station-card.is-active {
  border-color: var(--success);
  background: #fdfefe;
  box-shadow: 0 6px 20px rgba(5, 150, 105, 0.12);
}

.dash-station-card.is-waiting {
  border-color: #f59e0b;
  background: #fffdfa;
}

.dash-station-card.is-overtime {
  border-color: var(--danger);
  background: #fef8f8;
  animation: borderWarning 1.5s infinite;
}

@keyframes borderWarning {
  0%, 100% { border-color: var(--danger); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.2); }
  50% { border-color: #ef4444; box-shadow: 0 0 0 5px rgba(220, 38, 38, 0.1); }
}

.station-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.station-card-top h3 {
  margin: 0 0 4px;
  font-size: 1.06rem;
  font-weight: 800;
  color: #1e1b4b;
}

.station-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
}

.station-kids-box {
  background: var(--surface-alt);
  border: 1px dashed #cbd5e1;
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 0.84rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.station-kids-box.has-kids {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #065f46;
}

.station-kids-box.is-empty {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

/* Big Timer Display */
.big-timer-wrap {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border-radius: 12px;
  padding: 12px 16px;
  color: #ffffff;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dash-station-card.is-active .big-timer-wrap {
  background: linear-gradient(135deg, #064e3b 0%, #065f46 100%);
}

.dash-station-card.is-overtime .big-timer-wrap {
  background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%);
}

.big-timer-digits {
  font-size: 2.25rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  line-height: 1.1;
}

.big-timer-label {
  font-size: 0.76rem;
  opacity: 0.9;
  font-weight: 700;
}

.station-leader-action-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn {
  flex: 1;
}

/* SECTION 2: GROUPS LEADER CARDS */
.dash-groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.dash-group-card {
  background: #ffffff;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.group-location-banner {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.group-location-banner.in-station {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.group-location-banner.moving {
  background: #fffbeb;
  border-color: #fde68a;
}

.group-location-banner.late {
  background: #fef2f2;
  border-color: #fca5a5;
}

.banner-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.banner-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.banner-info strong {
  font-size: 0.92rem;
  color: #1e1b4b;
}

.banner-info span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.group-leader-action-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.highlight-info-box {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 800;
  color: #3730a3;
  font-size: 0.92rem;
}

.live-stations-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 470px;
  overflow-y: auto;
  padding-left: 3px;
}

.live-station-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 7px;
  transition: border-color 0.15s ease;
}

.live-station-item.is-active {
  border-right: 4px solid var(--success);
  background: #f0fdf4;
}
.live-station-item.is-waiting {
  border-right: 4px solid #f59e0b;
  background: #fffbeb;
}
.live-station-item.is-overtime {
  border-right: 4px solid var(--danger);
  background: #fef2f2;
}

.live-station-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.live-station-name {
  font-weight: 800;
  font-size: 0.94rem;
  cursor: pointer;
  color: var(--text);
}
.live-station-name:hover { color: var(--primary); }

.timer-badge {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 0.88rem;
  padding: 3px 9px;
  border-radius: 8px;
  background: #e2e8f0;
  color: #0f172a;
}
.timer-badge.running {
  background: var(--success);
  color: #fff;
}
.timer-badge.overtime {
  background: var(--danger);
  color: #fff;
}

.live-station-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.live-station-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: rgba(148, 163, 184, 0.25);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  transition: width 0.4s linear;
}
.progress-fill.overtime {
  background: var(--danger);
}

/* LATE GROUPS ALERT SECTION */
.late-alert-section {
  background: linear-gradient(135deg, #fef2f2, #fff7ed);
  border: 2px solid #fca5a5;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: 0 6px 20px rgba(220, 38, 38, 0.1);
}

.section-header-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-header-inline h2 {
  margin: 0;
  font-size: 1.02rem;
  color: #991b1b;
}

.late-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 10px;
}

.late-card {
  background: #fff;
  border: 1px solid #fecaca;
  border-right: 5px solid var(--danger);
  border-radius: 11px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.late-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 800;
}
.badge-success { background: var(--success-soft); color: #065f46; }
.badge-warning { background: var(--warning-soft); color: #92400e; }
.badge-danger { background: var(--danger-soft); color: #991b1b; }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: #e2e8f0; color: #334155; }

/* GROUPS OVERVIEW & FULL GRID */
.groups-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.groups-full-grid,
.stations-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.station-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.station-card-cover {
  position: relative;
  height: 155px;
  background: #e2e8f0;
  overflow: hidden;
  cursor: pointer;
}

.station-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.station-cover-badge {
  position: absolute;
  top: 10px;
  right: 10px;
}

.station-cover-timer {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  padding: 4px 10px;
  border-radius: 8px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

.station-card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.station-card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.station-desc {
  margin: 0;
  font-size: 0.83rem;
  color: var(--text-muted);
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 0.8rem;
  background: var(--surface-alt);
  padding: 9px 10px;
  border-radius: 10px;
}

.info-item strong {
  color: var(--text-muted);
  display: block;
  font-size: 0.72rem;
}

.station-card-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.group-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.group-color-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  font-size: 0.98rem;
}

.group-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* INPUTS & FORMS */
.search-input,
.filter-select,
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: #fff;
}

.search-input {
  width: auto;
  min-width: 240px;
}

.station-filter-box .search-input,
#cmdStationSearch {
  width: 100%;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-weight: 700;
  font-size: 0.84rem;
  margin-bottom: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 680px) {
  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

.map-coord-box {
  background: var(--surface-alt);
  border: 1px dashed #cbd5e1;
  padding: 10px 12px;
  border-radius: 10px;
}

.coord-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.coord-inputs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  font-weight: 700;
}

.coord-inputs input {
  width: 78px;
  padding: 4px 6px;
  display: inline-block;
}

.image-picker-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.upload-label {
  white-space: nowrap;
  cursor: pointer;
}

.image-preview-wrap {
  margin-top: 8px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  height: 150px;
  background: #f1f5f9;
}

.image-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 120;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-lg {
  max-width: 760px;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-alt);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 8px;
}
.modal-close:hover { background: #e2e8f0; }

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
}

/* QUICK COMMAND CALLOUT */
.command-callout {
  background: var(--primary-soft);
  border-right: 4px solid var(--primary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-top: 0;
}

.command-type-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--surface-alt);
}
.radio-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.radio-card input {
  width: auto;
  margin-top: 4px;
}
.radio-card strong {
  display: block;
  font-size: 0.88rem;
}
.radio-card span {
  display: block;
  font-size: 0.77rem;
  color: var(--text-muted);
}

.field-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--primary);
  font-weight: 700;
}

/* MATRIX TABLE & ACTIVITY LOG */
.table-responsive {
  overflow-x: auto;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: center;
}

.matrix-table th {
  background: var(--surface-alt);
  font-weight: 800;
}

.matrix-cell-current {
  background: #dcfce7;
  color: #166534;
  font-weight: 800;
}
.matrix-cell-done {
  background: #eef2ff;
  color: #3730a3;
  font-weight: 700;
}
.matrix-cell-todo {
  color: #94a3b8;
}

/* ==============================================================
   ROUND CONTROL BAR & ROTATION MOVEMENT SCHEDULE
   ============================================================== */

.round-control-panel {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  color: #fff;
  border-radius: 16px;
  padding: 16px 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 25px -5px rgba(49, 46, 129, 0.35);
}

.round-control-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.round-status-box {
  display: flex;
  align-items: center;
  gap: 14px;
}

.round-badge-pill {
  background: #f59e0b;
  color: #0f172a;
  font-weight: 900;
  font-size: 1.15rem;
  padding: 8px 16px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.45);
  white-space: nowrap;
}

.round-meta h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
}

.round-meta span {
  font-size: 0.82rem;
  color: #cbd5e1;
  display: block;
  margin-top: 2px;
}

.round-actions-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Group schedule status pill in group cards */
.group-schedule-strip {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
}

.schedule-pill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.schedule-pill-row strong {
  color: #1e293b;
}

/* Master Timetable Matrix */
.schedule-matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  min-width: 760px;
}

.schedule-matrix-table th,
.schedule-matrix-table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: center;
  vertical-align: middle;
}

.schedule-matrix-table th {
  background: var(--surface-alt);
  font-weight: 800;
}

.schedule-matrix-table th.col-current-round,
.schedule-matrix-table td.col-current-round {
  background: rgba(245, 158, 11, 0.09) !important;
  border-left: 2px solid #f59e0b;
  border-right: 2px solid #f59e0b;
}

.schedule-matrix-table th.col-current-round {
  color: #b45309;
}

.matrix-group-header {
  text-align: right !important;
  min-width: 170px;
  background: #f8fafc !important;
}

.schedule-cell-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: #fff;
  border: 1px dashed transparent;
}

.schedule-cell-box:hover {
  background: #eef2ff;
  border-color: #818cf8;
  transform: translateY(-1px);
}

.schedule-cell-station-name {
  font-weight: 800;
  color: #1e293b;
  font-size: 0.84rem;
}

.schedule-cell-status-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

.schedule-cell-status-tag.is-current {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.schedule-cell-status-tag.is-done {
  background: #eef2ff;
  color: #3730a3;
}

.schedule-cell-status-tag.is-moving {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.schedule-cell-status-tag.is-next {
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 800;
}

.schedule-cell-status-tag.is-future {
  background: #f1f5f9;
  color: #64748b;
}

.matrix-legend-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  font-weight: 700;
}

.legend-chip {
  padding: 3px 10px;
  border-radius: 99px;
}
.legend-chip.chip-current { background: #dcfce7; color: #166534; }
.legend-chip.chip-done { background: #eef2ff; color: #3730a3; }
.legend-chip.chip-moving { background: #fef3c7; color: #92400e; }
.legend-chip.chip-next { background: #e0f2fe; color: #0369a1; }
.legend-chip.chip-future { background: #f1f5f9; color: #64748b; }

.schedule-rounds-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 4px;
}

.round-pill-btn {
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.round-pill-btn:hover {
  background: #e0e7ff;
  border-color: #c7d2fe;
}

.round-pill-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(67, 56, 202, 0.3);
}

.round-pill-btn.active span {
  color: #c7d2fe;
}

.round-pill-btn span {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.schedule-round-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.round-assignment-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.round-assignment-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.assignment-group-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 0.94rem;
}

.assignment-station-box {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.activity-log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 440px;
  overflow-y: auto;
}

.log-item {
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-alt);
  border-right: 3px solid var(--primary);
  font-size: 0.82rem;
}

.log-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
}

/* SYNC BOX */
.sync-status-box {
  background: var(--success-soft);
  color: #065f46;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 0.86rem;
}
.sync-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* DISPLAY BOARD MODE */
body.display-mode .topbar-party-bar,
body.display-mode .admin-only,
body.display-mode .role-switcher {
  display: none !important;
}
body.display-mode .map-viewport {
  height: 540px;
}

/* GOOGLE AUTH BADGE IN TOPBAR */
.user-auth-strip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 99px;
  padding: 4px 10px 4px 6px;
}

.user-avatar-img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #fff;
}

.user-badge-info {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.user-badge-name {
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-badge-role {
  font-size: 0.68rem;
  color: #fde047;
  font-weight: 700;
}

/* AUTH WAITING / PENDING SCREEN */
.auth-waiting-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 60%, #1e1b4b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.auth-waiting-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.waiting-icon {
  font-size: 3rem;
  animation: pulseWait 2s infinite ease-in-out;
}

@keyframes pulseWait {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.waiting-user-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid #6366f1;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.auth-waiting-card h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 900;
  color: #1e1b4b;
}

.waiting-user-email {
  margin: 0;
  font-size: 0.85rem;
  color: #64748b;
  font-weight: 700;
}

.waiting-message-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: right;
  font-size: 0.88rem;
  color: #92400e;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.waiting-admin-contact {
  font-size: 0.8rem;
  color: #475569;
}
.waiting-admin-contact code {
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 700;
}

.waiting-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  width: 100%;
}
.waiting-actions .btn {
  flex: 1;
}

/* USERS ADMIN MODAL */
.users-modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.users-cards-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
}

.user-admin-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.user-admin-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-admin-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
}

.user-admin-details h4 {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 800;
}

.user-admin-details span {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
}

.user-admin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.role-tag {
  font-size: 0.78rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 99px;
}
.role-tag.admin { background: #fee2e2; color: #991b1b; }
.role-tag.party_leader { background: #fef3c7; color: #92400e; }
.role-tag.station_leader { background: #d1fae5; color: #065f46; }
.role-tag.group_leader { background: #e0e7ff; color: #3730a3; }
.role-tag.viewer { background: #f1f5f9; color: #475569; }

/* ROLE PERMISSIONS VISIBILITY */
body.role-admin .admin-only,
body.role-party_leader .admin-only {
  display: inline-flex !important;
}
body.role-admin #btnNewParty,
body.role-party_leader #btnNewParty,
body.role-admin #btnAddStation,
body.role-party_leader #btnAddStation,
body.role-admin #btnAddGroup,
body.role-party_leader #btnAddGroup {
  display: inline-flex !important;
}

body.role-viewer .admin-only,
body.role-viewer .station-control-only,
body.role-viewer .group-control-only,
body.role-viewer #btnQuickCommand,
body.role-viewer #btnDashQuickMove {
  display: none !important;
}

body.role-station_leader .admin-only,
body.role-station_leader .group-control-only {
  display: none !important;
}

body.role-group_leader .admin-only,
body.role-group_leader .station-control-only {
  display: none !important;
}

/* TOAST */
.toast-container {
  position: fixed;
  bottom: 18px;
  left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.toast.toast-success { background: #065f46; }
.toast.toast-warning { background: #b45309; }
.toast.toast-danger { background: #991b1b; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
