/* ================================================================
   Meraki Network Monitor - Custom Styles
   Dark-first design with Bootstrap 5
   ================================================================ */

:root {
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 68px;
  --topbar-height: 48px;
  --sidebar-bg: #0f172a;
  --content-bg: #0b1120;
  --card-bg: #1e293b;
  --border-color: #1e293b;
  --text-primary: #f8fafc;
  --text-muted: #64748b;
  --accent-primary: #3b82f6;
  --accent-success: #10b981;
  --accent-danger: #ef4444;
  --accent-warning: #f59e0b;
  --accent-purple: #8b5cf6;
}

[data-bs-theme="light"] {
  --sidebar-bg: #1e3a5f;
  --content-bg: #f1f5f9;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --text-primary: #1e293b;
  --text-muted: #64748b;
}

/* ── Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body, #root { height: 100%; }

/* Safety net: nothing in this app is meant to scroll sideways — a flex
   child with unshrinkable content (long status bar, wide table, ...)
   forcing the whole page wider than the viewport is always a bug
   somewhere else, not something to actually scroll through on mobile. */
html, body { overflow-x: hidden; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.875rem;
  background: var(--content-bg);
  color: var(--text-primary);
  margin: 0;
}

/* ── App Layout ───────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.25s ease;
}

.app-wrapper.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: width 0.25s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  overflow: hidden;
}

.sidebar--collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  min-height: var(--topbar-height);
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand-text { line-height: 1.2; color: #f8fafc; }

.sidebar-toggle {
  color: #64748b !important;
  padding: 0;
  border: none;
  background: none;
  font-size: 0.9rem;
}
.sidebar-toggle:hover { color: #f8fafc !important; }

.sidebar-mobile-close {
  color: #64748b !important;
  padding: 0;
  border: none;
  background: none;
  font-size: 1.1rem;
}
.sidebar-mobile-close:hover { color: #f8fafc !important; }

/* Sidebar Nav */
.sidebar-nav {
  flex: 1;
  padding: 8px 6px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: none;
  border-radius: 8px;
  color: #94a3b8;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 2px;
  white-space: nowrap;
}

.sidebar-nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: #f8fafc;
}

.sidebar-nav-item.active {
  background: rgba(59,130,246,0.15);
  color: var(--accent-primary);
}

.sidebar-nav-icon { font-size: 1.1rem; flex-shrink: 0; }
.sidebar-nav-label { font-size: 0.875rem; font-weight: 500; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 8px 0;
}

/* ── Top Bar ──────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* Flex items default to min-width:auto, which lets an unshrinkable child
   (the LiveStatusBar's own content) force this whole flex item — and with
   it the topbar and the page — wider than the viewport instead of
   respecting its own overflow:hidden. This is the actual fix; the .live-
   status-bar's d-sm-*/text-truncate classes just decide what gets hidden
   first once it's actually allowed to shrink. */
.topbar > .flex-grow-1 { min-width: 0; }

/* Live Status Bar */
.live-status-bar {
  display: flex;
  align-items: center;
  height: 100%;
  min-width: 0;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-success);
  display: inline-block;
  animation: pulse-live 2s infinite;
}

.live-dot-sm {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  display: inline-block;
  animation: pulse-live 2s infinite;
  margin-right: 4px;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16,185,129,0.6); }
  50% { opacity: 0.8; box-shadow: 0 0 0 4px rgba(16,185,129,0); }
}

/* ── Content Area ─────────────────────────────────────────────────── */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--content-bg);
}

/* ── Page Header ──────────────────────────────────────────────────── */
.page-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.page-header-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(59,130,246,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  font-size: 1.2rem;
}

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}

.card-header {
  background: transparent;
  border-bottom-color: var(--border-color);
  padding: 16px 20px;
}

.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; }

/* Stat Cards */
.stat-card {
  transition: transform 0.15s, box-shadow 0.15s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

/* Site Cards */
.site-card {
  transition: all 0.15s;
}
.site-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  border-color: var(--accent-primary);
}

/* Device Cards */
.device-card { transition: all 0.15s; }
.device-card:hover { border-color: var(--accent-primary); }

.device-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* ── Tables ───────────────────────────────────────────────────────── */
.table {
  --bs-table-bg: transparent;
  --bs-table-hover-bg: rgba(255,255,255,0.04);
  --bs-table-border-color: var(--border-color);
  color: var(--text-primary);
}

thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom-width: 1px;
  padding: 10px 16px;
}

tbody td { padding: 10px 16px; vertical-align: middle; }

/* ── Status Indicators ────────────────────────────────────────────── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ── Form Controls ────────────────────────────────────────────────── */
.form-control, .form-select {
  background-color: var(--card-bg);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
  background-color: var(--card-bg);
  border-color: var(--accent-primary);
  color: var(--text-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-control::placeholder { color: var(--text-muted); }

.input-group-text {
  background-color: var(--card-bg);
  border-color: var(--border-color);
  color: var(--text-muted);
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn-xs {
  padding: 2px 8px;
  font-size: 0.75rem;
  border-radius: 4px;
}

/* ── Progress ─────────────────────────────────────────────────────── */
.progress {
  background-color: rgba(255,255,255,0.06);
  border-radius: 999px;
}

/* ── Badges ───────────────────────────────────────────────────────── */
.badge { font-weight: 500; }

/* ── Traffic Gauge ────────────────────────────────────────────────── */
.traffic-gauge { padding: 8px 12px; background: rgba(255,255,255,0.03); border-radius: 8px; }

/* ── Avatar ───────────────────────────────────────────────────────── */
.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* ── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ── Utility ──────────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.tracking-wide { letter-spacing: 0.05em; }
.font-monospace { font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace; }

/* ── Nav Tabs ─────────────────────────────────────────────────────── */
.nav-tabs {
  border-bottom-color: var(--border-color);
}
.nav-tabs .nav-link {
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 16px;
}
.nav-tabs .nav-link:hover { color: var(--text-primary); border-bottom-color: var(--border-color); }
.nav-tabs .nav-link.active {
  color: var(--accent-primary);
  background: transparent;
  border-bottom-color: var(--accent-primary);
}

/* ── List Group ───────────────────────────────────────────────────── */
.list-group-item {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
  padding: 16px 20px;
}
.list-group-item-action:hover {
  background: rgba(255,255,255,0.03);
  color: var(--text-primary);
}

/* ── Alerts ───────────────────────────────────────────────────────── */
.alert { border-radius: 10px; }

/* ── Pagination ───────────────────────────────────────────────────── */
.page-link {
  background: var(--card-bg);
  border-color: var(--border-color);
  color: var(--text-muted);
}
.page-link:hover { background: rgba(255,255,255,0.06); color: var(--text-primary); }
.page-item.active .page-link { background: var(--accent-primary); border-color: var(--accent-primary); color: #fff; }
.page-item.disabled .page-link { background: var(--card-bg); opacity: 0.4; }

/* ── Light Theme Overrides ────────────────────────────────────────── */
[data-bs-theme="light"] .form-control,
[data-bs-theme="light"] .form-select,
[data-bs-theme="light"] .input-group-text {
  background-color: #fff;
  border-color: #e2e8f0;
  color: #1e293b;
}

[data-bs-theme="light"] .table {
  --bs-table-hover-bg: rgba(0,0,0,0.02);
}

[data-bs-theme="light"] .sidebar { background: #1e3a5f; }
[data-bs-theme="light"] .topbar { background: #fff; border-bottom-color: #e2e8f0; }
[data-bs-theme="light"] .content-area { background: #f1f5f9; }
[data-bs-theme="light"] .card { background: #fff; border-color: #e2e8f0; }

/* ── Loading Animation ────────────────────────────────────────────── */
@keyframes shimmer {
  0% { background-position: -1000px 0; }
  100% { background-position: 1000px 0; }
}

.skeleton {
  background: linear-gradient(90deg, #1e293b 25%, #263348 50%, #1e293b 75%);
  background-size: 1000px 100%;
  animation: shimmer 2s infinite;
  border-radius: 4px;
}

/* ── Responsive ───────────────────────────────────────────────────── */
/* Sidebar backdrop — mobile drawer only. `.sidebar-toggle` (desktop
   collapse chevron) is hidden below md via app.js's d-none d-md-inline-flex;
   `.sidebar-mobile-close` (the × button) is the mirror image, hidden above
   md via d-md-none — see Sidebar()'s JSX. */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999; /* just under .sidebar's 1000 */
}

@media (max-width: 768px) {
  /* Mobile is drawer-only — no icon-rail "collapsed" state exists here, so
     .sidebar--collapsed's narrower desktop width is ignored (!important)
     and visibility is driven entirely by .sidebar--mobile-open instead of
     the desktop collapsed/expanded distinction. */
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }
  .sidebar.sidebar--mobile-open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .main-content { margin-left: 0 !important; }
  .content-area { padding: 16px; }
}

/* ── Charts ───────────────────────────────────────────────────────── */
canvas { max-width: 100%; }

/* ── Print: site Topology diagram only (see TopologyModal in app.js) ── */
@media print {
  body * { visibility: hidden; }
  #topology-print-area, #topology-print-area * { visibility: visible; }
  #topology-print-area { position: absolute; left: 0; top: 0; width: 100%; }
}

/* ── Transitions ──────────────────────────────────────────────────── */
.sidebar,
.main-content,
.card,
.btn,
.sidebar-nav-item {
  transition: all 0.2s ease;
}
