/* ============================================================================
   FinFactum AI — base.css
   Design tokens, reset, typography, shared components, animation primitives.
   Aesthetic: institutional financial-intelligence terminal.
   ========================================================================== */
:root {
  /* surfaces */
  --ink: #070b14;
  --bg: #0a0f1c;
  --bg-2: #0c1322;
  --surface: #0e1525;
  --surface-2: #111b2e;
  --panel: rgba(17, 26, 46, 0.55);
  --glass: rgba(20, 30, 52, 0.45);
  --line: rgba(148, 163, 184, 0.1);
  --line-2: rgba(148, 163, 184, 0.18);

  /* text */
  --text: #e8edf5;
  --text-2: #c2cbda;
  --text-dim: #8a95a8;
  --text-faint: #5b677d;

  /* brand + accents */
  --accent: #2dd4a7;
  --accent-deep: #13b589;
  --accent-soft: rgba(45, 212, 167, 0.12);
  --gold: #e5b567;
  --blue: #5b8def;
  --violet: #9a8cfb;

  /* semantic score tones */
  --pos: #1fb583;
  --good: #34d399;
  --warn: #f0a93b;
  --caution: #ef8a2b;
  --neg: #f0566a;
  --ring-track: rgba(148, 163, 184, 0.14);

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 40px 110px -36px rgba(0, 0, 0, 0.85);
  --maxw: 1240px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Hanken Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
  letter-spacing: 0.1px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-optical-sizing: auto;
  font-feature-settings: "kern" 1, "liga" 1;
}
/* Fraunces display headings — optical sizing + balanced wrap reads as
   intentional, expert typesetting rather than default machine output. */
.hero h1, .section-title, .co-name, .rs-title, .cta-wrap h2, .brand-name, .prod-name, .rs-h {
  font-optical-sizing: auto;
  font-variation-settings: "opsz" 120, "wght" 600;
  text-wrap: balance;
}
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; letter-spacing: -0.2px; }
.num { text-align: right; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }
mark { background: rgba(45, 212, 167, 0.22); color: var(--accent); padding: 0 1px; border-radius: 3px; }
::selection { background: rgba(45, 212, 167, 0.28); color: #fff; }

/* atmospheric background field */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(900px 600px at 78% -8%, rgba(45, 212, 167, 0.1), transparent 60%),
    radial-gradient(800px 560px at 8% 8%, rgba(91, 141, 239, 0.09), transparent 58%),
    radial-gradient(700px 700px at 100% 100%, rgba(229, 181, 103, 0.06), transparent 60%),
    var(--bg);
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.5;
  background-image: linear-gradient(rgba(148, 163, 184, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.035) 1px, transparent 1px);
  background-size: 56px 56px;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 30%, #000 30%, transparent 78%);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 30%, #000 30%, transparent 78%);
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

/* ---- reveal + load animations ---- */
[data-reveal] { opacity: 0; transform: translateY(18px); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }
[data-reveal].is-revealed { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { [data-reveal] { opacity: 1; transform: none; transition: none; } }

@keyframes ringFill { to { stroke-dasharray: var(--ring-dash); } }
@keyframes floatUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes pulseDot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes shimmer { to { background-position: 200% center; } }

/* ============================ SHARED COMPONENTS ======================== */

/* glass panel */
.panel {
  background: linear-gradient(180deg, rgba(20, 30, 52, 0.6), rgba(12, 19, 34, 0.5));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  position: relative;
}
.panel-title {
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px;
}
.panel-title.pos { color: var(--good); }
.panel-title.neg { color: var(--neg); }
.panel-title.warn { color: var(--gold); }
.panel-lead { color: var(--text-dim); font-size: 0.86rem; margin-top: 12px; line-height: 1.6; }
.muted-tag { font-weight: 500; letter-spacing: 0.04em; color: var(--text-faint); text-transform: none; font-size: 0.74rem; }
.count-pill {
  font-family: var(--font-mono); font-size: 0.7rem; background: var(--accent-soft);
  color: var(--accent); padding: 2px 8px; border-radius: 20px; letter-spacing: 0;
}

.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }

/* buttons */
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #04140f; font-weight: 700; padding: 13px 22px; border-radius: 12px;
  letter-spacing: 0.01em; transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
  box-shadow: 0 14px 34px -12px rgba(45, 212, 167, 0.6);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 22px 48px -14px rgba(45, 212, 167, 0.7); }
.btn-ghost {
  border: 1px solid var(--line-2); color: var(--text-2); padding: 10px 18px; border-radius: 11px;
  font-weight: 600; font-size: 0.9rem; transition: all 0.25s var(--ease);
  background: rgba(255, 255, 255, 0.02);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* score rings */
.ring { position: relative; aspect-ratio: 1; display: grid; place-items: center; }
.ring-svg { transform: rotate(0deg); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-score { font-family: var(--font-mono); font-size: 2.1rem; font-weight: 600; line-height: 1; }
.ring-label { font-size: 0.64rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim); margin-top: 6px; text-align: center; max-width: 86px; }
.ring-sub { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; margin-top: 8px; text-align: center; }

/* bar gauge */
.gauge { background: rgba(10, 16, 28, 0.5); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px; }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.gauge-label { font-size: 0.82rem; color: var(--text-2); font-weight: 600; }
.gauge-val { font-size: 1.5rem; font-weight: 600; }
.gauge-of { font-size: 0.7rem; color: var(--text-faint); }
.gauge-track { height: 7px; background: var(--ring-track); border-radius: 20px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 20px; transition: width 1.1s var(--ease); }
.gauge-tag { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; margin-top: 8px; }
.gauge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; }

/* sparkline */
.spark { display: block; }

/* bullets */
.bullets li { position: relative; padding: 9px 0 9px 26px; font-size: 0.92rem; color: var(--text-2); border-bottom: 1px solid var(--line); line-height: 1.5; }
.bullets li:last-child { border-bottom: none; }
.bullets li::before { content: ""; position: absolute; left: 4px; top: 16px; width: 8px; height: 8px; border-radius: 2px; }
.bullets-pos li::before { background: var(--good); box-shadow: 0 0 10px rgba(52, 211, 153, 0.6); }
.bullets-neg li::before { background: var(--neg); box-shadow: 0 0 10px rgba(240, 86, 106, 0.5); }
.bullets li.muted { color: var(--text-faint); }
.bullets li.muted::before { background: var(--text-faint); }

/* tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -6px; }
.datatable { width: 100%; border-collapse: collapse; min-width: 640px; }
.datatable th {
  text-align: left; font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
.datatable td { padding: 14px 14px; border-bottom: 1px solid var(--line); font-size: 0.88rem; vertical-align: middle; }
.datatable tbody tr { transition: background 0.2s; }
.datatable tbody tr:hover { background: rgba(45, 212, 167, 0.04); }
.datatable .num { text-align: right; }
.row-flag { background: rgba(240, 86, 106, 0.05); }
.dir-name { font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dir-din { font-size: 0.7rem; color: var(--text-faint); margin-top: 2px; }
.chip-conn { font-size: 0.6rem; background: rgba(229, 181, 103, 0.16); color: var(--gold); padding: 2px 7px; border-radius: 10px; letter-spacing: 0.05em; text-transform: uppercase; font-weight: 700; }
.sc-pill { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; padding: 3px 9px; border-radius: 7px; border: 1px solid; }
.s164 { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 6px; }
.s164-clear { color: var(--good); background: rgba(52, 211, 153, 0.1); }
.s164-watch { color: var(--gold); background: rgba(229, 181, 103, 0.12); }
.s164-flagged { color: var(--neg); background: rgba(240, 86, 106, 0.12); }
td.danger { color: var(--neg); font-weight: 700; }
.legend { font-size: 0.74rem; color: var(--text-faint); margin-top: 14px; line-height: 1.5; }

/* tags */
.tag { font-size: 0.72rem; color: var(--text-dim); border: 1px solid var(--line-2); padding: 4px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.02); white-space: nowrap; }

/* autocomplete dropdown */
.ac-drop {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 60;
  background: rgba(10, 15, 26, 0.97); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow-lg); backdrop-filter: blur(20px); overflow: hidden;
  max-height: 0; opacity: 0; pointer-events: none; transition: opacity 0.2s, max-height 0.25s;
}
.ac-drop.open { max-height: 440px; opacity: 1; pointer-events: auto; overflow-y: auto; }
.ac-item { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); transition: background 0.15s; }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: rgba(45, 212, 167, 0.08); }
.ac-mark { width: 40px; height: 40px; flex-shrink: 0; border-radius: 9px; background: linear-gradient(135deg, rgba(45, 212, 167, 0.2), rgba(91, 141, 239, 0.16)); border: 1px solid var(--line-2); display: grid; place-items: center; font-family: var(--font-mono); font-size: 0.68rem; font-weight: 600; color: var(--accent); }
.ac-main { flex: 1; min-width: 0; }
.ac-name { display: block; font-weight: 600; font-size: 0.92rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-meta { display: block; font-size: 0.74rem; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-score { font-family: var(--font-mono); font-size: 1.2rem; font-weight: 600; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.ac-score small { font-size: 0.5rem; letter-spacing: 0.1em; color: var(--text-faint); margin-top: 3px; }

/* toast */
.toast-host { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: rgba(10, 15, 26, 0.96); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: 10px; padding: 13px 18px; font-size: 0.88rem; color: var(--text); box-shadow: var(--shadow-lg); transform: translateX(120%); opacity: 0; transition: all 0.35s var(--ease); backdrop-filter: blur(16px); max-width: 320px; }
.toast.show { transform: none; opacity: 1; }
.toast-bad { border-left-color: var(--neg); }
.toast b { color: var(--accent); }
.toast-bad b { color: var(--neg); }

.pos { color: var(--good) !important; }
.neg { color: var(--neg) !important; }
.warn { color: var(--gold) !important; }
.muted { color: var(--text-faint); }
