/* ─────────────────────────────────────────────────────────
 * Design tokens — single source of truth for typography + spacing
 * Use via CSS vars or via the helper classes below.
 * ───────────────────────────────────────────────────────── */
:root {
  /* Typography scale */
  --t-page-title:   1.5rem;     /* h2 — page titles */
  --t-section:      1.125rem;   /* h3 — section headers */
  --t-card-title:   1rem;       /* card / row name */
  --t-body:         0.875rem;   /* body / form labels */
  --t-meta:         0.75rem;    /* metadata, badges, table cell */
  --t-micro:        0.6875rem;  /* tag micro-labels, hints */

  /* Spacing scale (consistent with Tailwind 4-step) */
  --s-xs:  0.25rem;   /* 4px */
  --s-sm:  0.5rem;    /* 8px */
  --s-md:  0.75rem;   /* 12px */
  --s-lg:  1rem;      /* 16px */
  --s-xl:  1.5rem;    /* 24px */
  --s-2xl: 2rem;      /* 32px */

  /* Card radius + shadow */
  --r-sm: 0.375rem;
  --r-md: 0.5rem;
  --r-lg: 0.75rem;

  /* Brand accent palette quick-access */
  --c-blue-50:   #eff6ff;
  --c-blue-500:  #3b82f6;
  --c-blue-700:  #1d4ed8;
  --c-slate-50:  #f8fafc;
  --c-slate-200: #e2e8f0;
  --c-slate-700: #334155;
}

/* Helper classes — opt-in for new components */
.h-page    { font-size: var(--t-page-title); font-weight: 700; line-height: 1.25; }
.h-section { font-size: var(--t-section);    font-weight: 600; line-height: 1.3; }
.h-card    { font-size: var(--t-card-title); font-weight: 600; }
.t-body    { font-size: var(--t-body); }
.t-meta    { font-size: var(--t-meta);  color: var(--c-slate-700); }
.t-micro   { font-size: var(--t-micro); color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; }

.card {
  background: white;
  border: 1px solid var(--c-slate-200);
  border-radius: var(--r-md);
  padding: var(--s-lg);
}
.card-compact { padding: var(--s-md); }
.card-roomy   { padding: var(--s-xl); }
.card-section { margin-top: var(--s-xl); }
.stack-sm > * + * { margin-top: var(--s-sm); }
.stack-md > * + * { margin-top: var(--s-md); }
.stack-lg > * + * { margin-top: var(--s-lg); }

/* ───────────────────────────────────────────────────────── */
/* Custom styles beyond Tailwind */

.nav-link {
  border-bottom: 2px solid transparent;
  color: rgb(203 213 225);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0 0.875rem;
  height: 100%;          /* fill nav height — uniform alignment across direct + group items */
  white-space: nowrap;
  line-height: 1;
}
.nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: white;
}
.nav-link.active {
  border-bottom-color: #60a5fa;
  background: rgba(255,255,255,0.06);
  color: white;
}

/* Nav dropdown groups */
.nav-group {
  display: inline-flex;
  align-items: stretch;
  position: relative;
}
.nav-group-toggle {
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
}
.nav-group-chevron {
  transition: transform 150ms ease;
}
.nav-group:has(.nav-dropdown:not(.hidden)) .nav-group-chevron {
  transform: rotate(180deg);
}
.nav-group:has(.nav-dropdown:not(.hidden)) .nav-group-toggle {
  background: rgba(255,255,255,0.08);
  color: white;
}
.nav-dropdown {
  animation: navDropdownFade 140ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes navDropdownFade {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nav-separator {
  pointer-events: none;
  flex-shrink: 0;
}

/* Cross-link flash — used when navigating between Situation Monitor ↔ Brand Watch
   via ?highlight=<uuid> so the user can spot the same item across the two views. */
.cross-link-flash {
  animation: crossLinkFlash 2.2s ease-out;
  position: relative;
  z-index: 1;
}
@keyframes crossLinkFlash {
  0%   { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.55), 0 0 24px rgba(245, 158, 11, 0.45); background-color: #fef3c7; }
  60%  { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.30), 0 0 14px rgba(245, 158, 11, 0.20); background-color: #fffbeb; }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); background-color: transparent; }
}

/* Tables */
.admin-table {
  width: 100%;
  font-size: 0.875rem;
  border-collapse: collapse;
}
.admin-table thead th {
  text-align: left;
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
  padding: 0.625rem 0.875rem;
  border-bottom: 2px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 1;
}
.admin-table tbody td {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.admin-table tbody tr:hover { background: #f8fafc; }

/* Job row linkage — wrapper ↔ sub-jobs visual highlight on hover.
   Indigo glow matches the Sub-jobs group color. */
.job-row.is-related {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.12), rgba(99, 102, 241, 0.04));
  box-shadow: inset 3px 0 0 rgb(99, 102, 241);
}
.job-row.is-related td:first-child { color: rgb(79, 70, 229); }

/* KPI cards */
.kpi-card {
  background: white;
  border-radius: 0.75rem;
  padding: 1.125rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid #e2e8f0;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--accent, #3b82f6);
}
.kpi-card.green   { --accent: #10b981; }
.kpi-card.amber   { --accent: #f59e0b; }
.kpi-card.red     { --accent: #ef4444; }
.kpi-card.purple  { --accent: #8b5cf6; }

.kpi-num {
  font-size: 1.75rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.1;
}
.kpi-label {
  color: #64748b;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.kpi-trend {
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 0.375rem;
}
.kpi-trend.up   { color: #059669; }
.kpi-trend.down { color: #dc2626; }
.kpi-trend.flat { color: #94a3b8; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: #e2e8f0; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

code.mono {
  font-family: ui-monospace, monospace;
  background: #f1f5f9;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  color: #334155;
}

/* Toast notifications */
.toast {
  pointer-events: auto;
  background: white;
  border-radius: 0.5rem;
  padding: 0.875rem 1rem;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  border-left: 4px solid #64748b;
  min-width: 280px;
  max-width: 400px;
  display: flex;
  align-items: start;
  gap: 0.5rem;
  font-size: 0.875rem;
  animation: slide-in 0.2s ease-out;
}
.toast.success { border-left-color: #10b981; }
.toast.error   { border-left-color: #ef4444; }
.toast.warning { border-left-color: #f59e0b; }
.toast.info    { border-left-color: #3b82f6; }
.toast.fade-out { animation: slide-out 0.2s ease-in forwards; }

@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes slide-out {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 1rem;
  animation: fade-in 0.15s;
}
.modal-content {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  max-width: 32rem;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  animation: pop-in 0.15s ease-out;
}
.modal-content.large { max-width: 56rem; }
.modal-content.xl    { max-width: 80rem; }     /* ~1280px — wide for card grids */
.modal-content.full  { max-width: 95vw; }      /* near-fullscreen */

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes pop-in {
  from { transform: scale(0.96); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Form controls */
.form-input, .form-select, .form-textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 0.375rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
/* Compact inline variant — used in toolbars where the select shouldn't span
   the full row. Apply alongside .form-select. */
.form-select-inline,
.form-input-inline {
  width: auto;
  display: inline-block;
}

/* ─────────────────────────────────────────────────────────
 * Unified toolbar — single source of truth for compact filter/action rows
 *
 * Apply `.toolbar` to any container that holds search/select/buttons and
 * ALL children automatically get the same compact size + alignment.
 *
 * Replaces the inconsistent mix of `text-xs py-1`, `text-sm py-1.5`, etc.
 * scattered across pages.
 *
 * Heights are pinned so search inputs, dropdowns, and buttons line up
 * pixel-perfect even with different element types.
 * ───────────────────────────────────────────────────────── */
.toolbar {
  background: white;
  border: 1px solid var(--c-slate-200);
  border-radius: var(--r-md);
  padding: 0.375rem 0.5rem;            /* 6px 8px */
  display: flex;
  align-items: center;
  gap: 0.375rem;                       /* 6px */
  flex-wrap: wrap;
  font-size: 0.75rem;                  /* 12px */
  margin-bottom: 0.5rem;
}
/* Form controls inside .toolbar — all compact, uniform height (28px) */
.toolbar .form-input,
.toolbar .form-select,
.toolbar .form-textarea {
  padding: 0.25rem 0.5rem;             /* 4px 8px */
  font-size: 0.75rem;                  /* 12px */
  height: 28px;
  width: auto;
  display: inline-block;
  border-radius: 0.25rem;
  line-height: 1.2;
}
/* Search inputs inside toolbar — left padding for icon */
.toolbar .form-input[type="search"],
.toolbar input[type="search"].toolbar-search {
  padding-left: 1.75rem;
}
/* When caller wants a full-width search inside toolbar, opt-in via .grow */
.toolbar .form-input.grow,
.toolbar input.grow {
  flex: 1 1 200px;
  min-width: 160px;
  max-width: 320px;
  width: auto;
}
/* Buttons inside toolbar — same height as form controls */
.toolbar .btn,
.toolbar button.btn-sm {
  height: 28px;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  line-height: 1.2;
}
/* Vertical separator inside toolbar */
.toolbar .toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: var(--c-slate-200);
  margin: 0 2px;
}
/* Toolbar count line / status text */
.toolbar .toolbar-count {
  font-size: 0.6875rem;                /* 11px */
  color: #64748b;
  white-space: nowrap;
  margin-left: auto;
  padding-left: 0.5rem;
  border-left: 1px solid var(--c-slate-200);
}

/* viewExplainer — "About this view" collapsible cards across pages.
 * Hide native <details> marker so we can use our custom chevron icon. */
.view-explainer summary::-webkit-details-marker { display: none; }
.view-explainer summary { list-style: none; }
.view-explainer[open] summary .chevron { transform: rotate(90deg); }

/* ─────────────────────────────────────────────────────────
 * Page description — the paragraph under H2 page titles
 * Standard size across ALL hubs (was inconsistent: some text-sm, some text-xs).
 * ───────────────────────────────────────────────────────── */
.page-desc {
  font-size: 0.75rem;                  /* 12px — matches text-xs */
  color: #64748b;                      /* slate-500 */
  margin-top: 0.25rem;
  line-height: 1.5;
}
/* When the page description sits inline with badges/icons */
.page-desc-inline {
  font-size: 0.75rem;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  line-height: 1.4;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
/* Prevent SVG icons inside buttons from absorbing clicks (delegation safety) */
.btn svg, button svg { pointer-events: none; }
.btn-primary    { background: #2563eb; color: white; }
.btn-primary:hover    { background: #1d4ed8; }
.btn-secondary  { background: white; color: #475569; border-color: #cbd5e1; }
.btn-secondary:hover  { background: #f8fafc; }
.btn-danger     { background: #dc2626; color: white; }
.btn-danger:hover     { background: #b91c1c; }
.btn-ghost      { background: transparent; color: #475569; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }

/* Loading */
.spinner {
  display: inline-block;
  width: 1rem; height: 1rem;
  border: 2px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #94a3b8;
}
.empty-state-icon {
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: center;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  border-radius: 0 0 0.5rem 0.5rem;
  font-size: 0.875rem;
}
.pagination button {
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  border: 1px solid #cbd5e1;
  background: white;
  cursor: pointer;
  transition: all 0.1s;
}
.pagination button:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: #94a3b8;
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Sparkline */
.sparkline {
  display: inline-block;
  width: 100%;
  height: 32px;
}

/* Activity feed */
.activity-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
}
.activity-item:hover { background: #f8fafc; }
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 2rem; height: 2rem;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
}

/* Hide redundant page titles when sub-page is rendered inside a group hub.
 * Each sub-page (pageEntities, pageReview, etc.) draws its own h2.text-2xl +
 * description paragraph. Inside a hub the unified header already shows that —
 * so suppress the duplicate.
 *
 * Rule targets:
 *   - h2.text-2xl  (page title)
 *   - h2.text-2xl + p  (description paragraph that immediately follows)
 */
#data-outer h2.text-2xl,
#data-outer h2.text-2xl + p,
#config-outer h2.text-2xl,
#config-outer h2.text-2xl + p,
#admin-outer h2.text-2xl,
#admin-outer h2.text-2xl + p,
#explore-outer h2.text-2xl,
#explore-outer h2.text-2xl + p {
  display: none;
}

/* Help — sub-topic anchor highlight */
.help-h3-highlight {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.15), transparent);
  padding-left: 6px;
  border-left: 3px solid #3b82f6;
  transition: background 0.6s ease, border-color 0.6s ease;
}

/* Network view — fullscreen workspace overlay */
.graph-workspace {
  display: flex;
  flex-direction: column;
}
.graph-workspace.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: white;
  padding: 0.75rem;
  gap: 0.5rem;
}
/* When the network graph is fullscreen, hide all surrounding hub chrome
   (top header, footer, hub sidebar, hub tab bar). The graph canvas already
   covers the whole viewport via z-index 50 + position:fixed; this just
   removes any visible bits underneath that flash through during transition. */
body.graph-is-fullscreen header,
body.graph-is-fullscreen footer,
body.graph-is-fullscreen [id$="-outer"] > div > aside,
body.graph-is-fullscreen [id$="-outer"] > div > .min-w-0 > div:first-child {
  display: none !important;
}

/* ─── Places map fullscreen ─── */
.places-workspace.is-fullscreen {
  position: fixed !important;
  inset: 0;
  z-index: 60;
  background: white;
  padding: 0.5rem;
  height: 100vh !important;
  height: 100dvh !important;       /* mobile-aware viewport height */
  border-radius: 0;
}
.places-workspace.is-fullscreen #places-map {
  border-radius: 0.5rem;
  min-height: 0 !important;
}

/* Floating filter toolbar — display strictly controlled here.
   IMPORTANT: don't add Tailwind .flex class to the element; it would override
   .map-fs-toolbar { display:none } because Tailwind CDN injects styles AFTER
   style.css → same-specificity rules lose to whichever comes later in cascade.
   Use !important to win regardless of injection order. */
.map-fs-toolbar {
  display: none !important;
  position: absolute;
  top: 0.75rem;
  /* offset left to clear Leaflet zoom controls (~30px wide + 10px margin) */
  left: 60px;
  right: 0.75rem;
  z-index: 1000;
  align-items: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
  pointer-events: none;            /* let map clicks pass between pills */
}
.places-workspace.is-fullscreen .map-fs-toolbar {
  display: flex !important;
}
/* Pills — re-usable glass-effect group */
.map-fs-pill {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  border: 1px solid var(--c-slate-200);
  border-radius: 0.5rem;
  padding: 0.25rem 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
}
/* Exit button is also a pill, but with auto margin to push to right edge */
.map-fs-exit-btn {
  margin-left: auto;
  cursor: pointer;
  flex-shrink: 0;
}
.map-fs-exit-btn:hover {
  background: rgba(248, 250, 252, 1);
}
/* FS chip buttons */
.map-fs-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  border-radius: 0.25rem;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  transition: filter 0.12s;
  font: inherit;
}
.map-fs-chip:hover { filter: brightness(0.96); }

/* Hide hub chrome (header, footer, sidebar, hub tab-bar) when map is fullscreen */
body.places-is-fullscreen header,
body.places-is-fullscreen footer,
body.places-is-fullscreen [id$="-outer"] > div > aside,
body.places-is-fullscreen [id$="-outer"] > div > .min-w-0 > div:first-child {
  display: none !important;
}

/* ─── Mobile / tablet layout — fix list overlapping helper text ───
   The workspace has inline `height: calc(100vh - 280px); min-height: 500px;`
   which is fine on lg+ where the grid is 2-col. On narrower viewports the
   grid stacks vertically: map (50vh) + list (auto, scrollable) — but the
   fixed parent height clips the second row, causing the list to overflow
   onto the helper text below. Fix: drop the fixed height on small screens
   and let map + list each have their own height. */
@media (max-width: 1023.98px) {
  .places-workspace:not(.is-fullscreen) {
    height: auto !important;
    min-height: 0 !important;
    grid-template-columns: 1fr !important;
  }
  .places-workspace:not(.is-fullscreen) #places-map {
    height: 50vh;
    min-height: 320px;
  }
  .places-workspace:not(.is-fullscreen) > aside {
    max-height: 50vh;
  }
}
.graph-workspace .fs-header {
  display: none;
}
.graph-workspace.is-fullscreen .fs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.875rem;
  background: linear-gradient(to right, #eff6ff, #faf5ff);
  border: 1px solid #c7d2fe;
  border-radius: 0.5rem;
  flex-shrink: 0;
}
/* Strict 3-column layout — never collapses. Canvas can shrink, rails fixed. */
.graph-workspace .grid-wrapper {
  display: grid;
  grid-template-columns: 220px minmax(360px, 1fr) 280px;
  gap: 0.625rem;
  align-items: start;
}
.graph-workspace .grid-wrapper .canvas-wrap {
  min-width: 0;       /* allow grid item to shrink to fit */
  min-height: 600px;
}
.graph-workspace .grid-wrapper > .sidebar-left,
.graph-workspace .grid-wrapper > #graph-sidebar {
  min-width: 0;
}
.graph-workspace.is-fullscreen .grid-wrapper {
  flex: 1;
  min-height: 0;       /* critical for grid+overflow */
  overflow: hidden;
}
.graph-workspace.is-fullscreen .canvas-wrap {
  height: 100%;
  min-height: 0;
}
/* Only stretch the main graph SVG (direct child), NOT icon SVGs inside popups */
.graph-workspace.is-fullscreen .canvas-wrap > svg#graph-svg {
  height: 100%;
  width: 100%;
}
.graph-workspace.is-fullscreen .sidebar-scroll {
  overflow-y: auto;
  height: 100%;
  padding-right: 4px;
}

/* Search bar — line icon via SVG data URI */
.search-input-wrap {
  position: relative;
}
.search-input-wrap input {
  padding-left: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.625rem center;
}

/* ─────────────────────────────────────────────────────────
 * News view — Live dashboard styles
 * ───────────────────────────────────────────────────────── */

/* Fullscreen mode — fills viewport, hides chrome */
body.news-fullscreen header,
body.news-fullscreen footer { display: none !important; }
body.news-fullscreen #page { padding: 0 !important; max-width: none !important; }
.news-workspace.is-fullscreen {
  position: fixed; inset: 0; z-index: 50;
  background: #f8fafc; padding: 0.75rem;
  overflow-y: auto;
}

/* Category pill scroller — horizontal, sticky */
.cat-bar {
  display: flex; align-items: center; gap: 0.375rem;
  overflow-x: auto; scrollbar-width: thin;
  scroll-behavior: smooth;
  padding: 0.5rem;
}
.cat-bar::-webkit-scrollbar { height: 4px; }
.cat-bar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }
.cat-pill {
  flex-shrink: 0; white-space: nowrap;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem; font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.cat-pill:not(.active) { background: #f1f5f9; color: #475569; }
.cat-pill:not(.active):hover { background: #e2e8f0; color: #1e293b; }
.cat-pill.active { background: #2563eb; color: #fff; }

/* Grid-mode tile (image-first) */
.news-tile {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 0.5rem;
  overflow: hidden; transition: box-shadow 0.15s, transform 0.15s;
  display: flex; flex-direction: column;
  cursor: pointer;
}
.news-tile:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); transform: translateY(-1px); }
.news-tile-image {
  width: 100%; aspect-ratio: 16/9; background: #f1f5f9;
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  color: #cbd5e1;
}
.news-tile-body { padding: 0.75rem; flex: 1; display: flex; flex-direction: column; gap: 0.5rem; }

/* Live indicator + flash-new animation */
.live-pill {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.25rem 0.625rem; border-radius: 9999px;
  background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca;
  font-size: 0.7rem; font-weight: 600;
}
.live-pill.on { background: #dcfce7; color: #15803d; border-color: #86efac; }
.live-pill .dot { width: 7px; height: 7px; border-radius: 9999px; background: currentColor; }
.live-pill.on .dot { animation: live-pulse 1.6s ease-in-out infinite; }
@keyframes live-pulse {
  0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.45); }
  50%     { opacity: 0.7; box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}
.flash-new { animation: flash-bg 1.6s ease-out 1; }
@keyframes flash-bg {
  0%   { background-color: #fef9c3; }
  100% { background-color: transparent; }
}

/* View-mode segmented control */
.vm-toggle {
  display: inline-flex; border: 1px solid #e2e8f0; border-radius: 0.375rem; overflow: hidden;
}
.vm-toggle button {
  padding: 0.25rem 0.625rem; font-size: 0.7rem;
  background: #fff; color: #475569; transition: all 0.15s;
}
.vm-toggle button.active { background: #334155; color: #fff; }
.vm-toggle button:not(.active):hover { background: #f1f5f9; }

/* ═══════════════════════════════════════════════════════════════════
 * MOBILE RESPONSIVE LAYER
 *
 * Strategy: desktop UX is unchanged (≥768px). Below 768px we:
 *   1. collapse top nav → burger drawer
 *   2. collapse hub-shell sidebar → slide-in drawer
 *   3. wrap admin tables with horizontal scroll
 *   4. force grid-cols-{2,3,4} to stack to 1 column when not already
 *      using a sm:/md: prefix
 *   5. tighten content padding
 *
 * Breakpoint: 768px = Tailwind's `md`.
 * ═══════════════════════════════════════════════════════════════════ */

/* Burger button — visible only on small screens. */
.burger-btn {
  display: none;
  background: transparent;
  border: 0;
  color: #cbd5e1;
  padding: 0.5rem;
  border-radius: 0.375rem;
  cursor: pointer;
  flex-shrink: 0;
}
.burger-btn:hover { background: rgba(255,255,255,0.08); color: white; }
.burger-btn svg { display: block; width: 24px; height: 24px; pointer-events: none; }

/* Mobile nav drawer (overlay sliding from right) */
.mobile-nav-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(320px, 90vw);
  background: #0f172a;
  color: white;
  z-index: 60;
  box-shadow: -8px 0 24px rgba(0,0,0,0.3);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
}
.mobile-nav-drawer.open { transform: translateX(0); }
.mobile-nav-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms;
}
.mobile-nav-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.mobile-nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.875rem 1rem;
  color: #cbd5e1;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.9375rem;
  text-decoration: none;
}
.mobile-nav-link:hover { background: rgba(255,255,255,0.06); color: white; }
.mobile-nav-link.active { background: rgba(96,165,250,0.15); color: white; border-left: 3px solid #60a5fa; padding-left: calc(1rem - 3px); }

/* Hub sidebar — drawer behavior on mobile */
.hub-sidebar-toggle {
  display: none;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: #334155;
  cursor: pointer;
  flex-shrink: 0;
  align-items: center;
  gap: 0.5rem;
}
.hub-sidebar-toggle:hover { background: #f8fafc; border-color: #94a3b8; }
.hub-sidebar-toggle svg { width: 16px; height: 16px; }

/* Sidebar group collapse (used both on desktop AND mobile) */
.sidebar-group { margin-bottom: 0.75rem; }
.sidebar-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  user-select: none;
  border-radius: 0.25rem;
}
.sidebar-group-header:hover { background: #f1f5f9; }
.sidebar-group-header .chevron {
  transition: transform 150ms;
  width: 12px; height: 12px;
  color: #94a3b8;
  flex-shrink: 0;
}
.sidebar-group.collapsed .chevron { transform: rotate(-90deg); }
.sidebar-group.collapsed .sidebar-group-items { display: none; }
.sidebar-group-items {
  margin-top: 0.25rem;
}

/* ─── Mobile breakpoint: < 768px ─── */
@media (max-width: 767.98px) {

  /* Header — show burger, simplify */
  .burger-btn { display: inline-flex; }
  #main-nav.desktop-nav { display: none !important; }

  /* Tighten header padding */
  header > div.w-full { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
  /* Hide row-2 (status / API base) on mobile — accessible via drawer instead */
  #app > header > div:nth-child(2) { display: none; }

  /* Main content padding — covers both the original `#page` element and any
     renamed hub outers (data-outer, admin-outer, etc.) */
  main#page,
  main[id$="-outer"] {
    padding: 0.75rem !important;
  }

  /* Hub shell + Help shell — collapse 2-col grid into stacked layout.
     Targets:
       - groupHubShell:  [id$="-outer"] > div[style*="grid-template-columns"]
       - pageHelp:        #help-shell  (uses inline grid-template-columns) */
  [id$="-outer"] > div[style*="grid-template-columns"],
  #help-shell {
    display: block !important;
  }
  [id$="-outer"] > div > aside,
  #help-shell > aside {
    display: none;
    position: fixed !important;
    top: 0 !important;
    left: 0;
    bottom: 0;
    width: min(280px, 85vw);
    z-index: 60;
    border-radius: 0;
    border-left: 0;
    border-top: 0;
    border-bottom: 0;
    overflow-y: auto;
    max-height: none !important;
    box-shadow: 8px 0 24px rgba(0,0,0,0.18);
  }
  [id$="-outer"] > div > aside.open,
  #help-shell > aside.open { display: block; }
  [id$="-outer"] > div > .min-w-0,
  #help-shell > div.min-w-0 { width: 100%; }

  .hub-sidebar-toggle { display: inline-flex; }

  /* Hide page title duplicates IS already there — keep it */

  /* ─── Admin tables — horizontal scroll inside parent card ─── */
  /* The typical pattern: <div class="bg-white ... overflow-hidden"><table class="admin-table">.
     We override `overflow-hidden` to `overflow-x-auto` when it directly wraps a table. */
  div:has(> table.admin-table),
  div:has(> .pagination):has(> table.admin-table) {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  table.admin-table { min-width: 600px; }
  table.admin-table thead th,
  table.admin-table tbody td {
    padding: 0.5rem 0.625rem;
    font-size: 0.8125rem;
  }

  /* ─── Force narrow grids to stack ─── */
  /* Auto-stack ONLY 4-col grids — they become unreadable on phones (~85px/col).
     3-col stays because many `grid-cols-3` are inline metric strips ("Linked: 5
     · 24h: 3 · Trend: up") that read fine in 3 narrow cells.
     2-col stays because KPI strips use `grid-cols-2 md:grid-cols-4` and 2x2 fits.
     Opt-out via `.no-stack`. Opt-in stacking via `.stack-mobile`. */
  body.is-mobile .grid.grid-cols-4:not(.no-stack),
  body.is-mobile .grid.stack-mobile {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  /* For 3-col with bigger cards (not just inline metrics), allow 2-col on mobile */
  body.is-mobile .grid.grid-cols-3.lg\:grid-cols-3:not(.no-stack) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Modals — full screen */
  .modal-content {
    max-width: 100% !important;
    max-height: 100dvh !important;
    max-height: 100vh !important;          /* fallback for older browsers */
    max-height: 100dvh !important;          /* preferred — excludes mobile URL bar */
    border-radius: 0 !important;
    margin: 0;
    width: 100vw;
    height: 100dvh;
  }
  .modal-backdrop { padding: 0; align-items: stretch; }
  /* Modal forms — stack form-row grids */
  .modal-content .grid.grid-cols-2,
  .modal-content .grid.grid-cols-3 { grid-template-columns: 1fr !important; gap: 0.75rem !important; }

  /* KPI cards — 2-col is OK on phones (more info density), but make text smaller */
  .kpi-card { padding: 0.875rem; }
  .kpi-num  { font-size: 1.375rem; }

  /* Page-level h2 */
  h2.text-2xl { font-size: 1.25rem; line-height: 1.3; }

  /* Forms inside content — make form rows stack */
  form .grid.grid-cols-2,
  form .grid.grid-cols-3 { grid-template-columns: 1fr !important; gap: 0.75rem !important; }

  /* Buttons in toolbars — wrap if needed */
  .btn { padding: 0.4375rem 0.75rem; }

  /* Pagination spacing */
  .pagination { padding: 0.5rem 0.75rem; flex-wrap: wrap; gap: 0.375rem; }

  /* Code blocks (Help page mostly) — horizontal scroll on overflow.
     Many <pre> have overflow-auto already; this catches the rest. */
  pre {
    overflow-x: auto !important;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    font-size: 0.6875rem;
  }
  /* ASCII-diagram boxes (system map etc.) — already inside overflow-x-auto, ensure font fits */
  .font-mono.text-\[11px\] pre,
  pre.whitespace-pre {
    font-size: 0.625rem;
    line-height: 1.4;
  }

  /* Help page — content area gets less padding (was p-6 → p-3 in HTML), bigger margins for readability */
  #help-shell .prose, #help-shell #connect-content {
    font-size: 0.875rem;
  }
}

/* ─── Tablet breakpoint: 768-1024px ─── */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Hub sidebar slightly narrower on tablets */
  [id$="-outer"] > div[style*="grid-template-columns"] {
    grid-template-columns: 180px minmax(0, 1fr) !important;
  }
}

/* ─── Tap targets — make buttons / links touchable ─── */
@media (hover: none) and (pointer: coarse) {
  .btn-sm,
  button.text-xs, a.text-xs {
    min-height: 32px;
  }
  /* Remove sticky table headers on touch — they fight scroll */
  .admin-table thead th { position: static; }
}
