/* =========================================================
   MyFinance — Design tokens
   Palette chosen for a calm, trustworthy money app:
   deep ledger-green ink, warm parchment surface, a single
   emerald accent for primary action, rust reserved only
   for expense/negative figures (meaning, not decoration).
   ========================================================= */
:root {
    --ink: #16241f;
    --ink-soft: #3c4a44;
    --surface: #f6f5f0;
    --surface-raised: #ffffff;
    --border: #e2e0d4;
    --border-strong: #cfccbb;

    --accent: #1b6b54;
    --accent-dark: #124a3a;
    --accent-tint: #e4efe9;

    --gold: #b8862f;
    --gold-tint: #f6ecd8;

    --rust: #b0492f;
    --rust-tint: #f7e6e0;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --font-latin: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-heading: 'Manrope', var(--font-latin);
    --font-bn: 'Hind Siliguri', var(--font-latin);

    --sidebar-w: 236px;
    --topbar-h: 60px;
    --shadow-1: 0 1px 2px rgba(22, 36, 31, 0.06), 0 1px 1px rgba(22, 36, 31, 0.04);
    --shadow-2: 0 6px 20px rgba(22, 36, 31, 0.10);
}

html[lang="bn"], html[lang="bn"] body {
    font-family: var(--font-bn);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-latin);
    background: var(--surface);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--ink);
    line-height: 1.25;
    margin: 0 0 .4em;
}
html[lang="bn"] h1, html[lang="bn"] h2, html[lang="bn"] h3, html[lang="bn"] h4 {
    font-family: var(--font-bn);
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

p { margin: 0 0 1em; }

::selection { background: var(--accent-tint); color: var(--accent-dark); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--ink);
    color: #eef4f1;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 22px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .mark {
    width: 34px; height: 34px;
    background: var(--accent);
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-family: var(--font-heading);
    color: #fff;
    flex-shrink: 0;
}
.sidebar-brand .name {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.05rem;
    color: #fff;
}
.sidebar-brand .name small {
    display: block;
    font-family: var(--font-latin);
    font-weight: 400;
    font-size: .68rem;
    color: #9db3ab;
}

.sidebar-nav {
    flex: 1;
    padding: 14px 12px;
    overflow-y: auto;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: #cdd9d4;
    font-size: .92rem;
    font-weight: 500;
    text-decoration: none;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active { background: var(--accent); color: #fff; }
.sidebar-nav .icon { width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-foot {
    padding: 14px 16px 18px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: .82rem;
}
.sidebar-foot a { color: #cdd9d4; }

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

.topbar {
    height: var(--topbar-h);
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.menu-toggle {
    display: none;
    background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--ink);
}

.content {
    padding: 22px;
    flex: 1;
    max-width: 1180px;
    width: 100%;
}

.lang-switch {
    display: flex;
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    overflow: hidden;
    font-size: .78rem;
}
.lang-switch a {
    padding: 5px 12px;
    color: var(--ink-soft);
    text-decoration: none;
}
.lang-switch a.active { background: var(--ink); color: #fff; }

.avatar-btn {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent-tint); color: var(--accent-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem;
    text-decoration: none;
}

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--accent-dark), var(--ink) 70%);
    padding: 20px;
}
.auth-card {
    background: var(--surface-raised);
    border-radius: var(--radius-lg);
    padding: 36px 34px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-2);
}
.auth-card .mark {
    width: 44px; height: 44px; border-radius: 12px;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-family: var(--font-heading); font-size: 1.2rem;
    margin-bottom: 16px;
}
.auth-card p.sub { color: var(--ink-soft); margin-bottom: 22px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: .9rem; color: var(--ink-soft); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
label {
    display: block;
    font-size: .84rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--ink-soft);
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: .95rem;
    font-family: inherit;
    background: var(--surface-raised);
    color: var(--ink);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
}
.form-row { display: flex; gap: 14px; }
.form-row > * { flex: 1; }
.form-hint { font-size: .78rem; color: var(--ink-soft); margin-top: 4px; }

.radio-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-pills label {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--border-strong);
    padding: 8px 14px; border-radius: 20px;
    font-weight: 500; font-size: .85rem; cursor: pointer;
    margin: 0;
}
.radio-pills input { accent-color: var(--accent); }
.radio-pills input:checked + span {}
.radio-pills label:has(input:checked) {
    background: var(--accent-tint);
    border-color: var(--accent);
    color: var(--accent-dark);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: .9rem;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); text-decoration: none; }
.btn-block { width: 100%; }
.btn-outline { background: transparent; border-color: var(--border-strong); color: var(--ink); }
.btn-outline:hover { border-color: var(--ink); text-decoration: none; }
.btn-danger { background: var(--rust); color: #fff; }
.btn-danger:hover { background: #93381f; text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: none; }
.btn-ghost:hover { color: var(--ink); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Cards / stat grid ---------- */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.card {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
}
.card-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 16px 18px;
}
.stat.stat-expense { border-left-color: var(--rust); }
.stat.stat-gold { border-left-color: var(--gold); }
.stat .label { font-size: .78rem; color: var(--ink-soft); font-weight: 600; text-transform: none; margin-bottom: 6px; }
.stat .value { font-family: var(--font-heading); font-size: 1.5rem; font-weight: 800; }
.stat .sub { font-size: .78rem; color: var(--ink-soft); margin-top: 4px; }

.positive { color: var(--accent-dark); }
.negative { color: var(--rust); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--ink-soft); font-weight: 600; font-size: .78rem; }
tr:last-child td { border-bottom: none; }
td.wrap { white-space: normal; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .74rem;
    font-weight: 700;
}
.badge-income { background: var(--accent-tint); color: var(--accent-dark); }
.badge-expense { background: var(--rust-tint); color: var(--rust); }
.badge-transfer { background: var(--gold-tint); color: var(--gold); }
.badge-active { background: var(--gold-tint); color: var(--gold); }
.badge-partial { background: #fdf0e0; color: #a05a12; }
.badge-paid { background: var(--accent-tint); color: var(--accent-dark); }

.row-actions { display: flex; gap: 6px; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 46px 20px;
    color: var(--ink-soft);
}
.empty-state .glyph { font-size: 2.2rem; margin-bottom: 10px; }

/* ---------- Flash messages ---------- */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: .9rem; font-weight: 500; }
.flash-success { background: var(--accent-tint); color: var(--accent-dark); }
.flash-error { background: var(--rust-tint); color: var(--rust); }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(22, 36, 31, 0.5);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
    z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface-raised);
    border-radius: var(--radius-lg);
    padding: 26px;
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow-2);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { margin: 0; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface-raised);
    border-top: 1px solid var(--border);
    z-index: 40;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}
.bottom-nav ul { list-style: none; display: flex; margin: 0; padding: 0; }
.bottom-nav li { flex: 1; text-align: center; }
.bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--ink-soft); text-decoration: none; font-size: .68rem; padding: 6px 2px;
}
.bottom-nav a .icon { font-size: 1.15rem; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav a.fab { color: var(--accent); }
.bottom-nav a.fab .icon {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    margin-top: -18px;
    box-shadow: var(--shadow-2);
    font-size: 1.3rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 35;
}

/* ---------- Install banner ---------- */
.install-banner {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--ink);
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 18px;
}
.install-banner.show { display: flex; }
.install-banner p { margin: 0; font-size: .85rem; }
.install-banner strong { display: block; font-size: .92rem; }

/* ---------- Loan card ---------- */
.loan-card { border-left: 4px solid var(--gold); }
.loan-card.type-borrowed { border-left-color: var(--rust); }
.progress-track {
    background: var(--border);
    border-radius: 20px;
    height: 8px;
    overflow: hidden;
    margin: 8px 0;
}
.progress-fill { background: var(--accent); height: 100%; }

/* ---------- Notes ---------- */
.note-card { background: var(--gold-tint); border: 1px solid #ecdcb8; border-radius: var(--radius-md); padding: 16px; }
.note-card.pinned { border-color: var(--gold); }
.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.text-sm { font-size: .85rem; }
.text-muted { color: var(--ink-soft); }
.w-full { width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: block; }
    .sidebar-backdrop.open { display: block; }
    .bottom-nav { display: block; }
    .content { padding: 16px 14px 90px; }
    .form-row { flex-direction: column; gap: 0; }
}

@media (max-width: 560px) {
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .auth-card { padding: 28px 22px; }
    .topbar { padding: 0 14px; }
    th, td { padding: 9px 8px; font-size: .84rem; }
}

@media print {
    .sidebar, .topbar, .bottom-nav, .install-banner, .row-actions { display: none !important; }
    .main { margin-left: 0 !important; }
}
