/* ══ CSS Variables & Theme ══ */
:root {
  --bg-primary: #0b1623;
  --bg-secondary: #111f2e;
  --bg-card: #172233;
  --bg-hover: #1e2f40;
  --text-primary: #e8edf2;
  --text-secondary: #8899aa;
  --text-muted: #5c6f82;
  --accent: #00c2a8;
  --accent-hover: #00a891;
  --accent2: #0ea5e9;
  --success: #22d3a8;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #1e3045;
  --sidebar-width: 240px;
  --topbar-height: 60px;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #e8edf2;
  --text-primary: #1a2735;
  --text-secondary: #5c6f82;
  --text-muted: #8899aa;
  --border: #d5dde5;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* ══ Reset & Base ══ */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

/* ══ Sidebar ══ */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

#sidebar.collapsed { transform: translateX(-100%); }

.sidebar-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(0,194,168,0.08) 0%, transparent 100%);
}
.sidebar-logo {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo i { font-size: 20px; color: white; }
.sidebar-brand { display: flex; flex-direction: column; }
.brand-name { font-size: 15px; font-weight: 800; color: var(--text-primary); letter-spacing: 0.5px; }
.brand-sub { font-size: 11px; color: var(--accent); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }

.nav-menu { list-style: none; padding: 10px 0; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  color: var(--accent);
  background: rgba(0, 180, 216, 0.1);
  border-right: 3px solid var(--accent);
}
.nav-item i { width: 20px; text-align: center; }
.badge {
  background: var(--danger);
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
}

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border);
}
.connection-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--danger); }

/* ══ Main Content ══ */
#mainContent {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: margin-left 0.3s ease;
}
#mainContent.expanded { margin-left: 0; }

/* ══ Top Bar ══ */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 15px;
  flex-shrink: 0;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  gap: 8px;
}
.search-box i { color: var(--text-muted); font-size: 14px; }
.search-box input {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  width: 180px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px; height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.datetime { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

#sidebarToggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: none;
}

/* ══ Views ══ */
.views-container { flex: 1; overflow-y: auto; padding: 20px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ══ Stats Grid ══ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
  margin-bottom: 25px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.stat-icon.locations { background: rgba(0,194,168,0.15); color: var(--accent); }
.stat-icon.cameras { background: rgba(14,165,233,0.15); color: var(--accent2); }
.stat-icon.online { background: rgba(34,211,168,0.15); color: var(--success); }
.stat-icon.offline { background: rgba(239,68,68,0.15); color: var(--danger); }
.stat-icon.people { background: rgba(168,85,247,0.15); color: #a855f7; }
.stat-icon.alerts { background: rgba(245,158,11,0.15); color: var(--warning); }
.stat-value { font-size: 28px; font-weight: 700; display: block; }
.stat-label { font-size: 13px; color: var(--text-secondary); }

/* ══ Section Header ══ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}
.section-header h2 { font-size: 16px; font-weight: 600; }
.grid-controls { display: flex; gap: 5px; }

.btn-sm {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}
.btn-sm:hover { background: var(--bg-hover); }
.btn-sm.active { background: var(--accent); color: white; border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: var(--danger);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-danger:hover { opacity: 0.9; }

/* ══ Camera Grid ══ */
.camera-grid {
  display: grid;
  gap: 15px;
}
.grid-2x2 { grid-template-columns: repeat(2, 1fr); }
.grid-3x3 { grid-template-columns: repeat(3, 1fr); }
.grid-4x4 { grid-template-columns: repeat(4, 1fr); }
.grid-1x1 { grid-template-columns: 1fr; }
.grid-list { grid-template-columns: 1fr; }

.camera-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: all 0.2s;
  cursor: pointer;
}
.camera-card:hover { transform: translateY(-2px); border-color: var(--accent); }

.camera-feed {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.camera-feed .placeholder-icon {
  font-size: 48px;
  color: #333;
}
.camera-feed .cam-status {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(0,0,0,0.7);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
}
.camera-feed .cam-status .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
}
.camera-feed .cam-status .dot.online { background: var(--success); }
.camera-feed .cam-status .dot.offline { background: var(--danger); }

.camera-feed .cam-live-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--danger);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.camera-feed .cam-location-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0,0,0,0.7);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
}

.camera-feed .cam-time {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.7);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-family: 'Courier New', monospace;
}

/* Live snapshot image */
.cam-snapshot {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  position: absolute;
  top: 0; left: 0;
}

/* Alert settings */
.settings-section { margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.settings-section h3 { font-size: 14px; color: var(--text-secondary); margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.5px; }
.wa-number-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; }

/* People count badge */
.cam-people-badge {
  position: absolute;
  bottom: 40px;
  right: 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 3;
  transition: background 0.3s;
}

/* Crowd alert toast */
.crowd-alert-toast {
  position: fixed;
  top: 70px;
  right: 20px;
  background: var(--danger);
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* Simulated camera feed gradient */
.camera-feed .feed-simulation {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #0a1628 0%, #1a2a3a 40%, #0d1f2d 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.camera-feed .feed-simulation::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,180,216,0.03) 2px,
    rgba(0,180,216,0.03) 4px
  );
  pointer-events: none;
}
.camera-feed .feed-simulation .cam-icon {
  font-size: 40px;
  color: rgba(0,180,216,0.2);
}

.camera-info {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.camera-info .cam-name { font-size: 14px; font-weight: 600; }
.camera-info .cam-details {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.camera-info .cam-actions { display: flex; gap: 5px; }
.camera-info .cam-actions button {
  background: var(--bg-hover);
  border: none;
  color: var(--text-secondary);
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.2s;
}
.camera-info .cam-actions button:hover {
  background: var(--accent);
  color: white;
}

/* ══ Locations View ══ */
.locations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.locations-list { display: flex; flex-direction: column; gap: 15px; }

.location-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.location-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}
.location-card-header h3 { font-size: 16px; }
.location-meta { display: flex; gap: 15px; font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.location-meta span { display: flex; align-items: center; gap: 5px; }
.location-cameras { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.location-cam-item {
  background: var(--bg-hover);
  border-radius: 6px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.location-cam-item .dot { width: 8px; height: 8px; border-radius: 50%; }
.location-cam-item .dot.online { background: var(--success); }
.location-cam-item .dot.offline { background: var(--danger); }

.network-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.network-badge.local { background: rgba(46,204,113,0.15); color: var(--success); }
.network-badge.vpn { background: rgba(0,180,216,0.15); color: var(--accent); }
.network-badge.public { background: rgba(243,156,18,0.15); color: var(--warning); }

/* ══ Alerts ══ */
.alerts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.alert-filters { display: flex; gap: 5px; }
.alerts-list { display: flex; flex-direction: column; gap: 8px; }

.alert-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: var(--shadow);
}
.alert-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.alert-icon.motion { background: rgba(243,156,18,0.15); color: var(--warning); }
.alert-icon.offline { background: rgba(231,76,60,0.15); color: var(--danger); }
.alert-icon.tamper { background: rgba(155,89,182,0.15); color: #9b59b6; }
.alert-details { flex: 1; }
.alert-details .alert-title { font-size: 14px; font-weight: 600; }
.alert-details .alert-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.alert-severity {
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.alert-severity.high { background: rgba(231,76,60,0.15); color: var(--danger); }
.alert-severity.medium { background: rgba(243,156,18,0.15); color: var(--warning); }
.alert-severity.low { background: rgba(46,204,113,0.15); color: var(--success); }

/* ══ Integration Guide ══ */
.guide-container { max-width: 900px; }
.guide-subtitle { color: var(--text-secondary); margin-bottom: 25px; font-size: 14px; }
.guide-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; margin-bottom: 30px; }
.guide-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.guide-card h4 { color: var(--accent); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.guide-card p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.guide-card code {
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent);
}

.guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 25px;
  margin-bottom: 20px;
}
.guide-section h3 { margin-bottom: 15px; display: flex; align-items: center; gap: 10px; }

.architecture-diagram {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 20px;
  overflow-x: auto;
}
.architecture-diagram pre {
  color: var(--accent);
  font-size: 12px;
  line-height: 1.4;
}

.steps { display: flex; flex-direction: column; gap: 20px; }
.step { display: flex; gap: 15px; }
.step-number {
  width: 36px; height: 36px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.step-content h4 { margin-bottom: 5px; }
.step-content p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 5px; }
.code-block {
  background: var(--bg-primary);
  border-radius: 6px;
  padding: 12px;
  margin-top: 8px;
}
.code-block code {
  font-size: 12px;
  color: var(--success);
  display: block;
  line-height: 1.8;
}

.security-list { list-style: none; }
.security-list li {
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.security-list li:last-child { border-bottom: none; }
.security-list li i { color: var(--success); }

/* ══ Settings ══ */
.settings-container { max-width: 600px; }
.settings-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 15px;
}
.settings-group h3 { margin-bottom: 15px; font-size: 15px; }
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.setting-item:last-child { border-bottom: none; }
.setting-item label { font-size: 14px; color: var(--text-secondary); }
.setting-item input[type="text"],
.setting-item input[type="number"],
.setting-item select {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.setting-actions { display: flex; gap: 10px; }

/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.3s;
}
.slider::before {
  content: '';
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ══ Modal ══ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 18px;
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Modal form */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 5px; }
.form-group input, .form-group select {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ══ Live Controls ══ */
.live-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}
.live-controls select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14px;
}

/* ══ Branch Overview ══ */
.branch-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 4px;
}

.branch-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.25s;
}
.branch-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0,194,168,0.15);
}
.branch-card.offline-branch { border-color: rgba(239,68,68,0.3); }

.branch-thumb {
  position: relative;
  height: 140px;
  background: #0a1628;
  overflow: hidden;
}
.branch-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.branch-thumb .branch-status-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}
.branch-online-count {
  background: rgba(0,194,168,0.9);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
}
.branch-cam-count {
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
}
.branch-offline-overlay {
  position: absolute;
  inset: 0;
  background: rgba(239,68,68,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: rgba(239,68,68,0.5);
}

.branch-info {
  padding: 14px 16px;
}
.branch-info h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}
.branch-info .branch-addr {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.branch-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.branch-status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}
.branch-status-badge.online { color: var(--success); }
.branch-status-badge.offline { color: var(--danger); }
.branch-view-btn {
  font-size: 11px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

.branch-card.add-branch-card {
  border: 2px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 220px;
  background: transparent;
  color: var(--text-muted);
  gap: 10px;
  font-size: 14px;
}
.branch-card.add-branch-card:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0,194,168,0.04);
}
.branch-card.add-branch-card i { font-size: 28px; }

.btn-back {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all 0.2s;
}
.btn-back:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ══ Analytics View ══ */
.analytics-container { max-width: 1400px; }

.analytics-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.kpi-icon.people { background: rgba(168,85,247,0.15); color: #a855f7; }
.kpi-icon.peak   { background: rgba(0,194,168,0.15);  color: var(--accent); }
.kpi-icon.crowd  { background: rgba(239,68,68,0.15);   color: var(--danger); }
.kpi-icon.uptime { background: rgba(34,211,168,0.15);  color: var(--success); }
.kpi-info { display: flex; flex-direction: column; }
.kpi-value { font-size: 32px; font-weight: 800; line-height: 1; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.analytics-charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 0;
}

.analytics-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.analytics-chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.analytics-chart-card h3 i { color: var(--accent); }

.ai-status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(0,194,168,0.07);
  border: 1px solid rgba(0,194,168,0.2);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 16px;
}
.ai-status-bar i { color: var(--accent); }
.ai-status-bar.ai-offline { background: rgba(239,68,68,0.07); border-color: rgba(239,68,68,0.2); }
.ai-status-bar.ai-offline i { color: var(--danger); }

/* ══ Responsive ══ */
@media (max-width: 1200px) {
  .analytics-charts-row { grid-template-columns: 1fr; }
  .analytics-kpi-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); z-index: 200; box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
  #sidebar.mobile-open { transform: translateX(0); }
  #mainContent { margin-left: 0; }
  #sidebarToggle { display: flex !important; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .camera-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .analytics-kpi-row { grid-template-columns: repeat(2, 1fr); }
  .analytics-charts-row { grid-template-columns: 1fr; }
  .search-box input { width: 120px; }
  .datetime { display: none; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .camera-grid { grid-template-columns: 1fr !important; }
  .analytics-kpi-row { grid-template-columns: 1fr 1fr; }
  .topbar-right { gap: 6px; }
  .search-box { display: none; }
}

/* ══ Scrollbar ══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
