/* ===== acutes_daily_dashboard_html (HTML form, scoped) =====
   Loaded eagerly from anvil.yaml native_deps.head_html.

   SCOPED ON .ad-root, the form's wrapping root. .ad-dashboard is NOT the
   root, so it is wrapped like everything else: :where(.ad-root) .ad-dashboard
   at (0,1,0) and [data-theme="dark"] :where(.ad-root) .ad-dashboard at
   (0,2,0). :where() contributes zero specificity.

   .ad-root positions the banner. The shared refresh lifecycle inserts the
   out-of-date banner as get_dom_node(self).firstChild
   (_refresh_lifecycle.py:320-325). That node is .ad-root, so the banner is
   .ad-root's first child and sits OUTSIDE .ad-dashboard, where the --ad-timer-warning declared on
   .ad-dashboard does not resolve and the banner is not amber. .ad-root itself
   carries NO rule.

   .ad-stale-banner is therefore scoped on .ad-root and not on .ad-dashboard:
   it is a direct child of .ad-root, so .ad-dashboard is not one of its
   ancestors and scoping it there would stop it matching. It keeps
   color: var(--ad-timer-warning), which does not resolve there, so the banner
   is not amber.

   THE ONE ADDITION: :where(.ad-root) .ad-dashboard gains flex: 1 1 auto and
   min-height: 0. Those two declarations reach .ad-dashboard today through the
   parent shell's .dashboards-parent [anvil-slot="default"] > * > * rule,
   which after conversion lands on
   .ad-root instead. They are written out rather than argued away as inert:
   whether they are inert depends on the computed display of the Anvil wrapper,
   which neither repo declares.

   url('_/theme/noise.png') becomes url('../noise.png'): an external sheet
   resolves a relative url against itself and this file sits one directory
   below theme/assets/noise.png. One site, and no other url() in the block.

   @keyframes: all six are already ad-prefixed, so none is renamed and no
   animation: ident changes. No @font-face, no :root block, no html rule, and
   no .px-* class is declared here -- px-anvil-reset is used and never
   declared, so there is no shared-name violation and no order tie with the
   dependency's runtime-injected theme.

   NO DESIGNER GATE, and there is nothing to gate. The designer runs no Python,
   so a rule that hides content until the script runs would leave the canvas
   showing empty panels -- but the only node this screen hides is
   #ad-cards-container's JS-generated content, and the container ships empty in
   the template either way. There is no live class here to gate on.

   FAIL LOUD, CAUGHT NOWHERE. A missing element throws out of
   acutes_daily_dashboard.mjs, through the Python call site, into the app's
   error handling. Decided once for the whole analytics section. */

/* ACUTES DAILY DASHBOARD - Control Tower Theme */

/* ========================================
   BASE DASHBOARD STYLES
   ======================================== */
:where(.ad-root) .ad-dashboard {
  /* Accent colors */
  --accent: #d97706;
  --accent-hover: #f59e0b;
  --accent-subtle: rgba(217,119,6,0.25);
  --accent-text: #422006;
  --px-loading-accent: #d97706;

  /* Chart/semantic colors */
  --ad-color-yellow: #f59e0b;
  --ad-color-yellow-glow: rgba(245, 158, 11, 0.15);
  --ad-color-yellow-light: #fef3c7;
  --ad-color-green: #10b981;
  --ad-color-green-glow: rgba(16, 185, 129, 0.15);
  --ad-color-green-light: #d1fae5;
  --ad-color-purple: #8b5cf6;
  --ad-color-purple-glow: rgba(139, 92, 246, 0.15);
  --ad-color-purple-light: #ede9fe;

  /* Timer status colors */
  --ad-timer-safe: #10b981;
  --ad-timer-warning: #f59e0b;
  --ad-timer-urgent: #ef4444;
  --ad-timer-passed: #991b1b;

  font-family: var(--px-font);
  background: var(--px-bg-deep);
  color: var(--px-text-primary);
  transition: background 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  padding: 32px 48px;
  animation: ad-fadeIn 0.5s ease-out;

  /* Sizes .ad-dashboard as a flex item inside .ad-root, which fills the
     parent shell's default slot (dashboards_html). */
  flex: 1 1 auto;
  min-height: 0;
}

[data-theme="dark"] :where(.ad-root) .ad-dashboard {
  --ad-color-yellow-light: rgba(245, 158, 11, 0.15);
  --ad-color-green-light: rgba(16, 185, 129, 0.15);
  --ad-color-purple-light: rgba(139, 92, 246, 0.15);
}

@keyframes ad-fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   HEADER STYLES
   ======================================== */
:where(.ad-root) .ad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
  flex-wrap: wrap;
  gap: 16px;
}

:where(.ad-root) .ad-title-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

:where(.ad-root) .ad-title-bar {
  width: 5px;
  height: 48px;
  background: linear-gradient(180deg, var(--ad-color-yellow) 0%, var(--ad-color-green) 50%, var(--ad-color-purple) 100%);
  border-radius: 3px;
}

:where(.ad-root) .ad-dashboard h1 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.8rem;
  letter-spacing: 0.05em;
  color: var(--px-text-primary);
  line-height: 1;
  margin: 0;
}

:where(.ad-root) .ad-header-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

:where(.ad-root) .ad-live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--px-mono);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--px-text-secondary);
}

:where(.ad-root) .ad-live-dot {
  width: 10px;
  height: 10px;
  background: var(--ad-timer-safe);
  border-radius: 50%;
  position: relative;
}

:where(.ad-root) .ad-live-dot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  background: var(--ad-timer-safe);
  border-radius: 50%;
  opacity: 0;
  animation: ad-pulse 2s ease-in-out infinite;
}

@keyframes ad-pulse {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  50% { opacity: 0.4; transform: translate(-50%, -50%) scale(1); }
}

/* ========================================
   CARDS CONTAINER
   ======================================== */
:where(.ad-root) .ad-cards-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

/* ========================================
   ROUTE CARD STYLES
   ======================================== */
:where(.ad-root) .ad-route-card {
  background: var(--px-bg-card);
  border-radius: 16px;
  border: 1px solid var(--px-border);
  box-shadow: var(--px-shadow);
  overflow: hidden;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: ad-slideUp 0.5s ease-out backwards;
}

@keyframes ad-slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

:where(.ad-root) .ad-route-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--px-shadow-md);
}

:where(.ad-root) .ad-route-card.urgent {
  animation: ad-urgentPulse 2s ease-in-out infinite;
}

@keyframes ad-urgentPulse {
  0%, 100% { box-shadow: var(--px-shadow); }
  50% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.3), var(--px-shadow); }
}

:where(.ad-root) .ad-route-card.completed {
  opacity: 0.45;
  filter: grayscale(0.7);
}

:where(.ad-root) .ad-route-card.completed:hover {
  transform: none;
  box-shadow: var(--px-shadow);
}

:where(.ad-root) .ad-route-card.completed .ad-countdown-timer { animation: none; }

/* Multi-route gradient header */
:where(.ad-root) .ad-route-card.multi-route .ad-card-header::after {
  background: var(--gradient-colors, var(--route-color));
}

/* Unassigned homes card */
:where(.ad-root) .ad-route-card.unassigned {
  border-style: dashed;
  border-color: var(--px-text-muted);
}

:where(.ad-root) .ad-route-card.unassigned .ad-countdown-section {
  display: none;
}

/* ========================================
   CARD HEADER
   ======================================== */
:where(.ad-root) .ad-card-header {
  padding: 20px 24px 16px;
  position: relative;
}

:where(.ad-root) .ad-card-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 24px;
  right: 24px;
  height: 3px;
  border-radius: 2px;
  background: var(--route-color);
}

:where(.ad-root) .ad-cutoff-time {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.8rem;
  letter-spacing: 0.03em;
  color: var(--px-text-primary);
}

:where(.ad-root) .ad-route-label {
  font-family: var(--px-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 4px;
  color: var(--px-text-secondary);
  line-height: 1.4;
}

:where(.ad-root) .ad-prescription-cutoff {
  font-family: var(--px-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--px-text-muted);
  margin-top: 6px;
}

:where(.ad-root) .ad-prescription-cutoff .ad-cutoff-label {
  font-weight: 700;
}

/* ========================================
   CARD BODY
   ======================================== */
:where(.ad-root) .ad-card-body { padding: 24px; }

:where(.ad-root) .ad-counts-row {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 20px;
}

:where(.ad-root) .ad-count-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

:where(.ad-root) .ad-count-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2rem;
  color: var(--px-text-primary);
  position: relative;
  transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  background: var(--route-color-light);
  border: 3px solid var(--route-color);
}

:where(.ad-root) .ad-count-label {
  font-family: var(--px-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--px-text-secondary);
  font-weight: 700;
}

:where(.ad-root) .ad-earliest-time {
  font-family: var(--px-mono);
  font-size: 0.65rem;
  color: var(--px-text-muted);
  margin-top: 6px;
  text-align: center;
  line-height: 1.4;
}

:where(.ad-root) .ad-earliest-time .ad-earliest-label {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

:where(.ad-root) .ad-earliest-time .ad-earliest-value {
  display: block;
  font-weight: 700;
  font-size: 0.75rem;
}

:where(.ad-root) .ad-earliest-time .ad-earliest-date {
  display: block;
  font-size: 0.6rem;
  opacity: 0.8;
  margin-top: 1px;
}

:where(.ad-root) .ad-earliest-time .ad-earliest-value.before-cutoff { color: var(--ad-timer-urgent); }
:where(.ad-root) .ad-earliest-time .ad-earliest-value.after-cutoff { color: var(--ad-timer-safe); }
:where(.ad-root) .ad-earliest-time .ad-earliest-date.before-cutoff { color: var(--ad-timer-urgent); }
:where(.ad-root) .ad-earliest-time .ad-earliest-date.after-cutoff { color: var(--ad-timer-safe); }

/* ========================================
   COUNTDOWN SECTION
   ======================================== */
:where(.ad-root) .ad-countdown-section {
  text-align: center;
  padding: 20px;
  margin: 0 -24px;
  background: var(--px-bg-elevated);
  border-top: 1px solid var(--px-border-subtle);
}

:where(.ad-root) .ad-countdown-label {
  font-family: var(--px-mono);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--px-text-muted);
  margin-bottom: 8px;
}

:where(.ad-root) .ad-countdown-timer {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.4rem;
  letter-spacing: 0.05em;
  transition: color 0.3s ease;
}

:where(.ad-root) .ad-countdown-timer.safe { color: var(--ad-timer-safe); }
:where(.ad-root) .ad-countdown-timer.warning { color: var(--ad-timer-warning); }
/* R3-81: shown only while an automatic refresh has failed, so the
   numbers on screen are visibly ageing. Same amber the countdown
   warning uses - no new colour. */
:where(.ad-root) .ad-stale-banner {
  color: var(--ad-timer-warning);
  font-weight: 700;
  padding: 0.5rem 0 0 0;
}
:where(.ad-root) .ad-countdown-timer.urgent {
  color: var(--ad-timer-urgent);
  animation: ad-timerPulse 1s ease-in-out infinite;
}
:where(.ad-root) .ad-countdown-timer.passed { color: var(--ad-timer-passed); }

@keyframes ad-timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Secondary timer for prescription cutoff */
:where(.ad-root) .ad-rx-countdown-section {
  padding: 8px 24px 16px;
  text-align: center;
  border-top: 1px dashed var(--px-border-subtle);
}

:where(.ad-root) .ad-rx-countdown-label {
  font-family: var(--px-mono);
  font-size: 0.55rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--px-text-muted);
  margin-bottom: 4px;
}

:where(.ad-root) .ad-rx-countdown-timer {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.03em;
  transition: color 0.3s ease;
}

:where(.ad-root) .ad-rx-countdown-timer.safe { color: var(--ad-timer-safe); }
:where(.ad-root) .ad-rx-countdown-timer.warning { color: var(--ad-timer-warning); }
:where(.ad-root) .ad-rx-countdown-timer.urgent { color: var(--ad-timer-urgent); }
:where(.ad-root) .ad-rx-countdown-timer.passed { color: var(--ad-timer-passed); }

/* Hide Rx timer when same as dispatch or for unassigned */
:where(.ad-root) .ad-route-card.same-cutoffs .ad-rx-countdown-section,
:where(.ad-root) .ad-route-card.unassigned .ad-rx-countdown-section {
  display: none;
}

/* ========================================
   OWINGS SECTION
   ======================================== */
:where(.ad-root) .ad-owings-section {
  padding: 16px 24px;
  border-top: 1px solid var(--px-border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

:where(.ad-root) .ad-owings-label {
  font-family: var(--px-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--px-text-muted);
}

:where(.ad-root) .ad-owings-count {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.2rem;
  padding: 2px 10px;
  border-radius: 12px;
  background: var(--px-bg-elevated);
}

:where(.ad-root) .ad-owings-count.has-owings {
  background: rgba(239, 68, 68, 0.15);
  color: var(--ad-timer-urgent);
}

:where(.ad-root) .ad-owings-count.no-owings { color: var(--px-text-muted); }

/* ========================================
   CLICKABLE STATS
   ======================================== */
:where(.ad-root) .ad-clickable {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

:where(.ad-root) .ad-clickable:hover {
  transform: scale(1.08);
}

:where(.ad-root) .ad-count-item.ad-clickable:hover .ad-count-circle {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

:where(.ad-root) .ad-owings-section.ad-clickable:hover {
  background: var(--px-bg-elevated);
}

:where(.ad-root) .ad-owings-section.ad-clickable:hover .ad-owings-count {
  transform: scale(1.1);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 600px) {
  :where(.ad-root) .ad-dashboard { padding: 20px 20px; }
  :where(.ad-root) .ad-header { flex-direction: column; align-items: flex-start; }
  :where(.ad-root) .ad-dashboard h1 { font-size: 1.8rem; }
  :where(.ad-root) .ad-cards-container { grid-template-columns: 1fr; }
  :where(.ad-root) .ad-counts-row { gap: 20px; }
  :where(.ad-root) .ad-count-circle { width: 60px; height: 60px; font-size: 1.6rem; }
  :where(.ad-root) .ad-countdown-timer { font-size: 2rem; }
}

/* ========================================
   NOISE OVERLAY
   ======================================== */
:where(.ad-root) .ad-dashboard::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background-image: url('../noise.png');
  background-repeat: repeat;
  opacity: 0.015;
  z-index: 9999;
}

[data-theme="dark"] :where(.ad-root) .ad-dashboard::after { opacity: 0.025; }
