/* GuardianAI Cyber-Glassmorphic Dark Theme */
:root {
  --bg-primary: #080c14;
  --bg-secondary: #0f172a;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(30, 41, 59, 0.85);
  --bg-glass: rgba(15, 23, 42, 0.65);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow-red: rgba(239, 68, 68, 0.4);
  --border-glow-purple: rgba(139, 92, 246, 0.4);
  --border-glow-cyan: rgba(6, 182, 212, 0.4);

  --accent-sos: #ef4444;
  --accent-sos-glow: rgba(239, 68, 68, 0.3);
  --accent-purple: #8b5cf6;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-card: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 1px 1px rgba(255, 255, 255, 0.05);
  --shadow-glow-red: 0 0 25px rgba(239, 68, 68, 0.45);
  --shadow-glow-purple: 0 0 25px rgba(139, 92, 246, 0.35);
  --shadow-glow-cyan: 0 0 25px rgba(6, 182, 212, 0.35);
}

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

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(239, 68, 68, 0.12) 0px, transparent 50%),
    radial-gradient(at 50% 100%, rgba(6, 182, 212, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font-body);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px 24px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #ef4444, #8b5cf6);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
}

/* Navigation Links */
.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.nav-item a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  transform: translateX(4px);
}

.nav-item.active a {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(239, 68, 68, 0.2));
  color: #fff;
  border: 1px solid rgba(139, 92, 246, 0.4);
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.15);
}

.nav-badge {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.badge-sos {
  background: var(--accent-sos);
  color: #fff;
  animation: pulse-badge 1.5s infinite;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.supabase-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  color: #34d399;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding: 30px;
  max-width: 1600px;
  overflow-y: auto;
}

/* Top Header Bar */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  gap: 20px;
  flex-wrap: wrap;
}

.header-title h2 {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
}

.header-title p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.role-switcher {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 4px;
  border-radius: var(--radius-full);
  gap: 4px;
}

.role-tab {
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.role-tab:hover {
  color: var(--text-primary);
}

.role-tab.active-superadmin {
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #fff;
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.4);
}

.role-tab.active-guardian {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.4);
}

.role-tab.active-user {
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: #fff;
  box-shadow: 0 2px 10px rgba(244, 63, 94, 0.4);
}

/* Metric Cards Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.metric-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: all 0.3s ease;
}

.metric-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.18);
  background: var(--bg-card-hover);
}

.metric-card.card-sos {
  border: 1px solid var(--border-glow-red);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.15);
}

.metric-card.card-sos:hover {
  box-shadow: var(--shadow-glow-red);
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.metric-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.metric-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.icon-red { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.icon-purple { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
.icon-cyan { background: rgba(6, 182, 212, 0.15); color: #06b6d4; }
.icon-emerald { background: rgba(16, 185, 129, 0.15); color: #10b981; }

.metric-value {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
  margin-bottom: 6px;
}

.metric-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Split Section: Map & Incident Stream */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.8fr 1.2fr;
  gap: 24px;
  margin-bottom: 30px;
}

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

.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
}

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

.panel-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Map Container */
#live-map {
  height: 440px;
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  z-index: 10;
}

/* Live SOS Incident Feed */
.incident-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 440px;
  overflow-y: auto;
  padding-right: 4px;
}

.incident-card {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: all 0.2s ease;
  position: relative;
}

.incident-card.status-active {
  border-left: 4px solid var(--accent-sos);
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.12), rgba(15, 23, 42, 0.85));
}

.incident-card.status-dispatched {
  border-left: 4px solid var(--accent-amber);
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.1), rgba(15, 23, 42, 0.85));
}

.incident-card.status-resolved {
  border-left: 4px solid var(--accent-emerald);
  opacity: 0.75;
}

.incident-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.victim-name {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.victim-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.incident-status-tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.tag-active { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid #ef4444; }
.tag-dispatched { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid #f59e0b; }
.tag-resolved { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid #10b981; }

.incident-location {
  font-size: 0.83rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.incident-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Modern Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #fff;
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.3);
}
.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-sos {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 2px 10px rgba(239, 68, 68, 0.4);
}
.btn-sos:hover {
  box-shadow: var(--shadow-glow-red);
  transform: translateY(-1px);
}

.btn-emerald {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}
.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.75rem;
}

/* Data Tables */
.table-container {
  width: 100%;
  overflow-x: auto;
}

.cyber-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}

.cyber-table th {
  background: rgba(15, 23, 42, 0.9);
  padding: 14px 16px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.cyber-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
}

.cyber-table tbody tr {
  transition: background 0.15s ease;
}

.cyber-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* Role Badges */
.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.role-superadmin {
  background: rgba(139, 92, 246, 0.2);
  color: #c084fc;
  border: 1px solid rgba(139, 92, 246, 0.5);
}

.role-guardian {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.5);
}

.role-user {
  background: rgba(244, 63, 94, 0.2);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.5);
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 540px;
  padding: 28px;
  box-shadow: var(--shadow-card);
  animation: modal-enter 0.25s ease-out;
}

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

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

/* Animations */
@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* Map Pulse Radar Marker CSS */
.radar-pulse-marker {
  position: relative;
  width: 24px;
  height: 24px;
}

.radar-pulse-marker .core {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  background: #ef4444;
  border-radius: 50%;
  box-shadow: 0 0 10px #ef4444;
  border: 2px solid #fff;
}

.radar-pulse-marker .wave {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 38px;
  height: 38px;
  border: 2px solid #ef4444;
  border-radius: 50%;
  animation: radar-expand 1.8s infinite cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes radar-expand {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
}
