@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Hanken+Grotesk:wght@400;500;600;700&display=swap');

/* ============================================================
   FinanceProject — design system "Quiet Precision"
   Calm, editorial, finance-grade. Warm neutral foundation,
   one evergreen accent, hairline borders, editorial serif for
   the big moments. Restraint over decoration.
   ============================================================ */
:root {
  /* Type */
  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Warm neutral foundation */
  --bg: #FAF9F6;
  --surface: #FFFFFF;
  --surface-2: #F4F2EC;
  --surface-3: #EEEBE2;
  --border: #E7E3DA;
  --border-strong: #D7D2C6;
  --text: #1C1B17;
  --text-muted: #6E6A60;
  --text-faint: #9A958A;

  /* One confident accent — evergreen */
  --primary: #1C6B53;
  --primary-hover: #16553F;
  --primary-soft: #E8F0EB;
  --accent: #1C6B53;
  --on-primary: #FBFCF9;

  /* Muted, calm semantics */
  --success: #2F7A57;
  --danger: #A8412B;
  --warning: #97690F;
  --info: #2E6F8E;

  /* Geometry / depth / motion */
  --radius-sm: 6px;
  --radius: 9px;
  --radius-lg: 14px;
  --shadow: none;                                  /* flat by default — borders do the work */
  --shadow-sm: 0 1px 2px rgba(28,27,23,.05);
  --shadow-pop: 0 2px 4px rgba(28,27,23,.05), 0 12px 32px -10px rgba(28,27,23,.20);
  --transition: 160ms cubic-bezier(.4, 0, .2, 1);
  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 24%, transparent);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Editorial serif reserved for the big moments only (titles, hero figures). */
h1, h2 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.12;
  color: var(--text);
  margin: 0 0 .2em;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.45rem; }
h3 { font-family: var(--font-body); font-weight: 600; font-size: 1.02rem; letter-spacing: -0.003em; margin: 0; }
h4 { font-family: var(--font-body); font-weight: 600; font-size: .9rem; margin: 0; }
.numeric, .value, td.numeric, th.numeric { font-variant-numeric: tabular-nums; }

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 2px; }

/* Layout */
.app-shell {
  display: grid;
  grid-template-columns: 252px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: .85rem .55rem 2rem;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .6rem 1rem; margin-bottom: .35rem;
}
.logo {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; font-family: var(--font-display);
  font-weight: 600; font-size: 1.05rem;
}
.topbar-brand { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.topbar-brand .logo { width: 26px; height: 26px; font-size: .95rem; }
.topbar-brand strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .brand h1 { font-family: var(--font-body); font-size: 1.02rem; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.sidebar nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .48rem .65rem; margin: 1px .1rem;
  color: var(--text-muted); border-radius: var(--radius-sm);
  font-weight: 500; font-size: .885rem;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar nav a.active .fp-ico { color: var(--primary); }
.sidebar .nav-section {
  text-transform: uppercase;
  font-size: .67rem; font-weight: 600;
  color: var(--text-faint);
  padding: 1.05rem .85rem .3rem;
  letter-spacing: .09em;
}

/* Icons: one consistent single-stroke set (no emoji anywhere) */
.fp-ico { display: inline-flex; align-items: center; color: var(--text-faint); flex: 0 0 auto; }
.fp-ico svg { width: 18px; height: 18px; display: block; }
.icon-btn .fp-ico svg, button .fp-ico svg, .btn .fp-ico svg { width: 16px; height: 16px; }

.main { padding: 2rem 2.25rem; max-width: 1320px; }
.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 1.6rem; padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border); gap: 1rem;
}
.page-header h2 { margin: 0; font-size: 1.55rem; }

/* Signature staggered reveal on load (respects reduced-motion below) */
@keyframes fp-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.main > * { animation: fp-rise .5s cubic-bezier(.16, 1, .3, 1) both; }
.main > *:nth-child(1) { animation-delay: 0ms; }
.main > *:nth-child(2) { animation-delay: 45ms; }
.main > *:nth-child(3) { animation-delay: 90ms; }
.main > *:nth-child(4) { animation-delay: 135ms; }
.main > *:nth-child(5) { animation-delay: 180ms; }
.main > *:nth-child(6) { animation-delay: 225ms; }
.main > *:nth-child(n+7) { animation-delay: 270ms; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.15rem; gap: 1rem;
}
.card-header h3 { margin: 0; font-size: 1.02rem; }

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.metric { display: flex; flex-direction: column; gap: 0.3rem; }
.metric .label {
  font-size: 0.72rem; color: var(--text-faint); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
}
.metric .value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 500; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric .delta-up { color: var(--success); }
.metric .delta-down { color: var(--danger); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.7rem 0.8rem; }
th { font-weight: 600; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
     color: var(--text-faint); border-bottom: 1px solid var(--border); }
td { border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }

/* Forms */
.form-grid { display: grid; gap: 0.75rem; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.3rem; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: .9rem; background: var(--surface); color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--ring);
}

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: 0.55rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary);
  cursor: pointer; font: inherit; font-weight: 600; font-size: .885rem; line-height: 1.1;
}
button:hover, .btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:active, .btn:active { transform: translateY(.5px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border-strong); font-weight: 500;
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-faint); color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: #fee2e2; color: var(--danger); border-left: 4px solid var(--danger); }
.alert-info { background: #dbeafe; color: var(--primary); border-left: 4px solid var(--primary); }
.alert-success { background: #dcfce7; color: var(--success); border-left: 4px solid var(--success); }
.alert-warning { background: #fef3c7; color: var(--warning); border-left: 4px solid var(--warning); }

/* Tags / chips */
.tag {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: 0.18rem 0.55rem; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted); font-size: 0.72rem; font-weight: 600;
  border: 1px solid var(--border);
}
.tag-success { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.tag-warning { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); border-color: transparent; }
.tag-info { background: color-mix(in srgb, var(--info) 13%, transparent); color: var(--info); border-color: transparent; }

/* Login page */
.login-shell {
  display: grid; place-items: center; min-height: 100vh;
}
.login-card { width: 100%; max-width: 400px; padding: 2rem; }
.login-card h1 { text-align: center; margin-bottom: 1.5rem; }

/* Disclaimer */
.disclaimer {
  border-top: 1px solid var(--border);
  margin-top: 2rem; padding-top: 1rem;
  color: var(--text-muted); font-size: 0.85rem;
}

/* Utilities */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.right { text-align: right; }
.muted { color: var(--text-muted); font-size: 0.85rem; }
.success { color: var(--success); }
.danger { color: var(--danger); }
.bold { font-weight: 500; }

/* Responsive */
@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .form-grid { grid-template-columns: 1fr; }
}

/* Chart container */
.chart-container { width: 100%; height: 320px; }

/* Loading */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--surface-2); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toasts ---- */
.fp-toast-host {
  position: fixed; top: 1rem; right: 1rem; z-index: 9999;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.fp-toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--primary); border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0,0,0,.14); padding: 0.7rem 1rem;
  min-width: 240px; max-width: 380px; font-size: 0.88rem;
  animation: fp-toast-in .22s ease;
}
.fp-toast.success { border-left-color: var(--success); }
.fp-toast.error   { border-left-color: var(--danger); }
.fp-toast.info    { border-left-color: var(--primary); }
.fp-toast.warning { border-left-color: var(--warning); }
.fp-toast.hide    { animation: fp-toast-out .22s ease forwards; }
@keyframes fp-toast-in  { from { opacity:0; transform: translateX(24px);} to { opacity:1; transform:none;} }
@keyframes fp-toast-out { to { opacity:0; transform: translateX(24px);} }

/* ---- Modal ---- */
.fp-modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: grid; place-items: center; z-index: 9998; padding: 1rem;
  animation: fp-fade .15s ease;
}
@keyframes fp-fade { from { opacity: 0; } to { opacity: 1; } }
.fp-modal {
  background: var(--surface); border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
}
.fp-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.fp-modal-header h3 { margin: 0; font-size: 1.05rem; }
.fp-modal-body { padding: 1.25rem; }
.fp-modal-footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 1rem 1.25rem; border-top: 1px solid var(--border);
}
.fp-modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 .25rem;
}
.fp-modal-close:hover { color: var(--text); background: none; }

/* ---- KPI / dashboard ---- */
.kpi-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); margin-bottom: 1rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.25rem 1.35rem; box-shadow: var(--shadow); position: relative;
}
.kpi .label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 600; }
.kpi .value { font-family: var(--font-display); font-size: 1.95rem; font-weight: 500; letter-spacing: -.02em; margin-top: .4rem; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 0.82rem; margin-top: .3rem; color: var(--text-muted); }
.chart-grid { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fit, minmax(380px,1fr)); }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.35rem; box-shadow: var(--shadow); }
.chart-card h3 { margin: 0 0 .25rem; font-size: .95rem; }
.chart-card .chart-container { height: 300px; }
.chart-card.tall .chart-container { height: 340px; }

/* Row actions, states, segmented control */
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; }
.icon-btn { padding: .3rem .6rem; font-size: .8rem; }
.empty-state { text-align: center; color: var(--text-muted); padding: 2.5rem 1rem; }
.empty-state .big { font-size: 2rem; opacity: .5; display: block; margin-bottom: .5rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button { background: var(--surface); color: var(--text); border: none; border-radius: 0; padding: .4rem .9rem; }
.seg button:hover { background: var(--surface-2); }
.seg button.active { background: var(--primary); color: #fff; }
.help { cursor: help; color: var(--text-muted); border-bottom: 1px dotted var(--text-muted); }

/* ============================================================
   Design system v2 — motion, focus, dark mode, skeletons
   ============================================================ */
/* (motion / focus / radius tokens live in the root token block at the top) */

/* Smooth, consistent interaction transitions */
button, .btn, .btn-secondary, a, input, select, textarea, .kpi, .card, .tag {
  transition: background-color var(--transition), border-color var(--transition),
              color var(--transition), box-shadow var(--transition), transform var(--transition);
}
button:active, .btn:active { transform: translateY(1px); }

/* Accessible focus: visible ring only for keyboard/intent, not mouse clicks */
:focus { outline: none; }
a:focus-visible, button:focus-visible, .btn:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible,
.seg button:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--primary);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--ring);
}

/* Skeleton loaders (use instead of bare spinners for content) */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton 1.3s ease infinite;
  border-radius: var(--radius);
}
.skeleton-row { height: 14px; margin: 8px 0; }
.skeleton-row.w-60 { width: 60%; } .skeleton-row.w-40 { width: 40%; } .skeleton-row.w-80 { width: 80%; }
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

::selection { background: color-mix(in srgb, var(--primary) 25%, transparent); }

/* ---- Dark mode ---- via [data-theme="dark"] (toggle) and prefers-color-scheme ---- */
:root[data-theme="dark"] {
  --bg: #14130E; --surface: #1B1A14; --surface-2: #24221A; --surface-3: #2C2A20;
  --border: #322F24; --border-strong: #443F31;
  --text: #ECE8DE; --text-muted: #A7A091; --text-faint: #7D7768;
  --primary: #54BD9F; --primary-hover: #6FCDB1; --primary-soft: #1C2A24; --on-primary: #0E1A15;
  --accent: #54BD9F;
  --success: #57C39C; --danger: #E0876F; --warning: #D9AE5A; --info: #79B6D0;
  --shadow: none;
  --shadow-pop: 0 2px 4px rgba(0,0,0,.45), 0 16px 40px -12px rgba(0,0,0,.6);
}
:root[data-theme="dark"] .alert-error   { background: rgba(224,135,111,.14); color: #ECAE9C; }
:root[data-theme="dark"] .alert-info    { background: rgba(121,182,208,.14); color: #ACD2E2; }
:root[data-theme="dark"] .alert-success { background: rgba(87,195,156,.14);  color: #97D8C0; }
:root[data-theme="dark"] .alert-warning { background: rgba(217,174,90,.14);  color: #E6CD97; }
:root[data-theme="dark"] .tag           { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
:root[data-theme="dark"] .tag-success   { background: rgba(84,189,159,.18); color: #97D8C0; border-color: transparent; }
:root[data-theme="dark"] .tag-warning   { background: rgba(217,174,90,.18); color: #E6CD97; border-color: transparent; }
:root[data-theme="dark"] .tag-info      { background: rgba(121,182,208,.18); color: #ACD2E2; border-color: transparent; }
:root[data-theme="dark"] .kpi, :root[data-theme="dark"] .card, :root[data-theme="dark"] .chart-card { background: var(--surface); }
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea { background: var(--surface-2); color: var(--text); }

/* ---- App shell: mobile nav ---- */
.topbar { display: none; }
.nav-toggle { background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: .35rem .6rem; cursor: pointer; }
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: .35rem .55rem; cursor: pointer; }
.theme-toggle:hover, .nav-toggle:hover { background: var(--surface-2); }

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .6rem .9rem; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 260px; z-index: 100;
    transform: translateX(-100%); transition: transform var(--transition);
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .nav-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }
  .main { padding: 1rem; }
}
