/* ========================================================
   ETP Filing Tracker - REX Financial
   Clean Professional / Bloomberg-Style Design System
   ======================================================== */

:root {
  /* ===== COLOR PALETTE: Institutional Finance ===== */
  --navy:        #0f1923;
  --navy-light:  #1a2636;
  --navy-muted:  #2a3a4a;

  --blue:        #2196F3;
  --blue-hover:  #1976D2;
  --blue-subtle: #e3f2fd;

  --green:       #00C853;
  --green-bg:    #e8f5e9;
  --orange:      #FF9800;
  --orange-bg:   #fff3e0;
  --red:         #F44336;
  --red-bg:      #fdecea;
  --purple:      #7B1FA2;
  --purple-bg:   #f3e5f5;

  --gray-900:    #111827;
  --gray-700:    #374151;
  --gray-500:    #6B7280;
  --gray-400:    #9CA3AF;
  --gray-200:    #E5E7EB;
  --gray-100:    #F3F4F6;
  --gray-50:     #F9FAFB;
  --white:       #FFFFFF;

  /* Backwards-compatible aliases */
  --muted:       var(--gray-500);
  --border:      var(--gray-200);
  --light:       var(--gray-100);
  --gray:        var(--gray-500);

  /* ===== SPACING (4px base) ===== */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;  --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;  --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px;

  /* ===== TYPOGRAPHY ===== */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;

  --text-xs: 11px; --text-sm: 12px; --text-base: 13px; --text-md: 14px;
  --text-lg: 16px; --text-xl: 20px; --text-2xl: 24px; --text-3xl: 32px;

  /* ===== LAYOUT ===== */
  --container-width: 1280px;
  --nav-height: 48px;
  --radius-sm: 4px; --radius-md: 6px; --radius-lg: 8px; --radius-pill: 100px;

  /* ===== SHADOWS ===== */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);

  /* ===== TRANSITIONS ===== */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
}

/* ===== RESET & BASE ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  color: var(--gray-900);
  background: var(--gray-50);
  line-height: 1.5;
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--blue); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--blue-hover); text-decoration: none; }

.container { max-width: var(--container-width); margin: 0 auto; padding: var(--sp-5) var(--sp-6); }

.mono, .ticker-col, .accession-col {
  font-family: var(--font-mono);
  font-weight: 500;
}
.ticker-col {
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== STICKY NAV ===== */
.sticky-nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--navy);
  color: white;
  padding: 0 var(--sp-6);
  display: flex; align-items: center; gap: 0;
  height: var(--nav-height);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow-md);
}
.sticky-nav a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: 500;
  padding: 0 var(--sp-4);
  height: var(--nav-height);
  display: flex; align-items: center;
  border-bottom: 2px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.sticky-nav a:hover,
.sticky-nav a.active { color: white; text-decoration: none; }
.sticky-nav a.active { border-bottom-color: var(--blue); }
.sticky-nav .brand {
  font-weight: 700; font-size: 15px; color: white;
  letter-spacing: -0.3px;
  padding-right: var(--sp-6); margin-right: var(--sp-2);
  border-right: 1px solid rgba(255,255,255,0.15);
  border-bottom: none;
}
.sticky-nav select {
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.2);
  background: var(--navy-light); color: white;
  font-size: var(--text-sm);
}

/* ===== PAGE HEADER ===== */
.header { padding: var(--sp-8) 0 var(--sp-4); }
.header h1 {
  font-size: var(--text-2xl); font-weight: 700;
  color: var(--navy); letter-spacing: -0.5px; line-height: 1.3;
}
.header .date { color: var(--gray-500); font-size: var(--text-md); margin-top: var(--sp-1); }

/* Breadcrumb */
.breadcrumb { font-size: var(--text-sm); color: var(--gray-400); margin-bottom: var(--sp-1); }
.breadcrumb a { color: var(--gray-400); }
.breadcrumb a:hover { color: var(--blue); }
.breadcrumb .sep { margin: 0 var(--sp-1); }

/* ===== KPI CARDS ===== */
.kpi-row { display: flex; gap: var(--sp-3); margin: var(--sp-5) 0; flex-wrap: wrap; }
.kpi {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  flex: 1; min-width: 120px; text-align: center;
  border: 1px solid var(--border);
  border-top: 3px solid var(--navy);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base);
}
.kpi:hover { box-shadow: var(--shadow-md); }
.kpi .num {
  font-size: var(--text-3xl); font-weight: 700;
  font-family: var(--font-mono); line-height: 1.1;
}
.kpi .label {
  font-size: var(--text-xs); color: var(--gray-500);
  text-transform: uppercase; letter-spacing: 0.8px;
  font-weight: 600; margin-top: var(--sp-1);
}
.kpi-green .num { color: var(--green); }
.kpi-orange .num { color: var(--orange); }
.kpi-red .num { color: var(--red); }
.kpi-row-blue .kpi { border-top-color: var(--blue); }

/* ===== WHAT CHANGED BOX ===== */
.what-changed {
  background: var(--blue-subtle);
  border-left: 4px solid var(--blue);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-5) 0;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}
.what-changed h2 { font-size: var(--text-lg); margin-bottom: var(--sp-2); }
.what-changed .stat { display: inline-block; margin-right: var(--sp-5); font-size: var(--text-md); }
.what-changed .stat b { font-size: 18px; font-family: var(--font-mono); }

/* ===== SECTION HEADERS ===== */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: var(--sp-8) 0 var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 2px solid var(--navy);
}
.section-header h2 { font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.3px; }
.section-header .badge {
  background: var(--navy); color: white;
  padding: 2px 12px; border-radius: var(--radius-pill);
  font-size: var(--text-sm); font-weight: 600; font-family: var(--font-mono);
}

/* ===== TRUST ACCORDION ===== */
.trust-block {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  margin: var(--sp-3) 0; overflow: hidden;
  background: var(--white); box-shadow: var(--shadow-sm);
}
.trust-header {
  background: var(--gray-50); padding: var(--sp-3) var(--sp-4);
  cursor: pointer; display: flex; justify-content: space-between;
  align-items: center; user-select: none;
  transition: background var(--transition-fast);
}
.trust-header:hover { background: var(--gray-100); }
.trust-header h3 { font-size: 15px; margin: 0; font-weight: 600; }
.trust-header .stats { font-size: var(--text-sm); color: var(--gray-500); }
.trust-header .arrow { transition: transform var(--transition-base); font-size: var(--text-sm); }
.trust-block.open .arrow { transform: rotate(90deg); }
.trust-body { display: none; padding: 0; }
.trust-block.open .trust-body { display: block; }

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  align-items: center; flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.filter-bar input,
.filter-bar select {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  background: var(--white);
  transition: border-color var(--transition-fast);
}
.filter-bar input { width: 220px; }
.filter-bar input:focus,
.filter-bar select:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(33,150,243,0.1);
}
.filter-bar .count {
  font-size: var(--text-sm); color: var(--gray-500);
  margin-left: auto; font-family: var(--font-mono);
}

/* ===== PILL FILTERS ===== */
.pill {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm); font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--gray-200);
  background: var(--white); color: var(--gray-700);
  text-decoration: none;
  transition: all var(--transition-fast);
  display: inline-flex; align-items: center;
}
.pill:hover { background: var(--gray-100); text-decoration: none; border-color: var(--gray-400); }
.pill.active { background: var(--navy); color: white; border-color: var(--navy); }
.pill.active:hover { background: var(--navy-light); text-decoration: none; }

/* ===== TABLES ===== */
table {
  width: 100%; border-collapse: collapse;
  font-size: var(--text-base);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
th {
  background: var(--navy); color: rgba(255,255,255,0.9);
  padding: var(--sp-2) var(--sp-3);
  text-align: left; font-weight: 600;
  font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap; user-select: none;
  position: sticky; top: var(--nav-height); z-index: 10;
}
th.sortable { cursor: pointer; }
th.sortable:hover { background: var(--navy-light); }
th.sorted-asc::after { content: " \25B2"; font-size: 9px; opacity: 0.7; }
th.sorted-desc::after { content: " \25BC"; font-size: 9px; opacity: 0.7; }
td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tbody tr:first-child td { padding-top: var(--sp-3); }
tbody tr:nth-child(even) { background: var(--gray-50); }
tr.today-highlight { background: var(--green-bg); }

td.num-col, th.num-col { text-align: right; font-family: var(--font-mono); font-size: var(--text-sm); }
.ticker-col { font-family: var(--font-mono); font-weight: 600; font-size: var(--text-sm); letter-spacing: 0.3px; }
.accession-col { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--gray-500); }
.days-col { text-align: center; font-size: var(--text-sm); color: var(--gray-500); font-family: var(--font-mono); }
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
.table-wrap table { border: none; border-radius: 0; }

/* ===== STATUS BADGES ===== */
.status-effective { color: var(--green); font-weight: 600; }
.status-pending { color: var(--orange); font-weight: 600; }
.status-delayed { color: var(--red); font-weight: 600; }

/* ===== FORM BADGES ===== */
.form-badge {
  display: inline-block; padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 600;
  background: var(--gray-200); color: var(--navy);
}
.form-badge-effective { background: var(--green); color: white; }
.form-badge-extension { background: var(--blue); color: white; }
.form-badge-initial { background: var(--orange); color: white; }
.form-badge-supplement { background: var(--gray-500); color: white; }

/* Form filter pills (fund detail) */
.form-pill {
  cursor: pointer; padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  border: 2px solid var(--border);
  background: white; color: var(--navy); font-weight: 600;
}
.form-pill.active { background: var(--navy); color: white; border-color: var(--navy); }
.form-pill:hover { opacity: 0.8; }

/* REX badge */
.rex-badge {
  background: var(--blue); color: white;
  padding: 2px 8px; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 600;
  vertical-align: middle;
}

/* Tooltip */
.form-link { position: relative; }
.form-link .tooltip {
  display: none; position: absolute;
  background: #333; color: white;
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: var(--text-xs); white-space: nowrap;
  bottom: 100%; left: 0; z-index: 20;
}
.form-link:hover .tooltip { display: block; }

/* ===== TRUST CARD GRID (Dashboard) ===== */
.trust-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--sp-3); margin-top: var(--sp-3);
}
.trust-card {
  display: block; text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), border-color var(--transition-base), transform var(--transition-base);
}
.trust-card:hover {
  border-color: var(--blue); box-shadow: var(--shadow-md);
  transform: translateY(-1px); text-decoration: none; color: inherit;
}
.trust-card h3 { font-size: 14px; margin: 0; font-weight: 600; line-height: 1.3; }
.trust-card-header { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.trust-monogram {
  width: 40px; height: 40px; min-width: 40px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 14px;
  font-family: var(--font-mono); letter-spacing: -0.5px;
  text-transform: uppercase;
}
.trust-card-stats { display: flex; gap: var(--sp-3); font-size: var(--text-sm); color: var(--gray-500); flex-wrap: wrap; }
.trust-stat strong { font-family: var(--font-mono); font-size: var(--text-base); }
.trust-stat-green { color: var(--green); }
.trust-stat-orange { color: var(--orange); }
.trust-stat-red { color: var(--red); }
.trust-card-pending { font-size: var(--text-sm); color: var(--orange); font-weight: 600; }
.trust-card-pending span { font-weight: 400; color: var(--gray-400); font-size: var(--text-xs); }

/* ===== DOWNLOADS ===== */
.downloads { margin: var(--sp-5) 0; }
.dl-group { border: 1px solid var(--border); border-radius: var(--radius-lg); margin: var(--sp-2) 0; background: var(--white); box-shadow: var(--shadow-sm); }
.dl-group-header {
  background: var(--gray-50); padding: var(--sp-3) var(--sp-4);
  font-weight: 600; font-size: var(--text-md);
  cursor: pointer; display: flex; justify-content: space-between;
}
.dl-group-header:hover { background: var(--gray-100); }
.dl-group-body { display: none; padding: var(--sp-3) var(--sp-4); }
.dl-group.open .dl-group-body { display: block; }
.dl-btn {
  display: inline-block; padding: 6px 14px;
  margin: 3px 4px; border-radius: var(--radius-sm);
  font-size: var(--text-sm); color: white; text-decoration: none;
}
.dl-btn.excel { background: var(--green); }
.dl-btn.csv { background: var(--blue); }
.dl-btn:hover { opacity: 0.85; color: white; text-decoration: none; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: var(--text-base); font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer; border: none; text-decoration: none;
  transition: all var(--transition-fast); line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--navy); color: white; }
.btn-primary:hover { background: var(--navy-light); color: white; }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: #00a844; color: white; }
.btn-sm { padding: var(--sp-1) var(--sp-3); font-size: var(--text-sm); }

/* ===== DETAIL PAGE META ===== */
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--sp-5); }
.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-3); margin: var(--sp-4) 0;
}
.meta-item {
  background: var(--white); padding: var(--sp-3);
  border-radius: var(--radius-md); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.meta-item .meta-label {
  font-size: var(--text-xs); text-transform: uppercase;
  color: var(--gray-500); letter-spacing: 0.3px; font-weight: 600;
}
.meta-item .meta-value { font-size: 15px; font-weight: 600; margin-top: var(--sp-1); }

/* ===== ALERT BANNERS ===== */
.alert {
  padding: var(--sp-3) var(--sp-5);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  border-left: 4px solid; margin-bottom: var(--sp-4);
  font-size: var(--text-md);
}
.alert-success { background: var(--green-bg); border-color: var(--green); color: #1b5e20; }
.alert-warning { background: var(--orange-bg); border-color: var(--orange); color: #e65100; }
.alert-error { background: var(--red-bg); border-color: var(--red); color: #b71c1c; }
.alert-info { background: var(--blue-subtle); border-color: var(--blue); color: #0d47a1; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: var(--sp-10); color: var(--gray-500); }
.empty-state h3 { margin-bottom: var(--sp-2); }

/* ===== SCREENER: TIER TABLE HEADERS ===== */
.tier-1-header th { background: var(--green); }
.tier-1-header th:hover { background: #00a844; }
.tier-2-header th { background: var(--blue); }
.tier-2-header th:hover { background: var(--blue-hover); }
.tier-3-header th { background: var(--orange); }
.tier-3-header th:hover { background: #e68a00; }

/* ===== SCREENER: REX / RISK / CATEGORY ===== */
.rex-yes { color: var(--green); font-weight: 700; }
.rex-filed { color: var(--blue); font-weight: 700; }
.rex-no { color: var(--gray-400); }

.risk-low { color: var(--green); font-weight: 700; }
.risk-medium { color: var(--orange); font-weight: 700; }
.risk-high { color: var(--red); font-weight: 700; }
.risk-extreme { color: var(--purple); font-weight: 700; }
tr.risk-extreme-row { background: var(--red-bg); }
tr.risk-extreme-row:hover { background: #ffcdd2; }
tr.risk-high-row { background: var(--orange-bg); }
tr.risk-high-row:hover { background: #ffe0b2; }

.cat-badge { padding: 2px 8px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 600; }
.cat-single-stock { background: var(--green-bg); color: var(--green); }
.cat-index { background: var(--blue-subtle); color: var(--blue); }
.cat-crypto { background: var(--orange-bg); color: var(--orange); }

/* Score progress bar */
.score-bar { display: inline-block; width: 60px; height: 6px; background: #eee; border-radius: 3px; vertical-align: middle; margin-left: 4px; }
.score-fill { height: 100%; border-radius: 3px; }

/* ===== SCREENER SUB-NAV (Tab Style) ===== */
.sub-nav { display: flex; gap: 0; margin-bottom: var(--sp-6); border-bottom: 2px solid var(--gray-200); }
.sub-nav .pill {
  border: none; border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-base); font-weight: 500;
  color: var(--gray-500); background: transparent;
}
.sub-nav .pill:hover { color: var(--navy); background: transparent; border-bottom-color: var(--gray-400); }
.sub-nav .pill.active { color: var(--navy); background: transparent; border-bottom-color: var(--blue); font-weight: 600; }

/* ===== KEY FINDINGS ===== */
.key-findings { list-style: none; padding: 0; margin: var(--sp-4) 0; }
.key-findings li { padding: 6px 0 6px 20px; position: relative; font-size: var(--text-md); }
.key-findings li::before {
  content: ""; position: absolute; left: 0; top: 12px;
  width: 8px; height: 8px; background: var(--navy); border-radius: 50%;
}

/* ===== RISK LEGEND ===== */
.risk-legend {
  display: flex; gap: var(--sp-4); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: var(--sp-4);
  font-size: var(--text-base);
}
.risk-legend .legend-item { display: flex; align-items: center; gap: 6px; }
.risk-legend .legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ===== KPI ROW BLUE VARIANT ===== */
.kpi-row-blue .kpi { background: var(--blue-subtle); border-color: #bbdefb; }

/* ===== PIPELINE STATUS ===== */
.pipeline-status {
  padding: var(--sp-3) var(--sp-4);
  background: var(--orange-bg); border: 1px solid var(--orange);
  border-radius: var(--radius-lg); margin: var(--sp-3) 0; font-size: var(--text-base);
}
.pipeline-status.idle { background: var(--gray-100); border-color: var(--border); }

/* ===== ADMIN GRID ===== */
.admin-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: var(--sp-5); margin-bottom: var(--sp-6);
}
@media (max-width: 768px) { .admin-grid { grid-template-columns: 1fr; } }
.admin-card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--sp-5); background: var(--white); box-shadow: var(--shadow-sm);
}
.admin-card h3 { margin: 0 0 var(--sp-3); font-size: var(--text-lg); font-weight: 700; }
.admin-card p { font-size: var(--text-base); color: var(--gray-500); margin-bottom: var(--sp-3); }

/* ===== BACK TO TOP ===== */
.back-top {
  position: fixed; bottom: var(--sp-8); right: var(--sp-8);
  background: var(--navy); color: white;
  width: 44px; height: 44px;
  border-radius: var(--radius-pill);
  display: none; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px; z-index: 200;
  border: none; box-shadow: var(--shadow-lg);
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.back-top:hover { background: var(--navy-light); transform: translateY(-2px); }
.back-top.visible { display: flex; }

/* ===== FOOTER ===== */
.footer {
  color: var(--gray-500); font-size: var(--text-sm);
  margin-top: var(--sp-12); padding: var(--sp-5) 0;
  border-top: 1px solid var(--border); text-align: center;
}
