/* ============================================================
   Riey's Finance Manager — design system
   ============================================================ */

:root {
    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --border: #ecedf3;
    --border-strong: #e0e2ec;
    --text: #191c2b;
    --text-muted: #868da3;
    --heading: #12142a;

    --primary: #6366f1;
    --primary-600: #5558e3;
    --primary-soft: #eef0ff;
    --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --grad-blue: linear-gradient(135deg, #4f8cff 0%, #6366f1 100%);

    --success: #10b981;
    --success-soft: #e7f8f1;
    --danger: #ef4444;
    --danger-soft: #fdecec;
    --warning: #f59e0b;
    --warning-soft: #fef4e2;
    --info: #06b6d4;
    --info-soft: #e4f8fb;
    --gold: #eab308;
    --purple: #8b5cf6;

    --sidebar-bg: #16182e;
    --sidebar-bg-2: #1b1e38;
    --sidebar-text: rgba(255, 255, 255, .62);
    --sidebar-text-active: #ffffff;

    --shadow-sm: 0 1px 2px rgba(20, 22, 46, .05);
    --shadow: 0 4px 18px rgba(20, 22, 46, .06);
    --shadow-lg: 0 12px 34px rgba(20, 22, 46, .12);
    --radius: 16px;
    --radius-sm: 11px;

    --sidebar-w: 250px;
    --topbar-h: 66px;
}

[data-bs-theme="dark"] {
    --bg: #0e1017;
    --surface: #171a24;
    --surface-2: #1d212d;
    --border: #262a38;
    --border-strong: #2e3342;
    --text: #e5e8f0;
    --text-muted: #838aa0;
    --heading: #f2f4fa;
    --primary-soft: #23264a;
    --success-soft: #12241f;
    --danger-soft: #2a1a1c;
    --warning-soft: #2a2417;
    --info-soft: #12252b;
    --sidebar-bg: #0b0d16;
    --sidebar-bg-2: #12152400;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 4px 18px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 34px rgba(0, 0, 0, .5);
}

* { -webkit-font-smoothing: antialiased; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: .925rem;
    letter-spacing: -.01em;
}

h1, h2, h3, h4, h5, h6 { color: var(--heading); font-weight: 700; letter-spacing: -.02em; }
a { color: var(--primary); }
.text-muted { color: var(--text-muted) !important; }
hr { border-color: var(--border); opacity: 1; }

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

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--sidebar-bg);
    background-image: radial-gradient(120% 60% at 0% 0%, var(--sidebar-bg-2), transparent 60%);
    color: var(--sidebar-text);
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    border-right: 1px solid rgba(255, 255, 255, .05);
}

.sidebar-brand {
    display: flex; align-items: center; gap: .7rem;
    padding: 1.15rem 1.25rem 1.1rem;
    margin-bottom: .4rem;
}
.brand-logo {
    width: 40px; height: 40px; border-radius: 12px;
    display: grid; place-items: center;
    background: var(--grad); color: #fff; font-size: 1.25rem;
    box-shadow: 0 6px 16px rgba(99, 102, 241, .45);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { color: #fff; font-weight: 800; font-size: 1.02rem; }
.brand-sub { color: rgba(255, 255, 255, .45); font-size: .7rem; font-weight: 500; letter-spacing: .02em; }
.sidebar-close { margin-left: auto; background: none; border: 0; color: rgba(255,255,255,.6); font-size: 1.1rem; }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: 0 .8rem; }
.nav-group-label {
    font-size: .66rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
    color: rgba(255, 255, 255, .32);
    padding: 1rem .8rem .35rem;
}
.nav-item-link {
    display: flex; align-items: center; gap: .8rem;
    padding: .62rem .8rem; margin-bottom: 2px;
    border-radius: 11px;
    color: var(--sidebar-text);
    text-decoration: none; font-weight: 500; font-size: .9rem;
    transition: all .16s ease;
}
.nav-item-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.nav-item-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item-link.active {
    background: var(--grad); color: #fff;
    box-shadow: 0 6px 16px rgba(99, 102, 241, .4);
}
.text-danger-soft { color: #ff8a8a !important; }
.text-danger-soft:hover { background: rgba(239, 68, 68, .12) !important; color: #ff9d9d !important; }

.sidebar-foot { padding: .6rem .8rem 1rem; border-top: 1px solid rgba(255, 255, 255, .06); }

.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(5, 6, 15, .5);
    z-index: 1035; opacity: 0; visibility: hidden; transition: opacity .2s;
    backdrop-filter: blur(2px);
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

/* ---------- Main ---------- */
.main-wrap { flex: 1 1 auto; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    position: sticky; top: 0; z-index: 1020;
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.6rem;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar-title h1 { font-size: 1.22rem; margin: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

.icon-btn {
    width: 40px; height: 40px; border-radius: 11px;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text-muted); display: grid; place-items: center; font-size: 1.05rem;
    transition: all .15s;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

.theme-icon-light { display: none; }
[data-bs-theme="dark"] .theme-icon-dark { display: none; }
[data-bs-theme="dark"] .theme-icon-light { display: inline; }

.user-chip {
    display: flex; align-items: center; gap: .55rem;
    padding: .28rem .28rem; border-radius: 30px;
    border: 1px solid var(--border); background: var(--surface);
}
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--grad); color: #fff; font-weight: 700; font-size: .85rem;
    display: grid; place-items: center;
}
.user-name { font-weight: 600; font-size: .85rem; padding-right: .5rem; }

.page { padding: 1.7rem 1.6rem; flex: 1 1 auto; }
.page-foot { padding: 1rem 1.6rem 1.4rem; color: var(--text-muted); font-size: .78rem; text-align: center; }

/* ---------- Cards ---------- */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--text);
}
.card-header {
    background: transparent; border-bottom: 1px solid var(--border);
    font-weight: 700; color: var(--heading); padding: .95rem 1.15rem; font-size: .95rem;
}
.card-body { padding: 1.15rem; }

/* ---------- Stat cards ---------- */
.stat-card {
    position: relative; overflow: hidden; border-radius: var(--radius);
    transition: transform .18s ease, box-shadow .18s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card .card-body { padding: 1.1rem 1.15rem; }
.stat-card::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: var(--primary);
}
.stat-card.green::before { background: var(--success); }
.stat-card.red::before { background: var(--danger); }
.stat-card.gold::before { background: var(--gold); }
.stat-card.info::before { background: var(--info); }
.stat-card.purple::before { background: var(--purple); }
.stat-label {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
    font-weight: 700; color: var(--text-muted); margin-bottom: .15rem;
}
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--heading); letter-spacing: -.03em; line-height: 1.1; }
.stat-ico { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 1.25rem; flex: 0 0 auto; }
.stat-ico.primary { background: var(--primary-soft); color: var(--primary); }
.stat-ico.green { background: var(--success-soft); color: var(--success); }
.stat-ico.red { background: var(--danger-soft); color: var(--danger); }
.stat-ico.gold { background: var(--warning-soft); color: var(--gold); }
.stat-ico.info { background: var(--info-soft); color: var(--info); }
.stat-ico.purple { background: var(--primary-soft); color: var(--purple); }

/* ---------- Amounts / bits ---------- */
.amount-pos { color: var(--success); font-weight: 700; }
.amount-neg { color: var(--danger); font-weight: 700; }

.acct-icon {
    width: 44px; height: 44px; border-radius: 13px;
    display: grid; place-items: center; color: #fff; font-size: 1.2rem; flex: 0 0 auto;
    box-shadow: 0 4px 12px rgba(20, 22, 46, .16);
}

.mini-bar { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.mini-bar > span { display: block; height: 100%; border-radius: 4px; }

.badge-soft { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn { border-radius: 11px; font-weight: 600; letter-spacing: -.01em; padding: .5rem .95rem; }
.btn-sm { border-radius: 9px; padding: .34rem .7rem; }
.btn-primary { background: var(--grad); border: none; box-shadow: 0 6px 16px rgba(99, 102, 241, .32); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-600); box-shadow: 0 8px 20px rgba(99, 102, 241, .42); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-outline-secondary { border-color: var(--border-strong); color: var(--text-muted); }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-outline-primary { border-color: var(--primary); color: var(--primary); }
.btn-outline-primary.active, .btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-outline-danger { border-color: var(--danger); color: var(--danger); }

/* ---------- Tables ---------- */
.table { color: var(--text); --bs-table-bg: transparent; margin-bottom: 0; }
.table > thead th {
    background: var(--surface-2); color: var(--text-muted);
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
    border-bottom: 1px solid var(--border); padding: .7rem .9rem;
}
.table > tbody > tr { border-color: var(--border); }
.table > tbody > tr:last-child { border-bottom: 0; }
.table > :not(caption) > * > * { padding: .72rem .9rem; background: transparent; color: var(--text); }
.table-hover > tbody > tr:hover > * { background: var(--surface-2); }
.table-light { --bs-table-bg: var(--surface-2); }
.table-danger { --bs-table-bg: var(--danger-soft); }

/* ---------- List groups ---------- */
.list-group { border-radius: var(--radius); }
.list-group-item {
    background: var(--surface); border-color: var(--border); color: var(--text);
    padding: .85rem 1.15rem;
}
.list-group-item-action:hover { background: var(--surface-2); }

/* ---------- Forms ---------- */
.form-control, .form-select {
    background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
    border-radius: 11px; padding: .55rem .8rem; font-size: .9rem;
}
.form-control:focus, .form-select:focus {
    background: var(--surface); color: var(--text);
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, .16);
}
.form-control::placeholder { color: var(--text-muted); opacity: .7; }
.form-control-lg { font-size: 1.15rem; font-weight: 600; }
.form-label { font-weight: 600; font-size: .82rem; color: var(--text-muted); margin-bottom: .35rem; }
.form-text { color: var(--text-muted); font-size: .78rem; }
.form-control-color { min-height: 42px; padding: .25rem; }
.input-group-text { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-muted); border-radius: 11px; }
.form-check-input { border-color: var(--border-strong); }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

/* ---------- Badges ---------- */
.badge { font-weight: 600; padding: .4em .65em; border-radius: 7px; letter-spacing: .01em; }
.bg-success-subtle { background: var(--success-soft) !important; }
.bg-danger-subtle { background: var(--danger-soft) !important; }
.bg-secondary-subtle { background: var(--surface-2) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-info { color: var(--info) !important; }
.bg-info-subtle { background: var(--info-soft) !important; }

/* ---------- Progress ---------- */
.progress { background: var(--surface-2); border-radius: 30px; border: 1px solid var(--border); overflow: hidden; }
.progress-bar { background: var(--grad); font-weight: 700; font-size: .72rem; }
.progress-bar.bg-success { background: linear-gradient(90deg, #10b981, #34d399) !important; }

/* ---------- Alerts / modal ---------- */
.alert { border: 1px solid var(--border); border-radius: 13px; }
.alert-success { background: var(--success-soft); color: #0a7c5a; border-color: transparent; }
.alert-danger { background: var(--danger-soft); color: #c0362f; border-color: transparent; }
.alert-warning { background: var(--warning-soft); color: #a9720a; border-color: transparent; }
.alert-secondary { background: var(--surface-2); color: var(--text-muted); }
.modal-content { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.modal-header, .modal-footer { border-color: var(--border); }

/* ---------- Login ---------- */
.login-body {
    min-height: 100vh;
    background:
        radial-gradient(60% 55% at 15% 15%, rgba(139, 92, 246, .5), transparent 60%),
        radial-gradient(55% 55% at 90% 85%, rgba(79, 140, 255, .45), transparent 60%),
        #14162b;
}
.login-card { border-radius: 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }

/* ---------- Utilities ---------- */
.card-link-plain { text-decoration: none; color: inherit; }
.card-link-plain:hover .card { box-shadow: var(--shadow-lg); transform: translateY(-2px); transition: all .18s; }
.cursor-pointer { cursor: pointer; }

/* Cashflow Lab */
.card-footer { background: transparent; border-top: 1px solid var(--border); padding: .8rem 1.15rem; color: var(--text); }
.sim-table > :not(caption) > * > * { padding: .5rem .6rem; }
.sim-table thead th { font-size: .66rem; }
.sim-table .sim-label { min-width: 130px; }
.sim-table .sim-bucket { max-width: 96px; font-size: .78rem; }
.sim-off { opacity: .5; }
.sim-off .sim-label { text-decoration: line-through; }
.sim-foot td { border-top: 2px solid var(--border-strong); font-weight: 600; background: var(--surface-2); }
.sim-foot-surplus td { font-size: 1.02rem; border-top: 1px solid var(--border); }
.mini-bar > span { transition: width .3s ease; }
.form-range { accent-color: var(--primary); }
.catrow { border-radius: 6px; padding: 2px 4px; transition: background .12s; }
.catrow:hover { background: var(--surface-2); }
.catrow.cat-off { opacity: .4; }
.catrow.cat-off span { text-decoration: line-through; }
.drag-handle { cursor: grab; }
.drag-handle:active { cursor: grabbing; }
.drag-ghost { opacity: .45; background: var(--surface-2) !important; }
.text-decoration-none { text-decoration: none; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 20px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); transition: transform .24s ease; box-shadow: var(--shadow-lg); }
    .sidebar.show { transform: translateX(0); }
    .main-wrap { margin-left: 0; }
    .page { padding: 1.1rem; }
    .topbar { padding: 0 1rem; }
}
