/* ============================================================================
   FINANCEHQ — DESIGN SYSTEM
   Concept: "The Ledger" — ink & brass. Old-money bookkeeping meets a modern
   dashboard. Serif display for headline figures, tabular mono for money in
   tables, thin brass rule-lines borrowed from ledger paper as the signature
   structural device (used at section heads instead of generic card borders).
   ============================================================================ */

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

:root,
[data-bs-theme="light"] {
  --ink-900: #12161c;
  --ink-700: #33404d;
  --paper-0:  #ffffff;
  --paper-50: #f5f6f4;
  --paper-100: #eceee9;
  --line: #ddded9;
  --brass: #a9791f;
  --brass-strong: #8a6116;
  --brass-soft: #f1e6cd;
  --jade: #1f6f5c;
  --jade-soft: #e2f1ec;
  --rust: #a5402c;
  --rust-soft: #f6e5e0;
  --text-primary: var(--ink-900);
  --text-secondary: #5b6470;
  --text-muted: #8a92a0;
  --surface: var(--paper-0);
  --surface-alt: var(--paper-50);
  --bg-body: var(--paper-100);
  --shadow-sm: 0 1px 2px rgba(18,22,28,.06);
  --shadow-md: 0 6px 20px rgba(18,22,28,.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --sidebar-w: 260px;
}

[data-bs-theme="dark"] {
  --ink-900: #eef0f3;
  --ink-700: #c4cad3;
  --paper-0: #1b2028;
  --paper-50: #151920;
  --paper-100: #0e1116;
  --line: #2a313b;
  --brass: #d7ac4e;
  --brass-strong: #eac877;
  --brass-soft: #362c17;
  --jade: #4cbf9e;
  --jade-soft: #142723;
  --rust: #e07a5f;
  --rust-soft: #2c1a16;
  --text-primary: var(--ink-900);
  --text-secondary: #a9b1bd;
  --text-muted: #717b88;
  --surface: var(--paper-0);
  --surface-alt: var(--paper-50);
  --bg-body: var(--paper-100);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 10px 28px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

.font-display { font-family: 'Fraunces', Georgia, serif; }
.font-mono { font-family: 'IBM Plex Mono', 'SFMono-Regular', monospace; font-variant-numeric: tabular-nums; }

a { text-decoration: none; color: inherit; }

/* ---- Ledger rule: signature divider ---- */
.ledger-rule {
  position: relative;
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.5rem 0;
}
.ledger-rule::after {
  content: '';
  position: absolute;
  top: -1px; left: 0;
  width: 34px; height: 2px;
  background: var(--brass);
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem;
}
.section-head h2, .section-head h3 {
  font-family: 'Fraunces', serif; font-weight: 600; margin: 0;
  letter-spacing: -.01em;
}
.section-eyebrow {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--brass-strong); font-weight: 600; margin-bottom: .25rem; display: block;
}

/* ============================================================================
   APP SHELL / LAYOUT
   ============================================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1030;
  display: flex; flex-direction: column;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.4rem 1.3rem 1.1rem;
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 1.15rem;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand i { color: var(--brass); font-size: 1.4rem; }
.sidebar-close { margin-left: auto; background: none; border: none; color: var(--text-secondary); font-size: 1.1rem; }

.sidebar-nav { padding: .9rem .8rem 2rem; overflow-y: auto; flex: 1; }
.nav-section-title {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-muted); font-weight: 700; margin: 1.1rem .6rem .4rem;
}
.nav-section-title:first-child { margin-top: 0; }

.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: .8rem;
  padding: .62rem .8rem; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-weight: 500; font-size: .89rem;
  margin-bottom: .1rem; transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { width: 18px; text-align: center; font-size: 1rem; color: var(--text-muted); }
.sidebar-nav .nav-link:hover { background: var(--surface-alt); color: var(--text-primary); }
.sidebar-nav .nav-link.active {
  background: var(--brass-soft); color: var(--brass-strong); font-weight: 600;
}
.sidebar-nav .nav-link.active i { color: var(--brass-strong); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1025;
}

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

.app-topbar {
  height: 68px; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem; position: sticky; top: 0; z-index: 1010;
}

.topbar-icon-btn {
  background: none; border: none; color: var(--text-secondary);
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem; position: relative; transition: background .15s;
}
.topbar-icon-btn:hover { background: var(--surface-alt); }
.theme-icon-light { display: none; }
[data-bs-theme="dark"] .theme-icon-dark { display: none; }
[data-bs-theme="dark"] .theme-icon-light { display: inline-block; }

.notif-badge {
  position: absolute; top: 3px; right: 3px;
  background: var(--rust); color: #fff; font-size: .6rem; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

.topbar-search {
  position: relative; flex: 1; max-width: 420px;
  display: flex; align-items: center; gap: .55rem;
  background: var(--surface-alt); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: .5rem .9rem;
}
.topbar-search i { color: var(--text-muted); }
.topbar-search input {
  border: none; background: none; outline: none; flex: 1;
  color: var(--text-primary); font-size: .88rem;
}
.search-results-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); max-height: 380px; overflow-y: auto; z-index: 1050;
}
.search-results-dropdown.show { display: block; }
.search-result-item { padding: .65rem .9rem; border-bottom: 1px solid var(--line); font-size: .85rem; display: block; }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface-alt); }

.topbar-actions { display: flex; align-items: center; gap: .4rem; margin-left: auto; }

.profile-btn {
  display: flex; align-items: center; gap: .5rem; background: none; border: none;
  padding: .35rem .5rem; border-radius: var(--radius-sm); color: var(--text-primary); font-weight: 600; font-size: .85rem;
}
.profile-btn:hover { background: var(--surface-alt); }
.avatar-circle {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brass), var(--brass-strong));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; flex-shrink: 0;
}

.notif-dropdown { width: 340px; padding: 0; border-radius: var(--radius-md); border: 1px solid var(--line); overflow: hidden; }
.notif-header { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); font-weight: 700; font-size: .85rem; }
.notif-header a { font-size: .75rem; font-weight: 600; color: var(--brass-strong); }
.notif-list { max-height: 340px; overflow-y: auto; }
.notif-item { padding: .75rem 1rem; border-bottom: 1px solid var(--line); font-size: .82rem; display: flex; gap: .6rem; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--surface-alt); }
.notif-item i { margin-top: 2px; color: var(--brass); }

.app-content { padding: 1.6rem; flex: 1; }

/* ============================================================================
   CARDS
   ============================================================================ */
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 1.2rem 1.3rem; box-shadow: var(--shadow-sm); height: 100%;
}
.stat-card .stat-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); font-weight: 700; display: flex; align-items: center; gap: .4rem;
}
.stat-card .stat-value {
  font-family: 'Fraunces', serif; font-size: 1.65rem; font-weight: 600; margin-top: .35rem;
  letter-spacing: -.01em;
}
.stat-card .stat-sub { font-size: .78rem; color: var(--text-secondary); margin-top: .3rem; }
.stat-card .stat-icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
}
.icon-jade { background: var(--jade-soft); color: var(--jade); }
.icon-rust { background: var(--rust-soft); color: var(--rust); }
.icon-brass { background: var(--brass-soft); color: var(--brass-strong); }

.card-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 1.3rem; box-shadow: var(--shadow-sm);
}

.text-jade { color: var(--jade) !important; }
.text-rust { color: var(--rust) !important; }
.text-brass { color: var(--brass-strong) !important; }
.bg-jade-soft { background: var(--jade-soft) !important; }
.bg-rust-soft { background: var(--rust-soft) !important; }
.bg-brass-soft { background: var(--brass-soft) !important; }
.bg-secondary-soft { background: var(--surface-alt) !important; }

/* progress bars */
.ledger-progress { height: 8px; border-radius: 4px; background: var(--surface-alt); overflow: hidden; }
.ledger-progress > div { height: 100%; background: var(--brass); border-radius: 4px; transition: width .4s ease; }
.ledger-progress.over > div { background: var(--rust); }

/* tables */
.table-ledger { width: 100%; font-size: .87rem; }
.table-ledger th {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted);
  border-bottom: 1px solid var(--line); padding: .6rem .5rem; text-align: left; font-weight: 700;
}
.table-ledger td { padding: .7rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-ledger tbody tr:hover { background: var(--surface-alt); }
.amount-cell { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-variant-numeric: tabular-nums; }

.badge-soft { padding: .3rem .6rem; border-radius: 20px; font-size: .72rem; font-weight: 600; }

/* buttons using brass accent */
.btn-brass {
  background: var(--brass); border-color: var(--brass); color: #fff;
}
.btn-brass:hover { background: var(--brass-strong); border-color: var(--brass-strong); color: #fff; }
.btn-outline-brass { border: 1px solid var(--brass); color: var(--brass-strong); background: transparent; }
.btn-outline-brass:hover { background: var(--brass-soft); color: var(--brass-strong); }

/* form controls consistent with theme */
.form-control, .form-select {
  background: var(--surface); border: 1px solid var(--line); color: var(--text-primary);
}
.form-control:focus, .form-select:focus {
  border-color: var(--brass); box-shadow: 0 0 0 .2rem var(--brass-soft);
  background: var(--surface); color: var(--text-primary);
}
label.form-label { font-size: .82rem; font-weight: 600; color: var(--text-secondary); }

.modal-content { background: var(--surface); color: var(--text-primary); border: 1px solid var(--line); }
.dropdown-menu { background: var(--surface); border: 1px solid var(--line); color: var(--text-primary); }
.dropdown-item { color: var(--text-primary); }
.dropdown-item:hover { background: var(--surface-alt); color: var(--text-primary); }

/* ============================================================================
   TOASTS / FLASH
   ============================================================================ */
.toast-stack {
  position: fixed; top: 84px; right: 1.2rem; z-index: 2000;
  display: flex; flex-direction: column; gap: .5rem; max-width: 340px;
}
.app-toast {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brass);
  border-radius: var(--radius-sm); padding: .7rem .9rem; box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: .6rem; font-size: .85rem; animation: toastIn .2s ease;
}
.app-toast.toast-success { border-left-color: var(--jade); }
.app-toast.toast-success i { color: var(--jade); }
.app-toast.toast-danger { border-left-color: var(--rust); }
.app-toast.toast-danger i { color: var(--rust); }
.app-toast.toast-warning { border-left-color: var(--brass); }
.toast-close { margin-left: auto; background: none; border: none; color: var(--text-muted); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px);} to { opacity: 1; transform: translateX(0);} }

/* ============================================================================
   FAB
   ============================================================================ */
.fab-wrapper { position: fixed; right: 1.4rem; bottom: 5.4rem; z-index: 1040; }
.fab-main {
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--brass); color: #fff; font-size: 1.4rem; box-shadow: var(--shadow-md);
  display: flex; align-items: center; justify-content: center; transition: transform .2s;
}
.fab-main.open { transform: rotate(45deg); }
.fab-menu {
  position: absolute; bottom: 68px; right: 0; display: none; flex-direction: column; gap: .5rem;
  min-width: 190px;
}
.fab-menu.show { display: flex; }
.fab-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: .6rem .9rem; font-size: .84rem; font-weight: 600; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: .6rem; color: var(--text-primary);
}

@media (min-width: 992px) {
  .fab-wrapper { bottom: 2rem; }
}

/* ============================================================================
   BOTTOM NAV (mobile)
   ============================================================================ */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: 62px; z-index: 1035;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-item { display: flex; flex-direction: column; align-items: center; gap: .15rem; color: var(--text-muted); font-size: .65rem; font-weight: 600; }
.bottom-nav-item i { font-size: 1.15rem; }
.bottom-nav-item.active { color: var(--brass-strong); }
.bottom-nav-add {
  width: 46px; height: 46px; border-radius: 50%; background: var(--brass); color: #fff !important;
  display: flex; align-items: center; justify-content: center; margin-top: -22px; box-shadow: var(--shadow-md);
}
.bottom-nav-add i { font-size: 1.3rem; }

/* ============================================================================
   AUTH PAGES (login / register / forgot)
   ============================================================================ */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg-body); padding: 1.5rem;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); width: 100%; max-width: 420px; padding: 2.2rem 2rem;
}
.auth-brand { display: flex; align-items: center; gap: .6rem; font-family: 'Fraunces', serif; font-weight: 700; font-size: 1.4rem; margin-bottom: .3rem; }
.auth-brand i { color: var(--brass); }
.auth-sub { color: var(--text-secondary); font-size: .88rem; margin-bottom: 1.6rem; }

/* Loading skeletons */
.skeleton { background: linear-gradient(90deg, var(--surface-alt) 25%, var(--line) 37%, var(--surface-alt) 63%); background-size: 400% 100%; animation: skeletonShine 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeletonShine { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.show { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .app-main { margin-left: 0; }
  .app-content { padding: 1rem 1rem 5.5rem; }
  .topbar-search { max-width: none; }
}

@media (max-width: 575.98px) {
  .topbar-search span { display: none; }
  .app-topbar { padding: 0 .9rem; gap: .6rem; }
  .stat-card .stat-value { font-size: 1.4rem; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
