/* =====================================================================
   Өрхийн санхүү — UI
   Палитр: нарс ногоон sidebar, цайвар саарал-ногоон дэвсгэр.
   Орлого = ногоон, Зарлага = улаан, Хуримтлал = цэнхэр, Анхааруулга = шар.
   ===================================================================== */
:root {
    --pine: #12343b;
    --pine-2: #1b4750;
    --paper: #f2f5f4;
    --surface: #ffffff;
    --ink: #17282d;
    --muted: #62757a;
    --line: #dce4e2;
    --income: #1e8c5a;
    --income-soft: #e3f3ea;
    --expense: #c8414b;
    --expense-soft: #fbe9ea;
    --savings: #2a6fdb;
    --savings-soft: #e6effc;
    --warn: #d6921a;
    --warn-soft: #fdf3e0;
    --radius: 10px;
    --radius-sm: 6px;

    --bs-body-font-family: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--paper);
    --bs-primary: #1e6f5c;
    --bs-primary-rgb: 30, 111, 92;
    --bs-success: var(--income);
    --bs-success-rgb: 30, 140, 90;
    --bs-danger: var(--expense);
    --bs-danger-rgb: 200, 65, 75;
    --bs-warning: var(--warn);
    --bs-warning-rgb: 214, 146, 26;
    --bs-info-rgb: 42, 111, 219;
    --bs-border-color: var(--line);
    --bs-link-color: #1e6f5c;
    --bs-link-color-rgb: 30, 111, 92;
    --bs-link-hover-color: #134f41;
}

body { font-size: .95rem; line-height: 1.5; }
.num, .amount, table td.text-end, .ledger-value { font-variant-numeric: tabular-nums; }
a { text-decoration: none; }
:focus-visible { outline: 2px solid var(--savings); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn { border-radius: var(--radius-sm); font-weight: 500; }
.btn-primary { --bs-btn-bg: #1e6f5c; --bs-btn-border-color: #1e6f5c; --bs-btn-hover-bg: #175a4a; --bs-btn-hover-border-color: #175a4a; --bs-btn-active-bg: #134f41; }
.btn-income { --bs-btn-color: #fff; --bs-btn-bg: var(--income); --bs-btn-border-color: var(--income); --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #17724a; --bs-btn-hover-border-color: #17724a; }
.btn-outline-expense { --bs-btn-color: var(--expense); --bs-btn-border-color: var(--expense); --bs-btn-hover-color: #fff; --bs-btn-hover-bg: var(--expense); --bs-btn-hover-border-color: var(--expense); }
.btn-icon { border: 0; font-size: 1.5rem; line-height: 1; padding: .25rem .4rem; color: var(--ink); }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    --bs-offcanvas-width: 260px;
    --bs-offcanvas-bg: var(--pine);
    --bs-offcanvas-color: #d9e6e3;
    background: var(--pine);
    color: #d9e6e3;
    width: 250px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}
@media (min-width: 992px) {
    .sidebar { position: sticky; top: 0; height: 100vh; }
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1rem 1rem; }
.brand { display: flex; align-items: center; gap: .7rem; color: #fff; min-width: 0; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
    display: grid; place-items: center; font-size: 1.15rem;
    background: #2c6b5d; color: #fff;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: #9fbab4; font-size: .78rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: .5rem .6rem; flex: 1; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem .8rem; border-radius: var(--radius-sm);
    color: #c9dad6; font-weight: 500;
}
.nav-item i { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .85; }
.nav-item:hover { background: var(--pine-2); color: #fff; }
.nav-item.active { background: #fff; color: var(--pine); }
.nav-item.active i { opacity: 1; }
.sidebar-foot { padding: .6rem; border-top: 1px solid rgba(255,255,255,.08); }
.nav-item.as-button { background: none; border: 0; width: 100%; text-align: left; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: .75rem;
    padding: .9rem 1.5rem; background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 1020;
}
.topbar-title { font-size: 1.15rem; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: .5rem; }
.content { padding: 1.5rem; flex: 1; }
.app-footer { padding: 1rem 1.5rem; color: var(--muted); font-size: .8rem; }
@media (max-width: 575.98px) {
    .content { padding: 1rem .75rem; }
    .topbar { padding: .7rem .75rem; }
}

/* ---------- Panels ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    height: 100%;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; margin-bottom: .9rem; }
.panel-title { font-size: 1rem; font-weight: 600; margin: 0; }
.panel-link { font-size: .85rem; white-space: nowrap; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-flush .panel-head { padding: 1rem 1.25rem 0; }
.muted { color: var(--muted); }
.small-label { font-size: .8rem; color: var(--muted); }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; font-size: .9rem; }
.empty i { display: block; font-size: 1.6rem; margin-bottom: .35rem; opacity: .6; }

/* ---------- Ledger equation (dashboard-ын гол элемент) ---------- */
.ledger {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto 1fr auto 1.15fr;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.ledger-term { padding: 1.1rem 1.25rem; position: relative; }
.ledger-term::before { content: ""; position: absolute; left: 0; top: 1.1rem; bottom: 1.1rem; width: 3px; border-radius: 3px; }
.ledger-term.income::before { background: var(--income); }
.ledger-term.expense::before { background: var(--expense); }
.ledger-term.savings::before { background: var(--savings); }
.ledger.five { grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr auto 1.15fr; }
.ledger-term.opening::before { background: #8aa39b; }
.ledger.five .ledger-term { padding: 1rem .9rem; }
.ledger.five .ledger-value { font-size: 1.25rem; }
.ledger-term.balance { background: var(--pine); color: #fff; }
.ledger-term.balance .ledger-label { color: #a9c6bf; }
.ledger-label { font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.ledger-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.ledger-note { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.ledger-term.balance .ledger-note { color: #a9c6bf; }
.ledger-op { display: grid; place-items: center; color: #9fb1ad; font-size: 1.25rem; font-weight: 500; padding: 0 .1rem; }
@media (max-width: 1199.98px) {
    .ledger-value { font-size: 1.2rem; }
    .ledger.five .ledger-value { font-size: 1.05rem; }
}
@media (max-width: 991.98px) {
    .ledger { grid-template-columns: 1fr 1fr; }
    .ledger-op { display: none; }
    .ledger-term { border-bottom: 1px solid var(--line); }
    .ledger-term:nth-of-type(odd) { border-right: 1px solid var(--line); }
    .ledger-term.balance { border: 0; }
    .ledger.five .ledger-term { border-right: 0; }
    .ledger.five .ledger-term:nth-child(4n+1) { border-right: 1px solid var(--line); }
    .ledger.five .ledger-term.balance { grid-column: 1 / -1; border-right: 0; }
}

/* ---------- Stat (Savings, Finance) ---------- */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; height: 100%; }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.accent { background: var(--savings); border-color: var(--savings); color: #fff; }
.stat.accent .stat-label { color: #cfe0fb; }

.text-income { color: var(--income) !important; }
.text-expense { color: var(--expense) !important; }
.text-savings { color: var(--savings) !important; }
.text-warn { color: var(--warn) !important; }

/* ---------- Month selector ---------- */
.month-selector {
    display: inline-flex; align-items: center; gap: .25rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .2rem;
}
.ms-btn { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .75rem; border-radius: 999px; color: var(--ink); font-size: .85rem; }
.ms-btn:hover { background: var(--paper); }
.ms-label { font-weight: 600; padding: 0 .6rem; white-space: nowrap; }
.ms-today { font-size: .8rem; padding: .3rem .7rem; border-radius: 999px; background: var(--paper); margin-left: .2rem; }
.page-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }

/* ---------- Progress ---------- */
.progress { height: .55rem; background: #e8eeec; border-radius: 999px; }
.progress-bar { border-radius: 999px; }
.progress-thick { height: .8rem; }
.bar-income { background: var(--income); }
.bar-savings { background: var(--savings); }

/* ---------- Alerts / insights ---------- */
.alert { border-radius: var(--radius-sm); border-width: 1px; }
.flash { margin-bottom: 1rem; }
.signal { display: flex; gap: .65rem; align-items: flex-start; padding: .55rem 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.signal:last-child { border-bottom: 0; }
.signal i { font-size: 1rem; margin-top: .1rem; }
.signal.danger i { color: var(--expense); }
.signal.warning i { color: var(--warn); }
.signal.info i { color: var(--savings); }
.signal.success i { color: var(--income); }
.insight-list { list-style: none; padding: 0; margin: 0; }
.insight-list li { padding: .45rem 0 .45rem 1.1rem; position: relative; font-size: .9rem; }
.insight-list li::before { content: ""; position: absolute; left: 0; top: .95rem; width: 6px; height: 6px; border-radius: 50%; background: #1e6f5c; }

/* ---------- Tables / lists ---------- */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .65rem .75rem; border-bottom-color: var(--line); }
.table thead th { font-size: .8rem; font-weight: 600; color: var(--muted); background: #f7f9f8; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f6faf8; }
.cat-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; vertical-align: middle; }
.row-list { list-style: none; padding: 0; margin: 0; }
.row-list li { display: flex; align-items: center; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.row-list li:last-child { border-bottom: 0; }
.row-list .grow { flex: 1; min-width: 0; }
.row-list .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-weight: 500; }
.badge-overdue { background: var(--expense-soft); color: var(--expense); }

/* ---------- Tabs ---------- */
.subnav { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; }
.subnav a { padding: .55rem .9rem; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--ink); }
.subnav a.active { color: var(--ink); border-bottom-color: #1e6f5c; }

/* ---------- Forms ---------- */
.form-control, .form-select { border-radius: var(--radius-sm); border-color: #cfd9d6; }
.form-control:focus, .form-select:focus { border-color: #1e6f5c; box-shadow: 0 0 0 .2rem rgba(30, 111, 92, .15); }
.form-label { font-weight: 500; font-size: .88rem; margin-bottom: .3rem; }
.form-narrow { max-width: 720px; }
.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.type-switch input { position: absolute; opacity: 0; }
.type-switch label {
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem; text-align: center;
    cursor: pointer; font-weight: 600; background: var(--surface);
}
.type-switch input:focus-visible + label { outline: 2px solid var(--savings); outline-offset: 2px; }
.type-switch input[value="income"]:checked + label,
.type-switch input[value="deposit"]:checked + label { background: var(--income-soft); border-color: var(--income); color: var(--income); }
.type-switch input[value="expense"]:checked + label,
.type-switch input[value="withdrawal"]:checked + label { background: var(--expense-soft); border-color: var(--expense); color: var(--expense); }
.amount-input { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.filter-bar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.savings-hint { background: var(--savings-soft); border: 1px solid #c4d7f6; border-radius: var(--radius-sm); padding: .75rem .9rem; font-size: .88rem; }

/* ---------- Goals / wishlist ---------- */
.goal-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; height: 100%; display: flex; flex-direction: column; gap: .5rem; }
.goal-card .goal-amounts { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.wish-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; height: 100%; display: flex; flex-direction: column; }
.wish-img { aspect-ratio: 16 / 10; background: #e9efed center / cover no-repeat; display: grid; place-items: center; color: #9fb1ad; font-size: 2rem; }
.wish-img img { width: 100%; height: 100%; object-fit: cover; }
.wish-body { padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .45rem; flex: 1; }
.wish-price { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.cal-head { background: #f7f9f8; font-size: .8rem; font-weight: 600; color: var(--muted); padding: .5rem; text-align: center; border-bottom: 1px solid var(--line); }
.cal-day { min-height: 110px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: .35rem; font-size: .8rem; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day.other { background: #fafbfb; color: #b3c0bd; }
.cal-day.today { background: #f0f8f5; }
.cal-num { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: .25rem; }
.cal-num a { color: var(--muted); font-weight: 400; opacity: 0; }
.cal-day:hover .cal-num a, .cal-num a:focus { opacity: 1; }
.cal-task { display: block; padding: .15rem .35rem; border-radius: 4px; margin-bottom: 2px; background: var(--savings-soft); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-task.high { background: var(--expense-soft); }
.cal-task.done { text-decoration: line-through; opacity: .55; }
@media (max-width: 767.98px) {
    .cal-day { min-height: 70px; }
    .cal-task { font-size: .7rem; }
}

/* ---------- Chart ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 230px; }
.chart-panel {
    height: auto !important;
    min-height: 0 !important;
    align-self: start;
}
/* ---------- Auth ---------- */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; margin-bottom: 1.25rem; color: var(--pine); }
.auth-brand .brand-mark { background: var(--pine); }
.auth-card { width: 100%; max-width: 430px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; }
.auth-card.wide { max-width: 680px; }
.auth-card h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: .35rem; }
.auth-shell > .flash { width: 100%; max-width: 430px; }

/* ---------- Print ---------- */
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
