/* Design tokens + component styles copied verbatim from
   fda_scraper/public/styles.css (header, filter-panel, search-wrap, btn,
   results-bar, filter-grid). Keep these byte-identical to that source so a
   visitor can't tell they crossed a Worker boundary — see CLAUDE.md. */
:root {
  --app-header-h: 52px;
  --bg: #F7F8FA;
  --bg-raised: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F9FAFB;
  --bg-input: #FFFFFF;
  --border: #D8DDE5;
  --border-focus: #2D3F86;
  --text: #5E5E5E;
  --text-dim: #6B7280;
  --text-bright: #2D3F86;
  --accent: #2D3F86;
  --accent-dim: rgba(45,63,134,0.1);
  --accent-glow: rgba(45,63,134,0.05);
  --applied: #F97316;
  --green: #16a34a;
  --red: #E85036;
  --blue: #2D3F86;
  --slate: #9CA3AF;
  --font-display: 'Poppins', system-ui, sans-serif;
  --font-body: 'Poppins', system-ui, sans-serif;
  --font-mono: 'Menlo', 'Consolas', monospace;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

::selection { background: var(--accent); color: #fff; }

/* ── Header: /shared/site-header.css on the shared host (one copy for all
   three apps, loaded after this file). Not duplicated here. ── */

/* In-app tabs; switched from the header's Warning Letters menu ([data-app-tab]). */
.tab-content { display: none; }
.tab-content.tab-active { display: block; }

/* ── App container — matches fda_scraper's actual content width exactly:
   #dataTableTab's direct children use width: min(100%, 80vw, 1560px),
   centered. Neither edge-to-edge nor a small fixed column — same formula,
   same breakpoint, so the app doesn't feel like a different width. ── */
.app-container {
  width: min(100%, 80vw, 1560px);
  margin: 0 auto;
  padding: 20px 28px 60px;
}
@media (max-width: 1200px) {
  .app-container { width: 100%; }
}
@media (max-width: 700px) {
  .reg-layout { flex-direction: column; }
  .reg-sidebar { width: 100%; position: static; max-height: none; }
}

/* ── Filter panel — copied from fda_scraper .filter-panel / .filter-header / .filter-body ── */
.filter-panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  transition: border-color 0.2s;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.filter-panel:focus-within { border-color: var(--border-focus); }
.filter-header {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #E3E7EF;
  background: #F3F5FA;
  color: var(--text-bright);
}
.filter-header h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  color: var(--text-bright);
  flex: 1;
  margin: 0;
}
.filter-body { padding: 16px 20px 20px; }

.search-wrap { position: relative; margin-bottom: 14px; }
.search-wrap .search-wrap-icon {
  position: absolute; left: 14px; top: 13px;
  color: var(--text-dim); pointer-events: none;
}
.search-everything {
  width: 100%;
  padding: 11px 14px 11px 40px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-bright);
  font-family: var(--font-body);
  font-size: 15px;
  transition: all 0.2s;
  margin-bottom: 0;
}
.search-everything::placeholder { color: #C0C5CC; font-style: italic; }
.search-everything:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--bg-input);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px 12px;
  margin-bottom: 4px;
}
.filter-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.filter-grid input, .filter-grid select {
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  appearance: none;
  -webkit-appearance: none;
}
.filter-grid select {
  padding-right: 32px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
}
.filter-grid input:focus, .filter-grid select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.filter-actions { display: flex; gap: 8px; margin-top: 14px; }

/* ── Buttons — copied from fda_scraper .btn / .btn-primary ── */
.btn {
  padding: 7px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.02em;
}
.btn:hover { border-color: var(--text-dim); color: var(--text-bright); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}
.btn-primary:hover { background: #E85036; border-color: #E85036; color: #FFFFFF; }

/* ── Results bar — copied from fda_scraper .results-bar ── */
.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-bottom: none;
  background: var(--bg-raised);
  flex-shrink: 0;
}
.results-bar h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 300;
  color: var(--text-bright);
  letter-spacing: -0.02em;
  margin: 0;
}
.results-bar h2 strong {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.results-bar .meta { color: var(--text-dim); font-size: 13px; }
.reg-filter-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 12px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.reg-filter-chip-clear {
  border: none;
  background: none;
  color: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 50%;
}
.reg-filter-chip-clear:hover { background: rgba(0,0,0,0.08); }

/* ── Tabular view — new for this source; styled with the same tokens ── */
.table-wrap {
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--bg-raised);
  overflow-x: auto;
}
table.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.results-table thead th {
  position: sticky;
  top: 0;
  background: #F3F5FA;
  color: var(--text-dim);
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.results-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}
.results-table thead th.sortable:hover { color: var(--text-bright); }
.results-table thead th.sortable .sort-arrow {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.3;
  font-size: 10px;
}
.results-table thead th.sortable.sort-active { color: var(--accent); }
.results-table thead th.sortable.sort-active .sort-arrow { opacity: 1; }
.results-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  cursor: pointer;
}
.results-table tbody tr:last-child { border-bottom: none; }
.results-table tbody tr:hover { background: var(--bg-card-hover); }
.results-table td {
  padding: 12px 16px;
  vertical-align: top;
  color: var(--text);
}
.results-table td.col-company {
  color: var(--text-bright);
  font-weight: 600;
  max-width: 260px;
}
.results-table td.col-date { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.results-table td.col-subject { color: var(--text-dim); }
.results-table .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(22,163,74,0.1);
  color: var(--green);
}
.empty-state, .loading-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* ── Pagination ── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--bg-raised);
}
.pagination-bar .page-info {
  color: var(--text-dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pagination-bar .page-controls { display: flex; gap: 8px; align-items: center; }
.pagination-bar .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Regulations tab — tree sidebar + "at a glance" detail panel,
   modeled on fda.innolitics.com/submissions/{panel} ── */
.reg-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.reg-sidebar {
  width: 300px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  padding: 16px;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
}
.reg-sidebar .search-wrap { margin-bottom: 10px; }
.reg-sidebar-count {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.reg-sidebar-count strong { color: var(--text-bright); font-variant-numeric: tabular-nums; }
.reg-detail {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  padding: 24px;
}

/* Tree — three levels (Category > Part > Subpart), state driven entirely
   by JS (regTreeState in search.js), never by native <details> toggling:
   re-rendering after any selection must reproduce exactly what was open,
   or every click collapses everything else back to closed. */
.reg-tree-category { margin-bottom: 2px; }
.reg-tree-category-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: var(--radius-sm);
}
.reg-tree-category-header:hover { background: var(--bg-card-hover); }
.reg-tree-category-header.active { color: var(--accent); }
.reg-tree-category-name { flex: 1; }
.reg-tree-category-count { font-weight: 400; text-transform: none; letter-spacing: 0; }

.reg-tree-arrow {
  display: inline-flex;
  width: 14px;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 11px;
}

.reg-tree-part {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px 7px 20px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background 0.1s;
}
.reg-tree-part:hover { background: var(--bg-card-hover); }
.reg-tree-part.active { background: var(--accent-dim); }
.reg-tree-part.active .reg-tree-part-number { color: var(--accent); font-weight: 700; }
.reg-tree-part-number {
  font-family: var(--font-mono);
  color: var(--text-bright);
  font-weight: 600;
  flex-shrink: 0;
}
.reg-tree-part-name {
  flex: 1;
  min-width: 0;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reg-tree-part-count { color: var(--text-dim); font-size: 12px; flex-shrink: 0; }

.reg-tree-subpart {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 6px 38px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  transition: background 0.1s;
}
.reg-tree-subpart:hover { background: var(--bg-card-hover); }
.reg-tree-subpart.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.reg-tree-subpart-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reg-tree-subpart-count { flex-shrink: 0; }
.reg-tree-loading {
  padding: 6px 10px 6px 38px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

/* Detail panel breadcrumb + hint */
.reg-breadcrumb {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
.reg-breadcrumb-sep { margin: 0 4px; opacity: 0.5; }
.reg-detail-hint {
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
  margin: 0 0 12px;
}

/* Detail panel */
.reg-detail-header { margin-bottom: 20px; }
.reg-detail-header h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  color: var(--text-bright);
  margin: 0 0 4px;
}
.reg-detail-header .reg-detail-subtitle { color: var(--text-dim); font-size: 14px; }

.reg-glance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.reg-glance-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 12px 16px;
}
.reg-glance-tile .reg-glance-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.reg-glance-tile .reg-glance-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-bright);
  font-variant-numeric: tabular-nums;
}
.reg-glance-tile .reg-glance-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.reg-subpart { margin-bottom: 24px; }
.reg-subpart h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-bright);
  margin: 0;
}
.reg-subpart > h3 {
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.reg-subpart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.reg-subpart-header h3 { flex-shrink: 1; min-width: 0; }
.reg-section-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.reg-section-row:last-child { border-bottom: none; }
.reg-section-row .reg-section-id {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  flex-shrink: 0;
  width: 90px;
}
.reg-section-row .reg-section-title { flex: 1; color: var(--text); font-size: 14px; }
.reg-section-row .reg-section-count { color: var(--text-dim); font-size: 13px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.reg-section-row .reg-section-view { flex-shrink: 0; }
.reg-view-letters-btn { white-space: nowrap; }
.reg-section-row .reg-view-letters-btn,
.reg-subpart-header .reg-view-letters-btn {
  font-size: 12px;
  padding: 5px 12px;
}

/* ── Letter detail modal — copied from fda_scraper .modal-overlay/.modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  overflow-y: auto;
  padding: 40px 20px;
}
.modal-overlay.open { display: block; }
.modal {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  max-width: 820px;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  padding: 28px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 14px; right: 18px;
  font-size: 20px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-dim);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text-bright); background: #F6F6F6; }
.modal h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  color: var(--text-bright);
  margin: 0 0 4px;
  padding-right: 32px;
}
.modal .modal-subtitle { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.modal-section { margin-bottom: 20px; }
.modal-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.modal-section table { width: 100%; border-collapse: collapse; font-size: 14px; }
.modal-section td, .modal-section th {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.modal-section th {
  color: var(--text-dim);
  font-weight: 500;
  width: 140px;
  white-space: nowrap;
}
.modal-section td { color: var(--text); word-break: break-word; }
.modal-section .letter-body {
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
  max-height: 420px;
  overflow-y: auto;
  line-height: 1.6;
}
/* Fallback for the rare letter with no letter_html (raw HTML didn't match
   the expected template) -- render the flattened plain text as-is. */
.modal-section .letter-body-plain { white-space: pre-wrap; }
/* letter_html itself is FDA's own paragraph/list structure (see
   letter-html.ts / normalize.py::extract_letter_html) -- style it the way
   the official detail page does rather than relying on whitespace. */
.modal-section .letter-body p { margin: 0 0 12px; }
.modal-section .letter-body p:last-child { margin-bottom: 0; }
.modal-section .letter-body p.wl-center { text-align: center; }
.modal-section .letter-body strong, .modal-section .letter-body b { font-weight: 700; color: var(--text-bright); }
.modal-section .letter-body em, .modal-section .letter-body i { font-style: italic; }
.modal-section .letter-body ul, .modal-section .letter-body ol {
  margin: 0 0 12px;
  padding-left: 22px;
}
.modal-section .letter-body li { margin-bottom: 6px; }
.modal-hint {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  margin: -4px 0 10px;
}
.modal-section .cfr-chip {
  position: relative;
  display: inline-block;
  padding: 2px 8px;
  margin: 0 6px 6px 0;
  background: var(--accent-dim);
  color: var(--accent);
  border: none;
  border-radius: 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background 0.15s;
}
.modal-section .cfr-chip:hover,
.modal-section .cfr-chip:focus-visible {
  background: var(--accent);
  color: #FFFFFF;
}
.modal-section .cfr-chip-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: 260px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 10px 12px;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.12s, transform 0.12s;
  pointer-events: none;
}
.modal-section .cfr-chip:hover .cfr-chip-tooltip,
.modal-section .cfr-chip:focus-visible .cfr-chip-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.modal-section .cfr-chip-tooltip-title {
  display: block;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
  white-space: normal;
  margin-bottom: 4px;
}
.modal-section .cfr-chip-tooltip-meta {
  display: block;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-dim);
  white-space: normal;
  margin-bottom: 6px;
}
.modal-section .cfr-chip-tooltip-cta {
  display: block;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: normal;
}
.modal-footer-link { font-size: 13px; color: var(--text-dim); }
.modal-footer-link a { color: var(--accent); }

/* Visually hidden, still read by screen readers and search engines (the
   page's <h1>). Same rule as fda_scraper's public/styles.css .sr-only. */
.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;
}
