:root, :root[data-theme="light"] {
  --accent: #1d4ed8;
  --accent-dark: #1e3a8a;
  --accent-soft: rgba(29, 78, 216, 0.1);
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #1a2330;
  --muted: #64748b;
  --border: #dbe3ee;
  --error: #c0392b;
  --warn: #b45309;
  --ok: #15803d;
  --ok-soft: rgba(21, 128, 61, 0.12);
  --error-soft: rgba(192, 57, 43, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

:root[data-theme="dark"] {
  --accent: #4f7fee;
  --accent-dark: #6d95f2;
  --accent-soft: rgba(79, 127, 238, 0.16);
  --bg: #12161c;
  --card: #1b212b;
  --text: #eef1f6;
  --muted: #93a2b8;
  --border: #2b3340;
  --error: #e0655a;
  --warn: #e0a95a;
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.14);
  --error-soft: rgba(224, 101, 90, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

/* -------------------- Extra themes -------------------- */
:root[data-theme="midnight-fiber"] {
  --accent: #06b6d4; --accent-dark: #22d3ee; --accent-soft: rgba(6, 182, 212, 0.16);
  --bg: #0a0f1e; --card: #111a2e; --text: #e6f1f7; --muted: #7d93ab; --border: #1f2c42;
  --error: #f87171; --warn: #fbbf24; --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14); --error-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35); --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}
:root[data-theme="sunset-signal"] {
  --accent: #fb7185; --accent-dark: #fda4af; --accent-soft: rgba(251, 113, 133, 0.16);
  --bg: #1a1016; --card: #241620; --text: #fdf1ee; --muted: #c99a9f; --border: #3a2530;
  --error: #f87171; --warn: #fb923c; --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.14); --error-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35); --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}
:root[data-theme="forest-uplink"] {
  --accent: #f59e0b; --accent-dark: #fbbf24; --accent-soft: rgba(245, 158, 11, 0.16);
  --bg: #0d1710; --card: #142016; --text: #e8f3ea; --muted: #86a58f; --border: #223428;
  --error: #f87171; --warn: #fb923c; --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.14); --error-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35); --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}
:root[data-theme="cyber-neon"] {
  --accent: #e879f9; --accent-dark: #f0abfc; --accent-soft: rgba(232, 121, 249, 0.18);
  --bg: #08080c; --card: #121218; --text: #f2e9ff; --muted: #9b8fb0; --border: #23222f;
  --error: #ff5c8a; --warn: #ffd166; --ok: #5eff9d;
  --ok-soft: rgba(94, 255, 157, 0.14); --error-soft: rgba(255, 92, 138, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35); --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}
:root[data-theme="desert-dune"] {
  --accent: #c2410c; --accent-dark: #9a3412; --accent-soft: rgba(194, 65, 12, 0.1);
  --bg: #fbf3e9; --card: #ffffff; --text: #3b2a1e; --muted: #8a7561; --border: #e8dac6;
  --error: #c0392b; --warn: #b45309; --ok: #4d7c0f;
  --ok-soft: rgba(77, 124, 15, 0.12); --error-soft: rgba(192, 57, 43, 0.12);
}
:root[data-theme="arctic-frost"] {
  --accent: #0284c7; --accent-dark: #075985; --accent-soft: rgba(2, 132, 199, 0.1);
  --bg: #f0f7fb; --card: #ffffff; --text: #1c2b36; --muted: #5f7d8f; --border: #d5e6ef;
  --error: #c0392b; --warn: #b45309; --ok: #0f766e;
  --ok-soft: rgba(15, 118, 110, 0.12); --error-soft: rgba(192, 57, 43, 0.12);
}
:root[data-theme="royal-amethyst"] {
  --accent: #a78bfa; --accent-dark: #c4b5fd; --accent-soft: rgba(167, 139, 250, 0.16);
  --bg: #150f24; --card: #201933; --text: #f1ecfb; --muted: #a99bc4; --border: #322648;
  --error: #f87171; --warn: #fbbf24; --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.14); --error-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35); --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}
:root[data-theme="copper-circuit"] {
  --accent: #e0995e; --accent-dark: #f0b27a; --accent-soft: rgba(224, 153, 94, 0.16);
  --bg: #0f0d0c; --card: #1a1512; --text: #f3e9df; --muted: #a68f7c; --border: #2c2420;
  --error: #f87171; --warn: #fbbf24; --ok: #84cc16;
  --ok-soft: rgba(132, 204, 22, 0.14); --error-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35); --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}
:root[data-theme="ocean-depth"] {
  --accent: #2dd4bf; --accent-dark: #5eead4; --accent-soft: rgba(45, 212, 191, 0.16);
  --bg: #071a1e; --card: #0e2830; --text: #e2f5f5; --muted: #7fa8ac; --border: #163a41;
  --error: #f87171; --warn: #fbbf24; --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.14); --error-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35); --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}
:root[data-theme="rose-quartz"] {
  --accent: #db2777; --accent-dark: #9d174d; --accent-soft: rgba(219, 39, 119, 0.1);
  --bg: #fdf2f6; --card: #ffffff; --text: #3a1f2b; --muted: #97748a; --border: #f3d9e6;
  --error: #c0392b; --warn: #b45309; --ok: #15803d;
  --ok-soft: rgba(21, 128, 61, 0.12); --error-soft: rgba(192, 57, 43, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --accent: #4f7fee;
    --accent-dark: #6d95f2;
    --accent-soft: rgba(79, 127, 238, 0.16);
    --bg: #12161c;
    --card: #1b212b;
    --text: #eef1f6;
    --muted: #93a2b8;
    --border: #2b3340;
    --error: #e0655a;
    --warn: #e0a95a;
    --ok: #4ade80;
    --ok-soft: rgba(74, 222, 128, 0.14);
    --error-soft: rgba(224, 101, 90, 0.14);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background: var(--bg);
  color: var(--text);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--error); }

h1, h2, h3 { letter-spacing: -0.01em; }

/* -------------------- Buttons / inputs -------------------- */
.btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--error); }
.btn.danger:hover { background: var(--error-soft); border-color: var(--error); }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  width: 100%;
  font-family: inherit;
  color-scheme: dark;
}
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.85rem; }
label > input, label > select, label > textarea { margin-top: 0.3rem; color: var(--text); }

/* Some engines (WebKitGTK -- the native Linux app's renderer) draw <select>
   using the OS's own native widget theme, ignoring the background above
   while still applying our text color -- e.g. white text on the GTK theme's
   light widget background, unreadable. appearance:none forces it to
   actually use this stylesheet's colors like every other browser does;
   the custom arrow below replaces the native one that removing appearance
   also removes. */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%239aa4b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='5 8 10 13 15 8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 1rem;
  padding-right: 2rem;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.checkbox-field input[type="checkbox"] {
  width: auto;
  margin-top: 0;
  flex-shrink: 0;
}
.checkbox-row {
  display: flex;
  gap: 1.2rem;
  margin-top: -0.5rem;
  margin-bottom: 0.85rem;
}
.checkbox-row .checkbox-field { margin-bottom: 0; }

/* -------------------- Auth -------------------- */
.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.auth-actions { display: flex; gap: 0.6rem; margin-top: 0.5rem; }
.auth-actions .btn { flex: 1; }

/* -------------------- Brand (Toponexa logo + wordmark) -------------------- */
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-icon { width: 34px; height: 34px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text h1 { margin: 0; }
.brand-title-row { display: flex; align-items: baseline; gap: 0.45rem; flex-wrap: wrap; }
.brand-credit { font-size: 0.85rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.brand-lg { margin-bottom: 1.1rem; }
.brand-lg .brand-icon { width: 52px; height: 52px; }
.brand-lg .brand-credit { font-size: 1rem; }

/* -------------------- App shell -------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(0.9rem + var(--safe-top)) 1.25rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header h1 { font-size: 1.2rem; margin: 0; }
.header-right { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: capitalize;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1rem 0;
  overflow-x: auto;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; padding: 1rem 1.25rem 3rem; max-width: 1600px; margin: 0; }
.tab-panel.active { display: block; }

.about-list { margin: 0.5rem 0; padding-left: 1.2rem; font-size: 0.88rem; }
.about-list li { margin-bottom: 0.35rem; }

/* -------------------- Category/Type manager (Settings tab) -------------------- */
.manager-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.6rem; max-width: 480px; }
.manager-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; }
.manager-row .manager-name { flex: 1; font-size: 0.9rem; }
.manager-row input[type="color"] { width: 28px; height: 28px; padding: 0; border: none; background: none; cursor: pointer; }
.manager-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.inline-add-form { display: flex; align-items: center; gap: 0.5rem; max-width: 480px; }
.inline-add-form input[type="text"] { flex: 1; }
.inline-add-form input[type="color"] { width: 34px; height: 34px; padding: 0; border: none; background: none; cursor: pointer; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.search-field { flex: 1; min-width: 180px; }
.filter-field { min-width: 140px; }
.toolbar-spacer { flex: 1; }

/* -------------------- Category sections -------------------- */
.category-section { margin-bottom: 0.9rem; }
.category-section:last-child { margin-bottom: 0; }
.category-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.2rem;
  cursor: pointer;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0.6rem;
}
.category-header-spacer { flex: 1; }
.category-title { font-weight: 700; font-size: 1.05rem; }
.category-count {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}
.empty-state.small { margin: 0; padding: 0.8rem; font-size: 0.85rem; }

/* -------------------- Site cards / list -------------------- */
.site-list { display: flex; flex-direction: column; gap: 0.9rem; }
.site-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}
.site-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  cursor: pointer;
  margin: -0.2rem -0.2rem;
  padding: 0.2rem;
  border-radius: var(--radius-sm);
}
.site-card-top:hover { background: var(--accent-soft); }
.site-card-top-right { display: flex; align-items: center; gap: 0.6rem; }
.site-card-title { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.site-name { font-weight: 700; font-size: 1.02rem; }
.site-summary-field { font-size: 0.85rem; color: var(--muted); }
.site-summary-field::before { content: "·"; margin-right: 0.5rem; color: var(--border); }
.expand-chevron { color: var(--muted); font-size: 0.8rem; width: 1em; text-align: center; }
.child-toggle {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  cursor: pointer;
}
.child-toggle:hover { background: var(--accent); color: #fff; }
.site-children { margin-left: 1.3rem; padding-left: 1rem; border-left: 2px dashed var(--border); margin-top: 0.7rem; display: flex; flex-direction: column; gap: 0.7rem; }
.site-details { margin-top: 0.6rem; }
.site-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.35rem 1rem;
  margin: 0.6rem 0;
  font-size: 0.88rem;
}
.site-meta div span { color: var(--muted); display: block; font-size: 0.75rem; }
.site-notes { font-size: 0.88rem; color: var(--muted); margin-top: 0.3rem; white-space: pre-wrap; }
.site-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }

.type-pill { padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }

.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 0.35rem; vertical-align: middle; }
.status-online { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-orange { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.status-yellow { background: #eab308; box-shadow: 0 0 0 3px color-mix(in srgb, #eab308 22%, transparent); }
.status-offline { background: var(--error); box-shadow: 0 0 0 3px var(--error-soft); animation: status-blink 1.1s ease-in-out infinite; }
.status-unknown { background: var(--muted); }
.status-text-online { color: var(--ok); font-weight: 600; }
.status-text-warn { color: var(--warn); font-weight: 600; }
.status-text-offline { color: var(--error); font-weight: 600; }
.status-text-unknown { color: var(--muted); }

@keyframes status-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
  .status-offline { animation: none; }
}

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* -------------------- Dashboard -------------------- */
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.8rem; margin-bottom: 1.2rem; }
.dash-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
}
.dash-tile-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.dash-tile-label { color: var(--muted); font-size: 0.82rem; margin-top: 0.2rem; }
.dash-tile.tile-online .dash-tile-value { color: var(--ok); }
.dash-tile.tile-warn .dash-tile-value { color: var(--warn); }
.dash-tile.tile-offline .dash-tile-value { color: var(--error); }
.dash-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.2rem;
}
.dash-panel h2 { margin: 0 0 0.2rem; font-size: 1.05rem; }
.dash-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.dealer-uptime-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; margin-top: 0.4rem; }
.dealer-uptime-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--border); }
.dealer-uptime-table td { padding: 0.4rem; border-bottom: 1px solid var(--border); }

/* -------------------- Activity list (Dashboard + notification bell) -------------------- */
.activity-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.6rem; max-height: 420px; overflow-y: auto; }
.activity-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border-left: 3px solid var(--border);
  background: color-mix(in srgb, var(--border) 20%, transparent);
  font-size: 0.86rem;
}
.activity-row.sev-critical { border-left-color: var(--error); }
.activity-row.sev-warning { border-left-color: var(--warn); }
.activity-row.sev-success { border-left-color: var(--ok); }
.activity-row-msg { flex: 1; }
.activity-row-time { color: var(--muted); font-size: 0.76rem; white-space: nowrap; }

/* -------------------- Notification bell -------------------- */
.notif-wrap { position: relative; }
.notif-bell { position: relative; font-size: 1rem; }
.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--error);
  color: #fff;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.05rem 0.35rem;
  line-height: 1.3;
}
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-width: 90vw;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md, var(--shadow-sm));
  padding: 0.8rem;
  z-index: 50;
}
.notif-dropdown-header { font-weight: 700; margin-bottom: 0.4rem; font-size: 0.9rem; }

/* -------------------- Bulk actions (Sites tab) -------------------- */
.bulk-toolbar { background: color-mix(in srgb, var(--accent) 8%, var(--card)); border: 1px solid var(--accent); margin-top: 0.6rem; }
.bulk-count { font-weight: 600; font-size: 0.85rem; }
.site-bulk-checkbox { margin-right: 0.5rem; width: 16px; height: 16px; vertical-align: middle; }

/* -------------------- Loading overlay -------------------- */
.app-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 3rem 1rem;
  color: var(--muted);
}
.app-loading.hidden { display: none; }
.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------- Topology graph (radial spider view) -------------------- */
.topo-toolbar { display: flex; gap: 0.4rem; margin-bottom: 0.5rem; }
.topo-graph-container {
  height: 65vh;
  min-height: 420px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  background: var(--card);
  cursor: grab;
}
.topo-graph-container.grabbing { cursor: grabbing; }
.topo-graph { width: 100%; height: 100%; display: block; touch-action: none; }

/* Fullscreen expand -- the wrapper (toolbar + graph + popup) is what goes
   fullscreen, not just the graph, so zoom controls and the quick-actions
   popup stay usable while expanded. */
.topo-fullscreen-wrapper:fullscreen,
.topo-fullscreen-wrapper:-webkit-full-screen {
  background: var(--bg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}
.topo-fullscreen-wrapper:fullscreen .topo-graph-container,
.topo-fullscreen-wrapper:-webkit-full-screen .topo-graph-container {
  flex: 1;
  height: auto;
  min-height: 0;
}
.topo-link { stroke: var(--border); stroke-width: 2; }
.topo-node-circle { stroke: var(--card); stroke-width: 3; }
.topo-node { cursor: pointer; }
.topo-node-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.topo-node-sub { fill: var(--muted); font-size: 9px; }
.topo-popup {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  max-width: 260px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
}
.topo-popup-header { font-weight: 700; font-size: 0.88rem; padding: 0.2rem 0.4rem 0.5rem; border-bottom: 1px solid var(--border); margin-bottom: 0.4rem; }
.topo-popup-actions { display: flex; flex-direction: column; gap: 0.3rem; }
.topo-popup-actions button { width: 100%; text-align: left; }

/* -------------------- Screensaver -------------------- */
.screensaver-overlay { position: fixed; inset: 0; z-index: 9999; background: #000; cursor: none; }
.screensaver-overlay.hidden { display: none; }
#screensaver-canvas { width: 100%; height: 100%; display: block; }

/* -------------------- App Lock -------------------- */
/* Sits above the screensaver (10000 > 9999) -- a lock always wins over a
   purely-visual screensaver if both timers happen to fire close together. */
.applock-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
}
.applock-overlay.hidden { display: none; }
.applock-box { text-align: center; max-width: 280px; }
.applock-icon { font-size: 2.5rem; margin-bottom: 0.3rem; }
.applock-box h2 { margin: 0 0 0.2rem; }
.applock-input {
  width: 100%; text-align: center; font-size: 1.6rem; letter-spacing: 0.6em;
  padding: 0.6rem 0.6rem 0.6rem 0.9rem; margin: 0.9rem 0 0.6rem;
}
.applock-box .btn { width: 100%; margin-top: 0.4rem; }

/* -------------------- Command reference (MikroTik tab: simple list) -------------------- */
.cmd-category { margin-bottom: 1.4rem; }
.cmd-category h3 { margin-bottom: 0.5rem; }
.cmd-item { padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 0.5rem; background: var(--card); }
.cmd-code { display: block; font-family: "Courier New", Courier, monospace; font-size: 0.86rem; color: var(--accent); background: var(--accent-soft); padding: 0.3rem 0.5rem; border-radius: 6px; overflow-x: auto; white-space: pre; }
.cmd-desc { font-size: 0.85rem; color: var(--muted); margin-top: 0.35rem; }
.cmd-video-link { display: inline-block; font-size: 0.82rem; margin-top: 0.35rem; color: var(--accent); }

/* -------------------- Command reference (Cisco tab: sidebar + card grid) -------------------- */
.cmd-browser { display: flex; gap: 1.2rem; align-items: flex-start; }
.cmd-sidebar { width: 220px; flex-shrink: 0; position: sticky; top: 0.5rem; display: flex; flex-direction: column; gap: 0.7rem; }
.cmd-search-input { width: 100%; }
.cmd-category-list { display: flex; flex-direction: column; gap: 0.15rem; }
.cmd-category-item { display: flex; justify-content: space-between; align-items: center; padding: 0.45rem 0.65rem; border-radius: var(--radius-sm); cursor: pointer; font-size: 0.85rem; color: var(--text); }
.cmd-category-item:hover { background: var(--accent-soft); }
.cmd-category-item.active { background: var(--accent); color: #fff; }
.cmd-category-item .cmd-category-count { font-size: 0.72rem; opacity: 0.75; }
.cmd-grid { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 0.8rem; align-content: start; }
.cmd-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.8rem; background: var(--card); display: flex; flex-direction: column; gap: 0.5rem; box-shadow: var(--shadow-sm); }
.cmd-card-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 0.4rem 0.5rem; }
.cmd-card-title { font-weight: 700; font-size: 0.92rem; }
.cmd-card-badge { font-size: 0.65rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; flex-shrink: 0; }
.cmd-card-actions { display: flex; gap: 0.4rem; margin-top: auto; }

/* -------------------- Cisco step-by-step guides -------------------- */
.cmd-subtabs { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; }
.cisco-guides-list { display: flex; flex-direction: column; gap: 1rem; }
.guide-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; background: var(--card); box-shadow: var(--shadow-sm); }
.guide-title { margin: 0 0 0.2rem; font-size: 1.02rem; }
.guide-summary { margin: 0 0 0.9rem; }
.guide-steps { display: flex; flex-direction: column; gap: 0.7rem; }
.guide-step { display: flex; gap: 0.7rem; align-items: flex-start; }
.guide-step-num {
  flex-shrink: 0; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 700; margin-top: 0.1rem;
}
.guide-step-body { flex: 1; min-width: 0; }
.guide-step-explain { font-size: 0.88rem; margin-bottom: 0.35rem; }
.guide-step-cmd-row { display: flex; gap: 0.5rem; align-items: center; }
.guide-step-cmd-row .cmd-code { flex: 1; margin: 0; }

/* -------------------- Map -------------------- */
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.map-subtabs { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.map-toolbar { display: flex; gap: 0.4rem; margin-bottom: 0.5rem; }
#map-container { height: 65vh; min-height: 420px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
/* Fullscreen expand -- same pattern as .topo-fullscreen-wrapper: the
   toolbar + map together go fullscreen, not just the map box. */
.map-fullscreen-wrapper:fullscreen,
.map-fullscreen-wrapper:-webkit-full-screen {
  background: var(--bg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}
.map-fullscreen-wrapper:fullscreen #map-container,
.map-fullscreen-wrapper:-webkit-full-screen #map-container {
  flex: 1;
  height: auto;
  min-height: 0;
}
.map-places-icon { font-size: 1.1rem; }
/* Leaflet's own controls/panes use z-index up to 1000 (confirmed straight
   from leaflet.css) -- once this modal lives inside the fullscreened map
   wrapper, it's competing in the same stacking context, so the shared
   .modal-overlay z-index (100) isn't enough; it was rendering *behind* the
   map. This only needs to beat Leaflet's own max, not every other modal. */
#map-annotation-modal { z-index: 2000; }
.map-annotation-label {
  background: rgba(255, 255, 255, 0.92); color: #1a2330; border: none; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  font-size: 0.75rem; font-weight: 600; padding: 0.1rem 0.4rem; border-radius: 4px;
}
.map-annotation-label::before { display: none; }
.map-draw-line-info { font-size: 0.75rem; color: var(--muted); padding: 0.1rem 0.3rem; }
.map-legend { display: flex; flex-wrap: wrap; gap: 0.9rem; margin-top: 0.7rem; font-size: 0.82rem; color: var(--muted); }
.map-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.map-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.leaflet-popup-content { min-width: 190px; }
.popup-title { font-weight: 700; margin-bottom: 0.2rem; }
.popup-row { font-size: 0.82rem; margin: 0.15rem 0; }
.popup-actions { display: flex; gap: 0.3rem; margin-top: 0.5rem; flex-wrap: wrap; }
.popup-actions button { font-size: 0.75rem; padding: 0.3rem 0.5rem; }

.map-search-control {
  display: flex; background: var(--card); padding: 0.3rem; gap: 0.3rem; border-radius: var(--radius-sm);
}
.map-search-control input {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.35rem 0.5rem;
  font-size: 0.85rem; width: 170px; background: var(--card); color: var(--text);
}
.map-search-control button {
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card);
  cursor: pointer; padding: 0.3rem 0.5rem; font-size: 0.9rem;
}
.map-draw-control {
  display: flex; flex-direction: column; gap: 0.25rem; background: var(--card); padding: 0.3rem; border-radius: var(--radius-sm); margin-top: 0.5rem;
}
.map-draw-control button {
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card); color: var(--text);
  cursor: pointer; padding: 0.35rem 0.6rem; font-size: 0.8rem; white-space: nowrap; text-align: left;
}
.map-draw-control button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* -------------------- Modal -------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 14, 20, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2.5rem 1rem; overflow-y: auto; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 1.5rem; width: 100%; max-width: 480px;
}
.modal h2 { margin-top: 0; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.modal-wide { max-width: 680px; }

/* -------------------- History / graphs -------------------- */
.history-chart { width: 100%; height: auto; margin-top: 0.6rem; }
.history-subheading { font-size: 0.9rem; margin: 1.1rem 0 0.4rem; }
.history-transition-row {
  font-size: 0.85rem;
  padding: 0.4rem 0.1rem;
  border-bottom: 1px solid var(--border);
}
.history-transition-row:last-child { border-bottom: none; }

/* -------------------- Toast -------------------- */
#toast {
  position: fixed; bottom: calc(1.2rem + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.6rem 1.1rem; border-radius: 999px;
  font-size: 0.85rem; box-shadow: var(--shadow-lg); z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* -------------------- Ping results -------------------- */
.ping-result { font-size: 0.8rem; margin-top: 0.4rem; }
.ping-stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-top: 0.5rem; text-align: center; }
.ping-stat { background: var(--bg); border-radius: var(--radius-sm); padding: 0.5rem; }
.ping-stat .v { font-weight: 700; font-size: 1.05rem; }
.ping-stat .l { font-size: 0.72rem; color: var(--muted); }

/* -------------------- Users tab -------------------- */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

.admin-only.viewer-hide { display: none !important; }
.owner-only.viewer-hide { display: none !important; }
.tab-btn.tab-hidden { display: none !important; }
.tab-btn.tab-locked { opacity: 0.55; }
.tab-btn.tab-locked::after { content: " 🔒"; font-size: 0.75rem; }
.locked-tab-notice { text-align: center; padding: 4rem 1rem; max-width: 420px; margin: 0 auto; }
.locked-tab-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.locked-tab-notice h2 { margin: 0 0 0.5rem; }

@media (max-width: 640px) {
  .form-row-2 { grid-template-columns: 1fr; }
  .app-header h1 { font-size: 1.05rem; }
  .cmd-browser { flex-direction: column; }
  .cmd-sidebar { width: 100%; position: static; }
  .cmd-category-list { flex-direction: row; flex-wrap: wrap; }

  /* A dropdown positioned relative to the bell (right:0) can run off the
     left edge of a narrow screen once the header itself wraps -- anchoring
     to the viewport instead makes it immune to exactly where the bell
     ends up sitting. */
  .notif-dropdown {
    position: fixed;
    top: auto;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
  }
  .dash-stats { grid-template-columns: repeat(2, 1fr); }
  .bulk-toolbar { align-items: stretch; }
  .bulk-toolbar select { width: 100%; }
}
