/* ============================================================
   FinFlow — Precision Dark Finance
   Design tokens + global styles
   ============================================================ */

:root {
  /* Base surfaces */
  --bg:          #0A0F1E;
  --bg-sidebar:  #0D1424;
  --surface-1:   #111827;
  --surface-2:   #1A2235;
  --surface-3:   #243048;
  --surface-4:   #374563;
  --border:      #1E2D45;
  --border-soft: rgba(255,255,255,0.06);

  /* Accents */
  --cyan:   #00D4FF;
  --mint:   #00E5A0;
  --red:    #FF4757;
  --amber:  #FFB800;

  /* Text */
  --text:       #F1F5F9;
  --text-2:     #94A3B8;
  --text-3:     #475569;
  --text-4:     #374563;

  /* Type */
  --font-display: 'DM Sans', sans-serif;
  --font-body:    'Inter', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* Spacing */
  --xs: 4px; --sm: 8px; --md: 12px; --lg: 16px;
  --xl: 20px; --2xl: 24px; --3xl: 32px; --4xl: 48px;

  /* Radius */
  --r-card: 12px; --r-input: 8px; --r-chip: 6px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  /* Tweakable (overridden by JS) */
  --accent: #00D4FF;
  --accent-ink: #00D4FF; /* foreground-safe accent (JS sets a darker value in light mode) */
}

/* ============================================================
   LIGHT MODE — warm paper-grey
   ============================================================ */
:root[data-theme="light"] {
  --bg:          #F1EEE8;
  --bg-sidebar:  #FBFAF7;
  --surface-1:   #FFFFFF;
  --surface-2:   #F2EFE9;
  --surface-3:   #E8E3DA;
  --surface-4:   #D4CEC2;
  --border:      #E6E1D8;
  --border-soft: rgba(26,28,38,0.07);

  --mint:   #00A06E;
  --red:    #DC3A4B;
  --amber:  #B57E0A;

  --text:   #1B1E26;
  --text-2: #586173;
  --text-3: #8B8A80;
  --text-4: #B9B4A8;
}
:root[data-theme="light"] body { background: var(--bg); }

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#root { height: 100%; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
::selection { background: rgba(0,212,255,0.25); }

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 3px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: var(--surface-4); }

/* ---------- Layout shell ---------- */
.app {
  display: flex;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  position: relative;
}
.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 32px;
}
@media (prefers-reduced-motion: no-preference) {
  .page { animation: pageIn 220ms var(--ease); }
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px; flex: none; height: 100%;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 0 12px;
}
.sb-logo { height: 64px; display: flex; align-items: center; padding: 0 12px; }
.logo-text { font-weight: 300; font-size: 18px; letter-spacing: 0.15em; }
.sb-rule { height: 1px; background: var(--border-soft); margin: 0 4px; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; flex: 1; }
.sb-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  height: 48px; padding: 0 14px; border-radius: 8px;
  font-weight: 500; font-size: 13px; letter-spacing: 0.02em; color: var(--text-3);
  transition: background 150ms ease, color 150ms ease;
}
.sb-item .sb-bar {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%) scaleY(0);
  width: 3px; height: 24px; background: var(--accent); border-radius: 0 3px 3px 0;
  transition: transform 150ms var(--ease);
}
.sb-item:hover { background: rgba(255,255,255,0.04); color: var(--text-2); }
.sb-item.active { background: rgba(0,212,255,0.08); color: var(--text); }
.sb-item.active .sb-bar { transform: translateY(-50%) scaleY(1); }
.sb-user {
  display: flex; align-items: center; gap: 10px; padding: 14px 10px;
  border-top: 1px solid var(--border-soft); margin: 0 4px;
}
.sb-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--surface-2); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 500; font-size: 12px;
}
.sb-user-name { font-weight: 500; font-size: 13px; color: var(--text); }
.sb-sync { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-3); margin-top: 1px; }
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 6px rgba(0,229,160,0.6); }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: 64px; background: var(--bg-sidebar); border-top: 1px solid var(--border);
  display: none; align-items: stretch; padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bn-item { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; }
.bn-item.active::after {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px;
}

/* ---------- Type helpers ---------- */
.display { font-family: var(--font-display); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  font-family: var(--font-body); font-weight: 500;
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-3);
}
.page-title { font-family: var(--font-display); font-weight: 400; font-size: 28px; color: var(--text); letter-spacing: -0.01em; }
.page-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }

/* ---------- Card ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 20px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.card.hoverable:hover {
  border-color: rgba(0,212,255,0.2);
  box-shadow: inset 0 0 0 1px rgba(0,212,255,0.08);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 24px; border-radius: var(--r-input);
  font-family: var(--font-body); font-weight: 600; font-size: 14px;
  transition: filter 150ms ease, background 150ms ease, transform 80ms ease, border-color 150ms ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-cyan   { background: var(--accent); color: #0A0F1E; }
.btn-mint   { background: var(--mint); color: #0A0F1E; }
.btn-red    { background: var(--red); color: #fff; }
.btn-cyan:hover, .btn-mint:hover, .btn-red:hover { filter: brightness(1.1); }
.btn-outline { background: transparent; border: 1.5px solid currentColor; }
.btn-outline:hover { background: rgba(255,255,255,0.06); }
.btn-ghost { background: transparent; color: var(--text-2); font-weight: 500; }
.btn-ghost:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn-icon {
  width: 40px; height: 40px; padding: 0; border-radius: var(--r-input);
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 150ms ease;
}
.btn-icon:hover { color: var(--text); border-color: var(--surface-4); }
.btn-icon.active { color: var(--accent); border-color: rgba(0,212,255,0.4); background: rgba(0,212,255,0.08); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Inputs ---------- */
.field-label {
  display: block; font-weight: 500; font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: 6px;
}
.input {
  width: 100%; height: 44px; padding: 0 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-input);
  color: var(--text); font-size: 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.input::placeholder { color: var(--text-4); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,212,255,0.1); }
textarea.input { height: auto; padding: 12px 16px; resize: vertical; min-height: 72px; line-height: 1.5; }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 14px;
  border-radius: var(--r-chip); font-weight: 500; font-size: 12px; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  transition: all 150ms ease;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); color: #0A0F1E; border-color: var(--accent); }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px;
  border-radius: var(--r-chip); font-weight: 500; font-size: 11px; letter-spacing: 0.02em;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pending { background: rgba(255,184,0,0.15);  color: var(--amber); }
.badge-partial { background: rgba(0,212,255,0.15);  color: var(--cyan); }
.badge-settled { background: rgba(0,229,160,0.15);  color: var(--mint); }
.badge-overdue { background: rgba(255,71,87,0.15);  color: var(--red); }

/* ---------- Toggle ---------- */
.toggle { width: 42px; height: 24px; border-radius: 999px; background: var(--surface-2); position: relative; transition: background 200ms ease; flex: none; }
.toggle.on { background: var(--accent); }
:root[data-theme="light"] .toggle { background: #D9D4C9; }
:root[data-theme="light"] .toggle .thumb { box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle .thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.4); transition: transform 200ms var(--ease); }
.toggle.on .thumb { transform: translateX(18px); }

/* ---------- Transaction row ---------- */
.txn-row {
  display: flex; align-items: center; gap: 14px; height: 56px; padding: 0 8px;
  border-radius: 8px; transition: background 150ms ease; cursor: pointer;
}
.txn-row:hover { background: rgba(255,255,255,0.025); }
.txn-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; flex: none; }
.txn-mid { flex: 1; min-width: 0; }
.txn-reason { font-weight: 500; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.txn-amt { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 16px; flex: none; }
.divider-inset { height: 1px; background: var(--border); margin-left: 58px; }

/* ---------- Skeleton ---------- */
.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite linear; border-radius: 6px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 90; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast {
  background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--mint);
  border-radius: 8px; padding: 12px 16px; box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 320px;
  animation: toastIn 250ms var(--ease); font-size: 13px; color: var(--text);
}
.toast.error { border-left-color: var(--red); }
.toast.warn  { border-left-color: var(--amber); }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* ---------- Modal ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn 200ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 480px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
  position: relative; animation: modalIn 250ms var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(20px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ---------- Segmented control ---------- */
.segment { display: inline-flex; background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: var(--r-input); padding: 3px; gap: 2px; }
.segment button { height: 34px; padding: 0 18px; border-radius: 6px; font-weight: 500; font-size: 13px; color: var(--text-3); transition: all 150ms ease; }
.segment button.active { background: var(--accent); color: #0A0F1E; font-weight: 600; }

/* ---------- Light-mode hover + surface fixes ---------- */
:root[data-theme="light"] .txn-row:hover { background: rgba(26,28,38,0.035); }
:root[data-theme="light"] .dd-item:hover { background: rgba(26,28,38,0.04); }
:root[data-theme="light"] .btn-ghost:hover { background: rgba(26,28,38,0.05); color: var(--text); }
:root[data-theme="light"] .btn-outline:hover { background: rgba(26,28,38,0.05); }
:root[data-theme="light"] .sb-item:hover { background: rgba(26,28,38,0.04); }
:root[data-theme="light"] .card { box-shadow: 0 1px 2px rgba(26,28,38,0.04); }
:root[data-theme="light"] *::-webkit-scrollbar-thumb { background: var(--surface-4); }

/* ---------- Animations / counters ---------- */
.count-up { animation: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) and (min-width: 768px) {
  .page { padding: 24px; }
  .sidebar { width: 72px; padding: 0 10px; }
  .sb-logo { justify-content: center; padding: 0; }
  .logo-text { font-size: 0; }
  .logo-text span:first-child::after { content: 'FF'; font-size: 16px; letter-spacing: 0.1em; }
  .sb-label, .sb-user-meta { display: none; }
  .sb-item { justify-content: center; padding: 0; }
  .sb-user { justify-content: center; padding: 14px 0; }
}
@media (max-width: 767px) {
  .page { padding: 20px 16px 96px; }
  .page-title { font-size: 24px; }
}

.hide-mobile { }
.show-mobile { display: none !important; }
@media (max-width: 767px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: flex !important; }
}
