*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --border: #dde3ea;
  --accent: #1e5eff;
  --accent-hover: #1647cc;
  --header: #0f172a;
  --success: #0d7a4a;
  --error: #b42318;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.06);
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  background: var(--header);
  color: #fff;
  padding: 2rem 1.5rem;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
}

.header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: #94a3b8;
  font-size: 0.95rem;
}

.main {
  max-width: 1200px;
  margin: -1.25rem auto 3rem;
  padding: 0 1.5rem;
}

.search-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 0.9rem 1rem;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.tab:hover {
  background: #f8fafc;
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
  background: #f8fbff;
}

.tab-panel {
  display: none;
  padding: 1.5rem;
}

.tab-panel.active {
  display: block;
}

.search-form label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.input-row {
  display: flex;
  gap: 0.75rem;
}

.input-row input,
.input-row select {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.input-row input:focus,
.input-row select:focus {
  outline: 2px solid rgba(30, 94, 255, 0.25);
  border-color: var(--accent);
}

.input-row button,
.back-btn {
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.input-row button:hover,
.back-btn:hover {
  background: var(--accent-hover);
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.status {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.status.loading {
  background: #eff6ff;
  color: #1e40af;
}

.status.error {
  background: #fef3f2;
  color: var(--error);
}

.status.info {
  background: #f0fdf4;
  color: var(--success);
}

.hidden {
  display: none !important;
}

.list-section,
.detail-section {
  margin-top: 1.5rem;
}

.list-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.list-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.list-meta {
  font-size: 0.875rem;
  color: var(--muted);
}

.org-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.org-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  font: inherit;
  color: inherit;
}

.org-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.org-card-name {
  font-weight: 650;
  margin-bottom: 0.25rem;
}

.org-card-meta {
  font-size: 0.875rem;
  color: var(--muted);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.pagination button {
  min-width: 2.25rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  cursor: pointer;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pagination span {
  font-size: 0.875rem;
  color: var(--muted);
  padding: 0 0.5rem;
}

.back-btn {
  margin-bottom: 1rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.5rem 0.9rem;
}

.back-btn:hover {
  background: #f8fbff;
}

.org-detail {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.detail-hero {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f8fbff 0%, #fff 100%);
}

.detail-hero h2 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  line-height: 1.3;
}

.detail-hero .badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e8efff;
  color: #1e40af;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0;
}

.detail-block {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.detail-block:nth-child(odd) {
  border-right: 1px solid var(--border);
}

.detail-block h3 {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid #f1f5f9;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-row dt {
  color: var(--muted);
  flex-shrink: 0;
}

.detail-row dd {
  margin: 0;
  text-align: right;
  font-weight: 500;
  word-break: break-word;
}

/* --- Org profile: stats, tables, filings/financials --- */

.detail-loading {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--muted);
}

.detail-loading-title {
  font-weight: 650;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.stat-card {
  padding: 1.1rem 1.25rem;
  border-right: 1px solid var(--border);
  background: #fafbfd;
}

.stat-card:last-child {
  border-right: none;
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 0.25rem;
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.mission-block {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, #f0fdf4 0%, #fff 100%);
}

.mission-block h3 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.mission-block p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
}

.data-section {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.data-section.empty {
  color: var(--muted);
  font-size: 0.9rem;
  background: #fafbfd;
}

.data-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.data-section-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.data-section-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.detail-section-title {
  padding: 1rem 1.5rem 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  background: var(--surface);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
}

.data-table th {
  background: #f8fafc;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: #f8fbff;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table .mono {
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.mission-cell {
  max-width: 220px;
  color: var(--muted);
  font-size: 0.82rem;
}

.bar-cell {
  min-width: 100px;
  vertical-align: middle;
}

.bar-cell .bar {
  display: block;
  height: 6px;
  border-radius: 3px;
  margin: 2px 0;
  max-width: 100%;
}

.bar.revenue {
  background: var(--accent);
}

.bar.expense {
  background: #94a3b8;
}

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.status-badge.processed {
  background: #dcfce7;
  color: #166534;
}

.status-badge.pending {
  background: #fef9c3;
  color: #854d0e;
}

.inline-alert.error {
  margin: 1rem 1.5rem;
  padding: 0.75rem 1rem;
  background: #fef3f2;
  color: var(--error);
  border-radius: 8px;
  font-size: 0.9rem;
}

.financial-detail {
  background: #fafbfd;
}

.year-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.year-tab {
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.year-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.year-panel {
  display: none;
}

.year-panel.active {
  display: block;
}

.financial-summary-grid {
  margin-bottom: 1rem;
}

.sub-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.sub-section h4 {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text);
}

.count-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.data-table.compact th,
.data-table.compact td {
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
}

.flag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.flag-chip {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 0.75rem;
  font-weight: 500;
}

.schedule-badge {
  background: #f1f5f9;
  color: var(--text);
}

.supplemental-item {
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.supplemental-item summary {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

.supplemental-item p {
  margin: 0;
  padding: 0 0.75rem 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.55;
}

.muted-note {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.text-block p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}

.field-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.field-block .detail-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.84rem;
}

.field-block .detail-row:last-child {
  border-bottom: none;
}

.field-block .detail-row dt {
  color: var(--muted);
  font-weight: 500;
  flex-shrink: 0;
}

.field-block .detail-row dd {
  margin: 0;
  text-align: right;
  word-break: break-word;
}

.empty-row {
  text-align: center;
  color: var(--muted);
  font-style: italic;
}

.flags-table-wrap {
  max-height: 420px;
  overflow-y: auto;
}

.flag-yes {
  color: var(--success);
  font-weight: 600;
}

.flag-no {
  color: var(--muted);
}

.schedule-panels {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.schedule-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.schedule-panel summary {
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 650;
  background: #f8fafc;
}

.schedule-body {
  padding: 0.75rem 0.85rem;
  font-size: 0.82rem;
}

.data-tree-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.5rem;
}

.data-tree-table th,
.data-tree-table td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

.data-tree-table th {
  width: 45%;
  color: var(--muted);
  font-weight: 500;
}

.data-tree-node {
  margin-top: 0.5rem;
  padding-left: calc(var(--depth, 0) * 12px);
}

.data-tree-key {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
  font-size: 0.8rem;
}

.null-val {
  color: var(--muted);
  font-style: italic;
}

.financial-detail .year-panel {
  max-height: none;
}

#detail-section .org-detail {
  max-width: none;
}

@media (max-width: 600px) {
  .input-row {
    flex-direction: column;
  }

  .detail-block:nth-child(odd) {
    border-right: none;
  }

  .detail-row {
    flex-direction: column;
    gap: 0.15rem;
  }

  .detail-row dd {
    text-align: left;
  }

  .stat-card {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .stat-cards {
    grid-template-columns: 1fr;
  }
}
