/* ============================================================
   meraki-ipsk-manager — Material Design 3 skin over Bootstrap 5.3 (light/dark)
   ============================================================ */
/* Material Design 3 skin over Bootstrap 5.3.

   Bootstrap owns the light/dark machinery: `data-bs-theme` on <html>, set by the
   inline snippet in each page's <head> (saved preference, else the desktop's
   prefers-color-scheme). Every colour role below is therefore declared once per
   colour mode, so flipping that single attribute repaints the whole app.

   The --md-* names are kept (every component rule and BEM class already speaks
   them) and are derived from Bootstrap's own tokens where one exists, so the two
   systems cannot drift apart.

   Palette: the accent hexes are the official brand colours - Cisco Blue
   #049FD9 / #00BCEB (Cisco’s published brand palette) and Meraki green
   #56BA32 / #A1D73C (the stops of the Meraki wordmark gradient). Status
   meanings follow the Meraki dashboard: green = online, yellow = online
   with alerts, red = offline, grey = dormant. */
:root {
  /* Shape (theme-independent) */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 28px;
  --font: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  /* Native widgets (scrollbars, date pickers) follow the page theme. */
  color-scheme: light dark;
}

/* Light colour mode. */
:root,
[data-bs-theme="light"] {
  /* Brand palette. The accent hexes are official: Cisco Blue #049FD9 / #00BCEB
     are Cisco's published brand colours, and #56BA32 / #A1D73C are the stops of
     the Meraki wordmark gradient. The action and status tokens below are those
     same hues darkened (light mode) or lifted (dark mode) until they clear
     WCAG AA on their own background. */
  --meraki-blue: #049fd9;
  --meraki-green: #56ba32;
  --meraki-green-bright: #a1d73c;

  /* #049FD9 is only 3.0:1 on white, so the action shade is a step down the same
     hue: #036f99 keeps white-on-fill and link text at 5.6:1 on white, and 5.0:1
     against the app-bar surface. */
  --bs-primary: #036f99;
  --bs-primary-rgb: 3, 111, 153;
  --bs-link-color: #036f99;
  --bs-link-hover-color: #025a7d;
  --bs-focus-ring-color: rgba(4, 159, 217, .4);
  --bs-body-bg: #ffffff;
  --bs-body-color: #1b2227;
  --bs-secondary-bg: #eef2f5;
  --bs-tertiary-bg: #f4f7f9;
  --bs-border-color: #dde3e8;

  --md-primary: var(--bs-primary);
  --md-on-primary: #ffffff;
  --md-primary-container: #d6eff9;
  --md-on-primary-container: #003a50;
  --md-secondary-container: #dce7ed;
  --md-on-secondary-container: #0d2836;
  --md-error: #b3261e;
  --md-on-error: #ffffff;
  --md-error-container: #ffdad6;
  --md-on-error-container: #410002;
  --md-background: var(--bs-body-bg);
  --md-on-surface: var(--bs-body-color);
  --md-surface-variant: #dde3e8;
  --md-on-surface-variant: #46525b;
  --md-outline: #6f7c85;
  --md-outline-variant: #cbd5db;
  --md-surface-container-lowest: #ffffff;
  --md-surface-container-low: #f4f7f9;
  --md-surface-container: #eef2f5;
  --md-surface-container-high: #e3eaef;
  --md-inverse-surface: #2b3238;
  --md-inverse-on-surface: #eef2f5;

  /* Interaction + status roles: tokenized so dark mode flips them too.
     Status meanings follow the Meraki dashboard: green = online / no alerts,
     yellow = online with active alerts, red = offline, grey = dormant. */
  --md-hover: rgba(3, 111, 153, .08);
  --ok-bg: #e6f6d8;
  --ok-fg: #2f6b18;
  --warn-bg: #fff1cc;
  --warn-fg: #6b4a00;
  --live: #3f8e1e;
  --live-ring: rgba(86, 186, 50, .55);
  --info-bg: #d6eff9;
  --info-fg: #03556f;

  /* Elevation */
  --elev-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --elev-2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
  --elev-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px 1px rgba(0,0,0,.3);
}

/* Dark colour mode. Bootstrap's default primary is far too dark to read on a
   dark surface, so it is lifted to the MD3 dark tone. */
[data-bs-theme="dark"] {
  /* On dark surfaces the darker Cisco Blue is unreadable, so the action colour
     becomes Cisco's other published blue: #00BCEB reads 7.6:1 on the body
     background below. */
  --bs-primary: #00bceb;
  --bs-primary-rgb: 0, 188, 235;
  --bs-link-color: #00bceb;
  --bs-link-hover-color: #7ad9f5;
  --bs-focus-ring-color: rgba(0, 188, 235, .45);
  --bs-body-bg: #101a21;
  --bs-body-color: #e2eaf0;
  --bs-secondary-bg: #16232c;
  --bs-tertiary-bg: #1b2a34;
  --bs-border-color: #2b3a45;

  --md-primary: #00bceb;
  --md-on-primary: #00232e;
  --md-primary-container: #014b60;
  --md-on-primary-container: #b8e9fa;
  --md-secondary-container: #263a48;
  --md-on-secondary-container: #cfe3ee;
  --md-error: #ffb4ab;
  --md-on-error: #690005;
  --md-error-container: #93000a;
  --md-on-error-container: #ffdad6;
  --md-surface-variant: #2b3a45;
  --md-on-surface-variant: #b6c6d1;
  --md-outline: #7d8f9b;
  --md-outline-variant: #2b3a45;
  --md-surface-container-lowest: #0c141a;
  --md-surface-container-low: #131f27;
  --md-surface-container: #18262f;
  --md-surface-container-high: #22323c;
  --md-inverse-surface: #e2eaf0;
  --md-inverse-on-surface: #16232c;

  /* #A1D73C, the bright stop of the Meraki wordmark, is the online colour. */
  --md-hover: rgba(0, 188, 235, .14);
  --ok-bg: #1d4d17;
  --ok-fg: #a1d73c;
  --warn-bg: #4a3200;
  --warn-fg: #ffd48a;
  --live: #a1d73c;
  --live-ring: rgba(161, 215, 60, .5);
  --info-bg: #014b60;
  --info-fg: #b8e9fa;

  /* Dark surfaces get depth from a hairline + a soft shadow, not black blobs. */
  --elev-1: 0 1px 3px rgba(0,0,0,.7), 0 0 0 1px rgba(255,255,255,.05);
  --elev-2: 0 2px 6px rgba(0,0,0,.7), 0 0 0 1px rgba(255,255,255,.07);
  --elev-3: 0 6px 12px rgba(0,0,0,.7), 0 0 0 1px rgba(255,255,255,.09);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--md-background);
  color: var(--md-on-surface);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 400; }
::selection { background: var(--md-primary-container); color: var(--md-on-primary-container); }
input, select, textarea { accent-color: var(--md-primary); }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* Buttons.
   Bootstrap also defines .btn, so its visual defaults are overridden here — its
   --bs-btn-* variables included, since its :hover/:active rules read them and
   would otherwise paint a variant transparent on hover. */
.btn {
  --bs-btn-color: inherit;
  --bs-btn-hover-color: inherit;
  --bs-btn-active-color: inherit;
  --bs-btn-border-color: transparent;
  --bs-btn-hover-border-color: transparent;
  --bs-btn-active-border-color: transparent;
  --bs-btn-bg: transparent;
  --bs-btn-hover-bg: transparent;
  --bs-btn-active-bg: transparent;
  --bs-btn-disabled-opacity: .38;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 24px; border-radius: 20px;
  border: 1px solid transparent;
  color: inherit;
  font-size: 14px; font-weight: 500; letter-spacing: .1px; line-height: 1;
  text-decoration: none; /* .btn used on <a> links too */
  transition: box-shadow .15s, background-color .15s, opacity .15s;
}
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn--filled {
  --bs-btn-bg: var(--md-primary);
  --bs-btn-hover-bg: var(--md-primary);
  --bs-btn-active-bg: var(--md-primary);
  --bs-btn-color: var(--md-on-primary);
  --bs-btn-hover-color: var(--md-on-primary);
  background: var(--md-primary); color: var(--md-on-primary);
}
.btn--filled:hover:not(:disabled) { box-shadow: var(--elev-1); }
.btn--tonal {
  --bs-btn-bg: var(--md-secondary-container);
  --bs-btn-hover-bg: var(--md-secondary-container);
  --bs-btn-color: var(--md-on-secondary-container);
  --bs-btn-hover-color: var(--md-on-secondary-container);
  background: var(--md-secondary-container); color: var(--md-on-secondary-container);
}
.btn--tonal:hover:not(:disabled) { box-shadow: var(--elev-1); }
.btn--outlined {
  --bs-btn-bg: transparent;
  --bs-btn-hover-bg: var(--md-hover);
  --bs-btn-color: var(--md-primary);
  --bs-btn-hover-color: var(--md-primary);
  --bs-btn-border-color: var(--md-outline);
  --bs-btn-hover-border-color: var(--md-outline);
  border: 1px solid var(--md-outline); color: var(--md-primary); background: transparent;
}
.btn--outlined:hover:not(:disabled) { background: var(--md-hover); }
.btn--text {
  --bs-btn-hover-bg: var(--md-hover);
  --bs-btn-color: var(--md-primary);
  --bs-btn-hover-color: var(--md-primary);
  color: var(--md-primary); padding: 0 12px;
}
.btn--text:hover:not(:disabled) { background: var(--md-hover); }
/* Destructive text action (e.g. Delete on a key card). A class rather than an
   inline style, so the console can run under `style-src 'self'`. */
.btn--text-danger {
  --bs-btn-color: var(--md-error);
  --bs-btn-hover-color: var(--md-error);
  color: var(--md-error);
}
.btn--text-danger:hover:not(:disabled) { background: var(--md-hover); }
/* Muted "(optional)" hint inside a field label. Was an inline style. */
.hint-optional { color: var(--md-on-surface-variant); }
.btn--danger {
  --bs-btn-bg: var(--md-error);
  --bs-btn-hover-bg: var(--md-error);
  --bs-btn-color: var(--md-on-error);
  --bs-btn-hover-color: var(--md-on-error);
  background: var(--md-error); color: var(--md-on-error);
}
.btn--danger:hover:not(:disabled) { box-shadow: var(--elev-1); }

/* Text fields / selects */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { font-size: 13px; font-weight: 500; color: var(--md-on-surface-variant); }
.field input, .field select, .field textarea {
  height: 52px; padding: 0 14px; font: inherit; font-size: 16px;
  border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
  background: transparent; color: var(--md-on-surface);
}
/* A comment is prose, so it wraps: same skin as the other fields, but only the
   top padding is fixed and the box may be resized vertically. */
.field textarea {
  height: auto; min-height: 64px; padding: 14px;
  line-height: 1.4; resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--md-primary); border-width: 2px; padding: 0 13px;
}
.field textarea:focus { padding: 13px; }
.field .helper { font-size: 12px; color: var(--md-on-surface-variant); min-height: 16px; }

/* Top app bar */
.top-app-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 16px;
  background: var(--md-surface-container); color: var(--md-on-surface);
  box-shadow: var(--elev-1);
}
.top-app-bar__title {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 500;
}
/* Brand mark: the Meraki wordmark gradient, as a small logo square. */
.top-app-bar__title::before {
  content: ''; width: 12px; height: 12px; border-radius: 4px; flex: none;
  background: linear-gradient(135deg, var(--meraki-green-bright), var(--meraki-green));
}
.top-app-bar__actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
/* Live-update indicator (WebSocket); hidden until the socket reports in. */
.realtime-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--md-on-surface-variant);
}
.realtime-status::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--md-outline);
}
.realtime-status[data-state="live"]::before { background: var(--live); }
.realtime-status[data-state="off"]::before { background: var(--md-error); }

/* Content layout */
.content { max-width: 1120px; margin: 0 auto; padding: 24px 16px 96px; }
.content__header { margin-bottom: 24px; }
.headline { font-size: 28px; margin: 0 0 4px; }
.supporting { color: var(--md-on-surface-variant); margin: 0; }

/* Two-column layout with a left menu bar.
   The keys and clients pages keep their controls (search, filters, window/status
   chips) in a menu bar BESIDE the list instead of above it: the controls are all
   in one place, the list gets the full height of the window, and the bar is sticky
   — so the search box you reach for constantly never scrolls out of view. Below
   900px there is no room for a column beside the content, so the menu stacks above
   it and scrolls away with the page like any other block. */
.layout {
  display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px;
  align-items: start;
  max-width: 1440px; margin: 0 auto; padding: 24px 16px 96px;
}
/* Let the content column shrink: without this, a wide table or card pushes the
   grid wider than the viewport instead of scrolling inside its own column. */
.layout__main { min-width: 0; }
.menu-bar {
  position: sticky; top: 80px; /* clears the sticky app bar */
  display: flex; flex-direction: column; gap: 14px;
  /* A short window would otherwise put the last filter out of reach. */
  max-height: calc(100vh - 96px); overflow-y: auto;
  padding: 14px;
  background: var(--md-surface-container-low);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-md);
}
.menu-bar__title { margin: 0; font-size: 14px; font-weight: 500; color: var(--md-on-surface); }
.menu-bar__group { display: flex; flex-direction: column; gap: 6px; }
.menu-bar__label {
  margin: 0; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--md-on-surface-variant);
}
/* One control per row: there is no room for a label beside a select in 260px, and
   a full-width control is easier to hit than a narrow one. */
.menu-bar .search-bar { flex-direction: column; align-items: stretch; gap: 6px; margin-top: 0; }
.menu-bar .search-bar input { height: 40px; font-size: 14px; }
.menu-bar .filter-bar {
  flex-direction: column; align-items: stretch; flex-wrap: nowrap; gap: 10px; margin-top: 0;
}
.menu-bar .filter-field {
  flex-direction: column; align-items: stretch; gap: 4px; white-space: normal;
}
.menu-bar .filter-field select { width: 100%; height: 36px; }
.menu-bar .range-bar { flex-direction: column; align-items: stretch; gap: 8px; margin-top: 0; }
.menu-bar .range-field input { width: 100%; }
.menu-bar .range-hint { padding-bottom: 0; }
.menu-bar .btn { width: 100%; }

@media (max-width: 900px) {
  /* Stack the menu above the list and let it scroll with the page. */
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-bar { position: static; max-height: none; }
  .menu-bar .search-bar { flex-direction: row; align-items: center; }
  .menu-bar .filter-bar {
    flex-direction: row; flex-wrap: wrap; align-items: center;
  }
  .menu-bar .filter-field { flex-direction: row; align-items: center; }
  .menu-bar .filter-field select { width: auto; }
  .menu-bar .range-bar { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
  .menu-bar .btn { width: auto; }
  .menu-bar .search-bar input { height: 52px; font-size: 16px; }
}

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
}
.search-bar input {
  flex: 1; height: 52px; padding: 0 14px; font: inherit; font-size: 16px;
  border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
  background: transparent; color: var(--md-on-surface);
}
.search-bar input:focus {
  outline: none; border-color: var(--md-primary); border-width: 2px; padding: 0 13px;
}
.search-count { margin-top: 8px; }

/* Connected clients on key cards + report */
.client-list {
  margin: 0; padding: 0 0 0 14px; list-style: none;
  max-height: 140px; overflow-y: auto;
}
.client-list li { display: flex; flex-direction: column; gap: 1px; padding: 2px 0; }
.client-list li > span:first-child { font-size: 13px; color: var(--md-on-surface); }
.client-detail { font-size: 12px; color: var(--md-on-surface-variant); }
.client-list--report { max-height: 200px; }
/* Saved-history devices on a key card: useful, but visually secondary. */
.client-list--history {
  border-left: 2px solid var(--md-outline-variant);
  margin-left: 2px; padding-left: 12px;
}

/* Report + Connected clients pages (shared table styling) */
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn { padding: 0 8px; font-size: 12px; }
/* Compact Block action inside a key card's live client list. */
.client-block { align-self: flex-start; padding: 0 8px; font-size: 12px; color: var(--md-error); }
/* Row actions sit together: the allow-list edit beside the Meraki policy one. */
.client-row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.client-allow { padding: 0 8px; font-size: 12px; color: var(--md-primary); }
.client-unallow { padding: 0 8px; font-size: 12px; color: var(--md-on-surface-variant); }
.report-actions,
.page-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.report-table__grid,
.data-table {
  width: 100%; max-width: 1120px; border-collapse: collapse;
  background: var(--md-surface-container-lowest);
}
.report-table__grid th,
.data-table th {
  text-align: left; padding: 10px 12px; font-weight: 500;
  background: var(--md-surface-container); color: var(--md-on-surface-variant);
  border-bottom: 1px solid var(--md-outline-variant);
}
.report-table__grid td,
.data-table td {
  padding: 10px 12px; vertical-align: top;
  border-bottom: 1px solid var(--md-outline-variant); font-size: 14px;
}
.report-table__grid tbody tr:nth-child(even),
.data-table tbody tr:nth-child(even) { background: var(--md-surface-container-low); }
.report-none { color: var(--md-on-surface-variant); }

/* Report page: the at-a-glance tiles, the exceptions list and the per-key counts.
   Everything here has to survive both a screen and a sheet of paper, so it uses
   existing tokens (which the print block below flattens to ink) rather than
   screen-only effects. */
.report-placeholder { max-width: 720px; margin-top: 16px; }
.report-section-title {
  font-size: 16px; font-weight: 500; color: var(--md-on-surface);
  margin: 24px 0 10px;
}
.report-tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px; max-width: 1120px;
}
.report-tile {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--md-surface-container-low);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-md); padding: 10px 12px;
}
.report-tile__value { font-size: 24px; line-height: 1.1; color: var(--md-on-surface); }
.report-tile--danger .report-tile__value { color: var(--md-error); }
.report-tile--warn .report-tile__value { color: var(--warn-fg); }
.report-tile__label { font-size: 13px; color: var(--md-on-surface); }
.report-tile__hint { font-size: 12px; color: var(--md-on-surface-variant); }
.report-exceptions {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px; max-width: 1120px;
}
.report-exceptions li {
  padding: 8px 12px; font-size: 14px;
  background: var(--md-surface-container-low);
  border-left: 3px solid var(--md-outline-variant);
  border-radius: var(--radius-sm);
}
.report-exceptions li.report-exception--danger { border-left-color: var(--md-error); }
.report-exceptions li.report-exception--warn { border-left-color: var(--warn-fg); }
/* A count above a device list, so a cell reads "2 devices" before it reads names. */
.report-count { font-size: 13px; color: var(--md-on-surface); margin-bottom: 2px; }
/* MACs, in the same monospace the passphrase reveal uses. */
.report-mac {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--md-on-surface);
}

/* Connected clients page: window chips + inline toggles */
.filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 12px;
}
.filter-chip {
  display: inline-flex; align-items: center; height: 32px; padding: 0 14px;
  border: 1px solid var(--md-outline); border-radius: 16px;
  font-size: 13px; font-weight: 500; color: var(--md-on-surface-variant);
  background: transparent;
  transition: background-color .15s, color .15s, border-color .15s;
}
.filter-chip:hover { background: var(--md-hover); }
.filter-chip[aria-pressed="true"] {
  background: var(--md-secondary-container); color: var(--md-on-secondary-container);
  border-color: var(--md-secondary-container);
}
.filter-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--md-on-surface-variant); white-space: nowrap;
}

/* Dropdown filters (keys + clients views): label and control on one line. */
.filter-field {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--md-on-surface-variant); white-space: nowrap;
}
.filter-field select {
  height: 32px; padding: 0 8px; font: inherit; font-size: 13px;
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
  background: var(--md-surface-container-lowest);
}
.filter-field select:focus {
  outline: none; border-color: var(--md-primary); border-width: 2px;
}

/* Custom date-range controls on the Connected clients page */
.range-bar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  margin-top: 12px;
}
.range-field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--md-on-surface-variant);
}
.range-field input {
  height: 40px; padding: 0 12px; font: inherit; font-size: 14px;
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
  background: transparent;
}
.range-field input:focus {
  outline: none; border-color: var(--md-primary); border-width: 2px; padding: 0 11px;
}
.range-hint {
  font-size: 12px; color: var(--md-on-surface-variant); padding-bottom: 10px;
}

@media print {
  .top-app-bar, .report-actions, .page-actions, .filter-bar, .range-bar, #snackbar, .fab,
  .source-line, .theme-control, .report-placeholder, .report-viewing, .menu-bar { display: none; }
  .content { padding: 16px; }
  /* The controls are gone on paper, so the list gets the whole page. */
  .layout { display: block; max-width: none; padding: 16px; }
  .report-table__grid td, .data-table td { overflow: visible; }
  .client-list { max-height: none; overflow: visible; }
  /* A report runs to several pages, so repeat the header row on each one and never
     split a row across two sheets — half a device row is unreadable on paper. */
  .report-table__grid, .data-table { page-break-inside: auto; }
  .report-table__grid thead, .data-table thead { display: table-header-group; }
  .report-table__grid tr, .data-table tr { page-break-inside: avoid; }
  .report-tile, .report-exceptions li { page-break-inside: avoid; }
  /* The tables are wider than a portrait page: let them use the full width. */
  .report-table__grid, .data-table, .report-tiles, .report-exceptions { max-width: none; }
  .report-section-title { page-break-after: avoid; }
  table { font-size: 11px; }
  /* Reports go on paper: print light even when the app is running in dark mode. */
  [data-bs-theme="dark"] {
    --md-background: #ffffff;
    --md-on-surface: #000000;
    --md-on-surface-variant: #333333;
    --md-surface-container-lowest: #ffffff;
    --md-surface-container-low: #f7f7f7;
    --md-surface-container: #eeeeee;
    --md-surface-container-high: #e6e6e6;
    --md-surface-variant: #eeeeee;
    --md-outline: #6f7c85;
    --md-outline-variant: #bbbbbb;
    --ok-bg: #e6f6d8;
    --ok-fg: #2f6b18;
    --warn-bg: #fff1cc;
    --warn-fg: #6b4a00;
    --live: #3f8e1e;
    --live-ring: rgba(86, 186, 50, .55);
    --info-bg: #d6eff9;
    --info-fg: #03556f;
  }
}

/* Key grid + cards. Bootstrap defines .card too (with its own border and
   --bs-card-* variables), so those are neutralized here. */
.key-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  --bs-card-bg: var(--md-surface-container-lowest);
  --bs-card-border-color: transparent;
  --bs-card-border-width: 0;
  --bs-card-border-radius: var(--radius-md);
  background: var(--md-surface-container-lowest);
  border: 0; border-radius: var(--radius-md);
  box-shadow: var(--elev-1);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
  transition: box-shadow .15s;
}
.card:hover { box-shadow: var(--elev-2); }
.card__title { font-size: 16px; font-weight: 500; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card__meta { display: flex; flex-direction: column; gap: 4px; color: var(--md-on-surface-variant); font-size: 13px; }
.card__meta strong { color: var(--md-on-surface); font-weight: 500; }
.card__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: 8px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.chip--active { background: var(--ok-bg); color: var(--ok-fg); }
.chip--expiring { background: var(--warn-bg); color: var(--warn-fg); }
.chip--expired { background: var(--md-error-container); color: var(--md-on-error-container); }
/* Client connection status on the Connected clients page. */
.chip--online { background: var(--ok-bg); color: var(--ok-fg); }
.chip--offline { background: var(--md-surface-container-high); color: var(--md-on-surface-variant); }
/* MAC allow-list + compromise state on the key cards. */
.chip--compromised { background: var(--md-error); color: var(--md-on-error); }
/* "A device is connected right now" — green, with a pulsing dot so it reads as
   a live state rather than a static label. This is also the key card's usage
   indicator for a key in use, so the two can never say different things. */
.chip--live { background: var(--ok-bg); color: var(--ok-fg); }
/* The key card's usage indicator: how a key is being used, in one chip. Green
   with a pulsing dot (`.chip--live`) is "in use now"; a key whose devices have
   gone quiet is the information blue; one no device has ever used is neutral
   grey; and a chip with nothing to say is outlined rather than filled, so
   "unknown" cannot be mistaken for a state. */
.chip--usage-past { background: var(--info-bg); color: var(--info-fg); }
.chip--usage-never { background: var(--md-surface-container-high); color: var(--md-on-surface-variant); }
.chip--usage-unknown { background: transparent; color: var(--md-on-surface-variant); border: 1px dashed var(--md-outline); }
/* A chip that opens a panel is a control, not just a label. */
button.chip { cursor: pointer; }
button.chip:hover { box-shadow: var(--elev-1); }
button.chip:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 1px; }
/* An inline text button: a count you can open, without a 40px row of its own. */
.btn--inline { height: auto; padding: 0 6px; border-radius: 8px; }
/* The panel replaces the card's old inline lists, so it can afford to be longer. */
.client-list--panel { max-height: 32vh; }
/* Offending devices: a red rule, matching the chip that opened the list. */
.client-list--compromised {
  border-left: 2px solid var(--md-error);
  margin-left: 2px; padding-left: 12px;
}
/* Section headings inside the clients panel: small labels, not document titles. */
.panel-section {
  margin: 16px 0 4px; font-size: 13px; font-weight: 500;
  color: var(--md-on-surface-variant);
}
.panel-section:first-child { margin-top: 0; }
.chip__dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--live);
  box-shadow: 0 0 0 0 var(--live-ring);
  animation: live-pulse 2s ease-out infinite;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 var(--live-ring); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .chip__dot { animation: none; }
}
/* Meraki device policy badges on client rows: blocked is the alarming one, any
   other assigned policy is informational. */
.chip--blocked { background: var(--md-error); color: var(--md-on-error); }
.chip--policy { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }

/* "Where this data comes from" line: the D1 mirror vs a live Meraki read, and
   the loading state while a read is in flight. */
.source-line {
  display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 0;
  font-size: 12px; color: var(--md-on-surface-variant);
}
.source-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip--source { height: 20px; padding: 0 8px; border-radius: 6px; font-size: 11px; }
.chip--source-d1 { background: var(--md-surface-container-high); color: var(--md-on-surface-variant); }
.chip--source-meraki { background: var(--info-bg); color: var(--info-fg); }
.chip--source-idle { background: transparent; color: var(--md-on-surface-variant); border: 1px dashed var(--md-outline); }
.chip--source-error { background: var(--md-error-container); color: var(--md-on-error-container); }
.chip--source-loading { background: var(--md-surface-container-high); color: var(--md-on-surface-variant); }
.chip--source-loading::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: source-spin .8s linear infinite;
}
@keyframes source-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .chip--source-loading::before,
  .btn[aria-busy="true"]::before { animation: none; border-top-color: currentColor; }
}

/* Busy states. A re-read keeps what is on screen and says it is working:
   the button gets a spinner, the list it is refreshing dims rather than
   blanking (see `aria-busy` in loadClients/importFromMeraki). */
.btn[aria-busy="true"] { opacity: .7; }
.btn[aria-busy="true"]::before {
  content: ''; width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: source-spin .8s linear infinite;
}
#clients-table[aria-busy="true"] { opacity: .55; cursor: progress; }

/* Theme control (Bootstrap colour modes). Sits in the app bar, and floats in the
   corner of the login page, which has no bar of its own. */
.theme-control {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--md-on-surface-variant); white-space: nowrap;
}
.theme-control select {
  height: 32px; padding: 0 8px; font: inherit; font-size: 13px;
  color: var(--md-on-surface); background: var(--md-surface-container-lowest);
  border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
}
.theme-control select:focus {
  outline: none; border-color: var(--md-primary); border-width: 2px;
}
.login-theme { position: fixed; top: 16px; right: 16px; z-index: 5; }
/* Live vs saved-history client lists: green rule against the grey one. */
.client-list--live {
  border-left: 2px solid var(--live);
  margin-left: 2px; padding-left: 12px;
}
.chip-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card__alert {
  border-left: 3px solid var(--md-error); border-radius: 4px;
  padding: 6px 8px; font-size: 12px;
  background: var(--md-error-container); color: var(--md-on-error-container);
}
.mac-editor { display: flex; align-items: center; gap: 8px; }
.mac-editor input { flex: 1; min-width: 0; }
.mac-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 8px 0 0; }
.mac-list li {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 10px; border-radius: 14px; font-size: 12px;
  background: var(--md-surface-container-high); color: var(--md-on-surface-variant);
}
.mac-list li button { padding: 0 8px; font-size: 12px; }

/* FAB */
.fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 20;
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--md-primary-container); color: var(--md-on-primary-container);
  font-size: 28px; line-height: 1; box-shadow: var(--elev-3);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s;
}
.fab:hover { transform: translateY(-1px); }

/* The saved-report panel is a table, so it needs more room than a form dialog and
   scrolls inside it. */
#report-history-dialog { width: min(94vw, 880px); max-height: 85vh; }
.report-history { overflow: auto; }
.report-history .data-table { max-width: none; }

/* History on screen: the banner that keeps a frozen report from looking stale.
   Hidden in print — the report itself is what goes on paper. */
.report-viewing {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  margin: 16px 0 0; padding: 10px 14px;
  max-width: 1120px;
  background: var(--info-bg); color: var(--info-fg);
  border-radius: var(--radius-md);
  font-size: 14px;
}
.report-viewing .btn { flex: 0 0 auto; }

/* Dialogs */
dialog.dialog {
  border: none; border-radius: var(--radius-lg); padding: 24px;
  width: min(92vw, 440px);
  background: var(--md-surface-container-high); color: var(--md-on-surface);
  box-shadow: var(--elev-3);
}
dialog.dialog::backdrop { background: rgba(0,0,0,.5); }
/* The corner ✕ every dialog carries (injected by `decorateDialogs`). A modal
   <dialog> is itself positioned, so this anchors to its padding box. */
.dialog__close {
  position: absolute; top: 8px; right: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border-radius: 50%;
  font-size: 20px; line-height: 1;
  color: var(--md-on-surface-variant);
  background: transparent;
}
.dialog__close:hover { background: var(--md-hover); color: var(--md-on-surface); }
.dialog__close:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 1px; }
.dialog h2 { margin: 0 0 16px; padding-right: 36px; font-size: 22px; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
/* The connected-clients panel lists devices with their addresses, so it takes a
   little more room than a form dialog, and a long list scrolls inside it. */
#connected-dialog { width: min(92vw, 560px); max-height: 85vh; }
/* The bulk-create result puts a key's name beside its passphrase, and a long batch
   has to scroll inside the panel rather than off the screen. */
#bulk-result-dialog { width: min(92vw, 560px); max-height: 85vh; }

/* Passphrase box */
.passphrase-box {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--md-surface-variant); border-radius: var(--radius-sm); padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all;
}
/* A passphrase in the bulk-create result: the same monospaced treatment as the
   reveal box, because these are read off the screen onto a hand-out list. */
.bulk-passphrase { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Snackbar */
.snackbar {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(16px);
  background: var(--md-inverse-surface); color: var(--md-inverse-on-surface);
  padding: 14px 16px; border-radius: var(--radius-sm); box-shadow: var(--elev-3);
  opacity: 0; pointer-events: none; z-index: 50; max-width: min(90vw, 480px);
  transition: opacity .2s, transform .2s;
}
.snackbar--show { opacity: 1; transform: translateX(-50%) translateY(0); }
.snackbar--error { background: var(--md-error); color: var(--md-on-error); }

/* Empty state */
.empty-state { text-align: center; padding: 72px 16px; color: var(--md-on-surface-variant); }
.empty-state .icon { font-size: 48px; margin-bottom: 8px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  position: relative; overflow: hidden;
  width: 100%; max-width: 400px;
  background: var(--md-surface-container-lowest);
  border-radius: var(--radius-lg); box-shadow: var(--elev-2); padding: 32px;
}
/* Same brand mark as the app bar, as a rule across the top of the card. */
.login-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--meraki-green-bright), var(--meraki-green));
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card .subtitle { color: var(--md-on-surface-variant); margin: 0 0 24px; }
.login-card .btn { width: 100%; }
/* Entra ID SSO sits below the password form, behind a rule with an "or" label. */
.login-divider {
  display: flex; align-items: center; gap: 12px; margin: 24px 0 16px;
  font-size: 12px; color: var(--md-on-surface-variant);
}
.login-divider::before,
.login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--md-outline-variant);
}
.login-divider span { text-transform: lowercase; }
/* Signed-in operator in the app bar (hidden until /auth/me reports). */
.top-app-bar__user {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 240px; height: 32px; padding: 0 10px; border-radius: 16px;
  background: var(--md-surface-container); color: var(--md-on-surface);
  font-size: 12px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* A green dot marks a live session; the name/title says whose. */
.top-app-bar__user::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--live); flex: none;
}
.top-app-bar__user-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Audit log page: filters, event chips and the one-line facts beneath a summary. */
.table-wrap { overflow-x: auto; }
.audit-count { margin: 12px 0 8px; font-size: 13px; }
.filter-field input[type="search"],
.filter-field input[type="datetime-local"] {
  height: 32px; padding: 0 8px; font: inherit; font-size: 13px;
  color: var(--md-on-surface); background: var(--md-surface-container-lowest);
  border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
}
.filter-field input:focus {
  outline: none; border-color: var(--md-primary); border-width: 2px;
}
.audit-when { white-space: nowrap; color: var(--md-on-surface-variant); font-size: 13px; }
.audit-who { font-weight: 500; }
.audit-provider { display: block; font-size: 11px; color: var(--md-on-surface-variant); }
.audit-details {
  margin-top: 3px; font-size: 12px; color: var(--md-on-surface-variant);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.audit-ip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; white-space: nowrap;
}
.chip--audit { background: var(--md-surface-container-high); color: var(--md-on-surface); }
.chip--audit-ok { background: var(--ok-bg); color: var(--ok-fg); }
.chip--audit-danger { background: var(--md-error-container); color: var(--md-on-error-container); }
.chip--audit-warn { background: var(--warn-bg); color: var(--warn-fg); }

@media (max-width: 720px) {
  .top-app-bar {
    height: auto; min-height: 64px; flex-wrap: wrap; align-content: center;
    gap: 4px; padding-top: 8px; padding-bottom: 8px;
  }
  .top-app-bar__actions { justify-content: flex-end; }
}

@media (max-width: 600px) {
  .headline { font-size: 24px; }
  .top-app-bar__title { font-size: 18px; }
}
