/* ─── Modern UI polish — applied to every renderPage()-served page ─────────
 *
 * Targets the common class names already in use across the app:
 *   .topbar / .brand / .nav-tab           — top navigation
 *   .it-subnav / .it-sub-tab              — IT sub-nav strip
 *   .card / .sum-card / .mini-card /      — KPI / summary cards
 *   .res-card / .eng-stat /
 *   .hd-chart-card                         — chart panels on dashboards
 *   .btn / .btn-ghost / .icon-btn /        — buttons
 *   .qa-btn / .preset / .preset-btn
 *   .status-badge / .status-pill /
 *   .alert-count / .it-sub-badge           — badges
 *   .modal-overlay / .modal                — modals
 *
 * Goals: subtle depth (gradients + soft shadows), refined hover/active
 * states, smoother transitions, animated badges. Accessibility kept (focus
 * outlines preserved, color contrast maintained).
 *
 * Light + dark themes both supported via the existing CSS variables. Uses
 * rgba() over color-mix() for broader browser compatibility.
 */

/* ── Topbar polish ───────────────────────────────────────────────────────── */
/* ===== Design-system foundation (consolidated) ===== */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

/* Theme variables — single source of truth. This file loads AFTER each page's
   inline <style>, so these identical values are a no-op on legacy pages but
   let converted pages drop their inline :root. The tenant accent set at
   runtime by nav-init.js still wins (inline style on <html>). */
:root{--bg:#0d1117;--surface:#161b22;--border:#21262d;--text:#c9d1d9;--muted:#8b949e;--accent:#58a6ff;--green:#3fb950;--red:#f85149;--orange:#e3b341;--head:#0d1117}
[data-theme="light"]{--bg:#f6f8fa;--surface:#fff;--border:#d0d7de;--text:#24292f;--muted:#57606a;--accent:#0969da;--green:#1a7f37;--red:#cf222e;--orange:#9a6700;--head:#f6f8fa}

/* Shared components not previously centralised — values match the canonical
   inline copies used across pages (zero-variation per audit). */
.kpi-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:14px;margin-bottom:18px}
.kpi{background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:14px 18px}
.kpi .label{font-size:10.5px;text-transform:uppercase;letter-spacing:.5px;color:var(--muted);font-weight:600;margin-bottom:6px}
.kpi .value{font-size:24px;font-weight:700;font-family:'IBM Plex Mono',monospace}
.kpi.bad .value{color:var(--red)}.kpi.warn .value{color:var(--orange)}.kpi.good .value{color:var(--green)}
.pill{display:inline-block;padding:1px 8px;border-radius:10px;font-size:10.5px;border:1px solid var(--border)}
.pill.bad{color:var(--red);border-color:var(--red)}.pill.warn{color:var(--orange);border-color:var(--orange)}.pill.ok{color:var(--green);border-color:var(--green)}
.empty{padding:50px;text-align:center;color:var(--muted)}
.form-grid{display:grid;grid-template-columns:140px 1fr;gap:10px 14px;align-items:center;margin-top:8px}
.form-grid label{font-size:12px;color:var(--muted);text-align:right}
/* Toggle-style modal (the .modal-bg pattern used by ~46 pages). Width is left
   to the page (varies 600–880px) so wider modals aren't shrunk. */
.modal-bg{position:fixed;inset:0;background:rgba(0,0,0,.7);display:none;align-items:center;justify-content:center;z-index:1000;padding:16px}
.modal-bg.on{display:flex}
.modal-card{background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:22px;max-width:100%;max-height:90vh;overflow:auto}
.toast{position:fixed;bottom:16px;right:16px;background:var(--surface);color:var(--text);border:1px solid var(--border);padding:12px 16px;border-radius:6px;box-shadow:0 6px 20px rgba(0,0,0,.35);z-index:10000}

/* Responsive / mobile — applies to EVERY page (this file overrides inline),
   so dense tables get horizontal scroll, KPIs go 2-up, modals near full-width,
   and touch targets grow. Fixes the field-staff phone experience globally. */
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}
@media (max-width:760px){
  .section{padding:12px 10px}
  .card table, .section > table, .table-wrap > table{display:block;overflow-x:auto;white-space:nowrap}
  .kpi-grid{grid-template-columns:1fr 1fr !important}
  .btn, .icon-btn{min-height:36px}
  .modal-card, .modal-overlay .modal, .modal{width:96vw !important;max-width:96vw}
  .filters{flex-wrap:wrap}
}

/* ── Topbar polish ── */
.topbar {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 130%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 6px 14px -10px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  /* Force single-row flex layout. !important on every property because
     some pre-existing pages have their own .topbar block whose CSS is
     loaded AFTER this file in the cascade (per-page <style> blocks come
     after the auto-injected <link>). Without !important the per-page
     block wins source-order, but it doesn't set flex-wrap, so the
     default browser flex behavior allows wrapping on overflow. */
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  gap: 12px;
  /* Internal horizontal scroll keeps the document body from getting a
     scrollbar. We hide the visible scrollbar UI below — content stays
     reachable by mouse-wheel/swipe but no ugly grey strip appears under
     the topbar. */
  overflow-x: auto;
  overflow-y: visible;
}
/* Hide the horizontal-scroll affordance entirely — when the topbar
   overflows we let it overflow silently rather than show a permanent
   scrollbar strip (which was creating a visible dark bar under the
   topbar even when content fit). Children stay reachable via the
   :focus scroll behavior or arrow-key tabbing. */
.topbar { scrollbar-width: none; }
.topbar::-webkit-scrollbar { display: none; }
.brand {
  letter-spacing: -0.3px;
  text-shadow: 0 0 14px rgba(88, 166, 255, 0.18);
  transition: filter 0.2s ease;
}
.brand:hover { filter: brightness(1.15); }

/* Nav icons — small visual anchors before each label */
.nav-icon {
  display: inline-block;
  margin-right: 6px;
  font-size: 0.95em;
  opacity: 0.7;
  transition: opacity 0.15s ease, transform 0.15s ease;
  vertical-align: middle;
}
.nav-tab:hover .nav-icon,
.nav-tab.active .nav-icon,
.it-sub-tab:hover .nav-icon,
.it-sub-tab.active .nav-icon {
  opacity: 1;
  transform: scale(1.05);
}

/* Nav tabs — animated underline + better hover */
.nav-tab {
  position: relative;
  transition: color 0.15s ease;
}
.nav-tab::after {
  content: '';
  position: absolute;
  bottom: 0; left: 50%; right: 50%;
  height: 2px;
  background: var(--accent);
  transition: left 0.2s ease, right 0.2s ease, opacity 0.2s ease;
  opacity: 0;
}
.nav-tab:hover::after,
.nav-tab.active::after { left: 8px; right: 8px; opacity: 1; }
.nav-tab:hover { color: var(--text); }

/* ── IT sub-nav ──────────────────────────────────────────────────────────── */
.it-subnav {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%) !important;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 10px -8px rgba(0, 0, 0, 0.18);
}
.it-subnav .it-sub-tab {
  position: relative;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.it-subnav .it-sub-tab:hover { transform: translateY(-1px); }

/* ── Badges — subtle pulse so the eye catches new alerts ─────────────────── */
.alert-count,
.it-sub-badge,
#helpdesk-badge {
  background: linear-gradient(135deg, #f85149 0%, #d73a3a 100%) !important;
  box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.55);
  animation: badge-pulse 2.4s ease-in-out infinite;
  font-variant-numeric: tabular-nums;
}
@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.5); }
  50%      { box-shadow: 0 0 0 5px rgba(248, 81, 73, 0); }
}

/* ── Cards — depth + lift on hover ───────────────────────────────────────── */
.card,
.sum-card,
.mini-card,
.res-card,
.eng-stat,
.hd-chart-card {
  position: relative;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.018) 0%, transparent 60%);
}
[data-theme="light"] .card,
[data-theme="light"] .sum-card,
[data-theme="light"] .mini-card,
[data-theme="light"] .res-card,
[data-theme="light"] .eng-stat,
[data-theme="light"] .hd-chart-card {
  background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.012) 0%, transparent 60%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Hoverable cards: lift + glow */
.card:hover,
.sum-card-clickable:hover,
.mini-card:hover,
.res-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent) !important;
  box-shadow: 0 8px 18px -8px rgba(88, 166, 255, 0.28),
              0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Cursor for any clickable summary/KPI card. Defined globally so per-page
   CSS doesn't have to repeat it; pages just add the .sum-card-clickable
   class (or use <a class="card">) to opt-in. */
.sum-card-clickable, a.card, a.res-card { cursor: pointer; }

/* Cards with semantic color — get a tinted top accent strip */
.card.green   { box-shadow: inset 3px 0 0 rgba(63, 185, 80, 0.65); }
.card.red     { box-shadow: inset 3px 0 0 rgba(248, 81, 73, 0.7); }
.card.orange  { box-shadow: inset 3px 0 0 rgba(227, 179, 65, 0.7); }
.card.muted   { box-shadow: inset 3px 0 0 rgba(139, 148, 158, 0.45); }
.mini-card.green   { box-shadow: inset 3px 0 0 rgba(63, 185, 80, 0.65); }
.mini-card.red     { box-shadow: inset 3px 0 0 rgba(248, 81, 73, 0.7); }
.mini-card.orange  { box-shadow: inset 3px 0 0 rgba(227, 179, 65, 0.7); }
.mini-card.muted   { box-shadow: inset 3px 0 0 rgba(139, 148, 158, 0.45); }
.eng-stat.green    { box-shadow: inset 3px 0 0 rgba(63, 185, 80, 0.65); }
.eng-stat.red      { box-shadow: inset 3px 0 0 rgba(248, 81, 73, 0.7); }
.eng-stat.orange   { box-shadow: inset 3px 0 0 rgba(227, 179, 65, 0.7); }

.card .num,
.sum-num,
.mini-card .num,
.res-total,
.eng-stat .num {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  font-feature-settings: 'tnum' 1;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  background: linear-gradient(135deg, var(--accent) 0%, #4690d8 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1),
              inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition: transform 0.1s ease, box-shadow 0.18s ease, opacity 0.15s ease;
  font-weight: 600;
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px -4px rgba(88, 166, 255, 0.4),
              inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: transparent !important;
  box-shadow: none;
  font-weight: 500;
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(88, 166, 255, 0.1) !important;
  border-color: var(--accent);
  color: var(--text);
  transform: none;
}

.btn-danger {
  background: linear-gradient(135deg, #f85149 0%, #c43b35 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-danger:hover:not(:disabled) {
  box-shadow: 0 6px 14px -4px rgba(248, 81, 73, 0.45);
}
.btn-green {
  background: linear-gradient(135deg, #3fb950 0%, #2e8e3a 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.btn-green:hover:not(:disabled) {
  box-shadow: 0 6px 14px -4px rgba(63, 185, 80, 0.4);
}

.icon-btn {
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.icon-btn:hover:not(:disabled) {
  background: rgba(88, 166, 255, 0.07);
  border-color: var(--accent);
  color: var(--text);
}

/* ── Filter chips / preset buttons ───────────────────────────────────────── */
.qa-btn,
.preset,
.preset-btn {
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.qa-btn.active,
.preset.active,
.preset-btn.active {
  background: linear-gradient(135deg, var(--accent) 0%, #4690d8 100%) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
  box-shadow: 0 2px 6px -2px rgba(88, 166, 255, 0.45);
}

.filter-row label.on {
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.18) 0%, rgba(88, 166, 255, 0.08) 100%) !important;
  border-color: var(--accent) !important;
  color: var(--text) !important;
  font-weight: 600;
}

/* ── Status / priority pills — subtle gradient ───────────────────────────── */
.status-badge,
.status-pill,
.sla-pill,
.spec-pill,
.role-pill,
.action-pill {
  font-feature-settings: 'tnum' 1;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, transparent 100%);
  letter-spacing: 0.5px;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
thead th {
  background-image: linear-gradient(180deg, var(--head) 0%, var(--bg) 110%) !important;
  font-weight: 700 !important;
}
tbody tr {
  transition: background 0.1s ease;
}

/* Sticky-thead bug guard — when a list page contains its table in a
   scrollable wrap (overflow:auto / overflow-y:auto), the sticky thead
   must pin to the wrap's top edge (top:0), NOT to the page topbar
   height. Pages that incorrectly set top:44px would overlap with the
   IT sub-nav. Forcing top:0 here is safe because: (a) thead sticky is
   relative to its scrolling ancestor, so 0 means "top of wrap"; (b)
   pages that DO scroll the page (no inner wrap) have non-sticky thead
   anyway. */
[class*="-wrap"] > table > thead > tr > th[style*="sticky"],
[class*="-wrap"] > table thead th {
  /* No-op; the actual top: enforcement lives on the per-page selectors
     where applicable. This block kept as a hook for future defense. */
}

/* ── Modals — backdrop blur ──────────────────────────────────────────────── */
.modal-overlay {
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  background: rgba(0, 0, 0, 0.6);
}
.modal {
  box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.5),
              0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

/* ── Inputs / selects — focus glow ───────────────────────────────────────── */
input:focus, select:focus, textarea:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

/* ── Sub-nav badge animation ─────────────────────────────────────────────── */
.it-sub-badge {
  animation: badge-pulse 2.4s ease-in-out infinite;
}

/* Reduce motion preference — respect it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}

/* ── Mobile + tablet responsiveness pass ─────────────────────────────────
 * Touch-friendly tap targets, single-column page layouts on narrow viewports,
 * tables → cards stacked, modals full-width. Targets phones (<= 640px)
 * with a softer tablet break at <= 980px.
 * --------------------------------------------------------------------- */

@media (max-width: 980px) {
  /* Topbar — keep nav clickable but compress padding. */
  .topbar { gap: 8px !important; padding: 0 10px !important; }
  .nav-tab { padding: 12px 5px !important; font-size: 11px !important; }
  .it-subnav { overflow-x: auto !important; padding: 0 8px !important; gap: 4px !important; }
  .it-sub-tab { padding: 6px 8px !important; font-size: 11px !important; }
  /* Page wrappers stop demanding 24px side padding. */
  .wrap, .page-wrap { padding: 12px 10px !important; }
  /* Stat strips become single-column-friendly. */
  .kpis, .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 640px) {
  body { font-size: 12px; }
  /* Big enough buttons for touch. */
  .btn { padding: 8px 12px !important; min-height: 36px; }
  .btn-sm { padding: 6px 10px !important; min-height: 30px; }
  /* Section heads stack their action row below the heading. */
  .section-head { flex-direction: column !important; align-items: flex-start !important; }
  .section-head .actions { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
  /* Stat KPIs stack 1-per-row for max readability. */
  .kpis { grid-template-columns: 1fr !important; gap: 6px !important; }
  /* Modals: full viewport on phones, no surrounding padding. */
  .modal-backdrop, .modal-bg { padding: 0 !important; }
  .modal { max-width: 100% !important; max-height: 100vh !important; border-radius: 0 !important; }
  /* Drawer becomes full width. */
  .drawer { width: 100% !important; min-width: 100% !important; }
  /* Wide HTML tables — let them scroll horizontally instead of breaking layout. */
  table.dh, table.ssid-table, table.log, table { display: block; overflow-x: auto; white-space: nowrap; }
  /* Inputs / selects fill the width by default. */
  input[type="text"], input[type="number"], input[type="email"], input[type="password"], select, textarea {
    width: 100%; box-sizing: border-box;
  }
  /* Topbar brand label can shrink. */
  .brand { font-size: 12px !important; }
  /* Sub-nav badges visible but tighter. */
  .nav-icon { display: none; }
  /* Card grids → one column. */
  .ap-grid, .grid, .ctl-card { grid-template-columns: 1fr !important; }
  .ctl-card { flex-direction: column !important; align-items: stretch !important; }
}

/* Always-on tweaks (any viewport) */
.btn, .nav-tab, .chip { touch-action: manipulation; }   /* avoid double-tap zoom on iOS */
