/* dc_historical_html — the Historical Dispatches popup's own rules, kept
 * here because the Anvil server strips a template's <style> block. Rules are
 * scoped by their selector preludes.
 *
 * ROOT. The form root is the .dch-container div itself, so its rule stays
 * BARE and byte-identical: nothing added, nothing dropped. It declares no
 * width, min-width or max-width, so it takes theme.css's
 * `.px-anvil-reset [anvil-slot]>*` width reset exactly as the Anvil wrapper
 * chain did and needs no doubled twin.
 *
 * SCOPE. Every other rule is scoped :where(.dch-container), which contributes
 * zero specificity, so each rule keeps exactly the weight its bare selector
 * had. Nothing in this form is portaled out of the root: pxShowOverlay is
 * never called here, and px_form_alert moves the WHOLE form, root included.
 *
 * HEAD-LINK ORDER, the three ties this file could have lost.
 * - `.dch-table th` / `td` / `tbody tr` tie with theme.css's `.px-table th`
 *   (0,1,1) and `.px-table tbody tr` (0,1,1). This asset is a head <link>
 *   loaded AFTER theme.css, so those rules still win on order exactly as the
 *   body <style> block did, and the shared dependency declares no `.px-table`
 *   at all, so its runtime injection cannot get behind them.
 * - `.dch-card-actions .px-btn` is (0,2,0) against the dependency's `.px-btn`
 *   at (0,1,0), so it wins on specificity rather than on order, which is what
 *   matters: the dependency appends its theme to <head> after every link. Its
 *   four declarations (flex, min-width, text-align, justify-content) are
 *   disjoint from the dependency's `.px-btn` set in any case.
 * - `.themed-scrollbar` sits on #dch-home-dropdown and #dch-table-container
 *   and is declared NOWHERE here. It is the dependency's.
 *
 * The two @keyframes were already prefixed per screen in the template
 * (dchFadeIn, dchRowReveal) and stay global, as @keyframes must.
 */

.dch-container {
  --accent: #fbbf24; --accent-text: #422006;
  --accent-hover: #f59e0b;
  --accent-subtle: rgba(251,191,36,0.12);
  --px-loading-accent: #fbbf24;
  font-family: var(--px-font);
  color: var(--px-text-primary);
  background: var(--px-bg-deep);
  position: relative;
  isolation: isolate;
  z-index: 0;
}

:where(.dch-container) .dch-content {
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: dchFadeIn 0.4s ease;
}

@keyframes dchFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

:where(.dch-container) .dch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

/* ===== Filters Card ===== */
:where(.dch-container) .dch-filters-card {
  background: var(--px-bg-card);
  border: 1px solid var(--px-border);
  border-radius: 12px;
  box-shadow: var(--px-shadow);
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

:where(.dch-container) .dch-filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
  flex: 1;
}

:where(.dch-container) .dch-filter-group.dch-filter-dropdown {
  min-width: 280px;
  flex: 2;
}

:where(.dch-container) .dch-filter-label {
  font-family: var(--px-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--px-text-muted);
}

:where(.dch-container) .dch-input {
  font-family: var(--px-font);
  font-size: 13px;
  padding: 10px 14px;
  border: 1px solid var(--px-border);
  border-radius: 8px;
  background: var(--px-input-bg);
  color: var(--px-text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

:where(.dch-container) .dch-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

:where(.dch-container) .dch-input::placeholder {
  color: var(--px-text-muted);
}

:where(.dch-container) .dch-autocomplete {
  position: relative;
}

:where(.dch-container) .dch-autocomplete-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--px-bg-card);
  border: 1px solid var(--px-border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
}

:where(.dch-container) .dch-autocomplete-dropdown.open {
  display: block;
}

:where(.dch-container) .dch-autocomplete-option {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--px-text-primary);
  cursor: pointer;
  transition: background 0.15s;
}

:where(.dch-container) .dch-autocomplete-option:hover,
:where(.dch-container) .dch-autocomplete-option.active {
  background: var(--accent-subtle);
}

:where(.dch-container) .dch-autocomplete-option.dch-all-homes {
  font-style: italic;
  color: var(--px-text-muted);
  border-bottom: 1px solid var(--px-border);
}

/* Toggle switch */
:where(.dch-container) .dch-toggle-container {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}

:where(.dch-container) .dch-toggle-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--px-text-secondary);
  transition: color 0.2s;
}

:where(.dch-container) .dch-toggle-label.active {
  color: var(--accent);
}

:where(.dch-container) .dch-toggle {
  position: relative;
  width: 48px;
  height: 26px;
  cursor: pointer;
}

:where(.dch-container) .dch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

:where(.dch-container) .dch-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--px-border);
  border-radius: 13px;
  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;
}

:where(.dch-container) .dch-toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

:where(.dch-container) .dch-toggle input:checked + .dch-toggle-slider {
  background: var(--accent);
}

:where(.dch-container) .dch-toggle input:checked + .dch-toggle-slider::before {
  transform: translateX(22px);
}

/* ===== Table Card ===== */
:where(.dch-container) .dch-table-card {
  background: var(--px-bg-card);
  border: 1px solid var(--px-border);
  border-radius: 12px;
  box-shadow: var(--px-shadow);
  overflow: hidden;
}

:where(.dch-container) .dch-table-scroll {
  max-height: 60vh;
  overflow-y: auto;
}

:where(.dch-container) .dch-table th {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: #422006;
  font-family: var(--px-mono);
  font-size: 0.8rem;
  font-weight: 700;
}

:where(.dch-container) .dch-table th input {
  width: 100%;
  margin-top: 8px;
  padding: 6px 10px;
  border: 1px solid rgba(66, 32, 6, 0.3);
  border-radius: 4px;
  font-size: 12px;
  background: rgba(255,255,255,0.9);
  color: #422006;
}

:where(.dch-container) .dch-table th input::placeholder {
  color: rgba(66, 32, 6, 0.5);
}

:where(.dch-container) .dch-table th input:focus {
  outline: none;
  border-color: #422006;
  background: white;
}

:where(.dch-container) .dch-table td {
  font-size: 13px;
  color: var(--px-text-secondary);
}

:where(.dch-container) .dch-table tbody tr:hover {
  transform: translateX(4px);
}

:where(.dch-container) .dch-table tbody tr {
  animation: dchRowReveal 0.3s ease both;
}

@keyframes dchRowReveal {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

:where(.dch-container) .dch-no-results {
  text-align: center;
  padding: 48px 24px;
  color: var(--px-text-muted);
  font-size: 15px;
  font-family: var(--px-mono);
}

:where(.dch-container) .dch-note {
  text-align: center;
  font-style: italic;
  font-size: 12px;
  color: var(--px-text-muted);
  margin-top: -8px;
}

:where(.dch-container) .dch-action-cell {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  :where(.dch-container) .dch-content { padding: 16px; gap: 16px; }
  :where(.dch-container) .dch-filters-card { gap: 12px; }
  :where(.dch-container) .dch-filter-group { min-width: 140px; }
}

@media (max-width: 600px) {
  :where(.dch-container) .dch-content { padding: 12px; gap: 12px; }
  :where(.dch-container) .dch-filters-card { flex-direction: column; }
  :where(.dch-container) .dch-filter-group { min-width: 100%; }
  :where(.dch-container) .dch-table-card {
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }
  :where(.dch-container) .dch-table-scroll {
    max-height: none;
    overflow: visible;
  }
}

/* ===== Mobile Dispatch Cards ===== */
:where(.dch-container) .dch-cards-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

:where(.dch-container) .dch-card {
  background: var(--px-bg-card);
  border: 1px solid var(--px-border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--px-shadow);
  animation: dchRowReveal 0.3s ease both;
}

:where(.dch-container) .dch-card-field {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid rgba(128,128,128,0.1);
}

:where(.dch-container) .dch-card-field:last-of-type {
  border-bottom: none;
}

:where(.dch-container) .dch-card-label {
  font-family: var(--px-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--px-text-muted);
  flex-shrink: 0;
  margin-right: 12px;
}

:where(.dch-container) .dch-card-value {
  font-size: 13px;
  color: var(--px-text-primary);
  text-align: right;
  word-break: break-word;
}

:where(.dch-container) .dch-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

:where(.dch-container) .dch-card-actions .px-btn {
  flex: 1;
  min-width: 0;
  text-align: center;
  justify-content: center;
}
