:root {
  --ink: #111827;
  --graphite: #1f2937;
  --line: #d1d5db;
  --muted: #6b7280;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --accent: #2563eb;
  --accent-2: #1e40af;
  --danger: #64748b;
  --ok: #334155;
  --blue: #1d4ed8;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: #0f172a;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1.4fr) minmax(120px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  color: #f8fafc;
  background: #111827;
  border-bottom: 1px solid #374151;
}

.brand-block {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.brand-mark {
  display: block;
  width: min(220px, 46vw);
  height: 48px;
  object-fit: contain;
  object-position: left center;
  max-width: none;
}
.briefing-meta { margin: 0; color: #d1d5db; font-size: 12px; overflow-wrap: anywhere; }
.header-filter-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 8px;
}
.header-filter-zone .metric-sub { color: #cbd5e1; }
.header-filter-zone .link-button {
  flex: 0 0 auto;
  color: #bfdbfe;
}
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }

.workbench {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 0;
}

.app-footer {
  position: fixed;
  right: 10px;
  bottom: 8px;
  z-index: 20;
  padding: 4px 7px;
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid rgba(55, 65, 81, 0.9);
  color: #d1d5db;
  font-size: 11px;
  line-height: 1;
}
.app-footer strong {
  color: #f8fafc;
  font-weight: 850;
}

.filter-rail {
  background: #f9fafb;
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
  min-height: 0;
}
.filter-rail [draggable="true"].dragging {
  opacity: 0.54;
}

.rail-header, .panel-head, .table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rail-header h2, .panel-head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-label, .section-title {
  display: block;
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-field {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.search-field input {
  min-width: 0;
  border: 0;
  outline: 0;
}

.chip-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.stacked-options { display: grid; gap: 7px; }
.stacked-options.compact { grid-template-columns: 1fr; }
.badge-options { display: flex; flex-wrap: wrap; gap: 7px; }
#stanceFilters,
#statusFilters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.chip-button, .option-button, .filter-badge, .status-chip, .topic-chip, .stance-tag, .active-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 0;
}

.chip-button {
  min-height: 32px;
  padding: 6px 4px;
  font-size: 12px;
  font-weight: 800;
}

.option-button {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 9px;
  text-align: left;
  font-size: 12px;
}
.option-button span:first-child { min-width: 0; overflow-wrap: anywhere; }
.option-button span:last-child { flex-shrink: 0; }

.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  max-width: 100%;
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 750;
}
#stanceFilters .filter-badge,
#statusFilters .filter-badge {
  width: 100%;
}
.filter-badge span:first-child { min-width: 0; overflow-wrap: anywhere; }
.filter-badge span:last-child {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 11px;
}

.chip-button[aria-pressed="true"], .option-button[aria-pressed="true"], .filter-badge[aria-pressed="true"], .metric-card.active {
  border-color: var(--accent);
  background: #dbeafe;
  color: #1e3a8a;
}
.filter-badge[aria-pressed="true"] span:last-child { color: #1e3a8a; }

.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.date-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.date-grid input { width: 100%; min-width: 0; border: 1px solid var(--line); padding: 8px 6px; }

.main-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 16px;
  background: var(--surface-2);
  overflow: hidden;
}
.main-panel.drag-over::before {
  content: "Drop filter to apply";
  position: absolute;
  inset: 10px;
  z-index: 8;
  display: grid;
  place-items: start center;
  padding-top: 14px;
  border: 2px dashed #93c5fd;
  background: rgba(239, 246, 255, 0.72);
  color: #1e40af;
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.status-banner {
  display: block;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 13px;
}
[hidden].status-banner { display: none; }
.status-banner.ready { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.status-banner.error { background: #f8fafc; border-color: #94a3b8; color: #334155; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
}
.metric-card button {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}
.metric-value { display: block; font-size: 25px; font-weight: 850; }
.metric-label { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.metric-sub { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.active-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  min-width: 0;
  gap: 6px;
}
.active-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  min-height: 28px;
  padding: 3px 4px 3px 10px;
  font-size: 12px;
  font-weight: 750;
  overflow-wrap: anywhere;
  border-radius: 999px;
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e3a8a;
}
.active-chip span { min-width: 0; overflow-wrap: anywhere; }
.active-chip svg { flex: 0 0 auto; width: 13px; height: 13px; }
.active-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 22px;
  min-height: 22px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
}
.active-chip-remove:hover,
.active-chip-remove:focus-visible {
  background: #bfdbfe;
}
.active-chip.float-in {
  animation: filterFloatIn 420ms ease-out;
}

@keyframes filterFloatIn {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.35fr) repeat(3, minmax(180px, 1fr));
  grid-auto-rows: 238px;
  align-items: start;
  gap: 10px;
}

.chart-panel, .table-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 12px;
}
.chart-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 185px);
  gap: 8px;
  height: 238px;
  min-height: 0;
  max-height: 238px;
  overflow: hidden;
}
.chart-frame {
  position: relative;
  width: 100%;
  height: 185px;
  min-height: 0;
  overflow: hidden;
}
.chart-frame canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 185px !important;
  max-height: 185px !important;
}
.panel-head span, #resultCount { color: var(--muted); font-size: 12px; }

.table-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}
.table-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; min-width: 0; }

.text-button, .icon-button, .link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 0;
  text-decoration: none;
  font-size: 12px;
  font-weight: 750;
  white-space: normal;
}
.icon-button { width: 36px; padding: 0; }
.close-button {
  width: 30px;
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
}
.close-button:hover,
.close-button:focus-visible {
  color: var(--accent);
  background: transparent;
}
.link-button { border-color: transparent; background: transparent; color: var(--accent); }
.text-button svg, .icon-button svg, .search-field svg { width: 16px; height: 16px; }
.mobile-only { display: none; }

.status-chip, .topic-chip, .stance-tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.topic-chip { margin: 2px 3px 2px 0; border-color: #cbd5e1; background: #f8fafc; color: #334155; }
.stance-tag[data-stance="proactive"] { border-color: #93c5fd; background: #dbeafe; color: #1e3a8a; }
.stance-tag[data-stance="reactive"] { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }
.stance-tag[data-stance="resistance"] { border-color: #cbd5e1; background: #f1f5f9; color: #334155; }
.stance-tag[data-stance="study"] { border-color: #d1d5db; background: #f9fafb; color: #4b5563; }
.status-chip[data-status="passed/signed"] { border-color: #93c5fd; background: #dbeafe; color: var(--accent-2); }
.status-chip[data-status="failed"] { border-color: #cbd5e1; background: #f1f5f9; color: var(--danger); }
.status-chip[data-status="committee"] { border-color: #bfdbfe; background: #eff6ff; color: var(--blue); }

#billTable {
  margin-top: 10px;
  max-width: 100%;
  min-height: 0;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}
.tabulator { border: 1px solid var(--line); font-size: 12px; }
.tabulator .tabulator-header { border-bottom: 1px solid var(--line); }
.tabulator .tabulator-row.tabulator-selected { background: #dbeafe; }
.bill-dialog {
  width: min(880px, calc(100vw - 28px));
  max-height: min(860px, calc(100vh - 28px));
  border: 1px solid #111827;
  padding: 0;
  box-shadow: var(--shadow);
}
.metric-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: none;
  border: 1px solid #111827;
  padding: 0;
  box-shadow: var(--shadow);
  overflow: visible;
}
.metric-dialog::backdrop { background: rgba(15, 23, 42, 0.42); }
.metric-popover {
  display: grid;
  gap: 12px;
  overflow: visible;
  padding: 16px;
  background: var(--surface);
}
.metric-popover header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}
.metric-popover h2 { margin: 0; font-size: 18px; }
.metric-popover p { margin: 0; color: #334155; line-height: 1.45; }
.metric-popover dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.metric-popover dt { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.metric-popover dd { margin: 0; font-weight: 850; }
.metric-breakdown {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.metric-breakdown h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.metric-breakdown ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.metric-breakdown li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 6px 8px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  font-size: 13px;
}
.metric-breakdown span { min-width: 0; overflow-wrap: anywhere; }
.metric-actions { display: flex; justify-content: flex-end; gap: 8px; }
.bill-dialog::backdrop { background: rgba(17, 20, 24, 0.58); }
.modal-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  max-height: inherit;
  background: var(--surface);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-head p { margin: 6px 0 0; color: var(--muted); }
.modal-body { overflow: auto; padding: 16px; }
.modal-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
}
.source-link {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  text-decoration: none;
  text-transform: uppercase;
}
.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.detail-badge,
.detail-badges .status-chip,
.detail-badges .stance-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.2;
}
.detail-badge span,
.detail-badges .status-chip span,
.detail-badges .stance-tag span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}
.modal-notes {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.modal-copy { margin: 0; line-height: 1.45; color: #27313b; }
details { border-top: 1px solid var(--line); padding: 0; }
summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px 0;
  cursor: pointer;
  font-weight: 850;
}
.summary-title { min-width: 0; }
.summary-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}
.summary-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 7px;
  border: 1px solid #d1d5db;
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  text-transform: capitalize;
}
.section-copy {
  display: grid;
  gap: 10px;
  padding: 0 0 14px;
}
.section-copy p {
  max-width: 78ch;
  margin: 0;
  color: #27313b;
  font-size: 14px;
  line-height: 1.62;
}
.modal-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}

.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}
.toast {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 11px 12px;
  background: #111827;
  border: 1px solid #374151;
  color: #f9fafb;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.35;
}
.toast.error { background: #334155; border-color: #64748b; }
.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}
.toast-close svg { width: 15px; height: 15px; }

.copy-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid #111827;
  padding: 14px;
}
.copy-dialog form,
.copy-dialog label {
  display: grid;
  gap: 10px;
}
.copy-dialog label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.copy-dialog textarea {
  width: 100%;
  min-height: 170px;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  text-transform: none;
}

@media (max-width: 1180px) {
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: flex-start;
  }
  .header-filter-zone {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }
  .active-filters { justify-content: flex-start; }
  .topbar-actions { flex-shrink: 0; }
  .brand-block {
    display: grid;
    gap: 4px;
  }
  .brand-mark { width: min(180px, 48vw); height: 44px; max-width: none; }
  .briefing-meta { display: none; }
  .mobile-only { display: inline-flex; }
  .workbench { display: block; }
  .filter-rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    width: min(330px, 92vw);
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
  }
  .filter-rail.open { transform: translateX(0); }
  .main-panel { padding: 10px; }
  .metric-strip, .chart-grid { grid-template-columns: 1fr; }
  .table-head { align-items: flex-start; flex-direction: column; }
  .table-actions { justify-content: flex-start; width: 100%; }
  .table-actions .text-button { flex: 1 1 110px; min-width: 0; }
  .modal-foot { align-items: stretch; flex-direction: column; }
  #billTable .tabulator { min-width: 0; }
  .tabulator .tabulator-header-filter input { min-width: 0; }
  summary { grid-template-columns: 1fr; }
  .summary-tags { justify-content: flex-start; }
  .bill-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
  }
}
