:root {
  --rf-font: var(--madison-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  --rf-page: #f4f3ef;
  --rf-surface: #fffefa;
  --rf-surface-raised: #ffffff;
  --rf-surface-subtle: #f7f7f3;
  --rf-text: #20262e;
  --rf-heading: #171c22;
  --rf-muted: #56616d;
  --rf-faint: #626d79;
  --rf-border: #deded7;
  --rf-border-strong: #c9cac2;
  --rf-accent: #4153b3;
  --rf-accent-strong: #324296;
  --rf-accent-soft: #eef0ff;
  --rf-accent-border: #cdd3fb;
  --rf-primary-bg: #4153b3;
  --rf-primary-hover: #324296;
  --rf-primary-text: #ffffff;
  --rf-interest-bg: #f7f7f3;
  --rf-interest-hover: #efefe9;
  --rf-interest-text: #68717c;
  --rf-interest-border: #deded7;
  --rf-danger: #a23b3b;
  --rf-focus: rgba(65, 83, 179, 0.2);
  --rf-shadow: 0 18px 50px rgba(37, 39, 43, 0.07);
  --rf-radius-sm: 8px;
  --rf-radius-md: 12px;
  --rf-radius-lg: 20px;
  --rf-skeleton: #e8e8e2;
  --rf-skeleton-highlight: rgba(255, 255, 255, 0.72);
  --rf-highlight: #fff0a8;
  --rf-highlight-text: #302500;
  color-scheme: light;
}

html[data-theme="dark"],
body[data-theme="dark"],
:root[data-theme="dark"] {
  --rf-page: #111310;
  --rf-surface: #171a17;
  --rf-surface-raised: #1b1e1b;
  --rf-surface-subtle: #20231f;
  --rf-text: #e8e9e4;
  --rf-heading: #f6f6f2;
  --rf-muted: #c0c5bd;
  --rf-faint: #a3aba1;
  --rf-border: #30342f;
  --rf-border-strong: #454a43;
  --rf-accent: #aeb8ff;
  --rf-accent-strong: #c3caff;
  --rf-accent-soft: #252a48;
  --rf-accent-border: #424a79;
  --rf-primary-bg: #596bc9;
  --rf-primary-hover: #4d5db4;
  --rf-primary-text: #ffffff;
  --rf-interest-bg: #222620;
  --rf-interest-hover: #2b3029;
  --rf-interest-text: #d0d5cc;
  --rf-interest-border: #41473f;
  --rf-danger: #ffaaaa;
  --rf-focus: rgba(174, 184, 255, 0.24);
  --rf-shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
  --rf-skeleton: #292d28;
  --rf-skeleton-highlight: rgba(255, 255, 255, 0.06);
  --rf-highlight: #6b5717;
  --rf-highlight-text: #fff7d1;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]),
  body:not([data-theme="light"]) {
    --rf-page: #111310;
    --rf-surface: #171a17;
    --rf-surface-raised: #1b1e1b;
    --rf-surface-subtle: #20231f;
    --rf-text: #e8e9e4;
    --rf-heading: #f6f6f2;
    --rf-muted: #c0c5bd;
    --rf-faint: #a3aba1;
    --rf-border: #30342f;
    --rf-border-strong: #454a43;
    --rf-accent: #aeb8ff;
    --rf-accent-strong: #c3caff;
    --rf-accent-soft: #252a48;
    --rf-accent-border: #424a79;
    --rf-primary-bg: #596bc9;
    --rf-primary-hover: #4d5db4;
    --rf-primary-text: #ffffff;
    --rf-interest-bg: #222620;
    --rf-interest-hover: #2b3029;
    --rf-interest-text: #d0d5cc;
    --rf-interest-border: #41473f;
    --rf-danger: #ffaaaa;
    --rf-focus: rgba(174, 184, 255, 0.24);
    --rf-shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
    --rf-skeleton: #292d28;
    --rf-skeleton-highlight: rgba(255, 255, 255, 0.06);
    --rf-highlight: #6b5717;
    --rf-highlight-text: #fff7d1;
    color-scheme: dark;
  }
}

.research-page,
.research-page * {
  box-sizing: border-box;
}

body.research-page {
  min-height: 100vh;
  margin: 0;
  padding: 0;
  background: var(--rf-page);
  color: var(--rf-text);
  font-family: var(--rf-font);
  -webkit-font-smoothing: antialiased;
}

.research-page button,
.research-page textarea,
.research-page select,
.research-page summary {
  font: inherit;
}

.research-page [hidden],
.hidden,
.is-hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.research-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.research-header {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.research-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--rf-heading);
  text-decoration: none;
  border-radius: 12px;
}

.research-brand:hover .research-brand-mark {
  border-color: var(--rf-accent);
  background: var(--rf-accent-soft);
}

.research-brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rf-border-strong);
  border-radius: 11px;
  background: var(--rf-surface);
  color: var(--rf-heading);
  font: 700 1rem/1 var(--madison-serif-font);
}

.research-header h1 {
  margin: 0;
  color: var(--rf-heading);
  font-size: 1rem;
  font-weight: 720;
  letter-spacing: -0.01em;
}

.research-header p {
  margin: 2px 0 0;
  color: var(--rf-muted);
  font-size: 0.78rem;
}

.research-nav,
.research-context-actions,
.composer-submit-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.utility-menu,
.workspace-actions-menu {
  position: relative;
}

.utility-menu > summary,
.workspace-actions-menu > summary,
.bill-details > summary,
.section-comparison-details > summary {
  list-style: none;
}

.utility-menu > summary::-webkit-details-marker,
.workspace-actions-menu > summary::-webkit-details-marker,
.bill-details > summary::-webkit-details-marker,
.section-comparison-details > summary::-webkit-details-marker {
  display: none;
}

.research-page .icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--rf-border);
  border-radius: 999px;
  background: var(--rf-surface);
  color: var(--rf-muted);
  cursor: pointer;
}

.research-page .icon-btn:hover {
  border-color: var(--rf-accent-border);
  background: var(--rf-accent-soft);
  color: var(--rf-accent);
}

.research-page .icon-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.7;
}

.utility-menu-popover,
.workspace-actions-popover {
  position: absolute;
  z-index: 20;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  padding: 10px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-md);
  background: var(--rf-surface-raised);
  box-shadow: var(--rf-shadow);
}

.utility-menu-label {
  display: block;
  padding: 4px 6px 8px;
  color: var(--rf-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.history-nav-btn {
  min-height: 40px;
  padding-inline: 10px;
}

.account-btn {
  min-height: 40px !important;
  padding: 8px 14px !important;
}

.madison-dialog {
  width: min(94vw, 500px);
  max-height: min(86vh, 760px);
  margin: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: var(--rf-text);
}

.madison-dialog::backdrop {
  background: rgba(14, 18, 24, 0.58);
  backdrop-filter: blur(3px);
}

.dialog-card {
  position: relative;
  max-height: min(86vh, 760px);
  padding: 32px;
  overflow-y: auto;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-lg);
  background: var(--rf-surface-raised);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.25);
}

.dialog-card h2 {
  margin: 0;
  color: var(--rf-heading);
  font: 600 2rem/1.1 var(--madison-serif-font);
  letter-spacing: -0.025em;
}

.dialog-intro {
  margin: 10px 0 24px;
  color: var(--rf-muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.auth-oauth-providers {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.auth-oauth-providers[hidden] {
  display: none;
}

.auth-provider-btn {
  position: relative;
  display: inline-flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 42px;
  appearance: none;
  border: 1px solid var(--rf-border-strong);
  border-radius: 999px;
  background: var(--rf-surface);
  color: var(--rf-text);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 680;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.auth-provider-btn:hover:not(:disabled) {
  border-color: var(--rf-accent-border);
  background: var(--rf-accent-soft);
  color: var(--rf-accent);
}

.auth-provider-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.auth-provider-btn[aria-busy="true"]::after {
  position: absolute;
  right: 16px;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 700ms linear infinite;
}

.auth-provider-icon {
  position: absolute;
  left: 16px;
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
}

.auth-oauth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 5px 0 1px;
  color: var(--rf-muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.auth-oauth-divider::before,
.auth-oauth-divider::after {
  height: 1px;
  flex: 1;
  background: var(--rf-border);
  content: "";
}

.research-page .dialog-close {
  position: absolute;
  z-index: 1;
  top: 16px;
  right: 16px;
  font-size: 1.35rem;
  line-height: 1;
}

.account-form {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  background: transparent;
}

.account-form label {
  margin-top: 8px;
  color: var(--rf-text);
  font-size: 0.8rem;
  font-weight: 700;
}

.account-form input,
.history-search,
.history-rename-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--rf-border-strong);
  border-radius: 10px;
  outline: none;
  background: var(--rf-surface);
  color: var(--rf-text);
  font: inherit;
}

.account-form input:focus,
.history-search:focus,
.history-rename-input:focus {
  border-color: var(--rf-accent);
  box-shadow: 0 0 0 4px var(--rf-focus);
}

#auth-password-field {
  display: grid;
  gap: 9px;
}

.account-form .primary-btn {
  margin-top: 10px;
}

.auth-dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.form-status {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--rf-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.form-status[data-type="error"] {
  color: var(--rf-danger);
}

.form-status[data-type="success"] {
  color: var(--rf-accent);
}

.history-dialog {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(440px, calc(100vw - 40px));
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  border-left: 1px solid var(--rf-border);
  background: var(--rf-surface-raised);
  color: var(--rf-text);
  box-shadow: -24px 0 70px rgba(18, 22, 27, 0.18);
}

.history-dialog[open] {
  display: block;
  animation: historyDrawerIn 220ms ease-out both;
}

.history-dialog::backdrop {
  background: transparent;
}

.history-drawer-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--rf-surface-raised);
}

.history-drawer-header {
  min-height: 96px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: max(22px, env(safe-area-inset-top)) 24px 18px;
  border-bottom: 1px solid var(--rf-border);
}

.history-drawer-header .eyebrow {
  margin-bottom: 4px;
}

.history-drawer-header h2 {
  margin: 0;
  color: var(--rf-heading);
  font: 600 1.8rem/1.08 var(--madison-serif-font);
  letter-spacing: -0.025em;
}

.research-page .history-drawer-collapse {
  flex: 0 0 auto;
  margin-left: -44px;
  border-color: var(--rf-border-strong);
  background: var(--rf-surface-raised);
  color: var(--rf-accent);
  box-shadow: -8px 0 24px rgba(18, 22, 27, 0.1);
  font-size: 1.55rem;
  line-height: 1;
}

.history-drawer-tools {
  padding: 18px 24px 12px;
  border-bottom: 1px solid var(--rf-border);
  background: var(--rf-surface-raised);
}

.history-drawer-tools .dialog-intro {
  margin: 0 0 14px;
}

.history-search {
  margin-bottom: 2px;
  border-radius: 999px;
  background: var(--rf-surface-subtle);
}

.history-drawer-content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.history-list {
  display: grid;
  gap: 10px;
  padding: 16px 24px max(28px, env(safe-area-inset-bottom));
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 15px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-md);
  background: var(--rf-surface-subtle);
}

.history-item-copy {
  min-width: 0;
}

.history-item-name {
  margin: 0;
  overflow: hidden;
  color: var(--rf-heading);
  font-size: 0.94rem;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-query {
  display: -webkit-box;
  margin: 5px 0 8px;
  overflow: hidden;
  color: var(--rf-muted);
  font-size: 0.82rem;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.history-item-meta {
  color: var(--rf-faint);
  font-size: 0.72rem;
}

.history-item-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 5px;
  padding-top: 2px;
}

.history-item-actions .text-btn {
  padding: 5px 7px;
  font-size: 0.76rem;
}

.history-item-actions .history-delete-btn {
  color: var(--rf-danger);
}

.history-empty {
  padding: 56px 20px;
  border: 1px dashed var(--rf-border);
  border-radius: var(--rf-radius-md);
  color: var(--rf-muted);
  text-align: center;
}

.research-page .theme-picker {
  width: 100%;
  justify-content: space-between;
  border-color: var(--rf-border);
  background: var(--rf-surface-subtle);
}

.research-page .theme-picker-option {
  min-width: 40px;
  height: 34px;
  padding: 7px 12px;
}

.research-layout {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  flex: 1;
}

.research-composer-panel {
  width: min(820px, 100%);
  margin: clamp(64px, 10vh, 112px) auto 72px;
  padding: clamp(28px, 5vw, 48px);
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-lg);
  background: var(--rf-surface);
  box-shadow: var(--rf-shadow);
}

body:not([data-ui-state="idle"]) .research-composer-panel {
  margin-top: 32px;
}

.composer-heading {
  max-width: 680px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--rf-accent);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.composer-heading h2 {
  margin: 0;
  color: var(--rf-heading);
  font: 600 clamp(2rem, 5vw, 3.25rem)/1.05 var(--madison-serif-font);
  letter-spacing: -0.035em;
}

.composer-intro {
  max-width: 620px;
  margin: 16px 0 0;
  color: var(--rf-muted);
  font-size: 1rem;
  line-height: 1.65;
}

.research-page .research-form {
  display: block;
  margin: 0;
  padding: 0;
  background: transparent;
  overflow: visible;
}

.interest-presets {
  margin: 18px 0 20px;
}

.interest-presets-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--rf-faint);
  font-size: 0.76rem;
}

.interest-presets-heading > :first-child {
  color: var(--rf-text);
  font-size: 0.82rem;
  font-weight: 720;
}

.interest-preset-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.research-page .interest-preset {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 14px;
  border: 1px solid var(--rf-interest-border);
  border-radius: 999px;
  background: var(--rf-interest-bg);
  color: var(--rf-interest-text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  white-space: nowrap;
}

.research-page .interest-preset:hover {
  border-color: var(--rf-border-strong);
  background: var(--rf-interest-hover);
  color: var(--rf-text);
}

.interest-preset[aria-pressed="true"] {
  border-color: var(--rf-accent-border);
  background: var(--rf-accent-soft);
  color: var(--rf-accent-strong);
}

.interest-preset-check {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--rf-border-strong);
  border-radius: 50%;
  color: transparent;
  font-size: 0.68rem;
  line-height: 1;
}

.interest-preset[aria-pressed="true"] .interest-preset-check {
  border-color: var(--rf-accent);
  background: var(--rf-accent);
  color: var(--rf-page);
}

.policy-area-picker {
  position: relative;
  margin-top: 10px;
  max-width: 430px;
}

.policy-area-picker > summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 12px;
  border: 1px solid var(--rf-border);
  border-radius: 10px;
  background: var(--rf-surface);
  color: var(--rf-text);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 680;
  list-style: none;
}

.policy-area-picker > summary::-webkit-details-marker {
  display: none;
}

.policy-area-picker > summary::after {
  content: "⌄";
  color: var(--rf-faint);
  transition: transform 0.18s ease;
}

.policy-area-picker[open] > summary::after {
  transform: rotate(180deg);
}

.policy-area-picker-count {
  margin-left: auto;
  color: var(--rf-faint);
  font-size: 0.74rem;
  font-weight: 600;
}

.policy-area-picker-panel {
  position: absolute;
  z-index: 30;
  width: min(430px, calc(100vw - 48px));
  margin-top: 6px;
  padding: 12px;
  border: 1px solid var(--rf-border);
  border-radius: 12px;
  background: var(--rf-surface);
  box-shadow: var(--rf-shadow);
}

.policy-area-picker-panel input[type="search"] {
  width: 100%;
  min-height: 38px;
  box-sizing: border-box;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--rf-border);
  border-radius: 8px;
  background: var(--rf-page);
  color: var(--rf-text);
}

.policy-area-options {
  max-height: 280px;
  overflow-y: auto;
  display: grid;
  gap: 2px;
}

.policy-area-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 7px 6px;
  border-radius: 7px;
  color: var(--rf-text);
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1.3;
}

.policy-area-option:hover {
  background: var(--rf-interest-hover);
}

.policy-area-option input {
  margin-top: 2px;
  accent-color: var(--rf-accent);
}

.policy-area-empty {
  margin: 8px 4px 2px;
  color: var(--rf-faint);
  font-size: 0.8rem;
}

.research-form textarea {
  width: 100%;
  min-height: 144px;
  max-height: 280px;
  padding: 20px;
  resize: vertical;
  border: 1px solid var(--rf-border-strong);
  border-radius: 14px;
  outline: none;
  background: var(--rf-surface-raised);
  color: var(--rf-text);
  font-size: 1.05rem;
  line-height: 1.55;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.research-form textarea::placeholder {
  color: var(--rf-faint);
}

.research-form textarea:focus,
.research-congress-select:focus,
.research-page button:focus-visible,
.research-page summary:focus-visible,
.research-page a:focus-visible {
  outline: none;
  border-color: var(--rf-accent);
  box-shadow: 0 0 0 4px var(--rf-focus);
}

.composer-footer {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.research-congress-select {
  min-height: 44px;
  padding: 10px 36px 10px 14px;
  border: 1px solid var(--rf-border);
  border-radius: 999px;
  outline: none;
  background: var(--rf-surface-subtle);
  color: var(--rf-text);
  font-size: 0.88rem;
  font-weight: 650;
}

.research-congress-field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.congress-help {
  position: relative;
}

.congress-help > summary {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rf-border);
  border-radius: 50%;
  background: var(--rf-surface);
  color: var(--rf-accent);
  font-weight: 800;
  font-family: Georgia, serif;
  cursor: pointer;
  list-style: none;
}

.congress-help > summary::-webkit-details-marker {
  display: none;
}

.congress-help-popover {
  position: absolute;
  z-index: 20;
  left: 0;
  bottom: calc(100% + 10px);
  width: min(320px, calc(100vw - 48px));
  padding: 14px 16px;
  border: 1px solid var(--rf-border);
  border-radius: 12px;
  background: var(--rf-surface);
  color: var(--rf-text);
  box-shadow: var(--rf-shadow);
  font-size: 0.86rem;
  line-height: 1.5;
}

.congress-help-popover p {
  margin: 6px 0 0;
  color: var(--rf-muted);
}

.answer-stats {
  min-width: 0;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--rf-border);
}

.answer-stats-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.answer-stats-heading h3 {
  margin: 0;
  color: var(--rf-text);
  font-size: 0.96rem;
}

.answer-stats-heading span {
  color: var(--rf-muted);
  font-size: 0.76rem;
}

.answer-stats-chart {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  height: 180px;
  margin-top: 12px;
  padding: 12px 8px 0;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  overflow-x: auto;
  border: 1px solid var(--rf-border);
  border-radius: 12px;
  background: var(--rf-surface-subtle);
}

.answer-stats-bar-item {
  height: 100%;
  min-width: 24px;
  flex: 1 0 24px;
  display: grid;
  grid-template-rows: 18px 1fr 28px;
  align-items: end;
  justify-items: center;
  gap: 3px;
}

.answer-stats-count {
  color: var(--rf-muted);
  font-size: 0.7rem;
  align-self: start;
}

.answer-stats-bar {
  width: min(18px, 78%);
  min-height: 2px;
  border-radius: 5px 5px 1px 1px;
  background: var(--rf-accent);
}

.answer-stats-month {
  color: var(--rf-muted);
  font-size: 0.65rem;
  line-height: 1;
  text-align: center;
}

.answer-stats-month small {
  display: block;
  margin-top: 2px;
  font-size: 0.6rem;
}

.answer-stats-note {
  margin: 10px 0 0;
  color: var(--rf-muted);
  font-size: 0.78rem;
}

.research-followup {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--rf-border);
}

.research-followup h3 {
  margin: 3px 0 5px;
  font-size: 1rem;
}

.research-followup .muted {
  margin: 0;
}

.research-followup-form {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.research-followup-form input {
  min-height: 44px;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 13px;
  border: 1px solid var(--rf-border);
  border-radius: 10px;
  background: var(--rf-surface);
  color: var(--rf-text);
  font: inherit;
}

.research-followup-form input:focus {
  outline: none;
  border-color: var(--rf-accent);
  box-shadow: 0 0 0 4px var(--rf-focus);
}

.research-steps {
  margin-top: 12px;
  color: var(--rf-muted);
  font-size: 0.82rem;
}

.research-steps summary {
  cursor: pointer;
}

.research-steps summary span {
  display: inline-grid;
  min-width: 20px;
  min-height: 20px;
  margin-left: 5px;
  place-items: center;
  border-radius: 999px;
  background: var(--rf-surface-subtle);
  color: var(--rf-text);
}

.research-steps ol {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.research-step {
  display: grid;
  gap: 7px;
  margin: 10px 0;
  padding: 14px;
  border: 1px solid var(--rf-border);
  border-radius: 12px;
  background: var(--rf-surface);
  color: var(--rf-text);
}

.research-step.is-active {
  border-color: color-mix(in srgb, var(--rf-accent) 58%, var(--rf-border));
  box-shadow: 0 0 0 2px var(--rf-focus);
}

.research-step-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.research-step-open {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 7px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.research-step-open:focus-visible,
.research-step-delete:focus-visible {
  outline: 2px solid var(--rf-accent);
  outline-offset: 3px;
}

.research-step-delete {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid var(--rf-border);
  border-radius: 8px;
  background: transparent;
  color: var(--rf-muted);
  font: inherit;
  cursor: pointer;
}

.research-step-delete:hover {
  border-color: var(--rf-danger, #b42318);
  color: var(--rf-danger, #b42318);
}

.research-step-label {
  width: fit-content;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--rf-surface-subtle);
  color: var(--rf-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.research-step-query {
  font-size: 0.92rem;
}

.research-step-answer {
  color: var(--rf-muted);
  line-height: 1.55;
  white-space: pre-line;
}

@media (max-width: 640px) {
  .research-followup-form {
    grid-template-columns: 1fr;
  }
}

.research-page .primary-btn,
.research-page .secondary-btn,
.research-page .text-btn,
.research-page .menu-action {
  appearance: none;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.research-page .primary-btn,
.research-page .secondary-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 680;
}

.research-page .primary-btn {
  border: 1px solid var(--rf-primary-bg);
  background: var(--rf-primary-bg);
  color: var(--rf-primary-text);
}

.research-page .primary-btn:hover {
  border-color: var(--rf-primary-hover);
  background: var(--rf-primary-hover);
  transform: translateY(-1px);
}

.research-page .primary-btn-lg {
  min-height: 48px;
  padding: 12px 19px;
}

.research-page .primary-btn svg {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

.research-page .secondary-btn {
  border: 1px solid var(--rf-border-strong);
  background: var(--rf-surface);
  color: var(--rf-text);
}

.research-page .secondary-btn:hover {
  border-color: var(--rf-accent-border);
  background: var(--rf-accent-soft);
  color: var(--rf-accent);
}

.research-page .text-btn {
  padding: 4px;
  background: transparent;
  color: var(--rf-accent);
  font-size: 0.88rem;
  font-weight: 680;
}

.research-page .text-btn:hover {
  color: var(--rf-accent-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.research-page .primary-btn:disabled,
.research-page .secondary-btn:disabled,
.research-page .text-btn:disabled,
.research-page .menu-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.composer-secondary-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--rf-muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.guest-history-callout {
  margin: -10px 0 20px;
  padding: 12px 14px;
  border: 1px solid var(--rf-accent-border);
  border-radius: 12px;
  background: var(--rf-accent-soft);
  color: var(--rf-text);
}

.guest-history-callout > span {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  font-weight: 650;
}

.guest-history-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.research-page .composer-secondary-actions .text-btn {
  min-height: 24px;
  padding-block: 0;
  display: inline-flex;
  align-items: center;
  font-size: inherit;
  line-height: inherit;
}

body[data-ui-state="idle"] .composer-cancel-btn {
  display: none;
}

.research-workspace {
  margin: 20px auto 64px;
}

.research-context-bar {
  padding: 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-md);
  background: var(--rf-surface);
}

.research-context-copy {
  min-width: 0;
}

.context-scope {
  display: block;
  margin-bottom: 4px;
  color: var(--rf-accent);
  font-size: 0.72rem;
  font-weight: 740;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.research-context-copy p {
  margin: 0;
  overflow: hidden;
  color: var(--rf-heading);
  font-size: 1rem;
  font-weight: 640;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-toolbar {
  position: sticky;
  z-index: 10;
  top: 10px;
  margin: 16px 0 0;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--rf-border);
  border-radius: 999px;
  background: var(--rf-surface);
  box-shadow:
    0 0 0 12px var(--rf-page),
    0 8px 30px rgba(30, 33, 38, 0.06);
}

.results-display-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
}

.research-page .results-display-toggle-btn {
  min-height: 40px;
  padding: 9px 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--rf-muted);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 680;
}

.research-page .results-display-toggle-btn:not([aria-selected="true"]):hover {
  background: var(--rf-surface-subtle);
  color: var(--rf-text);
}

.research-page .results-display-toggle-btn[aria-selected="true"] {
  border-color: var(--rf-border);
  background: var(--rf-surface-raised);
  color: var(--rf-heading);
  box-shadow: 0 2px 8px rgba(32, 38, 46, 0.06);
}

.view-count {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--rf-surface-subtle);
  color: var(--rf-muted);
  font-size: 0.72rem;
}

.workspace-actions-menu > summary {
  min-height: 40px;
  padding: 8px 15px;
  cursor: pointer;
}

.workspace-actions-popover {
  display: grid;
  gap: 2px;
}

.research-page .menu-action {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border-radius: var(--rf-radius-sm);
  background: transparent;
  color: var(--rf-text);
  text-align: left;
  font-size: 0.86rem;
}

#research-brief-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#research-brief-toggle[aria-expanded="true"]::after {
  content: "✓";
  color: var(--rf-accent);
  font-size: 0.9rem;
  font-weight: 800;
}

.research-page .menu-action:hover {
  background: var(--rf-surface-subtle);
}

.research-progress {
  min-height: 42px;
  margin: 12px 4px 0;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--rf-muted);
  font-size: 0.82rem;
}

.progress-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #61a477;
}

.research-progress.is-active .progress-dot {
  background: var(--rf-accent);
  box-shadow: 0 0 0 5px var(--rf-focus);
  animation: progressPulse 1.4s ease-in-out infinite;
}

.research-progress.is-error {
  color: var(--rf-danger);
}

.research-progress.is-error .progress-dot {
  background: var(--rf-danger);
}

.workspace-content {
  overflow: clip;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-lg);
  background: var(--rf-surface);
  box-shadow: var(--rf-shadow);
}

.workspace-view {
  min-width: 0;
}

.workspace-section,
.workspace-summary-view {
  padding: clamp(24px, 4vw, 40px);
}

.workspace-section + .workspace-section {
  border-top: 1px solid var(--rf-border);
}

.workspace-section-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.workspace-section-header h2 {
  margin: 0;
  color: var(--rf-heading);
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  font-weight: 710;
  letter-spacing: -0.025em;
}

.workspace-section-header .muted {
  max-width: 680px;
  margin: 7px 0 0;
  line-height: 1.55;
}

.count-label {
  flex: 0 0 auto;
  color: var(--rf-muted);
  font-size: 0.8rem;
  font-weight: 680;
}

.card-stack,
.section-group,
.section-group-list {
  display: grid;
  gap: 10px;
}

.section-group + .section-group {
  margin-top: 18px;
}

.section-group-header {
  position: sticky;
  z-index: 2;
  top: 82px;
  padding: 8px 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--rf-surface);
}

.section-group-title {
  color: var(--rf-heading);
  font-family: var(--madison-serif-font);
  font-size: 0.82rem;
  font-weight: 740;
}

.pill {
  padding: 4px 8px;
  border: 1px solid var(--rf-border);
  border-radius: 999px;
  background: var(--rf-surface-subtle);
  color: var(--rf-muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.bill-card,
.section-card-inline {
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-md);
  background: var(--rf-surface-raised);
}

.bill-card {
  padding: 16px 18px;
}

.bill-card-primary,
.section-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.bill-card-primary {
  margin-bottom: 5px;
}

.bill-card-primary strong,
.section-card-header strong {
  color: var(--rf-heading);
}

.bill-card-primary > div,
.section-card-header strong {
  font-family: var(--madison-serif-font);
}

.bill-meta,
.section-preview,
.muted {
  color: var(--rf-muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.section-summary-status {
  color: var(--rf-muted);
  font-size: 0.9rem;
}

.bill-meta,
.section-preview {
  margin: 5px 0 0;
  font-size: 0.8rem;
  line-height: 1.5;
}

.bill-details {
  margin-top: 10px;
}

.bill-details > summary,
.section-comparison-details > summary {
  width: fit-content;
  color: var(--rf-accent);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 680;
}

.bill-details > summary::after,
.section-comparison-details > summary::after {
  content: " +";
}

.bill-details[open] > summary::after,
.section-comparison-details[open] > summary::after {
  content: " –";
}

.bill-details-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--rf-border);
}

.bill-metadata-group {
  display: grid;
  grid-template-columns: minmax(90px, 0.24fr) 1fr;
  gap: 10px;
  margin-top: 8px;
  color: var(--rf-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.bill-metadata-group > strong {
  color: var(--rf-text);
}

.bill-metadata-values a {
  color: var(--rf-accent);
}

.bill-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bill-actions .primary-btn,
.bill-actions .secondary-btn,
.section-view-link {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 0.78rem;
}

.section-card-inline {
  padding: 20px;
}

.section-card-header {
  margin-bottom: 14px;
}

.section-card-study-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.section-card-header > div > div {
  margin-top: 3px;
  color: var(--rf-muted);
  font-size: 0.83rem;
}

.section-card-inline a:not(.secondary-btn) {
  color: var(--rf-accent);
}

.section-ai-summary {
  margin-top: 12px;
}

.section-summary-progressive {
  display: grid;
  gap: 14px;
}

.section-summary-translation > h5,
.section-summary-pane > h5 {
  margin: 0 0 8px;
  color: var(--rf-muted);
  font-size: 0.69rem;
  font-weight: 760;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.section-summary-translation-body {
  color: var(--rf-text);
  font-size: 0.9rem;
  line-height: 1.65;
}

.section-summary-translation-body p {
  margin: 0 0 10px;
}

.section-summary-translation-body p:last-child,
.section-summary-main-copy > *:last-child {
  margin-bottom: 0;
}

.section-summary-translation-body.is-clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 70%, rgba(0, 0, 0, 0.3) 100%);
  mask-image: linear-gradient(to bottom, #000 70%, rgba(0, 0, 0, 0.3) 100%);
}

.research-page .section-summary-clamp-toggle {
  margin-top: 6px;
  padding-inline: 0;
  font-size: 0.8rem;
}

.section-comparison-details {
  padding-top: 12px;
  border-top: 1px solid var(--rf-border);
}

.section-comparison-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.section-summary-pane {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-sm);
  background: var(--rf-surface-subtle);
}

.section-summary-source pre {
  margin: 0;
  color: var(--rf-text);
  font: 0.82rem/1.65 var(--rf-font);
  white-space: pre-wrap;
}

.section-summary-detail-body > .section-summary-main-copy:first-child {
  display: none;
}

.analysis-bucket-grid {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.section-summary-impact-card,
.analysis-speculation-block,
.analysis-checklist,
.section-summary-grounding-note {
  padding: 12px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-sm);
  background: var(--rf-surface-raised);
}

.section-summary-impact-card h6,
.analysis-checklist-block h6,
.section-summary-grounding-note h6,
.analysis-speculation-label {
  margin: 0 0 6px;
  color: var(--rf-muted);
  font-size: 0.68rem;
  font-weight: 760;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.section-summary-impact-card ul,
.analysis-speculation-block ul,
.analysis-checklist ul,
.overall-summary-content ul,
.overall-summary-content ol {
  margin: 0;
  padding-left: 18px;
}

.section-summary-impact-card li + li,
.analysis-checklist li + li,
.overall-summary-content li + li {
  margin-top: 6px;
}

.analysis-speculation-block,
.analysis-checklist {
  margin-top: 10px;
}

.analysis-checklist > summary {
  color: var(--rf-accent);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 680;
}

.analysis-checklist-block {
  margin-top: 10px;
}

.analysis-buckets-details,
.analysis-speculation-details {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-sm);
  background: var(--rf-surface-raised);
}

.analysis-buckets-details > summary,
.analysis-speculation-details > summary {
  color: var(--rf-accent);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 680;
  list-style: none;
}

.analysis-buckets-details > summary::-webkit-details-marker,
.analysis-speculation-details > summary::-webkit-details-marker {
  display: none;
}

.analysis-buckets-details > summary::after,
.analysis-speculation-details > summary::after {
  content: " +";
}

.analysis-buckets-details[open] > summary::after,
.analysis-speculation-details[open] > summary::after {
  content: " –";
}

.analysis-buckets-details > .analysis-bucket-grid {
  margin-top: 12px;
}

/* The speculation block is already framed by the expander card; drop its own frame. */
.analysis-speculation-details > .analysis-speculation-block {
  margin-top: 12px;
  padding: 0;
  border: 0;
  background: transparent;
}

.section-summary-empty {
  margin: 0;
  color: var(--rf-muted);
  font-style: italic;
}

.overall-summary-panel {
  min-height: 180px;
}

.overall-summary-content.direct-answer-content {
  max-width: 42rem;
}

.overall-summary-content.direct-answer-content.has-answer-chart {
  width: 100%;
  max-width: none;
}

.direct-answer-card {
  display: grid;
  min-width: 0;
  box-sizing: border-box;
  gap: 0.85rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--rf-border);
  border-radius: 14px;
  background: var(--rf-surface-subtle);
}

.direct-answer-card p {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--rf-text);
}

.direct-answer-card ul {
  margin: 0;
  padding-left: 1.2rem;
}

.direct-answer-card li + li {
  margin-top: 0.35rem;
}

.direct-answer-card a {
  color: var(--rf-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

#overall-summary-card.is-direct-answer .summary-heading h2 {
  font-size: clamp(1.45rem, 2vw, 1.8rem);
}

.overall-summary-content {
  max-width: 800px;
  color: var(--rf-text);
  font-size: 0.96rem;
  line-height: 1.72;
}

.overall-summary-content h2,
.overall-summary-content h3,
.overall-summary-content h4 {
  margin: 24px 0 8px;
  color: var(--rf-heading);
  font-family: var(--madison-serif-font, Georgia, serif);
  font-size: 1rem;
  font-weight: 700;
}

.overall-summary-content p {
  margin: 0 0 12px;
}

.overall-summary-content .analysis-bucket-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.overall-summary-content .section-summary-impact-card {
  padding: 16px;
  background: var(--rf-surface-subtle);
}

.study-notebook-toggle {
  white-space: nowrap;
}

.study-notebook {
  position: fixed;
  z-index: 45;
  top: 84px;
  right: max(20px, calc((100vw - 1160px) / 2));
  width: min(390px, calc(100vw - 32px));
  max-height: calc(100vh - 108px);
  overflow: hidden;
  border: 1px solid var(--rf-border-strong);
  border-radius: var(--rf-radius-lg);
  background: var(--rf-surface-raised);
  box-shadow: var(--rf-shadow);
}

.study-notebook-header {
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--rf-border);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.study-notebook.is-dragging {
  user-select: none;
}

.study-notebook.is-dragging .study-notebook-header {
  cursor: grabbing;
}

.study-notebook-header h2,
.study-section-heading h3 {
  margin: 0;
  color: var(--rf-heading);
}

.study-notebook-header h2 {
  font-size: 1.15rem;
}

.study-notebook-header .muted {
  margin: 6px 0 0;
}

.study-notebook-body {
  max-height: calc(100vh - 245px);
  padding: 18px 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.study-session-note label {
  display: block;
  margin-bottom: 7px;
  color: var(--rf-heading);
  font-size: 0.82rem;
  font-weight: 720;
}

.study-session-note textarea,
.study-item-note {
  width: 100%;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-sm);
  background: var(--rf-surface);
  color: var(--rf-text);
  resize: vertical;
}

.study-session-note textarea {
  min-height: 92px;
  padding: 11px 12px;
  line-height: 1.5;
}

.study-save-status {
  min-height: 18px;
  display: block;
  margin-top: 5px;
  color: var(--rf-muted);
  font-size: 0.72rem;
}

.study-notebook-section {
  margin-top: 22px;
}

.study-section-heading {
  margin-bottom: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.study-section-heading h3 {
  font-size: 0.88rem;
}

.study-section-heading span {
  color: var(--rf-muted);
  font-size: 0.74rem;
}

.study-item-list {
  display: grid;
  gap: 9px;
}

.study-item-list > .muted {
  margin: 0;
}

.study-item {
  padding: 12px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-sm);
  background: var(--rf-surface-subtle);
}

.study-item-quote,
.study-item-label {
  margin: 0;
  color: var(--rf-text);
  font-size: 0.82rem;
  line-height: 1.5;
}

.study-item-quote {
  padding-left: 9px;
  border-left: 3px solid var(--rf-highlight);
}

.study-item-context {
  margin: 6px 0 0;
  color: var(--rf-muted);
  font-size: 0.7rem;
}

.study-item-note {
  min-height: 62px;
  margin-top: 9px;
  padding: 8px 9px;
  font-size: 0.78rem;
  line-height: 1.45;
}

.study-item-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.study-item-actions .text-btn {
  min-height: 30px;
  padding: 3px 0;
  font-size: 0.74rem;
}

.study-item-actions .study-delete-btn {
  color: var(--rf-danger);
}

.study-selection-toolbar {
  position: fixed;
  z-index: 60;
  display: flex;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--rf-border-strong);
  border-radius: 10px;
  background: var(--rf-heading);
  box-shadow: var(--rf-shadow);
}

.study-selection-toolbar button {
  min-height: 34px;
  padding: 6px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--rf-surface-raised);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
}

.study-selection-toolbar button:hover,
.study-selection-toolbar button:focus-visible {
  background: color-mix(in srgb, var(--rf-surface-raised) 16%, transparent);
}

.study-highlight {
  padding: 1px 0;
  border-radius: 2px;
  background: var(--rf-highlight);
  color: var(--rf-highlight-text);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  cursor: pointer;
}

.study-highlight:focus-visible,
.study-highlight.is-focused {
  outline: 3px solid var(--rf-accent);
  outline-offset: 2px;
}

.study-bookmark-btn {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--rf-border);
  border-radius: 8px;
  background: var(--rf-surface);
  color: var(--rf-accent);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
}

.study-bookmark-btn[aria-pressed="true"] {
  border-color: var(--rf-accent-border);
  background: var(--rf-accent-soft);
  color: var(--rf-accent-strong);
}

.section-card-inline.is-study-target,
.bill-card.is-study-target {
  scroll-margin-top: 110px;
  box-shadow: 0 0 0 3px var(--rf-focus);
}

.overall-summary-loading,
.overall-summary-skeleton,
.skeleton-lines {
  display: grid;
  gap: 10px;
}

.overall-summary-loading-head {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--rf-muted);
  font-size: 0.84rem;
}

.overall-summary-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--rf-border);
  border-top-color: var(--rf-accent);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

.skeleton-card {
  min-height: 82px;
  padding: 16px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-md);
  background: var(--rf-surface-raised);
}

.skeleton-line {
  position: relative;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--rf-skeleton);
}

.skeleton-line::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 -120px;
  width: 120px;
  background: linear-gradient(90deg, transparent, var(--rf-skeleton-highlight), transparent);
  animation: shimmer 1.4s infinite;
}

.skeleton-line.wide { width: 100%; }
.skeleton-line.medium { width: 68%; }
.skeleton-line.short { width: 40%; }

.summary-loading {
  opacity: 0.72;
}

.empty-state {
  min-height: 72px;
  display: grid;
  align-items: center;
  padding: 18px;
  border: 1px dashed var(--rf-border);
  border-radius: var(--rf-radius-md);
  background: var(--rf-surface-subtle);
}

.empty-state p {
  margin: 0;
  font-size: 0.86rem;
}

.research-brief {
  margin-top: 16px;
  padding: 24px;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius-lg);
  background: var(--rf-surface);
}

.research-brief-header {
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.research-brief-status {
  color: var(--rf-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.research-brief-body {
  max-height: 380px;
  overflow: auto;
  color: var(--rf-text);
  font-size: 0.88rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.research-brief-body.analysis-rendered {
  white-space: normal;
}

.research-disclaimer {
  width: min(760px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 32px;
  color: var(--rf-faint);
  font-size: 0.74rem;
  line-height: 1.5;
  text-align: center;
}

.research-disclaimer p {
  margin: 4px 0;
}

.research-disclaimer a {
  color: var(--rf-muted);
  text-underline-offset: 2px;
}

@media (min-width: 761px) {
  body[data-ui-state="idle"] .research-header {
    padding-block: 18px;
  }

  body[data-ui-state="idle"] .research-composer-panel {
    margin: clamp(32px, 5vh, 52px) auto 36px;
    padding: clamp(28px, 4vw, 36px);
  }

  body[data-ui-state="idle"] .composer-heading {
    margin-bottom: 20px;
  }

  body[data-ui-state="idle"] .composer-heading h2 {
    font-size: clamp(2rem, 4vw, 2.85rem);
  }

  body[data-ui-state="idle"] .composer-intro {
    margin-top: 12px;
    line-height: 1.5;
  }

  body[data-ui-state="idle"] .interest-presets {
    margin: 14px 0;
  }

  body[data-ui-state="idle"] .interest-presets-heading {
    margin-bottom: 8px;
  }

  body[data-ui-state="idle"] .interest-preset-rail {
    gap: 6px;
  }

  body[data-ui-state="idle"] .interest-preset {
    min-height: 34px;
    padding: 6px 10px 6px 12px;
  }

  body[data-ui-state="idle"] .research-form textarea {
    min-height: 124px;
    padding: 16px;
  }

  body[data-ui-state="idle"] .guest-history-callout {
    margin-bottom: 16px;
  }

  body[data-ui-state="idle"] .research-disclaimer {
    padding-block: 16px 22px;
  }
}

@media (min-width: 761px) and (max-height: 760px) {
  body[data-ui-state="idle"] .research-header {
    padding-block: 12px;
  }

  body[data-ui-state="idle"] .research-composer-panel {
    margin: 16px auto;
    padding: 24px;
  }

  body[data-ui-state="idle"] .composer-heading {
    margin-bottom: 14px;
  }

  body[data-ui-state="idle"] .eyebrow {
    margin-bottom: 5px;
  }

  body[data-ui-state="idle"] .composer-heading h2 {
    font-size: 2.55rem;
  }

  body[data-ui-state="idle"] .composer-intro {
    margin-top: 8px;
    font-size: 0.92rem;
    line-height: 1.4;
  }

  body[data-ui-state="idle"] .interest-presets {
    margin: 10px 0;
  }

  body[data-ui-state="idle"] .interest-presets-heading {
    margin-bottom: 6px;
  }

  body[data-ui-state="idle"] .interest-preset-rail {
    gap: 5px;
  }

  body[data-ui-state="idle"] .interest-preset {
    min-height: 30px;
    padding: 4px 8px 4px 10px;
    font-size: 0.78rem;
  }

  body[data-ui-state="idle"] .interest-preset-check {
    width: 16px;
    height: 16px;
  }

  body[data-ui-state="idle"] .research-form textarea {
    min-height: 92px;
    padding: 14px;
    font-size: 0.96rem;
  }

  body[data-ui-state="idle"] .composer-footer {
    margin-top: 10px;
  }

  body[data-ui-state="idle"] .research-congress-select,
  body[data-ui-state="idle"] .primary-btn-lg {
    min-height: 42px;
  }

  body[data-ui-state="idle"] .guest-history-callout {
    margin: -4px 0 10px;
    gap: 6px;
  }

  body[data-ui-state="idle"] .research-disclaimer {
    padding-block: 8px 12px;
    font-size: 0.7rem;
    line-height: 1.35;
  }

  body[data-ui-state="idle"] .research-disclaimer p {
    margin-block: 2px;
  }
}

.animate-in {
  animation: fadeUp 260ms ease both;
}

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

@keyframes historyDrawerIn {
  from { opacity: 0.75; transform: translateX(28px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes progressPulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

@keyframes shimmer {
  to { transform: translateX(240px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 760px) {
  .research-header,
  .research-layout {
    width: min(100% - 28px, 1120px);
  }

  .research-header {
    padding: 18px 0;
  }

  .research-brand p {
    display: none;
  }

  .research-nav {
    gap: 6px;
  }

  .history-nav-btn {
    padding-inline: 6px;
    font-size: 0.78rem;
  }

  .account-btn {
    padding-inline: 11px !important;
  }

  .dialog-card {
    padding: 28px 20px 20px;
  }

  .history-dialog {
    width: 100vw;
    border-left: 0;
    box-shadow: none;
  }

  .history-dialog::backdrop {
    background: transparent;
    backdrop-filter: none;
  }

  .history-drawer-header {
    min-height: 82px;
    padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  }

  .research-page .history-drawer-collapse {
    margin-left: 0;
    box-shadow: none;
  }

  .history-drawer-tools {
    padding: 14px 16px 10px;
  }

  .history-drawer-tools .dialog-intro {
    display: none;
  }

  .history-list {
    padding: 12px 16px max(20px, env(safe-area-inset-bottom));
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .history-item-actions {
    justify-content: flex-start;
  }

  .history-item-actions .text-btn {
    min-height: 42px;
    flex: 1;
    padding-inline: 8px;
    border: 1px solid var(--rf-border);
    border-radius: 9px;
    background: var(--rf-surface);
    text-align: center;
  }

  .research-composer-panel {
    margin-top: 32px;
    padding: 24px 20px;
    border-radius: 16px;
  }

  .composer-heading h2 {
    font-size: 2.15rem;
  }

  .interest-presets {
    margin: 16px 0 18px;
  }

  .interest-presets-heading > :last-child {
    display: none;
  }

  .interest-preset-rail {
    width: calc(100% + 20px);
    margin-right: -20px;
    padding-right: 20px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .interest-preset-rail::-webkit-scrollbar {
    display: none;
  }

  .interest-preset {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .composer-footer,
  .research-context-bar,
  .workspace-section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .composer-submit-actions {
    justify-content: space-between;
  }

  .research-congress-select {
    width: 100%;
  }

  .research-context-bar {
    gap: 16px;
  }

  .research-context-actions {
    justify-content: space-between;
  }

  .research-context-copy p {
    white-space: normal;
  }

  .workspace-toolbar {
    position: static;
    top: auto;
    gap: 6px;
    border-radius: 14px;
  }

  .results-display-toggle {
    flex: 1 1 auto;
    min-width: 0;
    gap: 2px;
  }

  .research-page .results-display-toggle-btn {
    min-height: 44px;
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.79rem;
    white-space: nowrap;
  }

  /* Compact "Sources & sections" so the toolbar fits narrow screens */
  .research-page .results-display-toggle-btn[data-results-display-order="sections-first"] {
    font-size: 0;
    gap: 0;
  }

  .research-page .results-display-toggle-btn[data-results-display-order="sections-first"]::before {
    content: "Sources";
    font-size: 0.79rem;
  }

  .research-page .results-display-toggle-btn[data-results-display-order="sections-first"] .view-count {
    margin-left: 5px;
    font-size: 0.7rem;
  }

  .research-page .workspace-actions-menu > summary {
    flex: 0 0 auto;
    min-width: 44px;
    padding-inline: 10px;
    font-size: 0;
  }

  .workspace-actions-menu > summary::after {
    content: "•••";
    font-size: 0.9rem;
    letter-spacing: 0.08em;
  }

  /* Must beat .research-page .secondary-btn font-size or both labels show */
  .research-page .study-notebook-toggle {
    flex: 0 0 auto;
    min-width: 44px;
    padding-inline: 10px;
    font-size: 0;
    gap: 0;
  }

  .research-page .study-notebook-toggle::before {
    content: "Notes";
    font-size: 0.78rem;
  }

  .research-page .study-notebook-toggle .view-count {
    margin-left: 5px;
    font-size: 0.7rem;
  }

  .study-notebook {
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    width: 100vw;
    max-height: min(78vh, 680px);
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
  }

  .study-notebook-header {
    cursor: default;
    touch-action: auto;
  }

  .study-notebook-body {
    max-height: calc(min(78vh, 680px) - 118px);
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .study-selection-toolbar {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px !important;
    top: auto !important;
    justify-content: stretch;
  }

  .study-selection-toolbar button {
    flex: 1;
  }

  .workspace-section,
  .workspace-summary-view {
    padding: 24px 18px;
  }

  .section-group-header {
    position: static;
    top: auto;
  }

  .bill-card-primary,
  .section-card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .section-view-link {
    align-self: flex-start;
  }

  .section-card-study-actions {
    justify-content: flex-start;
  }

  .section-comparison-grid,
  .overall-summary-content .analysis-bucket-grid {
    grid-template-columns: 1fr;
  }

  .composer-secondary-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .guest-history-actions {
    width: 100%;
    flex-wrap: wrap;
    white-space: normal;
  }

  .guest-history-actions .composer-action-separator {
    display: none;
  }
}

@media (max-width: 420px) {
  .research-page .results-display-toggle-btn {
    padding: 8px 8px;
  }

  .research-page .study-notebook-toggle {
    padding-inline: 8px;
  }

  .view-count {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .research-page *,
  .research-page *::before,
  .research-page *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
