/* FIRNETIX brand: 5-color theme
   --firnetix-dark: #22597A (slate blue, text/sidebar)
   --firnetix-teal: #2CA8A2 (primary)
   --firnetix-orange: #F08E2B (accent)
   --firnetix-white: #FFFFFF
   --firnetix-gray: #EBECEC (secondary bg)
*/
:root {
  --firnetix-dark: #22597A;
  --firnetix-teal: #2CA8A2;
  --firnetix-teal-hover: #25918c;
  --firnetix-orange: #F08E2B;
  --firnetix-orange-hover: #d97d26;
  --firnetix-white: #FFFFFF;
  --firnetix-gray: #EBECEC;

  --bg-page: #f8fafc;
  --bg-page-subtle: #EBECEC;
  --bg-card: #ffffff;
  --bg-sidebar: #22597A;
  --bg-sidebar-hover: rgba(255,255,255,.08);
  --bg-sidebar-active: rgba(44, 168, 162, .25);
  --border: #e2e8f0;
  --border-subtle: #EBECEC;
  --text: #22597A;
  --text-muted: #64748b;
  --text-sidebar: #b8d4e0;
  --text-sidebar-active: #ffffff;
  --primary: #2CA8A2;
  --primary-hover: #25918c;
  --primary-light: #e6f7f6;
  --accent: #F08E2B;
  --accent-light: #fef3e6;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fee2e2;
  --success: #059669;
  --success-light: #d1fae5;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 6px -1px rgba(0,0,0,.06), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.06), 0 4px 6px -4px rgba(0,0,0,.04);
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 64px;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

/* Dark mode (night mode) — keeps FIRNETIX teal/orange accents */
[data-theme="dark"] {
  --bg-page: #0f172a;
  --bg-page-subtle: #1e293b;
  --bg-card: #1e293b;
  --border: #334155;
  --border-subtle: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --bg-sidebar: #1a365d;
  --primary-light: rgba(44, 168, 162, .25);
  --accent-light: rgba(240, 142, 43, .2);
  --danger-light: rgba(220, 38, 38, .2);
  --success-light: rgba(5, 150, 105, .2);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow: 0 4px 6px -1px rgba(0,0,0,.3), 0 2px 4px -2px rgba(0,0,0,.2);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.3), 0 4px 6px -4px rgba(0,0,0,.2);
}
[data-theme="dark"] .main-topbar {
  background: rgba(30, 41, 59, .8);
  border-bottom-color: var(--border);
}
[data-theme="dark"] .data-table th {
  background: #0f172a;
  color: var(--text-muted);
  border-bottom-color: var(--border);
}
[data-theme="dark"] .data-table td { border-bottom-color: var(--border-subtle); }
[data-theme="dark"] .data-table tbody tr:hover { background: var(--primary-light); }
[data-theme="dark"] .table-wrap,
[data-theme="dark"] .card,
[data-theme="dark"] .chart-card,
[data-theme="dark"] .stat-card {
  background: var(--bg-card);
  border-color: var(--border-subtle);
}
[data-theme="dark"] .stat-card.stat-card-highlight { background: linear-gradient(135deg, var(--bg-card) 0%, var(--primary-light) 120%); }
[data-theme="dark"] .btn-ghost:hover { background: var(--bg-page-subtle); color: var(--text); }
[data-theme="dark"] .subtab:hover { color: var(--text); background: var(--bg-page-subtle); }
[data-theme="dark"] .subtab.active { background: var(--primary-light); }
[data-theme="dark"] .modal { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .dropdown-menu { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .preview-config,
[data-theme="dark"] .config-summary-table { background: #0f172a; border-color: var(--border); }
[data-theme="dark"] .form-stack input,
[data-theme="dark"] .form-stack select,
[data-theme="dark"] .org-selector,
[data-theme="dark"] .modal input,
[data-theme="dark"] .modal select {
  background: var(--bg-page-subtle);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="dark"] .muted { color: var(--text-muted); }
[data-theme="dark"] .chart-desc { color: var(--text-muted); }
[data-theme="dark"] .card-dashboard { background: var(--bg-card); border-color: var(--border-subtle); }
[data-theme="dark"] .dashboard-activity-row { border-bottom-color: var(--border-subtle); }
[data-theme="dark"] .btn-sidebar-open:hover { background: var(--bg-page-subtle); }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  background: var(--bg-page);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.app { display: flex; min-height: 100vh; min-width: 0; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.04);
  transition: width .2s ease, min-width .2s ease;
  overflow: hidden;
}
.sidebar.collapsed {
  width: var(--sidebar-width-collapsed);
  min-width: var(--sidebar-width-collapsed);
}
.sidebar.collapsed .logo-sub,
.sidebar.collapsed .nav-item span.nav-label { display: none; }
.sidebar.collapsed .sidebar-header { padding: 1rem 0.75rem; text-align: center; }
.sidebar.collapsed .logo { font-size: 0; text-indent: -999px; overflow: hidden; width: 2rem; height: 1.5rem; margin: 0 auto; display: block; }
.sidebar.collapsed .logo::before { content: 'F'; font-size: 1.25rem; font-weight: 700; color: #fff; text-indent: 0; display: block; line-height: 1.5; }
.sidebar.collapsed .sidebar-nav { padding: 0.75rem 0.5rem; }
.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 0.65rem;
  margin-bottom: 0.2rem;
}
.sidebar.collapsed .nav-item .nav-icon-svg { margin: 0; }
.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 0;
}
.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-sidebar);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .2s ease, color .2s ease;
}
.sidebar-collapse-btn:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}
.sidebar-collapse-icon {
  width: 1.25rem;
  height: 1.25rem;
}
.sidebar.collapsed .sidebar-header-row { justify-content: center; }
.sidebar.collapsed .sidebar-collapse-btn { position: absolute; right: 0.35rem; top: 50%; transform: translateY(-50%); }
.sidebar.collapsed.hover-expanded .sidebar-collapse-btn { position: static; transform: none; }
.sidebar-logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f2f2f2;
  border-radius: 8px;
  padding: 6px;
  flex-shrink: 0;
}
[data-theme="dark"] .sidebar-logo-wrap { background: rgba(255, 255, 255, 0.12); }
.sidebar-logo {
  height: 36px;
  width: 36px;
  max-width: 36px;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-header .logo { margin: 0; }
.sidebar.collapsed .sidebar-logo-wrap { padding: 4px; }
.sidebar.collapsed .sidebar-logo { height: 28px; width: 28px; max-width: 28px; }
.sidebar.collapsed.hover-expanded .sidebar-logo-wrap { padding: 6px; }
.sidebar.collapsed .sidebar-header-row { justify-content: center; }
.sidebar.collapsed .logo { font-size: 0; text-indent: -999px; overflow: hidden; width: 0; height: 0; margin: 0; display: block; min-width: 0; }
.sidebar.collapsed .logo::before { content: none; }
.sidebar.collapsed.hover-expanded .sidebar-header-row { flex-direction: row; }
.sidebar.collapsed.hover-expanded .sidebar-logo { height: 36px; width: 36px; max-width: 36px; }
.sidebar.collapsed.hover-expanded .logo {
  font-size: 1.25rem;
  text-indent: 0;
  overflow: visible;
  width: auto;
  height: auto;
  margin: 0;
  min-width: 0;
}
.sidebar.collapsed.hover-expanded .logo::before { content: none; }
.sidebar.collapsed.hover-expanded {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
}
.sidebar.collapsed.hover-expanded .logo-sub,
.sidebar.collapsed.hover-expanded .nav-item span.nav-label { display: block; }
.sidebar.collapsed.hover-expanded .sidebar-header { padding: 1.5rem 1.5rem 1.25rem; text-align: left; }
.sidebar.collapsed.hover-expanded .nav-item { justify-content: flex-start; padding: 0.65rem 1rem; margin-bottom: 0.25rem; }
.sidebar.collapsed.hover-expanded .sidebar-nav { padding: 1rem 0.75rem; }
.sidebar-header {
  padding: 1.5rem 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  position: relative;
}
.logo {
  display: block;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: #fff;
}
.logo-sub {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-sidebar);
  margin-top: 0.2rem;
  opacity: .9;
}
.sidebar-nav { padding: 1rem 0.75rem; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
  transition: background .2s ease, color .2s ease;
}
.nav-item .nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #e2e8f0;
}
.nav-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
}
.nav-icon-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .9;
}
.nav-item.nav-item-out { margin-top: 0.25rem; }

/* Main content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
  min-width: 0;
  max-width: 100%;
  background: linear-gradient(180deg, var(--bg-page) 0%, var(--bg-page-subtle) 100%);
}
.main-topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.6rem 2.5rem 0.6rem 2rem;
  background: rgba(255,255,255,.5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.main-topbar-spacer { flex: 1; }
.main-topbar-org { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.main-topbar-org-label { font-size: 0.875rem; font-weight: 500; color: var(--text-muted); }
.org-selector {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  min-width: 180px;
  background: var(--bg-card);
  color: var(--text);
}
.main-content {
  flex: 1;
  padding: 2rem 2.5rem;
  min-width: 0;
  overflow-x: hidden;
}
.main-content h1,
.main-content h2,
.main-content h3 { word-wrap: break-word; overflow-wrap: break-word; }
.page-header .subtitle { overflow-wrap: break-word; }
.page-header { margin-bottom: 1.75rem; }
.page-header-dashboard {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.page-header-dashboard .subtitle { margin: 0.25rem 0 0; }
.dashboard-header-actions { flex-shrink: 0; display: flex; align-items: center; gap: 0.75rem; }
.server-clock-widget {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.server-clock-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
}
.server-clock-icon svg { width: 1.1rem; height: 1.1rem; }
.server-clock-content { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; }
.server-clock-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.server-clock {
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}
[data-theme="dark"] .server-clock-widget { background: var(--bg-card); border-color: var(--border); }
.dashboard-section { margin-bottom: 2rem; }
.dashboard-section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 1rem;
}
.dashboard-activity-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9375rem;
}
.dashboard-activity-row:last-child { border-bottom: none; }
.dashboard-activity-row .small { font-size: 0.8125rem; color: var(--text-muted); }
.card-dashboard {
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow);
}
.org-dashboard-charts {
  grid-template-columns: 1fr 1fr;
}
.org-dashboard-charts .chart-card-full { grid-column: 1 / -1; }
.dashboard-auto-refresh {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
}
/* WireGuard overview (dashboard when no org selected) */
.wireguard-overview { margin-top: 0.5rem; }
.wireguard-overview-hint {
  font-size: 0.9375rem;
  margin: 0 0 1.25rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-page-subtle);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}
.dashboard-section-compact { margin-bottom: 1.5rem; }
.dashboard-section-compact .dashboard-section-title { margin-bottom: 0.65rem; }
.stats-grid-compact { gap: 0.75rem; }
.stats-grid-compact .stat-card { padding: 0.85rem 1rem; }
.stats-grid-compact .stat-icon { width: 34px; height: 34px; }
.stats-grid-compact .stat-icon svg { width: 18px; height: 18px; }
.stats-grid-compact .stat-value { font-size: 1.25rem; }
.stats-grid-compact .stat-label { font-size: 0.78rem; }
.charts-row-compact { gap: 1rem; }
.chart-card-sm .chart-desc { display: none; }
.chart-card-sm h3 { font-size: 0.9375rem; margin-bottom: 0.35rem; }
.chart-wrap-sm { height: 140px; max-height: 140px; }
.chart-card-bar .chart-desc { display: none; }
.chart-card-bar h3 { font-size: 0.9375rem; margin-bottom: 0.35rem; }
.chart-card-bar .chart-wrap-bar { height: 220px; }
.card-dashboard-compact { padding: 1rem 1.2rem; }
.stats-row,
.dashboard-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1.05rem 1.25rem;
  min-width: 12rem;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .2s ease;
}
.stat-card:hover { border-color: var(--border); box-shadow: var(--shadow); }
.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: var(--primary);
  flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-meta { min-width: 0; }
.stat-card .stat-value { display: block; font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); line-height: 1.15; }
.stat-card .stat-label { display: block; font-size: 0.82rem; color: var(--text-muted); font-weight: 500; margin-top: 0.1rem; }
.stat-card.stat-online .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.stat-offline .stat-icon { background: #f1f5f9; color: var(--text-muted); }
.page-header h1 {
  margin: 0;
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.page-header h2.panel-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}
.subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
}

/* Subtab navigation (Configuration > WireGuard / Firewall / Network) */
.subtab-nav {
  display: flex;
  gap: 0.25rem;
  margin-top: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.subtab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color .15s ease, background .15s ease;
}
.subtab:hover { color: var(--text); background: var(--bg-page-subtle); }
.subtab.active {
  color: var(--primary);
  background: var(--primary-light);
}
.subtab-disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
.subtab-disabled:hover { color: var(--text-muted); background: transparent; }

.subtab-panel {
  margin-top: 1.25rem;
}
.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 0.75rem;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color .15s ease;
}
.back-link:hover { color: var(--primary-hover); }
.config-name-edit {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
.config-name-edit input[type="text"] {
  max-width: 220px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
}
#config-id-badge { font-size: 0.875rem; font-weight: 500; }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-subtle);
  margin-bottom: 1.25rem;
  transition: box-shadow .2s ease, border-color .2s ease;
}
.card:hover { border-color: var(--border); }
.card h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.card.span-2 { grid-column: span 2; }

.detail-dl { margin: 0 0 1rem; }
.detail-dl dt { font-weight: 600; font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.75rem; margin-bottom: 0.2rem; }
.detail-dl dt:first-child { margin-top: 0; }
.detail-dl dd { margin: 0; font-size: 0.9375rem; }
.detail-dl dd code { font-size: 0.875rem; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}
.stats-grid .stat-card { min-width: 0; padding: 1.2rem 1.35rem; box-shadow: var(--shadow); }
.stats-grid .stat-card.stat-card-highlight { border-left: 4px solid var(--primary); background: linear-gradient(135deg, var(--bg-card) 0%, var(--primary-light) 120%); }
.stats-grid .stat-card.stat-card-success { border-left: 4px solid var(--success); }
.stats-grid .stat-icon { width: 42px; height: 42px; }
.stats-grid .stat-card .stat-value { font-size: 1.6rem; }

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-subtle);
}
.chart-card.full-width { grid-column: 1 / -1; }
.chart-card h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
}
.chart-wrap {
  height: 200px;
  max-height: 200px;
  overflow: hidden;
  position: relative;
}
.chart-wrap.chart-wrap-sm { height: 120px; max-height: 120px; }
.chart-wrap.chart-wrap-md { height: 220px; max-height: 220px; }
.chart-wrap.chart-wrap-bar { height: 280px; max-height: 280px; }
.chart-wrap.chart-wrap-line { height: 260px; max-height: 260px; }
.chart-wrap canvas { max-height: 100%; }
.chart-desc {
  margin: -0.5rem 0 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.chart-controls {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.chart-controls label { font-size: 0.875rem; color: var(--text-muted); }
.chart-device-filter {
  font-size: 0.875rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text);
}
.chart-card.full-width { grid-column: 1 / -1; }
.chart-card.chart-card-full { grid-column: 1 / -1; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-subtle);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.data-table th {
  text-align: left;
  padding: 0.875rem 1.25rem;
  background: #fafafa;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 500;
}
.data-table tbody tr {
  transition: background .12s ease;
}
.data-table tbody tr:hover { background: var(--primary-light); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .mono { font-family: 'SF Mono', ui-monospace, monospace; font-size: 0.875em; }
.org-action-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.org-action-btns .btn { margin: 0; }
.row { display: flex; justify-content: space-between; padding: 0.4rem 0; }
.row .mono { font-size: 0.8125rem; color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .2s ease, transform .1s ease, box-shadow .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(79, 70, 229, .25);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger-hover);
  box-shadow: 0 4px 12px rgba(220, 38, 38, .25);
}
.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
}
.btn-sm:hover { transform: none; }

/* Forms */
.form-stack label { display: block; margin-bottom: 0.75rem; font-weight: 500; font-size: 0.875rem; }
.form-stack label:last-of-type { margin-bottom: 1rem; }
.form-stack input[type="text"],
.form-stack input[type="number"],
.form-stack input[type="url"],
.form-stack input[type="password"] {
  width: 100%;
  max-width: 340px;
  padding: 0.6rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9375rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-stack input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-inline.compact {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.form-inline.compact label { margin-bottom: 0; }
.add-section .add-actions { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.out {
  background: #f8fafc;
  padding: 0.6rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-family: ui-monospace, monospace;
  white-space: pre-wrap;
  margin-top: 0.5rem;
  max-height: 140px;
  overflow: auto;
  border: 1px solid var(--border);
}
.out.small { font-size: 0.75rem; max-height: 80px; }

/* Detail view */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.dl-inline dt {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-top: 0.75rem;
}
.dl-inline dt:first-child { margin-top: 0; }
.dl-inline dd { margin: 0.2rem 0 0; font-weight: 500; }
.controller-badge {
  margin-top: 1rem;
  padding: 0.65rem 1rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}
.controller-badge.bound {
  background: var(--success-light);
  color: var(--success);
}
.peers-list { list-style: none; padding: 0; margin: 0; }
.peers-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border-subtle); }
.peers-list a { color: var(--primary); font-weight: 500; margin-right: 0.75rem; }
.mono { font-family: 'SF Mono', ui-monospace, monospace; font-size: 0.875em; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); font-weight: 500; }
.alert { padding: 0.875rem 1.25rem; border-radius: var(--radius-sm); }
.alert-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fecaca;
}

/* Nested list (legacy) */
.config-list { margin-top: 0.5rem; }
.nested-list { list-style: none; padding: 0; margin: 0; }
.nested-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--bg-card);
  overflow: hidden;
  transition: box-shadow .2s ease;
}
.nested-item:hover { box-shadow: var(--shadow); }
.nested-item-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
}
.nested-item-title { font-weight: 600; color: var(--text); }
.nested-item-meta { font-size: 0.875rem; color: var(--text-muted); flex: 1; min-width: 200px; }

/* Peer table */
.peer-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.peer-table th {
  text-align: left;
  padding: 0.65rem 1rem;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.peer-table td { padding: 0.65rem 1rem; border-bottom: 1px solid var(--border-subtle); }
.peer-table .peer-name-input {
  width: 100%;
  max-width: 180px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.875rem;
}
.peer-table .peer-allowed-ips-input {
  width: 100%;
  max-width: 140px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-size: 0.8125rem;
}
.peer-table .th-checkbox,
.peer-table .td-checkbox { width: 2.5rem; text-align: center; }
.config-summary-table .actions-cell { white-space: nowrap; }
.config-summary-table .actions-cell .btn { margin-right: 0.35rem; }
.controller-details {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border-subtle);
}
.controller-details-inline {
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  line-height: 1.5;
}
/* Controller binding card: balanced sections */
.card-controller-binding .controller-binding-section {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
}
.card-controller-binding .controller-binding-heading {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.form-controller .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.form-controller .form-row label { margin-bottom: 0; }
.form-controller .form-row label input,
.form-controller .form-row-single label input {
  display: block;
  margin-top: 0.35rem;
  width: 100%;
  max-width: 100%;
}
.form-controller .form-row-single {
  grid-template-columns: 1fr;
  margin-bottom: 0.75rem;
}
.form-controller .form-row-single label {
  display: block;
  margin-bottom: 0.35rem;
}
@media (max-width: 640px) {
  .form-controller .form-row { grid-template-columns: 1fr; }
}
.controller-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
.controller-actions .btn { flex-shrink: 0; }
.controller-binding-output {
  margin-top: 0.75rem;
}
.card-controller-binding .controller-stats {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
}
.card-controller-binding .controller-stats .controller-binding-heading {
  margin-bottom: 0.5rem;
}
.btn-icon {
  padding: 0.35rem 0.6rem;
  font-size: 0.8125rem;
  margin-right: 0.35rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1.5rem;
}
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 90%;
  width: 100%;
  max-height: 90%;
  overflow: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow-md), 0 25px 50px -12px rgba(0,0,0,.15);
  border: 1px solid var(--border);
}
.modal.modal-lg {
  max-width: 560px;
  min-width: 420px;
  padding: 1.75rem;
}
.modal.modal-xl {
  max-width: 640px;
  min-width: 480px;
  padding: 1.75rem;
}
.modal h4 { margin: 0 0 1rem; font-weight: 600; }
.modal-close {
  float: right;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  transition: color .15s ease;
}
.modal-close:hover { color: var(--text); }
.preview-config {
  white-space: pre-wrap;
  font-size: 0.8125rem;
  font-family: ui-monospace, monospace;
  background: #f8fafc;
  padding: 1rem;
  border-radius: var(--radius-sm);
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
}

/* Icons (SVG use) */
.icon {
  width: 1.25em;
  height: 1.25em;
  display: inline-block;
  vertical-align: -0.3em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon[href*="check"],
.icon[href*="dots-v"] { stroke: none; fill: currentColor; }
.icon[href*="dots-v"] { stroke-width: 0; }
.icon-sm { width: 1em; height: 1em; vertical-align: -0.2em; }

/* Dropdown menu */
.dropdown-menu {
  position: fixed;
  z-index: 200;
  min-width: 160px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  padding: 0.35rem 0;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  transition: background .12s ease;
}
.dropdown-item:hover { background: var(--primary-light); }
.btn-icon-only {
  padding: 0.4rem;
  min-width: auto;
}
.btn-menu {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-menu:hover { color: var(--primary); border-color: var(--primary); }

/* Modal add peer/multiple */
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1rem; flex-wrap: wrap; }
.modal label { display: block; margin-bottom: 0.35rem; font-weight: 500; font-size: 0.875rem; }
.modal input[type="text"],
.modal input[type="number"],
.modal input[type="email"],
.modal input[type="url"],
.modal input[type="password"],
.modal select,
.modal textarea.form-stack-input {
  display: block;
  width: 100%;
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  margin-bottom: 0.5rem;
  box-sizing: border-box;
}
.modal.modal-lg .form-org-modal .form-group { margin-bottom: 1.25rem; }
.modal.modal-lg .form-org-modal .form-group label { display: block; margin-bottom: 0.4rem; }
.modal.modal-lg .form-org-modal .form-group input { margin-bottom: 0; }
.modal.modal-lg input[type="text"],
.modal.modal-lg input[type="number"],
.modal.modal-lg input[type="email"],
.modal.modal-lg input[type="url"],
.modal.modal-lg input[type="password"],
.modal.modal-lg select,
.modal.modal-lg textarea.form-stack-input,
.modal.modal-xl input[type="text"],
.modal.modal-xl input[type="number"],
.modal.modal-xl input[type="email"],
.modal.modal-xl input[type="url"],
.modal.modal-xl input[type="password"],
.modal.modal-xl select,
.modal.modal-xl textarea.form-stack-input {
  max-width: 100%;
}
.modal .form-stack-aligned label { display: block; margin-bottom: 0.25rem; }
.modal .form-stack-aligned label + input,
.modal .form-stack-aligned label + select,
.modal .form-stack-aligned label + textarea { margin-top: 0; }
.modal .form-stack-aligned label.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.modal .form-stack-aligned label.checkbox-label input[type="checkbox"] { margin: 0; }
.modal-tabs { display: flex; gap: 0; margin: 0 0 1rem; border-bottom: 1px solid var(--border); }
.modal-tab {
  padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 500; background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--text-muted);
  cursor: pointer; font-family: var(--font);
}
.modal-tab:hover { color: var(--text); }
.modal-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.modal-tab-panel { margin-bottom: 0.5rem; }
.modal-tab-panel.active { display: block; }
.form-help { font-size: 0.8125rem; color: var(--text-muted); margin: -0.25rem 0 0.75rem; display: flex; align-items: flex-start; gap: 0.35rem; }
.form-help .form-help-icon { display: inline-flex; align-items: center; justify-content: center; width: 1.1em; height: 1.1em; font-size: 0.9em; font-weight: 600; color: var(--primary); background: var(--primary-light); border-radius: 50%; }
.success-msg {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--success);
  font-weight: 500;
  margin-bottom: 1rem;
}
.success-msg .icon { color: var(--success); }
.error-msg {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--danger);
  font-weight: 500;
  margin-top: 0.75rem;
}
.error-msg .icon { flex-shrink: 0; color: var(--danger); }
/* QR code display: clean container, crisp image */
.peer-result-qr {
  margin: 1rem 0;
  padding: 1.25rem;
  background: #fff;
  border-radius: var(--radius);
  display: inline-block;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.peer-result-qr img {
  max-width: 220px;
  width: 220px;
  height: auto;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
.modal-qr-wrap {
  padding: 1rem;
  background: #fff;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: inline-block;
  margin-top: 0.5rem;
}
.modal-qr-wrap img {
  display: block;
  max-width: 280px;
  width: 280px;
  height: auto;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }

/* Firewall zone modal tabs */
.modal-zone-wide {
  max-width: 920px;
  width: 96%;
  padding: 2rem 2.5rem;
  margin: 1rem;
}
.zone-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 0.75rem;
}
.zone-form-row-cols {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem;
  margin-bottom: 0.75rem;
}
.zone-form-row-cols .form-group { margin-bottom: 0; }
.zone-check-group { margin-bottom: 0.5rem; }
.zone-input-wide { max-width: 100% !important; }
.zone-modal-panel .form-group { margin-bottom: 1rem; }
.zone-modal-panel .help-text { margin-top: 0.35rem; }
.zone-modal-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.zone-modal-tab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-family: var(--font);
  transition: color .15s ease, border-color .15s ease;
}
.zone-modal-tab:hover { color: var(--text); }
.zone-modal-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.zone-modal-panel { display: none; }
.zone-modal-panel.active { display: block; }
.zone-modal-panel-stack .form-group { margin-bottom: 1rem; }
.zone-modal-panel .form-group { margin-bottom: 0.75rem; }
.zone-modal-panel label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.875rem; }
.zone-modal-panel input[type="text"],
.zone-modal-panel select {
  width: 100%;
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
}
.zone-modal-panel .help-text { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }
.zone-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.zone-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  background: var(--bg-page-subtle);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  border: 1px solid var(--border-subtle);
}
.zone-list li .zone-name { font-weight: 600; color: var(--text); }
.zone-list li .zone-actions { display: flex; gap: 0.5rem; }
.fw-multiselect {
  min-height: 88px;
  width: 100%;
  max-width: 100%;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 0.875rem;
}
.fw-multiselect option { padding: 0.25rem 0.5rem; }

/* Firewall zone editor card: more room */
.firewall-zone-editor.card {
  max-width: 100%;
  padding: 2rem 2.5rem;
}
.firewall-preview .preview-config {
  max-height: 380px;
}
.firewall-preview h4 { margin-top: 1.5rem; }
.firewall-preview h4:first-child { margin-top: 0; }
.fw-zones-table-wrap { margin: 1.25rem 0; overflow-x: auto; }
.fw-controller-stats-table { margin-top: 1.5rem; }
.fw-controller-stats-table .data-table td { font-size: 0.875rem; }
.controller-stats-expand-cell { background: var(--primary-light); vertical-align: top; }
.controller-stats-expand-inner { padding: 0.5rem 0.75rem; font-size: 0.875rem; }
.controller-stats-table-inner { margin: 0; font-size: 0.875rem; }
.controller-stats-table-inner th { padding: 0.35rem 0.5rem; }
.controller-stats-table-inner td { padding: 0.35rem 0.5rem; }
.btn-zone-stats-toggle .icon-chevron-down { width: 1em; height: 1em; transition: transform 0.2s; }
.btn-zone-stats-toggle.expanded .icon-chevron-down { transform: rotate(180deg); }
.btn-iface-stats-toggle .icon-chevron-down { width: 1em; height: 1em; transition: transform 0.2s; }
.btn-iface-stats-toggle.expanded .icon-chevron-down { transform: rotate(180deg); }
.config-stats-toggle .icon-chevron-down { width: 1em; height: 1em; transition: transform 0.2s; }
.config-stats-toggle.expanded .icon-chevron-down { transform: rotate(180deg); }
.fw-publish-configs-list { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; margin: 0.5rem 0; }
.fw-publish-config-label { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 500; cursor: pointer; }
.fw-publish-config-label .mono { color: var(--text-muted); font-weight: 400; }

.status-online { color: var(--success); font-weight: 600; }
.status-offline { color: var(--text-muted); }
.nav-item-link { color: var(--primary); text-decoration: none; font-weight: 500; }
.nav-item-link:hover { text-decoration: underline; }

/* Devices tab: controller devices table */
.badge { display: inline-block; padding: 0.2rem 0.5rem; font-size: 0.75rem; font-weight: 600; border-radius: 4px; background: var(--border); color: var(--text-muted); }
.badge-success { background: var(--success); color: #fff; }
.device-action-cell { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.device-action-cell select.form-control { min-width: 140px; max-width: 200px; }
/* Device templates multi-select: compact dropdown height, not full-page scroll */
.device-templates-select.fw-multiselect { max-height: 7rem; min-height: 2.5rem; width: 100%; max-width: 220px; }

/* Device templates: dropdown with checkboxes */
.device-templates-dropdown { position: relative; display: inline-block; }
.device-templates-dropdown-btn { display: inline-flex; align-items: center; gap: 0.35rem; }
.device-templates-dropdown-btn .icon-chevron { width: 1em; height: 1em; transition: transform 0.2s; }
.device-templates-dropdown.open .device-templates-dropdown-btn .icon-chevron { transform: rotate(180deg); }
.device-templates-dropdown-panel {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 2px;
  min-width: 200px;
  max-height: 14rem;
  overflow-y: auto;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 0.35rem;
}
.device-templates-dropdown.open .device-templates-dropdown-panel { display: block; }
.device-templates-search {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 0.35rem 0;
  padding: 0.4rem 0.5rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
}
.device-templates-dropdown-list { max-height: 10rem; overflow-y: auto; }
.device-templates-cell { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.device-templates-cell .device-templates-dropdown { margin-right: 0; }
.device-templates-dropdown-item {
  display: block;
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-templates-dropdown-item:hover { background: var(--bg-page-subtle); }
.device-templates-dropdown-item input { margin-right: 0.5rem; vertical-align: middle; }

@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .card.span-2 { grid-column: span 1; }
  .main-content { padding: 1.25rem 1.5rem; }
  .main-topbar { padding-left: 1.5rem; padding-right: 1.5rem; }
}

/* ========== Mobile-friendly / Web app ========== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.btn-sidebar-open {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  margin: 0 -0.5rem 0 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.btn-sidebar-open:hover {
  background: var(--bg-page-subtle);
  color: var(--primary);
}
.btn-sidebar-open .nav-icon-svg { width: 22px; height: 22px; }

.btn-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.btn-theme-toggle:hover {
  background: var(--bg-page-subtle);
  color: var(--text);
}
.theme-icon {
  width: 20px;
  height: 20px;
}
.theme-icon-moon { display: none; }
.theme-icon-sun { display: block; }
[data-theme="dark"] .theme-icon-sun { display: none !important; }
[data-theme="dark"] .theme-icon-moon { display: block !important; }
[data-theme="dark"] .btn-theme-toggle:hover { background: var(--bg-page-subtle); }

/* Touch-friendly minimum tap targets */
.nav-item {
  min-height: 44px;
  padding: 0.75rem 1rem;
}
.btn {
  min-height: 44px;
  padding: 0.5rem 1rem;
}
.btn-sm { min-height: 38px; padding: 0.4rem 0.75rem; }

/* Safe area for notched devices */
.main-topbar {
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
}
.main-content {
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

@media (max-width: 991px) {
  .sidebar-backdrop {
    display: block;
  }
  body.sidebar-mobile-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .btn-sidebar-open {
    display: flex;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    width: var(--sidebar-width) !important;
    min-width: var(--sidebar-width) !important;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.collapsed {
    width: var(--sidebar-width) !important;
    min-width: var(--sidebar-width) !important;
  }
  .sidebar.collapsed .logo-sub,
  .sidebar.collapsed .nav-item span.nav-label {
    display: block;
  }
  .sidebar.collapsed .logo {
    font-size: 1.25rem;
    text-indent: 0;
    overflow: visible;
    width: auto;
    height: auto;
    margin: 0;
  }
  .sidebar.collapsed .logo::before { content: none; }
  .sidebar.collapsed .sidebar-header { padding: 1.5rem 1.5rem 1.25rem; text-align: left; }
  .sidebar.collapsed .sidebar-header-row { flex-direction: row; }
  .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 0.75rem 1rem; }
  .sidebar.collapsed .sidebar-nav { padding: 1rem 0.75rem; }
  body.sidebar-mobile-open .sidebar {
    transform: translateX(0);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
  }
  body.sidebar-mobile-open {
    overflow: hidden;
  }
  .main {
    min-width: 0;
  }
  .main-content {
    padding: 1.25rem 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  .main-topbar {
    padding: 0.5rem 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
  }
  .main-topbar-org-label { display: none; }
  .org-selector { min-width: 0; max-width: 160px; }
  .page-header-dashboard { flex-direction: column; align-items: stretch; }
  .dashboard-header-actions { align-self: flex-start; }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  .stats-grid .stat-card .stat-value { font-size: 1.35rem; }
  .stats-grid .stat-card .stat-label { font-size: 0.75rem; }
  .page-header h1 { font-size: 1.4rem; }
  .subtitle { font-size: 0.875rem; }
  .charts-row { grid-template-columns: 1fr; }
  .chart-card { padding: 1rem; }
  .chart-card h3 { font-size: 0.9375rem; }
  .chart-desc { font-size: 0.8125rem; }
  .chart-wrap.chart-wrap-bar { height: 240px; }
  .chart-wrap.chart-wrap-line { height: 220px; }
  .table-wrap { border-radius: var(--radius-sm); overflow: hidden; }
  .data-table th,
  .data-table td { padding: 0.65rem 0.75rem; font-size: 0.875rem; }
  .dashboard-section-title { font-size: 0.75rem; }
  .main-content { font-size: 0.9375rem; }
}

@media (max-width: 480px) {
  html { font-size: 15px; }
  .main-content { padding: 0.75rem 0.5rem; font-size: 0.875rem; }
  .main-topbar { padding: 0.4rem 0.5rem; }
  .stats-grid { grid-template-columns: 1fr; gap: 0.5rem; }
  .stats-grid .stat-card { padding: 0.75rem 1rem; }
  .stats-grid .stat-card .stat-value { font-size: 1.2rem; }
  .stats-grid .stat-card .stat-label { font-size: 0.7rem; }
  .stats-grid .stat-icon { width: 36px; height: 36px; }
  .page-header { margin-bottom: 1rem; }
  .page-header h1 { font-size: 1.2rem; line-height: 1.3; }
  .subtitle { font-size: 0.8125rem; margin-top: 0.2rem; }
  .page-header-dashboard .subtitle { font-size: 0.8125rem; }
  .org-selector { max-width: 100%; font-size: 0.875rem; }
  .card-dashboard,
  .card { padding: 0.75rem; }
  .card h3 { font-size: 0.9375rem; }
  .chart-card h3 { font-size: 0.875rem; }
  .chart-desc { font-size: 0.75rem; margin-top: 0.25rem; }
  .chart-wrap.chart-wrap-bar { height: 200px; }
  .chart-wrap.chart-wrap-line { height: 200px; }
  .chart-wrap.chart-wrap-md { height: 180px; }
  .btn-sidebar-open { margin-right: 0; width: 40px; min-width: 40px; }
  .btn-theme-toggle { width: 36px; height: 36px; min-width: 36px; min-height: 36px; }
  .theme-icon { width: 18px; height: 18px; }
  .data-table th,
  .data-table td { padding: 0.5rem 0.5rem; font-size: 0.8125rem; }
  .data-table .mono { font-size: 0.75rem; }
  .dashboard-section-title { font-size: 0.7rem; margin-bottom: 0.5rem; }
  .dashboard-section { margin-bottom: 1.25rem; }
  .dashboard-activity-row { font-size: 0.8125rem; }
  .dashboard-auto-refresh { font-size: 0.75rem; margin-top: 0.35rem; }
  .form-stack input[type="text"],
  .form-stack input[type="number"],
  .form-stack input[type="url"],
  .form-stack input[type="password"],
  .form-stack select,
  .modal input[type="text"],
  .modal input[type="number"],
  .modal select {
    min-height: 44px;
    font-size: 16px;
  }
  .btn { font-size: 0.875rem; padding: 0.45rem 0.75rem; }
  .btn-sm { font-size: 0.8125rem; min-height: 36px; padding: 0.35rem 0.6rem; }
  .panel-header { gap: 0.5rem; margin-bottom: 0.75rem; }
  .back-link { font-size: 0.8125rem; }
  .subtab { font-size: 0.8125rem; padding: 0.4rem 0.75rem; }
}

@media (max-width: 360px) {
  html { font-size: 14px; }
  .main-content { padding: 0.5rem 0.4rem; }
  .page-header h1 { font-size: 1.1rem; }
  .stats-grid .stat-card .stat-value { font-size: 1.1rem; }
  .data-table th,
  .data-table td { font-size: 0.75rem; padding: 0.4rem 0.35rem; }
  .card-dashboard,
  .card { padding: 0.6rem; }
  .chart-card { padding: 0.6rem; }
  .chart-wrap.chart-wrap-bar,
  .chart-wrap.chart-wrap-line { height: 180px; }
}
