:root {
  --brand-blue: #3a63ca;
  --brand-pink: #c93aa0;
  --brand-purple: #a156c8;
  --brand-pink-button: #e21386;
  --brand-orange: #f59e0b;
  --button-gradient-start: #e83dfb;
  --button-gradient-middle: #c65ff6;
  --button-gradient-end: #4382ff;

  --background: oklch(11% 0 0); /* ~#1a1a1a */
  --foreground: oklch(98.5% 0 0); /* ~#f5f5f5 */
  --accent-pink: #fb7299;
  --card: oklch(20.5% 0 0); /* ~#2e2e38 */
  --card-foreground: oklch(98.5% 0 0);
  --popover: oklch(20.5% 0 0);
  --popover-foreground: oklch(98.5% 0 0);
  --primary: oklch(14.96% 0 0);
  --primary-foreground: oklch(100% 0 0);
  --secondary: oklch(26.9% 0 0);
  --secondary-foreground: oklch(98.5% 0 0);
  --muted: oklch(26.9% 0 0);
  --muted-foreground: oklch(70.8% 0 0);
  --accent: oklch(26.9% 0 0);
  --accent-foreground: oklch(98.5% 0 0);
  --destructive: oklch(70.4% 0.191 22.216); /* red */
  --destructive-foreground: oklch(100% 0 0);
  --border: oklch(100% 0 0 / 0.1); /* subtle border */
  --input: oklch(100% 0 0 / 0.15);
  --ring: oklch(55.6% 0 0);

  /* Charts */
  --chart-1: oklch(48.8% 0.243 264.376); /* purple-blue */
  --chart-2: oklch(69.6% 0.17 162.48); /* green */
  --chart-3: oklch(76.9% 0.188 70.08); /* yellow-green */
  --chart-4: oklch(62.7% 0.265 303.9); /* pink */
  --chart-5: oklch(64.5% 0.246 16.439); /* orange */

  --success: oklch(72.3% 0.191 142.5); /* green */
  --gradient-purple: oklch(52.56% 0.168 265.2);
  --gradient-pink: oklch(68.92% 0.2469 341.51);

  --radius: 0.3rem;

  /* Aliases for existing layout CSS */
  --bg: oklch(11% 0 0);
  --surface: oklch(20.5% 0 0);
  --surface-muted: oklch(26.9% 0 0);
  --text: oklch(98.5% 0 0);
  --text-muted: oklch(70.8% 0 0);
  --text-soft: oklch(50% 0 0);
  --border-color: oklch(100% 0 0 / 0.1);
  --border-strong: oklch(100% 0 0 / 0.2);
  --success-bg: oklch(72.3% 0.191 142.5 / 0.2);
  --warning-bg: oklch(64.5% 0.246 16.439 / 0.2);
  --danger-bg: oklch(70.4% 0.191 22.216 / 0.2);
  --info-bg: oklch(48.8% 0.243 264.376 / 0.2);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}
body > * {
  position: relative;
  z-index: 1;
}

/* ---------- Sidebar (open-on-hover) ---------- */
.sidebar-wrap {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 50px;
  overflow: hidden;
  z-index: 60;
  transition: width 0.2s ease;
}
.sidebar-wrap:hover {
  width: 200px;
}
.sidebar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100vh;
  width: 200px;
  background: rgba(26, 26, 26, 0.95);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
/* all collapsed state rules deleted — overflow:hidden on wrapper handles it */
/* collapsed — logo left-aligned, small */
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo img {
  height: 32px;
  width: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
  transition:
    background 0.15s ease,
    color 0.15s ease;
  cursor: pointer;
}
.nav-item:hover {
  background: var(--surface-muted);
  color: var(--text);
}
.nav-item .nav-icon {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  opacity: 0.85;
}
.nav-item.active {
  color: var(--text);
  background: rgba(251, 114, 153, 0.12);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(
    180deg,
    var(--button-gradient-start),
    var(--button-gradient-end)
  );
}
.nav-item.active .nav-icon {
  opacity: 1;
}
.nav-item.chat-btn {
  color: var(--brand-purple);
  margin-top: auto;
}
.nav-item.chat-btn .chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: linear-gradient(
    135deg,
    var(--button-gradient-start),
    var(--button-gradient-end)
  );
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  margin-left: auto;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--button-gradient-start),
    var(--button-gradient-end)
  );
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.2;
}

/* ---------- Layout ---------- */
.page {
  max-width: 1440px;
  margin-left: 50px;
  margin-right: 0;
  padding: 24px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  /* No transition on margin — margin changes trigger layout reflow, causes stutter */
}

/* ---------- Page router ---------- */
.page-content {
  display: none;
}
.page-content.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 4px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}
.page-header .page-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

/* ---------- KPI row ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.kpi {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  opacity: 0;
  animation: fadeSlideIn 0.4s ease forwards;
}
.kpi:nth-child(1) {
  animation-delay: 0s;
}
.kpi:nth-child(2) {
  animation-delay: 0.1s;
}
.kpi:nth-child(3) {
  animation-delay: 0.2s;
}
.kpi:nth-child(4) {
  animation-delay: 0.3s;
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.kpi-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  background: linear-gradient(
    135deg,
    var(--gradient-pink),
    var(--gradient-purple)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.kpi-trend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.kpi-trend .trend-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.kpi-trend .trend-pill.up {
  color: #16a34a;
  background: rgba(22, 163, 74, 0.18);
}
.kpi-trend .trend-pill.down {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.18);
}
.kpi-trend .trend-pill.flat {
  color: #9aa0b3;
  background: rgba(154, 160, 179, 0.14);
}

/* ---------- Generic panels ---------- */
.row {
  display: grid;
  gap: 16px;
}
.row-2 {
  grid-template-columns: 1.4fr 1fr;
}
.row > .panel {
  width: auto;
  max-width: 100%;
  min-width: 0;
}

.panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
  overflow: hidden;
  transition:
    box-shadow 0.2s ease,
    transform 0.2s ease;
  opacity: 0;
  animation: fadeSlideIn 0.4s ease forwards;
}
.panel:nth-child(1) {
  animation-delay: 0.2s;
}
.panel:nth-child(2) {
  animation-delay: 0.3s;
}
.panel:nth-child(3) {
  animation-delay: 0.4s;
}
.panel:nth-child(4) {
  animation-delay: 0.5s;
}
.panel:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}
.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    var(--button-gradient-start),
    var(--button-gradient-middle),
    var(--button-gradient-end)
  );
  z-index: 1;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  margin: 0;
}
.panel-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}
.panel-body {
  padding: 14px 18px 18px;
  min-width: 0;
}
.panel-body.tight {
  padding: 8px 0 0;
}
.chart-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
}
.chart-hero {
  height: 280px;
}
.chart-md {
  height: 240px;
}

/* ---------- Session table ---------- */
.session-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.session-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.session-table tbody td {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.session-table tbody tr:last-child td {
  border-bottom: 0;
}
.session-table tbody tr:hover {
  background: var(--surface-muted);
}
.ip-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--text);
}
.country-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 14px;
  border-radius: 2px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0;
  margin-right: 6px;
  flex-shrink: 0;
}
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

/* Map container */
#map {
  height: 320px;
  width: 100%;
}
@media (max-width: 768px) {
  #page-dashboard .panel:has(#map) {
    height: 380px !important;
  }
  #page-dashboard .panel:has(#map) .panel-body {
    height: 500px !important;
  }
}

/* Overview page: contracted sessions table */
#page-dashboard .table-scroll {
  max-height: 280px;
  overflow-y: auto;
}

/* Mobile: overview sessions extends fully */
@media (max-width: 768px) {
  #page-dashboard .table-scroll {
    max-height: none;
    overflow-y: visible;
  }
  /* Move Recent Sessions section to the bottom on mobile */
  #overview-sessions {
    order: 3;
    display: flex;
    flex-wrap: wrap;
  }
  #overview-sessions > .panel:first-child {
    order: 2;
  }
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-ok {
  color: var(--success);
  background: var(--success-bg);
}
.status-warn {
  color: var(--warning);
  background: var(--warning-bg);
}
.status-err {
  color: var(--danger);
  background: var(--danger-bg);
}
.status-pill.success {
  color: var(--success);
  background: rgba(22, 163, 74, 0.15);
}
.status-pill.error,
.status-pill.timeout,
.status-pill.geo-block {
  color: #f87171;
  background: rgba(248, 113, 113, 0.15);
}

/* ---------- Live indicator dot ---------- */
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  animation: pulse-green 2s ease-in-out infinite;
}
@keyframes pulse-green {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(22, 163, 74, 0);
  }
}

/* ---------- Sessions page ---------- */
.sessions-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 4px;
}
.sessions-stat {
  font-size: 13px;
  color: var(--text-muted);
}
.sessions-stat strong {
  color: var(--text);
  font-weight: 600;
}

/* ---------- Alert rules (alerts page) ---------- */
.alert-rules {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.alert-rule {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.alert-rule-body {
  flex: 1;
}
.alert-rule-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
.alert-rule-condition {
  font-size: 12px;
  color: var(--text-muted);
}
.alert-rule-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.alert-rule-delete {
  background: rgba(220, 38, 38, 0.15);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: #f87171;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.alert-rule-delete:hover {
  background: rgba(220, 38, 38, 0.25);
}

/* ---------- Toggle switch ---------- */
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-muted);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* ---------- Bandwidth bar ---------- */
.bandwidth-bar {
  width: 100%;
  height: 10px;
  background: var(--surface-muted);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
.bandwidth-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-blue), var(--brand-purple));
  border-radius: 999px;
  transition: width 0.5s ease;
}
.peak-stat {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}
.peak-stat strong {
  color: var(--text);
  font-weight: 600;
}

/* ---------- Settings cards ---------- */
.settings-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.settings-card-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 10px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child {
  border-bottom: none;
}
.settings-label {
  font-size: 13px;
  color: var(--text);
}
.settings-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.settings-danger {
  border-color: rgba(220, 38, 38, 0.4);
}
.settings-danger .settings-card-title {
  color: #f87171;
}
.btn-danger {
  background: rgba(220, 38, 38, 0.15);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: #f87171;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-danger:hover {
  background: rgba(220, 38, 38, 0.3);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}
.btn-copy {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-copy:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- Charts row ---------- */
.charts-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.charts-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 1100px) {
  .charts-row {
    grid-template-columns: 1fr 1fr;
  }
  .charts-row-2 {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 768px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- Add alert form ---------- */
.add-alert-form {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}
.add-alert-form select,
.add-alert-form input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.add-alert-form select:focus,
.add-alert-form input:focus {
  border-color: var(--brand-blue);
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--surface-muted);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .row-2 {
    grid-template-columns: 1fr;
  }
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .page {
    margin-left: 0;
  }
  .topbar {
    margin-left: 0;
  }
}
@media (max-width: 640px) {
  .page {
    padding: 16px;
  }
  .topbar {
    padding: 12px 16px;
  }
  .topbar-title {
    display: none;
  }
  .kpi-row {
    grid-template-columns: 1fr;
  }
  .kpi-value {
    font-size: 26px;
  }
}

/* ---------- Toasts ---------- */
.toast {
  background: rgba(46, 46, 56, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 280px;
  max-width: 360px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  pointer-events: all;
  animation: toastIn 0.3s ease;
  position: relative;
}
.toast::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 3px 0 0 3px;
}
.toast.upsell::before {
  background: var(--brand-purple);
}
.toast.warning::before {
  background: #f59e0b;
}
.toast.info::before {
  background: var(--brand-blue);
}
.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}
.toast-body {
  flex: 1;
}
.toast-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.toast-msg {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}
.toast-action {
  font-size: 12px;
  font-weight: 600;
  color: var(--brand-purple);
  cursor: pointer;
  margin-top: 6px;
  display: inline-block;
}
.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
.toast.out {
  animation: toastOut 0.2s ease forwards;
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 9000;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.open {
  display: flex;
}
.modal {
  background: #1e1e2e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 36px;
  max-width: 440px;
  width: 90%;
  position: relative;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}
.modal-icon {
  font-size: 40px;
  margin-bottom: 16px;
}
.modal-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
}
.modal-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 24px;
  line-height: 1.5;
}
.modal-plans {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.modal-plan {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.modal-plan.selected {
  border-color: var(--brand-purple);
  background: rgba(161, 86, 200, 0.1);
}
.plan-name {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.plan-price {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.plan-price span {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}
.plan-features {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}
.modal-cta {
  display: block;
  width: 100%;
  padding: 12px;
  background: linear-gradient(
    135deg,
    var(--button-gradient-start),
    var(--button-gradient-end)
  );
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
}
.modal-chat-link {
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-chat-link:hover {
  color: var(--brand-purple);
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---------- Chat ---------- */
.chat-modal {
  max-width: 380px;
  height: 520px;
  display: flex;
  flex-direction: column;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-purple), var(--brand-pink));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}
.chat-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}
.chat-msg {
  display: flex;
  flex-direction: column;
}
.chat-msg.user {
  align-items: flex-end;
}
.chat-msg.agent {
  align-items: flex-start;
}
.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
}
.chat-msg.agent .chat-bubble {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
.chat-msg.user .chat-bubble {
  background: linear-gradient(
    135deg,
    var(--button-gradient-start),
    var(--button-gradient-end)
  );
  color: #fff;
}
.chat-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.chat-input:focus {
  border-color: var(--brand-purple);
}
.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(
    135deg,
    var(--button-gradient-start),
    var(--button-gradient-end)
  );
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Entrance animation ---------- */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Pulsing chat notification badge ---------- */
.chat-badge {
  animation: pulseBadge 2s ease-in-out infinite;
}
@keyframes pulseBadge {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

/* Leaflet dark theme overrides */
.leaflet-container {
  background: #06060f !important;
}
.leaflet-tile-pane {
  filter: brightness(0.8) contrast(1.1);
}

/* ---------- Light theme ---------- */
body.light {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-muted: #f0f0f2;
  --text: #1a1a2e;
  --text-muted: #6b6f80;
  --text-soft: #9aa0b3;
  --border-color: #e0e0e0;
  --border: #e0e0e0;
  background: var(--bg);
  color: var(--text);
}
body.light::before {
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
}
body.light .sidebar {
  background: #ffffff;
}
body.light .panel,
body.light .kpi,
body.light .settings-card {
  background: #ffffff;
  border-color: #e0e0e0;
}
body.light .session-table thead th {
  background: #f0f0f2;
  color: #6b6f80;
}
body.light .session-table tbody tr:hover {
  background: #f0f0f2;
}
body.light ::-webkit-scrollbar-track {
  background: #f0f0f2;
}
body.light .btn-secondary {
  background: #f0f0f2;
  border-color: #d0d0d2;
  color: #1a1a2e;
}
body.light .btn-secondary:hover {
  background: #e8e8ea;
}
body.light .btn-copy {
  background: #f0f0f2;
  border-color: #d0d0d2;
  color: #1a1a2e;
}
body.light .btn-copy:hover {
  background: #e8e8ea;
}
body.light .add-alert-form {
  background: #ffffff;
  border-color: #e0e0e0;
}
body.light .add-alert-form select,
body.light .add-alert-form input {
  background: #f5f5f7;
  border-color: #e0e0e0;
  color: #1a1a2e;
}
body.light .alert-rule {
  background: #ffffff;
  border-color: #e0e0e0;
}
body.light .bandwidth-bar {
  background: #e8e8ea;
}
body.light .settings-row {
  border-color: #e0e0e0;
}
body.light .toggle-slider {
  background: #e0e0e0;
}
body.light .toggle-switch input:checked + .toggle-slider {
  background: var(--brand-blue);
}
body.light .alert-rule-delete {
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.2);
}
body.light .country-flag {
  background: #f0f0f2;
  border-color: #d0d0d2;
}
body.light .modal {
  background: #ffffff;
  border-color: #e0e0e0;
}
body.light .modal-plan {
  background: #f5f5f7;
  border-color: #e0e0e0;
}
body.light .chat-input {
  background: #f5f5f7;
  border-color: #e0e0e0;
  color: #1a1a2e;
}
body.light .chat-msg.agent .chat-bubble {
  background: #f0f0f2;
  color: #1a1a2e;
}
body.light .toast {
  background: rgba(255, 255, 255, 0.98);
  border-color: #e0e0e0;
}

/* ---------- Alert history ---------- */
.alerts-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.alerts-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.alerts-section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.alert-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.alert-history-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
  font-style: italic;
}
.alert-history-entry {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 12px 16px;
  position: relative;
  overflow: hidden;
  animation: fadeSlideIn 0.3s ease forwards;
}
.alert-history-entry::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
}
.alert-history-entry.severity-critical::before {
  background: #ef4444;
}
.alert-history-entry.severity-warning::before {
  background: #f59e0b;
}
.alert-history-entry.severity-info::before {
  background: var(--brand-blue);
}

.alert-history-entry.severity-critical {
  border-color: rgba(239, 68, 68, 0.2);
  background: rgba(239, 68, 68, 0.06);
}
.alert-history-entry.severity-warning {
  border-color: rgba(245, 158, 11, 0.2);
  background: rgba(245, 158, 11, 0.04);
}

.alert-history-sev-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  margin-top: 1px;
}
.severity-critical .alert-history-sev-icon {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}
.severity-warning .alert-history-sev-icon {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}
.severity-info .alert-history-sev-icon {
  background: rgba(58, 99, 202, 0.2);
  color: #60a5fa;
}

.alert-history-body {
  flex: 1;
}
.alert-history-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.alert-history-condition {
  font-size: 12px;
  color: var(--text-muted);
}
.alert-history-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* Light theme for alert history */
body.light .alert-history-entry {
  background: rgba(255, 255, 255, 0.6);
  border-color: #e0e0e0;
}
body.light .alert-history-entry.severity-critical {
  background: rgba(239, 68, 68, 0.04);
  border-color: rgba(239, 68, 68, 0.2);
}
body.light .alert-history-entry.severity-warning {
  background: rgba(245, 158, 11, 0.04);
  border-color: rgba(245, 158, 11, 0.2);
}
body.light .alert-history-entry.severity-info {
  background: rgba(58, 99, 202, 0.04);
  border-color: rgba(58, 99, 202, 0.2);
}
body.light .alert-rules-count,
body.light .alerts-section-count {
  background: #f0f0f2;
  color: #6b6f80;
}

/* ---------- Bandwidth alert banner ---------- */
.bandwidth-alert-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius);
  padding: 14px 16px;
  animation: fadeSlideIn 0.4s ease forwards;
  position: relative;
}
.bandwidth-alert-banner::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 3px 0 0 3px;
  background: #f59e0b;
}
.bandwidth-alert-icon {
  font-size: 20px;
  flex-shrink: 0;
}
.bandwidth-alert-body {
  flex: 1;
}
.bandwidth-alert-title {
  font-size: 13px;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 2px;
}
.bandwidth-alert-msg {
  font-size: 13px;
  color: var(--text-muted);
}
.bandwidth-alert-cta {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.bandwidth-alert-cta:hover {
  opacity: 0.85;
}
.bandwidth-alert-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.bandwidth-alert-close:hover {
  color: var(--text);
}

/* Light theme for bandwidth alert */
body.light .bandwidth-alert-banner {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.25);
}

/* ---------- Mobile bottom nav ---------- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: rgba(26, 26, 26, 0.97);
  border-top: 1px solid var(--border);
  z-index: 100;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition:
    color 0.15s,
    background 0.15s;
  min-width: 56px;
}

.mobile-nav-item .nav-icon {
  width: 20px;
  height: 20px;
  opacity: 0.7;
}

.mobile-nav-item.active {
  color: var(--text);
}

.mobile-nav-item.active .nav-icon {
  opacity: 1;
}

.mobile-nav-item.active::before {
  display: none; /* remove desktop sidebar indicator */
}

/* Show mobile nav only below 768px */
@media (max-width: 768px) {
  .mobile-nav {
    display: flex;
  }
  .page {
    padding-bottom: 80px; /* space for bottom nav */
  }
}
