/* ==========================================================================
   TrueNorth Economic Impact Engine — Institutional Control-Tower Design System
   Grounded in Deep Research Section 1–5 Blueprint (Linear / Stripe / Foundry / IMPLAN v7)
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', monospace;

  --bg-canvas: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --bg-rail: #0B192C;
  --bg-rail-hover: #132742;
  --bg-rail-active: #0064FA;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;

  --border-hairline: #E2E8F0;
  --border-strong: #CBD5E1;

  --color-direct: #0064FA;
  --color-indirect: #0891B2;
  --color-induced: #338736;
  --color-fiscal: #D97706;
  --color-leakage: #E11D48;
  --color-navy: #0F2942;

  --shadow-card: 0 1px 3px 0 rgba(15, 23, 42, 0.04), 0 1px 2px -1px rgba(15, 23, 42, 0.02);
  --shadow-drawer: -10px 0 32px -4px rgba(15, 23, 42, 0.16);
  --shadow-modal: 0 20px 45px -10px rgba(15, 23, 42, 0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.tabular-nums {
  font-variant-numeric: tabular-nums lining-nums;
}

.font-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums;
}

/* ==========================================================================
   1. Control-Tower 100vh Shell & Collapsible Left Vertical Navigation Rail
   ========================================================================== */
.ct-shell {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.ct-rail {
  width: 236px;
  background-color: var(--bg-rail);
  color: #E2E8F0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid #1E293B;
  transition: width 0.16s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  z-index: 30;
}

.ct-rail.collapsed {
  width: 62px;
}

.ct-rail-brand {
  height: 54px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1E293B;
}

.ct-rail-logo-group {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
}

.ct-rail-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, #0064FA 0%, #0891B2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.ct-rail-logo-img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}

.ct-rail.collapsed .ct-rail-title-wrap,
.ct-rail.collapsed .ct-nav-label,
.ct-rail.collapsed .ct-nav-badge,
.ct-rail.collapsed .ct-rail-footer-text {
  display: none;
}

.ct-rail-title {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #FFFFFF;
}

.ct-rail-subtitle {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #38BDF8;
}

.ct-rail-toggle {
  background: #162944;
  border: 1px solid #263E5F;
  color: #94A3B8;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  flex-shrink: 0;
}

.ct-rail-toggle:hover {
  color: #FFFFFF;
  background: #1E3A5F;
}

.ct-nav-list {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.ct-nav-section-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748B;
  padding: 8px 10px 4px;
}

.ct-rail.collapsed .ct-nav-section-label {
  display: none;
}

.ct-nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: #CBD5E1;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s ease;
  white-space: nowrap;
}

.ct-nav-btn:hover {
  background-color: var(--bg-rail-hover);
  color: #FFFFFF;
}

.ct-nav-btn.active {
  background-color: var(--bg-rail-active);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.ct-nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke-width: 1.85;
}

.ct-rail-footer {
  padding: 12px;
  border-top: 1px solid #1E293B;
  background: #081221;
  font-size: 11px;
  color: #94A3B8;
}

/* ==========================================================================
   2. Persistent Top Scenario Context & Governance Bar (54px)
   ========================================================================== */
.ct-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.ct-topbar {
  height: 52px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-hairline);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  z-index: 20;
}

.ct-topbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.ct-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ct-preset-select {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  color: #0F172A;
  background: #F8FAFC;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 4px 5px;
  cursor: pointer;
  width: 84px;
  flex-shrink: 0;
}

.ct-scenario-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #F1F5F9;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: #0F172A;
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
}

.ct-scenario-pill:hover {
  background: #E2E8F0;
  border-color: #94A3B8;
}

.ct-scenario-code {
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: #0F2942;
  color: #FFFFFF;
  padding: 1.5px 6px;
  border-radius: 4px;
}

.ct-cmdk-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.ct-cmdk-btn:hover {
  border-color: #0064FA;
  color: #0F172A;
}

.ct-kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  background: #F1F5F9;
  border: 1px solid #CBD5E1;
  border-radius: 4px;
  padding: 1px 5px;
  color: #334155;
}

.ct-preset-select {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  color: #0F172A;
  background: #F8FAFC;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  max-width: 220px;
}

.ct-mode-segmented {
  display: inline-flex;
  background: #F1F5F9;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 2px;
}

.ct-mode-btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  white-space: nowrap;
}

.ct-mode-btn.active {
  background: #0F2942;
  color: #FFFFFF;
  font-weight: 600;
}

.ct-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: #1E293B;
  cursor: pointer;
  white-space: nowrap;
}

.ct-action-btn:hover {
  background: #F8FAFC;
  border-color: #64748B;
}

.ct-action-btn.primary {
  background: #0064FA;
  border-color: #0055D4;
  color: #FFFFFF;
}

.ct-action-btn.primary:hover {
  background: #0052CC;
}

/* ==========================================================================
   3. Scrollable Analytical Canvas & Sub-Navigation Bar
   ========================================================================== */
.ct-subnav {
  background: #FFFFFF;
  border-bottom: 1px solid var(--border-hairline);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  flex-shrink: 0;
}

.ct-subtabs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ct-subtabs::-webkit-scrollbar {
  display: none;
}

.ct-subtab-btn {
  border: none;
  background: transparent;
  padding: 9px 9px;
  font-size: 11.5px;
  font-weight: 500;
  color: #475569;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.ct-subtab-btn:hover {
  color: #0F172A;
}

.ct-subtab-btn.active {
  color: #0064FA;
  border-bottom-color: #0064FA;
  font-weight: 600;
}

.ct-canvas {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   4. Five-Card 4-Zone Institutional KPI Scorecard Grid
   ========================================================================== */
.ct-kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
}

@media (max-width: 1280px) {
  .ct-kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.ct-kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 13px 14px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  transition: border-color 0.12s ease;
}

.ct-kpi-card:hover {
  border-color: #94A3B8;
}

.ct-kpi-zone1 {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.ct-kpi-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
  line-height: 1.25;
}

.ct-kpi-badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  padding: 1.5px 5.5px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-va { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.badge-add { background: #EFF6FF; color: #1E40AF; border: 1px solid #BFDBFE; }
.badge-sub { background: #ECFEFF; color: #155E75; border: 1px solid #A5F3FC; }
.badge-gross { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.badge-tax { background: #EEF2FF; color: #3730A3; border: 1px solid #C7D2FE; }

.ct-kpi-zone2 {
  margin: 2px 0 6px;
}

.ct-kpi-value {
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: clamp(1.32rem, 1.65vw, 1.72rem);
  font-weight: 800;
  color: #0F172A;
  letter-spacing: -0.02em;
  white-space: nowrap;
  line-height: 1.15;
}

.ct-kpi-sub {
  font-size: 10.5px;
  color: #64748B;
  font-weight: 500;
  margin-top: 2px;
  line-height: 1.3;
}

.ct-kpi-zone3 {
  margin-bottom: 8px;
}

.ct-kpi-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  color: #334155;
  background: #F1F5F9;
  border: 1px solid #E2E8F0;
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
}

.ct-kpi-zone4 {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ct-split-bar {
  height: 6px;
  width: 100%;
  background: #E2E8F0;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}

.ct-split-legend {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: #64748B;
}

/* ==========================================================================
   5. Analytical Cards, Two-Column Grids & Sticky Matrix Tables
   ========================================================================== */
.ct-grid-2 {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 14px;
}

@media (max-width: 1150px) {
  .ct-grid-2 {
    grid-template-columns: 1fr;
  }
}

.ct-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ct-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-hairline);
  background: #F8FAFC;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ct-panel-title {
  font-size: 13px;
  font-weight: 700;
  color: #0F172A;
}

.ct-panel-subtitle {
  font-size: 11.5px;
  color: #64748B;
  margin-top: 1px;
}

.ct-panel-body {
  padding: 14px 16px;
}

/* Sticky Left/Right Data Grid */
.ct-table-wrap {
  width: 100%;
  overflow-x: auto;
  max-height: 430px;
}

.ct-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 11.5px;
}

.ct-table th {
  position: sticky;
  top: 0;
  z-index: 15;
  background: #F1F5F9;
  color: #334155;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  padding: 6px 7px;
  border-bottom: 1px solid #CBD5E1;
  text-align: left;
  white-space: nowrap;
}

.ct-table th.num,
.ct-table td.num {
  text-align: right;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  white-space: nowrap;
}

.ct-table td {
  padding: 6px 7px;
  border-bottom: 1px solid #E2E8F0;
  color: #1E293B;
  white-space: normal;
  line-height: 1.28;
}

.ct-table td.sticky-left {
  white-space: nowrap;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums lining-nums;
}

body.mode-economist .ct-table td {
  padding: 5px 6px;
  font-size: 11px;
}

.ct-table tr:hover td {
  background-color: #F8FAFC;
}

.ct-table th.sticky-left,
.ct-table td.sticky-left {
  position: sticky;
  left: 0;
  z-index: 10;
  background: #FFFFFF;
  border-right: 1px solid #CBD5E1;
}

.ct-table th.sticky-left {
  z-index: 25;
  background: #F1F5F9;
}

.ct-table th.sticky-right,
.ct-table td.sticky-right {
  background: #F8FAFC;
  border-left: 1px solid #CBD5E1;
  font-weight: 700;
  color: #0F172A;
}

.ct-table th.sticky-right {
  background: #E2E8F0;
}

/* ==========================================================================
   6. Slide-Over Drawers (480px) & Command Palette Modal (640px)
   ========================================================================== */
.ct-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  z-index: 50;
  display: none;
}

.ct-backdrop.open {
  display: block;
}

.ct-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: 500px;
  max-width: 92vw;
  background: #FFFFFF;
  border-left: 1px solid #CBD5E1;
  box-shadow: var(--shadow-drawer);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ct-drawer.open {
  transform: translateX(0);
}

.ct-drawer-header {
  padding: 14px 18px;
  background: #0B192C;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1E293B;
}

.ct-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ct-form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ct-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #334155;
}

.ct-input,
.ct-select {
  width: 100%;
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: #0F172A;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
}

.ct-input:focus,
.ct-select:focus {
  outline: none;
  border-color: #0064FA;
  box-shadow: 0 0 0 2px rgba(0, 100, 250, 0.15);
}

/* Command Palette Modal */
.ct-modal-wrap {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 70;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 72px;
}

.ct-modal-wrap.open {
  display: flex;
}

.ct-cmd-modal {
  width: 660px;
  max-width: 94vw;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 10px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ct-cmd-input-row {
  padding: 12px 16px;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ct-cmd-input {
  flex: 1;
  border: none;
  font-size: 13.5px;
  color: #0F172A;
}

.ct-cmd-input:focus {
  outline: none;
}

.ct-cmd-list {
  max-height: 400px;
  overflow-y: auto;
}

.ct-cmd-item {
  width: 100%;
  padding: 9px 16px;
  border: none;
  border-bottom: 1px solid #F1F5F9;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  font-size: 12.5px;
  color: #1E293B;
}

.ct-cmd-item:hover {
  background: #EFF6FF;
}

.ct-economist-banner {
  display: none;
  background: #0F2942;
  color: #E2E8F0;
  border: 1px solid #1E3A8A;
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

body.mode-economist .ct-economist-banner {
  display: flex;
}
