/**
 * Compact top-of-page chrome for dashboard modules.
 * Keeps themes (via --ct-* / existing colors) and frees viewport for the primary map/tool.
 */
:root {
  --ct-chrome-pad-y: 6px;
  --ct-chrome-pad-x: 12px;
  --ct-chrome-gap: 6px;
  --ct-map-min: 60vh;
}

/* Shared dashboard shell — % fills shell iframe; min-height covers standalone */
#threat-dashboard.ct-compact,
.ct-compact#threat-dashboard {
  padding: var(--ct-chrome-pad-y) var(--ct-chrome-pad-x) !important;
  gap: 0;
  box-sizing: border-box;
  height: 100%;
  max-height: 100%;
  min-height: 100%;
  overflow: hidden;
}

/* Directory / Toolbox: compact header only; keep page scroll */
body.ct-compact .header h1,
body.ct-compact .tb-header .header-title,
body.ct-compact .tb-header h1 {
  font-size: 18px !important;
  letter-spacing: 1px !important;
  margin: 0.2em 0 !important;
}
body.ct-compact .header p,
body.ct-compact .tb-header .sub {
  font-size: 11px !important;
  margin: 0.15em 0 !important;
  opacity: 0.75;
}
body.ct-compact .header .ct-social,
body.ct-compact .tb-header .ct-social {
  margin-top: 4px !important;
}
body.ct-compact .tb-header {
  padding-top: 8px !important;
  padding-bottom: 6px !important;
}

.ct-compact .header,
#threat-dashboard.ct-compact .header {
  flex-shrink: 0;
  padding-bottom: 4px !important;
  margin: 0 !important;
  border-bottom-width: 1px !important;
  gap: 8px;
  min-height: 0;
  align-items: center !important;
}

.ct-compact .header-branding {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.ct-compact .header-title,
#threat-dashboard.ct-compact .header-title {
  font-size: 15px !important;
  letter-spacing: 1px !important;
  line-height: 1.2 !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 !important;
}

.ct-compact .header-subtitle,
#threat-dashboard.ct-compact .header-subtitle {
  display: none !important;
}

.ct-compact .header-controls {
  gap: 10px !important;
  flex-shrink: 0;
}

.ct-compact .header-time,
.ct-compact .header-timer {
  font-size: 11px !important;
}

.ct-compact #td-countdown,
.ct-compact .header-timer #td-countdown {
  font-size: 14px !important;
  margin-left: 4px !important;
}

.ct-compact .btn-refresh {
  padding: 4px 10px !important;
  font-size: 10px !important;
}

/* KPI / status strips → chip row */
.ct-compact .kpi-board,
.ct-compact .status-board {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center;
  gap: 6px 10px !important;
  margin: var(--ct-chrome-gap) 0 !important;
  padding: 4px 8px !important;
  overflow-x: auto;
  flex-shrink: 0;
}

.ct-compact .kpi-item,
.ct-compact .metric-block {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: baseline;
  gap: 4px;
  border-right: 1px solid rgba(128, 128, 128, 0.25) !important;
  padding: 0 8px 0 0 !important;
  margin: 0 !important;
  flex: 0 0 auto !important;
  text-align: left !important;
}

.ct-compact .kpi-item:last-child,
.ct-compact .metric-block:last-child {
  border-right: none !important;
}

.ct-compact .kpi-value,
.ct-compact .metric-val {
  font-size: 13px !important;
  margin: 0 !important;
  line-height: 1.2 !important;
}

.ct-compact .kpi-label,
.ct-compact .metric-lbl {
  font-size: 9px !important;
  letter-spacing: 0.4px !important;
  white-space: nowrap;
}

.ct-compact .status-indicator {
  font-size: 12px !important;
  padding: 3px 10px !important;
}

.ct-compact .status-board > div:first-child {
  min-width: 0;
}

.ct-compact .env-metrics {
  gap: 8px !important;
  flex-wrap: nowrap;
}

/* Filters / controls — one compact row; collapsible on narrow viewports */
.ct-compact .control-panel,
.ct-compact .controls-row {
  margin: 0 0 var(--ct-chrome-gap) 0 !important;
  padding: 4px 8px !important;
  gap: 6px !important;
  flex-shrink: 0;
  align-items: center !important;
}

.ct-compact .filter-select,
.ct-compact .dropdown-button {
  padding: 3px 8px !important;
  font-size: 11px !important;
  min-width: 0 !important;
}

.ct-compact .dropdown-button {
  min-width: 140px !important;
}

.ct-compact .search-box input {
  padding: 3px 8px !important;
  font-size: 11px !important;
}

.ct-compact .filters-collapse,
.ct-compact .filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  width: 100%;
}

.ct-compact .filters-toggle {
  display: none;
  background: var(--ct-panel, #222);
  border: 1px solid var(--ct-border, #444);
  color: var(--ct-accent, #4caf50);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
  width: 100%;
  margin-bottom: 4px;
}

.ct-compact .filters-toggle[aria-expanded="true"] {
  border-color: var(--ct-accent, #4caf50);
}

/*
 * Height chain (desktop):
 *   #threat-dashboard (100vh flex col)
 *     → .dashboard-content (flex: 1 1 0; min-height: 0)
 *       → side map + lists OR full-bleed columns
 *         → .section (flex: 1 1 0) → .scroll-area (overflow-y: auto)
 * The PR #23 clamp of every .lists-container to ~200px/22vh collapsed
 * side panels. Later PRs narrowed the clamp but left height:auto +
 * map min-height:60vh, which still failed to fill / stretch on some
 * desktop chrome heights. Use flex-basis 0 + height 100% throughout.
 */
/*
 * Fill the embedding frame (standalone OR shell iframe). Prefer % over vh:
 * inside #master-frame, 100vh can disagree with the iframe box, and the
 * iframe is ~300px narrower than the window — so a 1024px "mobile"
 * breakpoint was firing on desktop shell views (~980–1140px wide).
 */
html:has(#threat-dashboard.ct-compact),
body:has(#threat-dashboard.ct-compact) {
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

#threat-dashboard.ct-compact,
.ct-compact#threat-dashboard {
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  max-height: 100% !important;
}

.ct-compact .dashboard-content {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  overflow: hidden !important;
  gap: 8px !important;
  display: flex !important;
}

/* Alerts: map on top may keep a minimum; side layouts must not. */
.ct-compact .map-container {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: auto !important;
}

.ct-compact .dashboard-content.ct-lists-below .map-container {
  min-height: var(--ct-map-min) !important;
}

/*
 * lists-container layouts:
 *   - Alerts: stacked under the map (ct-lists-below) → keep a short strip
 *   - Land / Multi / Flight_Ops: side column (ct-lists-side) → fill map height
 *   - Cyber / News / SIGINT: full-bleed columns (ct-lists-fill / ct-primary-pane)
 */
.ct-compact .dashboard-content.ct-lists-below .lists-container {
  flex: 0 0 auto !important;
  height: auto !important;
  max-height: min(200px, 22vh) !important;
  min-height: 100px;
}

.ct-compact .dashboard-content.ct-lists-side {
  flex-direction: row !important;
  align-items: stretch !important;
}

.ct-compact .dashboard-content.ct-lists-side .lists-container {
  flex: 1 1 38% !important;
  width: auto !important;
  max-width: 42% !important;
  height: 100% !important;
  max-height: none !important;
  min-height: 0 !important;
  align-self: stretch !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 8px !important;
}

.ct-compact .dashboard-content.ct-lists-side .map-container {
  flex: 1 1 62% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: 100% !important;
  align-self: stretch !important;
}

.ct-compact .dashboard-content.ct-lists-side .section {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

.ct-compact .dashboard-content.ct-lists-side .scroll-area {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

/* Land cameras: taller share of the column; cards sized so 2–3 are visible */
.ct-compact .dashboard-content.ct-lists-side .cam-sec {
  flex: 2.4 1 0% !important;
}

.ct-compact .dashboard-content.ct-lists-side .hazard-sec {
  flex: 1 1 0% !important;
}

.ct-compact .dashboard-content.ct-lists-side .cam-img-container {
  aspect-ratio: 16 / 9 !important;
  min-height: 110px !important;
  max-height: 160px !important;
}

/*
 * Full-bleed list columns (Cyber & OSINT, News, SIGINT):
 * fill leftover viewport height; each column scrolls independently.
 */
.ct-compact .dashboard-content.ct-primary-pane,
.ct-compact .dashboard-content.ct-lists-fill {
  display: flex !important;
  flex-direction: row !important;
  align-items: stretch !important;
  flex: 1 1 0% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

.ct-compact .dashboard-content.ct-primary-pane .lists-container,
.ct-compact .dashboard-content.ct-lists-fill .lists-container {
  flex: 1 1 auto !important;
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  max-height: none !important;
  min-height: 0 !important;
  align-self: stretch !important;
  overflow: hidden !important;
  /* ThreatIntel uses CSS grid; News uses flex row — force both to fill */
  grid-template-rows: minmax(0, 1fr) !important;
  align-items: stretch !important;
}

.ct-compact .dashboard-content.ct-primary-pane .section,
.ct-compact .dashboard-content.ct-lists-fill .section {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  max-height: none !important;
  height: 100% !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

.ct-compact .dashboard-content.ct-primary-pane .scroll-area,
.ct-compact .dashboard-content.ct-lists-fill .scroll-area {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

/* SIGINT / Comms: feed list + player share the primary pane */
.ct-compact .dashboard-content.ct-primary-pane .feed-selector,
.ct-compact .dashboard-content.ct-primary-pane .player-container {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  max-height: none !important;
  height: 100% !important;
  align-self: stretch !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

.ct-compact .dashboard-content.ct-primary-pane .feed-list-container {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  overflow-y: auto !important;
}

/* Toolbox / Links content panes (page-scroll, not locked viewport columns) */
.ct-compact .main-content,
.ct-compact .content-area,
.ct-compact .tools-grid,
.ct-compact .directory-grid {
  flex: 1 1 auto;
  min-height: var(--ct-map-min);
  overflow: auto;
}

/*
 * True phone / narrow drawer widths only. Do NOT use 1024px — the shell
 * iframe at a 1280–1440 desktop window is often 980–1140px wide and must
 * keep the locked desktop height chain.
 */
@media (max-width: 768px) {
  html:has(#threat-dashboard.ct-compact),
  body:has(#threat-dashboard.ct-compact) {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .ct-compact#threat-dashboard,
  #threat-dashboard.ct-compact {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    min-height: 100dvh;
  }

  .ct-compact .filters-toggle {
    display: block;
  }

  .ct-compact .filters-collapse {
    display: none;
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }

  .ct-compact .filters-collapse.is-open {
    display: flex;
  }

  .ct-compact .control-panel,
  .ct-compact .controls-row {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .ct-compact .map-container,
  .ct-compact .dashboard-content.ct-lists-below .map-container,
  .ct-compact .dashboard-content.ct-lists-side .map-container {
    min-height: 50vh !important;
    height: 50vh !important;
    flex: none !important;
  }

  .ct-compact .lists-container,
  .ct-compact .dashboard-content.ct-lists-below .lists-container,
  .ct-compact .dashboard-content.ct-lists-side .lists-container,
  .ct-compact .dashboard-content.ct-primary-pane .lists-container,
  .ct-compact .dashboard-content.ct-lists-fill .lists-container {
    flex: none !important;
    height: auto !important;
    max-height: none !important;
    max-width: none !important;
    width: 100% !important;
    overflow: visible !important;
  }

  .ct-compact .dashboard-content.ct-lists-side .map-container {
    flex: none !important;
    width: 100% !important;
  }

  .ct-compact .dashboard-content {
    overflow: visible !important;
    height: auto !important;
  }

  .ct-compact .dashboard-content.ct-lists-side .cam-sec,
  .ct-compact .dashboard-content.ct-lists-side .hazard-sec,
  .ct-compact .dashboard-content.ct-primary-pane .section,
  .ct-compact .dashboard-content.ct-lists-fill .section {
    flex: none !important;
    max-height: none !important;
    height: auto !important;
  }

  .ct-compact .dashboard-content.ct-primary-pane .scroll-area,
  .ct-compact .dashboard-content.ct-lists-fill .scroll-area {
    flex: none !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .ct-compact .dashboard-content.ct-primary-pane .feed-selector,
  .ct-compact .dashboard-content.ct-primary-pane .player-container {
    flex: none !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
  }

  .ct-compact .kpi-board,
  .ct-compact .status-board {
    flex-wrap: wrap !important;
  }

  .ct-compact .header {
    flex-wrap: wrap;
  }
}

@media (max-height: 520px) and (min-width: 1025px) {
  .ct-compact .dashboard-content.ct-lists-below .map-container {
    min-height: calc(100vh - 140px) !important;
  }
  .ct-compact .dashboard-content.ct-lists-below .lists-container {
    flex: 0 0 22% !important;
    height: 22% !important;
    max-height: 180px;
  }
  .ct-compact .kpi-board,
  .ct-compact .status-board {
    margin: 2px 0 !important;
    padding: 2px 6px !important;
  }
}
