/* ============================================================================
   VIBRANT CashFlow — design system
   ============================================================================ */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f8f9fc;
  --border: #e4e8f1;
  --border-strong: #d3d9e6;
  --text: #1b2333;
  --text-muted: #6b7590;
  --text-faint: #657089;

  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eceafd;
  --accent: #0d9488;
  --accent-light: #e3f6f3;

  --success: #15803d;
  --success-bg: #e9f9ee;
  --warning: #9a4b08;
  --warning-bg: #fef3e0;
  --danger: #dc2626;
  --danger-bg: #fdeceb;
  --info: #2563eb;
  --info-bg: #eaf1fe;

  --sidebar-bg: #12162b;
  --sidebar-bg-alt: #1a1f3a;
  --sidebar-text: #b7bdd6;
  --sidebar-text-active: #ffffff;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 45, 0.06);
  --shadow: 0 4px 16px rgba(20, 24, 45, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 24, 45, 0.14);

  --sidebar-w: 248px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
#root { height: 100%; }
a { color: inherit; }
button { font-family: inherit; }
.visually-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important;
}
::selection { background: var(--primary-light); }

/* ---- scrollbars ---- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- animations ---- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

.fade-in { animation: fadeIn .25s ease both; }
.slide-up { animation: slideUp .3s cubic-bezier(.2,.7,.3,1) both; }
.slide-down { animation: slideDown .18s ease both; }

/* ============================================================================
   App shell
   ============================================================================ */
.app-shell { display: flex; min-height: 100%; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-alt));
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 20;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 20px 16px 16px;
}
.brand-logo { display: block; max-width: 100%; height: auto; object-fit: contain; user-select: none; }
.brand-logo-on-dark { background: rgba(255,255,255,.97); border-radius: 7px; padding: 2px 5px; }
.sidebar-brand-logo { width: 64px; flex: 0 0 64px; filter: drop-shadow(0 3px 7px rgba(0,0,0,.24)); }
.sidebar-brand-text { line-height: 1.2; }
.sidebar-brand-text b { display: block; color: #fff; font-size: 14px; letter-spacing: .1px; white-space: nowrap; }
.sidebar-brand-text span { font-size: 10.5px; color: var(--sidebar-text); opacity: .75; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 12px; }
.sidebar-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #6d759a; margin: 18px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-text); text-decoration: none; cursor: pointer;
  font-size: 13.5px; font-weight: 500; margin-bottom: 2px;
  transition: background .15s ease, color .15s ease;
  border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(124, 108, 242, .18);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-item .nav-ico { width: 18px; text-align: center; font-size: 15px; opacity: .9; }

.sidebar-footer {
  padding: 14px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px; color: #8890b3;
}

.main-area { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-brand-logo { width: 48px; flex: 0 0 48px; }

.user-chip { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 8px; border: 0; color: inherit; background: transparent; border-radius: 999px; transition: background .15s; }
.user-chip:hover { background: var(--surface-alt); }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-meta { line-height: 1.2; }
.user-meta b { display: block; font-size: 12.5px; }
.user-meta span { font-size: 11px; color: var(--text-muted); }

.page-content { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* ============================================================================
   Buttons
   ============================================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: transform .1s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
  /* A <button> never needed this, but a <button>-styled <a> (e.g. the
     Dashboard quick actions) otherwise keeps the browser's link underline —
     visited links especially — since nothing here reset it. */
  text-decoration: none;
}
.btn:visited { color: inherit; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.disabled { pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 10px rgba(79,70,229,.28); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; box-shadow: 0 2px 10px rgba(13,148,136,.28); }
.btn-accent:hover:not(:disabled) { background: #0b7d72; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-alt); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; }

/* ============================================================================
   Forms
   ============================================================================ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.input, .select, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font-size: 13.5px; background: var(--surface);
  color: var(--text); transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.input[disabled] { background: var(--surface-alt); color: var(--text-faint); }
.input[type="date"], .input[type="month"] { max-width: 170px; }
.help-text { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
.error-text { font-size: 12px; color: var(--danger); margin-top: 6px; }

/* ---- searchable select ---- */
.sselect { position: relative; }
.sselect.open { z-index: 70; }
.sselect-control {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-size: 13.5px; min-height: 38px;
}
.sselect-control:hover { border-color: var(--text-faint); }
.sselect.open .sselect-control { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.sselect-placeholder { color: var(--text-faint); }
.sselect-caret { color: var(--text-faint); font-size: 11px; transition: transform .15s; }
.sselect.open .sselect-caret { transform: rotate(180deg); }
.sselect-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 260px; overflow: hidden; display: flex; flex-direction: column;
}
/* Portal-rendered menus (SearchableSelect) sit directly under <body>, above
   modals and toasts too, so they're never clipped by a scrollable ancestor
   (a table) or hidden behind it by table row stacking quirks. */
.sselect-menu-portal { z-index: 300; }
.sselect-search { padding: 8px; border-bottom: 1px solid var(--border); }
.sselect-search input { width: 100%; border: none; outline: none; font-size: 13px; padding: 6px 8px; background: var(--surface-alt); border-radius: var(--radius-sm); }
.sselect-options { overflow-y: auto; padding: 6px; }
.sselect-option { padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.sselect-option { width: 100%; border: 0; background: transparent; color: inherit; text-align: left; }
.sselect-option:hover, .sselect-option.hi { background: var(--primary-light); }
.sselect-option.selected { color: var(--primary); font-weight: 600; }
.sselect-empty { padding: 14px; text-align: center; color: var(--text-faint); font-size: 12.5px; }
.sselect-clear { color: var(--text-faint); cursor: pointer; padding: 2px 4px; border: 0; background: transparent; line-height: 1; }
.sselect-clear:hover { color: var(--danger); }
.sselect.sm .sselect-control { padding: 6px 9px; min-height: 32px; font-size: 12.5px; }

/* ============================================================================
   Cards / stat tiles
   ============================================================================ */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 20px;
}
.card-title { font-size: 14.5px; font-weight: 700; margin: 0 0 2px; }
.card-sub { font-size: 12px; color: var(--text-muted); margin: 0 0 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease;
}
.stat-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-tile-icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 17px; margin-bottom: 12px;
}
.stat-tile-label { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.stat-tile-value { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.stat-tile-delta { font-size: 11.5px; margin-top: 6px; font-weight: 600; }
.stat-tile.accent-success .stat-tile-icon { background: var(--success-bg); color: var(--success); }
.stat-tile.accent-danger .stat-tile-icon { background: var(--danger-bg); color: var(--danger); }
.stat-tile.accent-primary .stat-tile-icon { background: var(--primary-light); color: var(--primary); }
.stat-tile.accent-warning .stat-tile-icon { background: var(--warning-bg); color: var(--warning); }

/* ============================================================================
   Tables
   ============================================================================ */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
table.dtable { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
table.dtable thead th {
  position: sticky; top: 0; background: var(--surface-alt); text-align: left;
  padding: 11px 14px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.dtable tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.dtable tbody tr:last-child td { border-bottom: none; }
table.dtable tbody tr:hover { background: var(--surface-alt); }
table.dtable tfoot td { padding: 11px 14px; font-weight: 700; background: var(--surface-alt); border-top: 2px solid var(--border-strong); }
.cell-num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-muted { color: var(--text-muted); }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .01em;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* variance colour coding (used in Outflow analysis + exports) */
.var-under { color: var(--success); font-weight: 700; }
.var-near { color: var(--warning); font-weight: 700; }
.var-over { color: var(--danger); font-weight: 700; }
.bg-under { background: var(--success-bg); }
.bg-near { background: var(--warning-bg); }
.bg-over { background: var(--danger-bg); }

/* ============================================================================
   Toolbar / filters
   ============================================================================ */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; background: var(--surface-alt); padding: 4px; border-radius: var(--radius); border: 1px solid var(--border); width: fit-content; }
.tab-btn { border: none; background: transparent; padding: 7px 14px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: all .15s; }
.tab-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.tab-btn:disabled { opacity: .5; cursor: not-allowed; }
.user-menu-action { justify-content: flex-start; }

button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(79, 70, 229, .35);
  outline-offset: 2px;
}

/* ============================================================================
   Modal / toast
   ============================================================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 35, .5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 100; animation: fadeIn .15s ease;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-box.wide { max-width: 860px; }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 18px; color: var(--text-faint); cursor: pointer; padding: 4px; }

.toast-stack { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--text); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; min-width: 240px;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
.toast.info { background: #1e293b; }

/* ============================================================================
   Login page
   ============================================================================ */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 15% 20%, #241f4d 0%, #12162b 45%, #0b0e1e 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 34px 32px; position: relative;
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 24px; }
.login-brand-logo { width: 176px; }
.boot-error-logo { width: 150px; }
.login-brand h1 { font-size: 19px; margin: 0; text-align: center; }
.login-brand p { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--text-faint); font-size: 11.5px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ============================================================================
   Misc
   ============================================================================ */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .ico { font-size: 34px; margin-bottom: 10px; opacity: .5; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(0,0,0,.12);
  border-top-color: var(--primary); animation: spin .7s linear infinite; display: inline-block;
}
.spinner.on-dark { border-color: rgba(255,255,255,.25); border-top-color: #fff; }

.muted { color: var(--text-muted); }
.chip { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; background: var(--surface-alt); border: 1px solid var(--border); font-size: 11.5px; font-weight: 600; }

.progress-track { height: 7px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }

/* ---- boot splash ---- */
.splash { display: flex; flex-direction: column; align-items: center; gap: 18px; animation: fadeIn .3s ease both; }
.splash-logo { width: 190px; padding: 6px 10px; box-shadow: 0 10px 30px rgba(0,0,0,.32); animation: splashPulse 1.6s ease-in-out infinite; }
.splash-title { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .3px; opacity: .92; }
.splash-bar { width: 160px; height: 4px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; }
.splash-bar-fill { height: 100%; width: 40%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), #7c6cf2); animation: splashSlide 1.1s ease-in-out infinite; }
@keyframes splashPulse { 0%, 100% { transform: scale(1); box-shadow: 0 10px 30px rgba(124, 108, 242, .5); } 50% { transform: scale(1.08); box-shadow: 0 14px 40px rgba(124, 108, 242, .7); } }
@keyframes splashSlide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

.mobile-menu-btn { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; z-index: 30; }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 18, 35, .45); z-index: 15; animation: fadeIn .15s ease; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 12px; }
  .topbar-sub, .topbar-right > .chip, .user-meta { display: none; }
  .page-content { padding: 16px 12px; }
  .login-card { padding: 28px 22px; }
  .modal-overlay { padding: 12px; }
  .tabs { max-width: 100%; overflow-x: auto; }
  .topbar-brand-logo { width: 40px; flex-basis: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
