/*
════════════════════════════════════════════════════
CLEARFi Intelligence™ — Platform Stylesheet
Dark institutional theme. Matches every class referenced in app.js,
allocation-intelligence.js and opportunity-intelligence.js.
════════════════════════════════════════════════════
*/
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-primary: #0A1628;
  --bg-surface: #0F1F36;
  --bg-elevated: #142A47;
  --border: #1E3354;
  --border-gold: rgba(196, 155, 60, .35);
  --navy: #0B2545;
  --gold: #C49B3C;
  --gold-light: #E0B85C;
  --teal: #0E7C7B;
  --teal-light: #14A3A1;
  --green: #22C55E;
  --red: #EF4444;
  --amber: #F59E0B;
  --blue: #3B82F6;
  --text-primary: #F4F7FB;
  --text-secondary: #B8C4D4;
  --text-dim: #6B7E96;
  --font-sans: 'Inter', sans-serif;
  --font-serif: 'Fraunces', serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-ui: 'Inter', sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select {
  font-family: inherit;
}

ul {
  list-style: none;
}

/* ─── APP SHELL ─────────────────────────────────── */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand img {
  height: 32px;
  width: auto;
  border-radius: 6px;
}

.sidebar-brand .brand-text {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
}

.sidebar-brand .brand-text .tm {
  color: var(--gold);
  font-size: 10px;
  vertical-align: super;
}

.nav-list {
  flex: 1;
  padding: 14px 10px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(196, 155, 60, .12);
  color: var(--gold-light);
}

.nav-icon {
  font-size: 15px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-label {
  flex: 1;
}

.sidebar-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 10.5px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* MAIN CONTENT */

.main-content {
  flex: 1;
  margin-left: 248px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

#hamburger {
  display: none;
  font-size: 20px;
  color: var(--text-secondary);
}

.page-title-block #page-title {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-title-block #page-subtitle {
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.content-area {
  flex: 1;
  padding: 26px 28px 60px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.page-content {
  display: none;
}

.page-content.active {
  display: block;
  animation: fadeIn .25s ease;
}

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

/* ─── BUTTONS ─────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all .15s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--gold);
  color: #171008;
}

.btn-primary:hover {
  background: var(--gold-light);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-ghost:hover {
  border-color: var(--gold);
  color: var(--gold-light);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

/* ─── FORM ELEMENTS ─────────────────────────────────── */

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.form-input, .form-select, .filter-input, .filter-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13.5px;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--gold);
}

.input-eye-wrap {
  position: relative;
}

.input-eye-wrap .form-input {
  padding-right: 38px;
}

.input-eye-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
}

.input-eye-btn:hover {
  color: var(--text-primary);
}

.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-input {
  max-width: 260px;
}

.filter-select {
  max-width: 170px;
  width: auto;
}

/* ─── CARDS & PANELS ─────────────────────────────────── */

.data-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.section-title .accent {
  color: var(--gold-light);
}

.section-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.two-col {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}

@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

/* STAT CARDS */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-label {
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-value.gold {
  color: var(--gold-light);
}

.stat-value.green {
  color: var(--green);
}

.stat-change {
  font-size: 11px;
  margin-top: 6px;
}

.stat-change.up {
  color: var(--green);
}

.stat-change.down {
  color: var(--red);
}

.stat-change.neutral {
  color: var(--text-dim);
}

/* PROTOCOL GRID & CARDS */

.protocol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.protocol-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}

.protocol-card:hover {
  border-color: var(--border-gold);
  transform: translateY(-2px);
}

.protocol-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.protocol-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}

.protocol-category {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.protocol-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}

.protocol-metric-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.protocol-metric-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  margin-top: 2px;
}

.protocol-metric-value.apy {
  color: var(--green);
}

.protocol-footer {
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* CHAIN TAG */

.chain-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.chain-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

/* BADGES */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 600;
  border: 1px solid currentColor;
}

.badge-green {
  color: var(--green);
  background: rgba(34, 197, 94, .1);
}

.badge-amber {
  color: var(--amber);
  background: rgba(245, 158, 11, .1);
}

.badge-red {
  color: var(--red);
  background: rgba(239, 68, 68, .1);
}

.badge-blue {
  color: var(--blue);
  background: rgba(59, 130, 246, .1);
}

.badge-gold {
  color: var(--gold-light);
  background: rgba(196, 155, 60, .12);
}

/* SCORE BARS */

.score-bar {
  height: 5px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
}

.risk-score {
  display: flex;
  align-items: center;
  gap: 8px;
}

.risk-score .score-bar {
  flex: 1;
  min-width: 50px;
}

/* DATA TABLES */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: var(--bg-elevated);
}

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

/* COLOR UTILITIES */

.green {
  color: var(--green);
}

.gold {
  color: var(--gold-light);
}

.positive {
  color: var(--green);
}

.neutral {
  color: var(--text-dim);
}

.accent {
  color: var(--gold-light);
}

/* GOLD LINE DIVIDER */

.gold-line {
  height: 1px;
  background: linear-gradient(90deg, var(--gold), transparent);
  margin: 14px 0;
}

/* RISK FACTOR LIST (Risk Intelligence page) */

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

.risk-framework-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.risk-factor-list {
  margin-top: 10px;
}

.risk-factor-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.risk-factor-item:last-child {
  border-bottom: none;
}

.rf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.rf-title {
  font-weight: 600;
  font-size: 13px;
}

.rf-name {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.rf-subtitle {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.rf-score-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rf-score-num {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
}

.rf-minibar {
  width: 60px;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
}

.rf-mini-fill {
  height: 100%;
  border-radius: 2px;
}

/* PORTFOLIO PAGE */

.portfolio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

@media (max-width: 900px) {
  .portfolio-grid {
    grid-template-columns: 1fr;
  }
}

.projection-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.projection-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 14px;
}

.projection-big {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--gold-light);
}

.projection-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.projection-breakdown {
  margin-top: 16px;
}

.proj-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.proj-label {
  color: var(--text-dim);
}

.proj-val {
  font-family: var(--font-mono);
  font-weight: 500;
}

.allocation-list {
  margin-top: 10px;
}

.allocation-row {
  margin-bottom: 14px;
}

.alloc-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 5px;
}

.alloc-value {
  font-family: var(--font-mono);
}

.alloc-pct {
  font-family: var(--font-mono);
  color: var(--text-dim);
}

.alloc-bar-wrap {
  height: 7px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.alloc-bar {
  height: 100%;
  border-radius: 4px;
}

/* REPORTS PAGE */

.report-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.report-generate-btn {
  margin-top: 6px;
}

.report-preview {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  margin-top: 14px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 480px;
  overflow-y: auto;
}

.rp-header {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.rp-meta {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* EMPTY STATE */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-icon {
  font-size: 34px;
  margin-bottom: 12px;
  opacity: .5;
}

/* MODAL */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, .7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  font-size: 20px;
  color: var(--text-dim);
  padding: 4px 8px;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 22px;
}

/* TOAST */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text-primary);
  opacity: 0;
  pointer-events: none;
  transition: all .25s ease;
  z-index: 2000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* LIVE DOT */

.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 5px;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, .6);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, .5);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

/* AI PANELS (shared by app.js, allocation-intelligence.js, opportunity-intelligence.js) */

.ai-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px;
  font-size: 13px;
  color: var(--text-dim);
}

.ai-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.ai-result {
  padding: 18px 20px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.ai-result strong {
  color: var(--text-primary);
}

.ai-error {
  padding: 18px;
  color: var(--red);
  font-size: 13px;
}

/* AUTH MODAL (supabase-client.js) */

.auth-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, .75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.auth-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 380px;
  width: 100%;
  padding: 26px;
}

/* SCROLLBAR */

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* RESPONSIVE */

@media (max-width: 880px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  #hamburger {
    display: block;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
