/* Dividis Capital — Design Tokens & Shared Components
   Refined institutional dark aesthetic, Goldman/Stripe Capital influence */

/* ════════ LIGHT THEME ════════ */
html[data-theme="light"] {
  --bg: #F6F4EF;          /* warm paper */
  --bg-1: #FFFFFF;
  --bg-2: #F0EDE6;
  --surface: #FFFFFF;
  --surface-2: #F8F6F1;
  --surface-3: #EDEAE3;

  --line: rgba(20, 30, 45, 0.08);
  --line-2: rgba(20, 30, 45, 0.13);
  --line-3: rgba(20, 30, 45, 0.22);

  --text: #131A28;
  --text-2: #3E4858;
  --text-3: #6B7689;
  --text-4: #9AA3B3;

  --emerald: #1F9F62;
  --emerald-2: #167a4a;
  --emerald-glow: rgba(31, 159, 98, 0.10);
  --emerald-line: rgba(31, 159, 98, 0.30);

  --gold: #9B7E3A;
  --gold-glow: rgba(155, 126, 58, 0.10);
  --gold-line: rgba(155, 126, 58, 0.30);

  --blue: #3868CC;
  --blue-glow: rgba(56, 104, 204, 0.10);

  --red: #C53A3F;
  --red-glow: rgba(197, 58, 63, 0.08);

  --amber: #B7841F;
  --amber-glow: rgba(183, 132, 31, 0.10);

  --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 0 0 1px var(--line);
  --shadow-pop: 0 24px 60px -20px rgba(20,30,45,0.20), 0 8px 24px -8px rgba(20,30,45,0.10);
}

html[data-theme="light"] body {
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(31,159,98,0.06), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(56,104,204,0.04), transparent 60%),
    var(--bg);
}
html[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(20,30,45,0.12); }
html[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(20,30,45,0.22); }
html[data-theme="light"] .topbar { background: rgba(246, 244, 239, 0.85); }
html[data-theme="light"] .nav { background: rgba(255, 255, 255, 0.85); }
html[data-theme="light"] .sb-avatar { color: #FFFFFF; }
html[data-theme="light"] .avatar { color: #FFFFFF; }
html[data-theme="light"] .btn-primary { color: #FFFFFF; }
html[data-theme="light"] .badge-invoice { color: #2A55AB; border-color: rgba(56,104,204,0.22); }
html[data-theme="light"] .badge-equity { color: #7F6324; }
html[data-theme="light"] .badge-fixed { color: #167a4a; }
html[data-theme="light"] .badge-seed { color: #A02C30; border-color: rgba(197,58,63,0.22); }

/* ════════ READABLE FONT MODE ════════ */
html[data-font="readable"] {
  --serif: "Inter", "Söhne", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --sans: "Inter", "Söhne", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 15px;
}
html[data-font="readable"] body {
  font-feature-settings: "ss01", "cv11";
  line-height: 1.55;
}
html[data-font="readable"] .page-title,
html[data-font="readable"] .serif {
  letter-spacing: -0.02em;
  font-weight: 600;
}
html[data-font="readable"] .page-title { font-size: 32px; }
html[data-font="readable"] .num,
html[data-font="readable"] .mono { font-family: var(--mono); }

:root {
  /* Surfaces */
  --bg: #0A0D14;
  --bg-1: #0E1320;
  --bg-2: #131927;
  --surface: #161D2D;
  --surface-2: #1B2336;
  --surface-3: #222C42;

  /* Lines */
  --line: rgba(255, 255, 255, 0.06);
  --line-2: rgba(255, 255, 255, 0.10);
  --line-3: rgba(255, 255, 255, 0.16);

  /* Text */
  --text: #E6EAF1;
  --text-2: #B8C0CE;
  --text-3: #828B9C;
  --text-4: #5A6377;

  /* Accents — institutional palette */
  --emerald: #2DBE7E;
  --emerald-2: #4BD193;
  --emerald-glow: rgba(45, 190, 126, 0.10);
  --emerald-line: rgba(45, 190, 126, 0.30);

  --gold: #C8A961;
  --gold-glow: rgba(200, 169, 97, 0.10);
  --gold-line: rgba(200, 169, 97, 0.28);

  --blue: #5B8DEF;
  --blue-glow: rgba(91, 141, 239, 0.10);

  --red: #E5484D;
  --red-glow: rgba(229, 72, 77, 0.10);

  --amber: #E0A93B;
  --amber-glow: rgba(224, 169, 59, 0.10);

  /* Type */
  --serif: "Instrument Serif", "Source Serif Pro", Georgia, serif;
  --sans: "Söhne", "Geist", "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --mono: "JetBrains Mono", "IBM Plex Mono", "SF Mono", Menlo, monospace;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* Shadow */
  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 0 0 1px var(--line);
  --shadow-pop: 0 24px 60px -20px rgba(0,0,0,0.7), 0 8px 24px -8px rgba(0,0,0,0.5);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-feature-settings: "ss01", "cv11";
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(45,190,126,0.06), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(91,141,239,0.04), transparent 60%),
    var(--bg);
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.12); }

/* ── Typography utilities */
.serif { font-family: var(--serif); font-weight: 400; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); font-feature-settings: "tnum"; }
.eyebrow {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}
.num { font-family: var(--mono); font-feature-settings: "tnum"; }

/* ── App shell (sidebar+main layout in §App shell below) */

/* ── Top nav */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 13, 20, 0.85);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-left { display: flex; align-items: center; gap: 36px; }
.nav-right { display: flex; align-items: center; gap: 12px; }

.logo {
  display: flex;
  align-items: baseline;
  gap: 1px;
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.logo-mark {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: linear-gradient(150deg, var(--emerald), #1c8a5c);
  margin-right: 10px;
  position: relative;
  display: inline-block;
}
.logo-mark::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1.5px solid var(--bg);
  border-radius: 2px;
  border-bottom: none;
  border-right: none;
}
.logo .dot { color: var(--emerald); }

.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-link {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  transition: color .15s, background .15s;
  cursor: pointer;
  border: none;
  background: transparent;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.nav-link.active { color: var(--text); background: rgba(255,255,255,0.05); }

.nav-icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  position: relative;
}
.nav-icon-btn:hover { background: var(--surface); border-color: var(--line-3); color: var(--text); }
.nav-icon-btn .dot-notif {
  position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 2px var(--bg);
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  color: var(--bg);
  background: linear-gradient(140deg, var(--emerald), #1c8a5c);
  letter-spacing: 0.02em;
}

/* ── Page chrome */
.page {
  flex: 1;
  padding: 32px 32px 80px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 24px;
}
.page-title {
  font-family: var(--serif);
  font-size: 38px;
  letter-spacing: -0.025em;
  line-height: 1.05;
}
.page-sub {
  color: var(--text-3);
  font-size: 14px;
  margin-top: 6px;
}

/* ── Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.card-pad { padding: 20px; }
.card-pad-lg { padding: 28px; }

/* ── App shell */
.app { display: flex; flex-direction: row; min-height: 100vh; background: var(--bg); }
.sidebar {
  width: 232px; flex-shrink: 0;
  height: 100vh; position: sticky; top: 0;
  display: flex; flex-direction: column;
  padding: 22px 14px;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
}
.sb-logo {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 22px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.sb-section-l {
  font-size: 10px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 16px 10px 8px;
  font-weight: 500;
}
.sb-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.sb-item:hover { background: var(--surface-2); color: var(--text); }
.sb-item.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line-2);
}
.sb-item.active::before {
  content: '';
  display: block;
  width: 2px; height: 14px;
  background: var(--emerald);
  border-radius: 2px;
  margin-left: -10px; margin-right: -1px;
}
.sb-spacer { flex: 1; min-height: 12px; }
.sb-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
}
.sb-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--emerald), var(--emerald-2));
  color: #062817;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex; flex-direction: column;
}
.app-scroll {
  flex: 1;
  overflow-y: auto;
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 32px;
  background: rgba(8,11,16,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  gap: 24px;
}
.search {
  flex: 1; max-width: 480px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 8px;
}
.search input {
  flex: 1;
  background: transparent;
  border: none; outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.search input::placeholder { color: var(--text-3); }
.kbd {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
  padding: 2px 6px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--bg-1);
}
.balance {
  display: flex; flex-direction: column;
  align-items: flex-end;
  padding: 4px 12px;
  border-left: 1px solid var(--line);
  margin-left: 6px;
}

/* ── Density modes (toggle from Tweaks) */
.density-compact .page { padding: 22px 24px 60px; }
.density-compact .page-header { margin-bottom: 18px; }
.density-compact .card-pad { padding: 14px; }
.density-compact .card-pad-lg { padding: 20px; }
.density-compact .stat-label { font-size: 10px; }
.density-compact .page-title { font-size: 28px !important; }
.density-comfortable .page { padding: 36px 36px 90px; }

/* ── Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.005em;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn-primary {
  background: var(--emerald);
  color: #062817;
}
.btn-primary:hover { background: var(--emerald-2); transform: translateY(-1px); }
.btn-primary:disabled { background: rgba(45,190,126,0.20); color: rgba(255,255,255,0.30); cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  border-color: var(--line-3);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface); border-color: var(--line-3); }

.btn-quiet {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
}
.btn-quiet:hover { background: var(--surface-3); }

.btn-lg { padding: 13px 22px; font-size: 14px; border-radius: 10px; }

/* ── Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-invoice { background: var(--blue-glow); color: #8DAFEF; border-color: rgba(91,141,239,0.18); }
.badge-equity { background: var(--gold-glow); color: var(--gold); border-color: var(--gold-line); }
.badge-fixed { background: var(--emerald-glow); color: var(--emerald-2); border-color: var(--emerald-line); }
.badge-seed { background: var(--red-glow); color: #F38A8E; border-color: rgba(229,72,77,0.20); }
.badge-rating {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0;
}

.tag {
  display: inline-flex; align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px; font-weight: 500;
}
.tag-active { background: var(--emerald-glow); color: var(--emerald-2); }
.tag-pending { background: var(--amber-glow); color: var(--amber); }
.tag-closed { background: rgba(255,255,255,0.05); color: var(--text-3); }

/* ── Inputs */
.input {
  width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.input:focus { border-color: var(--emerald-line); background: var(--bg); }
.input::placeholder { color: var(--text-4); }

.input-amount {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  padding: 14px 16px;
  letter-spacing: -0.01em;
}

/* ── Stat card */
.stat {
  display: flex; flex-direction: column; gap: 8px;
}
.stat-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-3);
}
.stat-value {
  font-family: var(--serif);
  font-size: 32px;
  letter-spacing: -0.02em;
  line-height: 1;
}
.stat-value.num {
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: -0.01em;
}
.stat-sub { font-size: 12px; color: var(--text-3); }
.stat-delta-up { color: var(--emerald-2); font-weight: 500; }
.stat-delta-down { color: var(--red); font-weight: 500; }

/* ── Progress */
.progress {
  height: 4px;
  background: rgba(255,255,255,0.05);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--emerald), var(--emerald-2));
  border-radius: 2px;
}

/* ── Ticker / row */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.row:last-child { border-bottom: none; }

/* ── Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--emerald);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* ── Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(5, 8, 14, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.18s ease;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
  animation: slideUp 0.25s cubic-bezier(0.16,1,0.3,1);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }

/* ── Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  animation: slideUp 0.25s cubic-bezier(0.16,1,0.3,1);
  box-shadow: var(--shadow-pop);
}

/* ── Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
.tab {
  padding: 12px 18px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 1.5px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text-2); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--emerald);
}

/* ── Risk pill */
.risk {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 500;
}
.risk-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
}
.risk-very-low .risk-dot { background: #4BD193; }
.risk-low .risk-dot { background: var(--emerald); }
.risk-medium .risk-dot { background: var(--gold); }
.risk-medium-high .risk-dot { background: var(--amber); }
.risk-high .risk-dot { background: var(--red); }

/* ── Tweaks panel hooks (dark theme) */
.tweaks-panel { color-scheme: dark; }
