/* ═══════════════════════════════════════════════════
   ONE Operations Console — Design System
   Aligned with ONE Central (cloud-console) look & feel:
   tokens, shell, sidebar, topbar, cards, dashboard, tables, badges, buttons.
   ═══════════════════════════════════════════════════ */

:root {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E8E8EC;
  --text: #1A1F36;
  --text-secondary: #6B7C8C;
  --primary: #01A982;
  --primary-dark: #008A6A;
  --primary-light: #E6F7F1;
  --danger: #FF4D4F;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --sidebar-w: 230px;
  --topbar-h: 56px;

  /* Status */
  --ok: #01A982;
  --warn: #C77700;
  --error: #D64545;
  --info: #0050B3;

  /* Platform colors */
  --plat-win: #0078D4;
  --plat-mac: #8E8E93;
  --plat-linux: #E8912D;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }

/* ═══════════════════════
   Landing / login
   ═══════════════════════ */
.landing { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.landing .card {
  background: var(--surface); border-radius: 16px; box-shadow: 0 8px 30px rgba(16,24,40,.08);
  padding: 44px 40px; text-align: center; width: 380px; max-width: 90vw; border: 1px solid var(--border);
}
.landing .brand-logo { display: inline-flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 20px; font-size: 20px; font-weight: 700; }
.landing h1 { font-size: 22px; margin: 0 0 8px; }
.subtitle { color: var(--text-secondary); font-size: 14px; margin: 0 0 28px; }
.foot { color: var(--text-secondary); font-size: 12px; margin-top: 26px; opacity: .8; }

/* ═══════════════════════
   App Shell
   ═══════════════════════ */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

/* ═══════════════════════
   Sidebar
   ═══════════════════════ */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sb-brand {
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 700; color: var(--text);
}
.sb-brand svg { flex-shrink: 0; }
.sb-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none; cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sb-item:hover { background: #F0F2F5; color: var(--text); }
.sb-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sb-item svg { flex-shrink: 0; }
.sb-foot {
  padding: 14px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-secondary);
}
.role-chip {
  background: var(--primary-light); color: var(--primary);
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .4px;
}
.sb-ver { margin-left: auto; opacity: .8; }

/* ═══════════════════════
   Topbar
   ═══════════════════════ */
.topbar {
  grid-area: topbar;
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
}
.tb-title { font-size: 18px; font-weight: 700; }
.tb-actions { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 4px 4px; border-radius: 20px; background: #F0F2F5;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.user-chip span { font-size: 13px; font-weight: 500; }

/* ═══════════════════════
   Main content
   ═══════════════════════ */
.main { grid-area: main; padding: 24px 28px; overflow-y: auto; }
.view-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }

/* ═══════════════════════
   Tab bar — segmented pills
   ═══════════════════════ */
.tabbar { display: inline-flex; gap: 4px; background: #EEF1F5; padding: 4px; border-radius: 10px; margin-bottom: 22px; }
.tab {
  padding: 8px 18px; border: none; background: none; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Sub-tabs (underline style) inside a view */
.subtabbar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.subtab {
  padding: 9px 16px; border: none; background: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.15s;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--primary); border-bottom-color: var(--primary); }
.subpanel { display: none; }
.subpanel.active { display: block; }

/* ═══════════════════════
   Buttons
   ═══════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: all 0.15s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #F0F2F5; }
.btn-danger { background: #D64545; color: #fff; border-color: #D64545; }
.btn-danger:hover { background: #B83535; border-color: #B83535; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-link {
  background: none; border: none; color: var(--primary);
  font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 4px 8px; border-radius: 4px;
}
.btn-link:hover { background: var(--primary-light); }

/* ═══════════════════════
   Cards
   ═══════════════════════ */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 0;
}
.card-header h3 { font-size: 14px; font-weight: 700; color: var(--text); }
.card-header-actions { display: flex; align-items: center; gap: 10px; }
.card-sub { font-size: 12px; color: var(--text-secondary); padding: 2px 20px 0; }
.card-body { padding: 16px 20px 20px; }

/* ═══════════════════════
   Dashboard — card grid
   ═══════════════════════ */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: stretch; }
.dash-grid .card { margin-bottom: 0; }

/* Dashboard donut (Device Inventory / Certificate Health) */
.donut {
  position: relative; width: 132px; height: 132px; border-radius: 50%; flex-shrink: 0;
  background: var(--border);
}
.donut-hole {
  position: absolute; inset: 13px; border-radius: 50%;
  background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-total { font-size: 24px; font-weight: 800; color: var(--text); line-height: 1; }
.donut-cap { font-size: 11px; color: var(--text-secondary); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }

/* Device Inventory — compact platform tiles */
.card:has(.inv-tiles) { display: flex; flex-direction: column; }
.card:has(.inv-tiles) .card-body { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.inv-count { font-size: 13px; color: var(--text-secondary); }
.inv-count strong { font-size: 15px; font-weight: 800; color: var(--text); }
.inv-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 10px; }
.inv-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
.inv-tile-icon { width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.inv-tile-icon svg { width: 19px; height: 19px; }
.inv-tile-val { font-size: 20px; font-weight: 800; color: var(--text); line-height: 1; }
.inv-tile-name { font-size: 12px; font-weight: 600; color: var(--text-secondary); }

/* Installer Downloads — bars + total pill */
.dl-list { display: flex; flex-direction: column; gap: 16px; margin-bottom: 18px; }
.dl-row { display: grid; grid-template-columns: 96px 44px 1fr; align-items: center; gap: 12px; }
.dl-name { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.dl-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dl-val { font-size: 15px; font-weight: 800; color: var(--text); text-align: right; }
.dl-track { height: 10px; border-radius: 6px; background: #EEF1F5; overflow: hidden; }
.dl-fill { display: block; height: 100%; border-radius: 6px; min-width: 4px; }
.dl-total {
  display: flex; align-items: center; gap: 10px;
  background: #F5F7FA; border-radius: 8px; padding: 12px 14px;
}
.dl-total-icon { display: flex; color: var(--info); }
.dl-total-icon svg { width: 18px; height: 18px; }
.dl-total-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); flex: 1; }
.dl-total-val { font-size: 16px; font-weight: 800; color: var(--text); }

/* Events Severity (24h) — two rings */
/* Ring cards are content-light; fill the stretched card height and center the rings. */
.card:has(.sev-rings) { display: flex; flex-direction: column; }
.card:has(.sev-rings) .card-body { flex: 1; display: flex; align-items: center; justify-content: center; }
.sev-rings { display: flex; justify-content: center; gap: 32px; padding: 4px 0; }
.sev-ring { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.ring {
  position: relative; width: 112px; height: 112px; border-radius: 50%; flex-shrink: 0;
}
.ring-hole {
  position: absolute; inset: 13px; border-radius: 50%;
  background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-pct { font-size: 12px; color: var(--text-secondary); }
.ring-val { font-size: 24px; font-weight: 800; color: var(--text); line-height: 1; }
.ring-label { font-size: 14px; font-weight: 600; color: var(--text); }

/* Dashboard card loading / error placeholders */
.card-loading, .card-error {
  font-size: 13px; color: var(--text-secondary); text-align: center; padding: 16px 0;
}
.card-error { color: #D64545; }

/* Recent events list */
.recent-list { display: flex; flex-direction: column; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-top: 1px solid var(--border); font-size: 13px; }
.recent-item:first-child { border-top: none; }
.recent-item.clickable { cursor: pointer; border-radius: 6px; }
.recent-item.clickable:hover { background: #F5F7FA; }
.recent-item .re-evt { font-weight: 600; color: var(--text); min-width: 120px; }
.recent-item .re-dev { color: var(--text-secondary); font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.recent-item .re-msg { color: var(--text-secondary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .re-time { margin-left: auto; color: var(--text-secondary); flex-shrink: 0; }

/* ═══════════════════════
   Filter bar
   ═══════════════════════ */
.filter-bar { padding: 12px 20px; border-bottom: 1px solid var(--border); background: #FAFBFC; }
.filter-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-label {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
}
.input, .select {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px; background: var(--surface); color: var(--text);
  outline: none; height: 36px;
}
.select { cursor: pointer; }
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.input.search { flex: 1; min-width: 240px; }

/* ═══════════════════════
   Data table
   ═══════════════════════ */
.table-card { padding: 0; overflow: hidden; }
.diag-events-box { padding: 20px; border: 1px solid var(--border); border-radius: 8px; background: white; min-width: 0; }
.diag-events-box h3 { margin: 0 0 20px; font-size: 20px; }
#diag-dd-logs { overflow-x: auto; min-height: 160px; }
.diag-device-events-table { min-width: 850px; }
.diag-device-events-table td { overflow-wrap: anywhere; }
.diag-evt:focus-visible { outline: 2px solid #008567; outline-offset: -2px; }
.diag-device-events-table .diag-json { white-space: pre-wrap; overflow-wrap: anywhere; }
.device-table-scroll { overflow-x: auto; }
#dev-table { min-width: 1000px; table-layout: fixed; }
#dev-table td { overflow-wrap: anywhere; white-space: normal; }
#subtab-list .table-foot { flex-wrap: wrap; gap: 10px; }
#dev-refresh, #dev-prev, #dev-next { width: 34px; height: 32px; padding: 0; }
#tab-devices button:focus-visible { outline: 2px solid #008567; outline-offset: 2px; }
#tab-devices button:disabled { opacity: 0.5; cursor: not-allowed; }
@media (max-width: 600px) {
  body:has(#tab-devices.active) .shell { grid-template-columns: 64px minmax(0, 1fr); grid-template-rows: auto 1fr; }
  body:has(#tab-devices.active) .topbar { flex-wrap: wrap; height: auto; gap: 8px; padding: 12px; }
  body:has(#tab-devices.active) .tb-actions,
  body:has(#tab-devices.active) .user-chip { flex-wrap: wrap; min-width: 0; }
  body:has(#tab-devices.active) .user-chip span { overflow-wrap: anywhere; }
  body:has(#tab-devices.active) .main { min-width: 0; padding: 16px 12px; }
  #tab-devices .input.search { min-width: 0; width: 100%; flex-basis: 100%; }
  #tab-devices .card-header { flex-wrap: wrap; gap: 8px; }
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  background: #F8F9FB; text-align: left; padding: 10px 16px;
  font-weight: 600; color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  white-space: nowrap;
}
.data-table tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover td { background: #FAFBFC; }
.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--text-secondary); }
.row-arrow { color: var(--text-secondary); text-align: right; }
.table-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-top: 1px solid var(--border);
  background: #FAFBFC; font-size: 12px; color: var(--text-secondary);
}
.pager { letter-spacing: 4px; }
.pager-btns { display: inline-flex; align-items: center; gap: 10px; }
.pager-page { letter-spacing: normal; color: var(--text-secondary); font-size: 12px; }
.lookup-result { padding: 4px 20px 16px; }
.lookup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 24px; margin: 4px 0 14px; }
.lookup-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.lookup-row .dd-key { color: var(--text-secondary); min-width: 76px; }

/* ═══════════════════════
   Badges & dots
   ═══════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
}
.badge-blue   { background: #E6F1FF; color: #0050B3; }
.badge-gray   { background: #F0F2F5; color: #6B7C8C; }
.badge-yellow { background: #FFF7E6; color: #AD6800; }
.badge-green  { background: #E6F7F1; color: #00805F; }
.badge-red    { background: #FFF1F0; color: #CF1322; }
.badge-violet { background: #F0EBFF; color: #6D28D9; }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.lvl { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; }
.lvl-info { color: var(--info); }
.lvl-warn { color: var(--warn); }
.lvl-error { color: var(--error); }

/* Expandable event row */
.evt-toggle { cursor: pointer; color: var(--text-secondary); user-select: none; text-align: center; }
.evt-json {
  background: #F8F9FB; border-radius: 8px; padding: 12px 14px; margin: 0;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px;
  color: var(--text); white-space: pre-wrap;
}

/* Cloud pull */
.pull-card { padding: 16px 20px; }
.pull-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pull-label { font-weight: 600; color: var(--text); font-size: 14px; }
.pull-hint { color: var(--text-secondary); font-size: 12px; }

/* ═══════════════════════
   Device detail modal
   ═══════════════════════ */
.device-modal { width: 560px; max-height: 84vh; }
.device-modal .modal-body { overflow-y: auto; }
.dd-section { margin-bottom: 22px; }
.dd-section:last-child { margin-bottom: 0; }
.dd-section h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); margin: 0 0 10px; font-weight: 700; }
.dd-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 13px; border-bottom: 1px solid var(--border); }
.dd-row:last-child { border-bottom: none; }
.dd-key { color: var(--text-secondary); }
.dd-val { color: var(--text); font-weight: 500; text-align: right; word-break: break-word; }
.dd-muted { color: var(--text-secondary); font-weight: 400; font-size: 12px; }
.dd-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dd-sec-head h4 { margin: 0; }

/* Log timeline inside the device modal */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot { position: absolute; left: -23px; top: 3px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.tl-dot.warn { background: var(--warn); }
.tl-dot.error { background: var(--error); }
.tl-head { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 6px; }
.tl-event { font-weight: 700; color: var(--text); }
.tl-mod { color: var(--text-secondary); font-family: 'SF Mono', 'Fira Code', monospace; }
.tl-time { margin-left: auto; color: var(--text-secondary); }
.tl-payload {
  margin: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 11.5px; line-height: 1.5;
  color: var(--text); white-space: pre-wrap; word-break: break-word;
  max-height: 150px; overflow: auto; background: #FAFBFC;
}
.log-empty { color: var(--text-secondary); font-size: 13px; padding: 8px 0; }

/* Table action cell */
.actions-cell { text-align: right; white-space: nowrap; }

/* ═══════════════════════
   Toast notifications (top-right stack)
   ═══════════════════════ */
.toast-stack {
  position: fixed; top: 16px; right: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: 12px 14px; border-radius: 8px; font-size: 13px; line-height: 1.4;
  color: #fff; cursor: pointer; box-shadow: 0 4px 12px rgba(16,24,40,.18);
  border-left: 4px solid rgba(255,255,255,.5);
  animation: toast-in .18s ease-out;
}
.toast-error   { background: #CF1322; }
.toast-success { background: #00805F; }
.toast-info    { background: #0050B3; }
.toast-out { animation: toast-out .18s ease-in forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(16px); } }

/* ═══════════════════════
   Center modal (Pull Logs request)
   ═══════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(16,24,40,.4);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  width: 440px; max-width: 100%; background: var(--surface);
  border-radius: 12px; box-shadow: 0 20px 60px rgba(16,24,40,.25);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 16px; color: var(--text-secondary); cursor: pointer; padding: 6px; border-radius: 6px; }
.modal-close:hover { color: var(--text); background: #F0F2F5; }
.modal-body { padding: 20px; }
.modal-sub { font-size: 13px; color: var(--text-secondary); margin: 0 0 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* Installer Versions settings modal — wider to fit the versions table. */
.installer-modal { width: 640px; }
.installer-modal .modal-body { padding: 0; }
.installer-toolbar { display: flex; align-items: center; gap: 12px; padding: 16px 20px; }
.installer-status { font-size: 13px; color: var(--text-secondary); }
.installer-status.is-error { color: #CF1322; }
.installer-status.is-ok { color: #00805F; }
.installer-modal .data-table { border-top: 1px solid var(--border); }
.reqlog-dates { display: flex; gap: 12px; margin: 8px 0 16px; }
.reqlog-dates .filter-group { flex: 1; }
.reqlog-quick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.reqlog-quick .btn.active { background: var(--accent, #01A982); border-color: var(--accent, #01A982); color: #fff; }
.reqlog-note { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); background: #F8F9FB; border-radius: 8px; padding: 10px 12px; margin: 0; }
.reqlog-note[hidden] { display: none; }
.reqlog-note-warn { align-items: flex-start; color: #AD6800; background: #FFF7E6; }
.reqlog-note-warn svg { flex-shrink: 0; margin-top: 1px; }
.textarea { width: 100%; height: auto; min-height: 76px; resize: vertical; line-height: 1.5; font-family: inherit; margin-top: 6px; }

/* ═══════════════════════
   Log viewer modal (fetched log lines)
   ═══════════════════════ */
.log-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(16,24,40,.4);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.log-overlay[hidden] { display: none; }
.log-panel {
  width: 900px; max-width: 100%; max-height: 80vh;
  background: var(--surface); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(16,24,40,.25);
  display: flex; flex-direction: column; overflow: hidden;
}
.log-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.log-panel-head h4 { margin: 0; font-size: 14px; font-weight: 700; }
.log-panel-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.log-panel-actions { display: flex; align-items: center; gap: 8px; }
.logview-toolbar { display: flex; gap: 16px; align-items: flex-end; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.log-panel-body { overflow-y: auto; flex: 1; max-height: 55vh; }
.log-lines { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; line-height: 1.6; }
.log-line { display: flex; gap: 12px; padding: 3px 20px; border-bottom: 1px solid #F0F2F5; }
.log-line:hover { background: #FAFBFC; }
.log-ts { color: var(--text-secondary); min-width: 150px; flex-shrink: 0; }
.log-lvl { min-width: 48px; font-weight: 700; text-align: center; padding: 0 4px; border-radius: 3px; flex-shrink: 0; }
.log-level-info  { color: #0050B3; background: #E6F1FF; }
.log-level-warn  { color: #AD6800; background: #FFF7E6; }
.log-level-error { color: #CF1322; background: #FFF1F0; }
.log-level-debug { color: #6B7C8C; background: #F0F2F5; }
.log-host { color: var(--text-secondary); min-width: 110px; flex-shrink: 0; }
.log-msg { color: var(--text); flex: 1; }

/* ═══════════════════════
   Empty state (table)
   ═══════════════════════ */
.empty-cell { text-align: center; padding: 32px; color: var(--text-secondary); }
.error-cell { color: #CF1322; }

/* ═══════════════════════
   Responsive
   ═══════════════════════ */
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
  .shell { grid-template-columns: 64px 1fr; }
  .sb-brand span, .sb-item .sb-label, .role-chip, .sb-ver { display: none; }
  .sb-item { justify-content: center; }
  .sb-brand { justify-content: center; padding-left: 0; padding-right: 0; }
}

/* ═══════════════════════
   Diagnostics — auto-grouped errors & warnings
   ═══════════════════════ */
.diag-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.diag-custom { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.diag-custom input { max-width: 100%; min-width: 0; }
.diag-pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 16px 0; }
.diag-pagination [role="status"] { min-width: 70px; text-align: center; font-size: 13px; }
.diag-event-detail { border-bottom: 1px solid var(--border); padding: 12px 0; overflow-wrap: anywhere; }
.diag-event-detail summary { cursor: pointer; font-size: 13px; }
.diag-event-detail p { font-size: 13px; }
#diag-table { min-width: 1000px; }
#diag-table td { max-width: 320px; overflow-wrap: anywhere; }
.diag-json { max-height: 360px; }
body:has(#tab-diagnostics.active) .main { min-width: 0; }
#tab-diagnostics .table-card { overflow-x: auto; }
#tab-diagnostics .input.search { min-width: 0; max-width: 100%; }
.diag-dd-grid > *, .diag-dd-head > * { min-width: 0; }
.diag-dd-name, .diag-inforow > span { overflow-wrap: anywhere; }
@media (max-width: 600px) {
  body:has(#tab-diagnostics.active) .shell { grid-template-columns: 64px minmax(0, 1fr); grid-template-rows: auto 1fr; }
  body:has(#tab-diagnostics.active) .topbar { flex-wrap: wrap; height: auto; gap: 8px; padding: 12px; }
  body:has(#tab-diagnostics.active) .tb-actions,
  body:has(#tab-diagnostics.active) .user-chip { flex-wrap: wrap; min-width: 0; }
  body:has(#tab-diagnostics.active) .user-chip span { overflow-wrap: anywhere; }
  body:has(#tab-diagnostics.active) .main { padding: 16px 12px; }
}
.diag-custom[hidden] { display: none; }

/* Group boxes */
.diag-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-bottom: 20px; }
.diag-group {
  text-align: left; font: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; transition: box-shadow .15s, border-color .15s;
}
.diag-group:hover { box-shadow: 0 6px 18px rgba(16,24,40,.08); }
.diag-group.sel { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.dg-title { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.3; margin-bottom: 6px; }
.dg-sev { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 5px; }
.dg-sev.error { background: var(--error); }
.dg-sev.warn { background: var(--warn); }
.dg-skel {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 11px; color: var(--text-secondary);
  line-height: 1.35; margin-bottom: 10px; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dg-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--text-secondary); }
.dg-count { font-weight: 700; color: var(--text); }

/* Filter row */
.diag-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.diag-chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  font: inherit; font-size: 12px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.diag-chip.on { background: var(--text); color: #fff; border-color: var(--text); }
.diag-spacer { flex: 1; }
.diag-clear { font-size: 12px; color: var(--primary); cursor: pointer; text-decoration: underline; }
.diag-clear[hidden] { display: none; }

/* Event table */
.diag-ico { display: inline-flex; width: 16px; height: 16px; vertical-align: middle; }
.diag-ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.diag-ico.err { color: #A56666; }
.diag-ico.warn { color: #947345; }
.diag-muted { color: var(--text-secondary); }
.diag-msg { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diag-drawer-row td { background: #FAFBFC; padding: 0; }
.diag-drawer { padding: 14px 16px; }
.diag-drawer-k { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.diag-json {
  background: #0F172A; color: #E2E8F0; border-radius: 8px; padding: 12px;
  overflow: auto; font-size: 12px; line-height: 1.5; margin: 0 0 10px;
  white-space: pre-wrap; word-break: break-word;
}

/* Device detail view */
.diag-back { color: var(--primary); cursor: pointer; font-size: 13px; margin-bottom: 12px; display: inline-block; }
.diag-dd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.diag-dd-name { margin: 0 0 4px; font-size: 20px; }
.diag-dd-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.diag-inforow { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.diag-inforow:last-child { border-bottom: none; }
.diag-lbl { color: var(--text-secondary); }
.diag-sec-head { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; color: var(--text-secondary); font-weight: 700; margin: 6px 2px 12px; }
.diag-sec-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.diag-sec-row .diag-sec-head { margin-bottom: 0; }
.diag-range { display: flex; gap: 6px; margin-bottom: 12px; }
.diag-logline { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.diag-lh { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.diag-lt { margin-left: auto; color: var(--text-secondary); font-weight: 400; font-size: 12px; }

/* VPN ledger — summary strip, connection path (device → gateways), paged session table */
.vpn-stats { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; margin-bottom: 16px; }
.vpn-stat-v { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.1; }
.vpn-stat-v.ok { color: var(--primary-dark); }
.vpn-stat-k { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; color: var(--text-secondary); margin-top: 2px; }
.vpn-note { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); margin-left: auto; }
.vpn-dot { width: 8px; height: 8px; border-radius: 50%; background: #B8C2CC; flex: none; }
.vpn-dot.live { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* Connection path (device → gateways) */
.vpn-path { display: flex; align-items: center; padding: 14px 8px 18px; margin-bottom: 8px; }
.vpn-node { min-width: 0; }
.vpn-node.dev {
  position: relative; flex: none; width: 150px; padding: 18px 12px 14px; text-align: center;
  background: #F6F8FA; border: 1px solid var(--border); border-radius: 12px;
}
.vpn-node.dev.live { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.vpn-node.dev .vpn-dot { position: absolute; top: 10px; left: 10px; width: 9px; height: 9px; }
.vpn-node-ic { color: var(--text); display: flex; justify-content: center; }
.vpn-node.dev .vpn-node-ic { margin-bottom: 8px; }
.vpn-node-name { font-weight: 700; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vpn-node-meta { font-size: 12px; color: var(--text-secondary); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.vpn-node-meta .badge { font-size: 10.5px; }
/* Device → trunk stub; trunk is drawn by the branches' ::before so it spans exactly first→last row. */
.vpn-stub { flex: none; width: 48px; height: 3px; background: #C5CDD5; }
.vpn-stub.live { background: var(--primary); }
.vpn-branches { position: relative; display: flex; flex-direction: column; flex: 1; min-width: 0; }
.vpn-branch { position: relative; display: flex; align-items: center; padding: 10px 0; }
.vpn-branch::before { content: ""; position: absolute; left: 0; width: 3px; top: 0; bottom: 0; background: #C5CDD5; }
.vpn-branch:first-child::before { top: 50%; }
.vpn-branch:last-child::before { bottom: 50%; }
.vpn-branch:only-child::before { display: none; }
.vpn-branch.live::before { background: var(--primary); }
/* A closed branch sitting between live ones keeps the trunk green above it, so paint the trunk by neighbours too. */
.vpn-branch.live + .vpn-branch::before { background: linear-gradient(var(--primary) 0 50%, #C5CDD5 50%); }
.vpn-branch.live + .vpn-branch.live::before { background: var(--primary); }
.vpn-link { flex: none; width: 110px; height: 3px; margin-right: 14px; background: repeating-linear-gradient(90deg, #C5CDD5 0 8px, transparent 8px 14px); }
.vpn-branch.live .vpn-link { background: var(--primary); }
.vpn-node.gw { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); flex: 1; min-width: 0; max-width: 560px; }
.vpn-branch.live .vpn-node.gw { border-color: var(--primary); background: #FBFEFD; }
.vpn-node.gw .vpn-node-ic { flex: none; width: 40px; height: 40px; border-radius: 10px; align-items: center; background: #F0F2F5; color: var(--text-secondary); }
.vpn-branch.live .vpn-node.gw .vpn-node-ic { background: var(--primary-light); color: var(--primary-dark); }
.vpn-node-body { min-width: 0; flex: 1; }
/* "+N more gateways" toggle sits at the end of the branch column, indented past the trunk. */
.vpn-more { align-self: flex-start; margin: 6px 0 0 124px; }
@media (max-width: 720px) {
  .vpn-path { flex-direction: column; align-items: stretch; }
  .vpn-node.dev { width: auto; }
  .vpn-stub { width: 3px; height: 20px; margin-left: 24px; }
  .vpn-branches { margin-left: 24px; }
  .vpn-link { width: 28px; }
  .vpn-node.gw { max-width: none; }
  .vpn-more { margin-left: 42px; }
}
.vpn-table { margin-top: 6px; }
.vpn-table .data-table thead th, .vpn-table .data-table tbody td { padding: 10px 12px; }
.vpn-pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 4px 0; font-size: 12px; }
.vpn-pager-btns { display: flex; gap: 6px; }
@media (max-width: 720px) {
  .vpn-pager { flex-direction: column; align-items: flex-start; }
}


