/* ═══════════════════════════════════════════════════════════════════════════
   YF Design System — "Ledger" theme
   Premium fintech look: layered soft shadows, indigo accent gradient,
   restrained motion. Views consume these tokens via CSS variables (usable
   inside React inline styles) and the component classes below.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── Typography ── */
  --font-body: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Sora', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  /* ── Ink ── */
  --ink: #0F172A;
  --ink-2: #5B6472;
  --ink-3: #8A93A6;

  /* ── Planes ── */
  --page: #F4F5FA;
  --surface: #FFFFFF;
  --surface-2: #F8F9FD;
  --border: #E7E9F2;
  --border-strong: #D9DCEA;

  /* ── Brand ── */
  --primary: #4F46E5;
  --primary-deep: #4338CA;
  --primary-soft: #EEF0FE;
  --primary-glow: rgba(79, 70, 229, 0.28);
  --accent-grad: linear-gradient(135deg, #6D66F5 0%, #4F46E5 55%, #4338CA 100%);

  /* ── Money semantics ── */
  --income: #059669;
  --income-bright: #10B981;
  --income-soft: #E7F6F0;
  --expense: #DC2626;
  --expense-bright: #F0532F;
  --expense-soft: #FDEEEC;
  --warning: #B45309;
  --warning-bright: #F59E0B;
  --warning-soft: #FEF6E7;
  --info: #2A78D6;
  --info-soft: #EAF2FC;

  /* ── Shadows (layered, soft) ── */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px -4px rgba(16, 24, 40, 0.06);
  --shadow-lift: 0 4px 8px -2px rgba(16, 24, 40, 0.06), 0 16px 32px -12px rgba(16, 24, 40, 0.14);
  --shadow-pop: 0 8px 16px -6px rgba(16, 24, 40, 0.12), 0 24px 56px -16px rgba(16, 24, 40, 0.22);
  --shadow-primary: 0 4px 14px -3px var(--primary-glow);

  /* ── Radii ── */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;

  /* ── Motion ── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --t-fast: 0.15s;
  --t-med: 0.28s;
}

/* ── Page canvas: soft ambient color washes behind everything ── */
body {
  background:
    radial-gradient(1100px 480px at 85% -8%, rgba(99, 102, 241, 0.07), transparent 60%),
    radial-gradient(900px 420px at -10% 30%, rgba(16, 185, 129, 0.05), transparent 55%),
    var(--page) !important;
  background-attachment: fixed !important;
}

::selection { background: rgba(79, 70, 229, 0.18); }

/* ── Scrollbars ── */
* { scrollbar-width: thin; scrollbar-color: #C9CDDF transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #C9CDDF; border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: #AEB4CE; }
*::-webkit-scrollbar-track { background: transparent; }

/* ── Focus ── */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline-offset: 0; }

/* ═══ Keyframes ═══════════════════════════════════════════════════════════ */

/* Entrance keyframes MUST end at `transform: none` — a retained transform
   (even translateY(0) kept by fill-mode) turns the element into the containing
   block for position:fixed descendants, which shoves modals below the fold. */
@keyframes yfFadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
@keyframes yfFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes yfScaleIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes yfShimmer {
  0% { background-position: -600px 0; }
  100% { background-position: 600px 0; }
}
@keyframes yfGrowX { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes yfGrowY { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes yfDrawLine { to { stroke-dashoffset: 0; } }
@keyframes yfFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(24px, -18px) scale(1.06); }
  66% { transform: translate(-16px, 14px) scale(0.97); }
}
@keyframes yfPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes yfSpin { to { transform: rotate(360deg); } }
@keyframes yfPopIn {
  0% { opacity: 0; transform: scale(0.6); }
  70% { transform: scale(1.04); }
  100% { opacity: 1; transform: none; }
}

/* ═══ Entrance choreography ═══════════════════════════════════════════════ */

/* fill-mode MUST be `backwards`, never `both`/`forwards`: a transform
   animation that stays applied makes the element the containing block for
   position:fixed descendants — modals opened inside it get centered against
   the page instead of the viewport and vanish below the fold. `backwards`
   covers the pre-delay gap, then the animation detaches cleanly. */
.yf-enter { animation: yfFadeUp 0.5s var(--ease-out) backwards; }
.yf-enter-1 { animation: yfFadeUp 0.5s var(--ease-out) 0.05s backwards; }
.yf-enter-2 { animation: yfFadeUp 0.5s var(--ease-out) 0.12s backwards; }
.yf-enter-3 { animation: yfFadeUp 0.5s var(--ease-out) 0.19s backwards; }
.yf-enter-4 { animation: yfFadeUp 0.5s var(--ease-out) 0.26s backwards; }
.yf-enter-5 { animation: yfFadeUp 0.5s var(--ease-out) 0.33s backwards; }

/* Stagger direct children of a container (cards in a grid, rows in a list) */
.yf-stagger > * { animation: yfFadeUp 0.5s var(--ease-out) backwards; }
.yf-stagger > *:nth-child(1) { animation-delay: 0.03s; }
.yf-stagger > *:nth-child(2) { animation-delay: 0.09s; }
.yf-stagger > *:nth-child(3) { animation-delay: 0.15s; }
.yf-stagger > *:nth-child(4) { animation-delay: 0.21s; }
.yf-stagger > *:nth-child(5) { animation-delay: 0.27s; }
.yf-stagger > *:nth-child(6) { animation-delay: 0.33s; }
.yf-stagger > *:nth-child(7) { animation-delay: 0.39s; }
.yf-stagger > *:nth-child(8) { animation-delay: 0.45s; }
.yf-stagger > *:nth-child(n+9) { animation-delay: 0.5s; }

/* ═══ Cards ═══════════════════════════════════════════════════════════════ */

.yf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out), border-color var(--t-med);
}
.yf-card-hover:hover {
  box-shadow: var(--shadow-lift);
  transform: translateY(-3px);
  border-color: var(--border-strong);
}
.yf-card-hero {
  position: relative;
  background: linear-gradient(140deg, #191c3a 0%, #23265c 55%, #2c2a72 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 24px -8px rgba(35, 33, 97, 0.45);
  overflow: hidden;
}
.yf-card-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(420px 200px at 90% -30%, rgba(129, 140, 248, 0.35), transparent 65%),
    radial-gradient(300px 160px at 5% 115%, rgba(16, 185, 129, 0.18), transparent 60%);
  pointer-events: none;
}

/* ═══ Buttons ═════════════════════════════════════════════════════════════ */

.yf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--t-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.yf-btn:active { transform: scale(0.97); }
.yf-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.yf-btn-primary {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: var(--shadow-primary), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.yf-btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px -4px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  filter: brightness(1.06);
}
.yf-btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.yf-btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-2); }
.yf-btn-danger { background: var(--expense); color: #fff; box-shadow: 0 4px 12px -3px rgba(220, 38, 38, 0.35); }
.yf-btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.yf-btn-soft { background: var(--primary-soft); color: var(--primary-deep); }
.yf-btn-soft:hover:not(:disabled) { background: #E2E5FD; }

/* ═══ Inputs ══════════════════════════════════════════════════════════════ */

.yf-input, .yf-select {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 13px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  box-shadow: var(--shadow-xs);
}
.yf-input::placeholder { color: var(--ink-3); }
.yf-input:hover, .yf-select:hover { border-color: var(--border-strong); }
.yf-input:focus, .yf-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px rgba(79, 70, 229, 0.13);
}

/* ═══ Pills / segmented controls ══════════════════════════════════════════ */

.yf-pill {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
}
.yf-pill:hover { border-color: var(--border-strong); color: var(--ink); }
.yf-pill.active, .yf-pill[data-active="true"] {
  background: var(--primary-soft);
  border-color: rgba(79, 70, 229, 0.35);
  color: var(--primary-deep);
  font-weight: 600;
  box-shadow: inset 0 1px 2px rgba(79, 70, 229, 0.08);
}

/* ═══ Badges ══════════════════════════════════════════════════════════════ */

.yf-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  line-height: 1.4;
}
.yf-badge-income { background: var(--income-soft); color: var(--income); }
.yf-badge-expense { background: var(--expense-soft); color: var(--expense); }
.yf-badge-warning { background: var(--warning-soft); color: var(--warning); }
.yf-badge-info { background: var(--info-soft); color: var(--info); }
.yf-badge-neutral { background: #EEF0F6; color: var(--ink-2); }
.yf-badge-primary { background: var(--primary-soft); color: var(--primary-deep); }

/* ═══ Tables ══════════════════════════════════════════════════════════════ */

.yf-table-modern { width: 100%; border-collapse: collapse; }
.yf-table-modern thead th {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
.yf-table-modern tbody td {
  padding: 12px 14px;
  font-size: 0.875rem;
  color: var(--ink);
  border-bottom: 1px solid #F0F1F7;
}
.yf-table-modern tbody tr { transition: background var(--t-fast); }
.yf-table-modern tbody tr:hover { background: #F7F8FE; }
.yf-table-modern tbody tr:last-child td { border-bottom: none; }

/* ═══ Modals ══════════════════════════════════════════════════════════════ */

.yf-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 34, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: yfFadeIn 0.2s ease both;
}
.yf-modal-card {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  border: 1px solid rgba(255, 255, 255, 0.6);
  animation: yfScaleIn 0.3s var(--ease-out) both;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

/* ═══ Skeletons ═══════════════════════════════════════════════════════════ */

.yf-shimmer {
  background: linear-gradient(90deg, #EDEFF6 25%, #F7F8FC 50%, #EDEFF6 75%);
  background-size: 600px 100%;
  animation: yfShimmer 1.4s linear infinite;
  border-radius: 8px;
}

/* ═══ Progress / meter bars ═══════════════════════════════════════════════ */

.yf-meter { height: 7px; background: #EEF0F6; border-radius: 999px; overflow: hidden; }
.yf-meter > div {
  height: 100%;
  border-radius: 999px;
  transform-origin: left;
  animation: yfGrowX 0.9s var(--ease-out) both;
}

/* ═══ Charts ══════════════════════════════════════════════════════════════ */

.yf-chart-line { stroke-dasharray: 1600; stroke-dashoffset: 1600; animation: yfDrawLine 1.4s var(--ease-out) 0.15s forwards; }
.yf-chart-area { animation: yfFadeIn 0.9s ease 0.5s both; }
.yf-chart-dot { animation: yfPopIn 0.35s var(--ease-spring) both; }
.yf-chart-bar { transform-origin: bottom; animation: yfGrowY 0.7s var(--ease-out) both; }

.yf-tip {
  position: absolute;
  pointer-events: none;
  background: rgba(17, 20, 40, 0.94);
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.75rem;
  line-height: 1.5;
  box-shadow: var(--shadow-pop);
  z-index: 50;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
  transition: opacity 0.12s ease;
}
.yf-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(17, 20, 40, 0.94);
}

/* ═══ Misc polish ═════════════════════════════════════════════════════════ */

.yf-icon-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  flex-shrink: 0;
}
.yf-divider { height: 1px; background: var(--border); border: none; }
.yf-link { color: var(--primary); font-weight: 600; text-decoration: none; transition: color var(--t-fast); }
.yf-link:hover { color: var(--primary-deep); text-decoration: underline; text-underline-offset: 3px; }

.yf-money { font-family: var(--font-mono); font-variant-ligatures: none; letter-spacing: -0.01em; }

.yf-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-2);
}
.yf-empty .yf-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.yf-spin { animation: yfSpin 0.8s linear infinite; }

/* Number tick when values update */
.yf-tick { transition: color 0.3s ease; }

/* ═══ Sidebar (app shell) ═════════════════════════════════════════════════ */

.yf-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 13px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: rgba(226, 230, 246, 0.62);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
}
.yf-nav-item:hover { background: rgba(255, 255, 255, 0.055); color: rgba(240, 242, 252, 0.92); }
.yf-nav-item.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.24), rgba(99, 102, 241, 0.1));
  color: #fff;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(129, 140, 248, 0.18);
}
.yf-nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 20%;
  bottom: 20%;
  width: 3.5px;
  border-radius: 4px;
  background: linear-gradient(180deg, #818CF8, #6366F1);
  box-shadow: 0 0 12px rgba(129, 140, 248, 0.8);
}

/* ═══ Login ═══════════════════════════════════════════════════════════════ */

.yf-login-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(1200px 700px at 75% -10%, #1e2150 0%, transparent 55%),
    radial-gradient(1000px 600px at -5% 105%, #14304a 0%, transparent 55%),
    #0e1027;
}
.yf-login-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.5;
  animation: yfFloat 14s ease-in-out infinite;
}
.yf-login-card {
  position: relative;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 24px;
  box-shadow: 0 24px 80px -16px rgba(5, 8, 40, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  animation: yfScaleIn 0.55s var(--ease-out) both;
}

/* ═══ Accessibility ═══════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .yf-chart-line { stroke-dasharray: none; stroke-dashoffset: 0; }
}
