/* =========================================================
   MOI — stylesheet
   Mobile first. Bottom tab bar on phones, sidebar on desktop.
   ========================================================= */

:root {
    --brand:        #A61C3C;
    --brand-dark:   #7E1430;
    --brand-soft:   #FBE9ED;
    --gold:         #C08A2E;
    --gold-soft:    #FBF2DF;

    --bg:           #FAF6F2;
    --surface:      #FFFFFF;
    --surface-2:    #F4EEE8;
    --border:       #E6DCD3;
    --text:         #2C1F1C;
    --muted:        #7B6A64;

    --in:           #16785A;   /* moi received */
    --in-soft:      #E4F4EE;
    --out:          #B4530F;   /* moi given */
    --out-soft:     #FCEEE2;
    --danger:       #C0392B;

    --radius:       14px;
    --radius-sm:    9px;
    --shadow:       0 1px 2px rgba(44,31,28,.06), 0 6px 18px rgba(44,31,28,.06);
    --shadow-lg:    0 10px 40px rgba(44,31,28,.18);
    --font:         "Segoe UI", system-ui, -apple-system, "Noto Sans Tamil", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --brand:      #F2879F;
        --brand-dark: #E3627F;
        --brand-soft: #3A1A24;
        --gold:       #E0B45C;
        --gold-soft:  #3A2F1A;

        --bg:         #17110F;
        --surface:    #221A18;
        --surface-2:  #2C2220;
        --border:     #3A2D2A;
        --text:       #F3E9E5;
        --muted:      #A9948D;

        --in:         #5CCCA5;
        --in-soft:    #11322A;
        --out:        #F0A265;
        --out-soft:   #38241A;
        --danger:     #F08A7E;

        --shadow:     0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
        --shadow-lg:  0 10px 40px rgba(0,0,0,.6);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; }
p  { margin: 0 0 .6rem; }

/* ---------- boot / spinner ---------- */
.boot {
    min-height: 100vh; display: grid; place-content: center; gap: 1.2rem; justify-items: center;
}
.boot__mark {
    font-size: 2.4rem; font-weight: 800; letter-spacing: .3em; color: var(--brand); padding-left: .3em;
}
.spinner {
    width: 26px; height: 26px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--brand);
    animation: spin .8s linear infinite;
}
.spinner--sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   AUTH
   ========================================================= */
.auth {
    min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
    background: radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), var(--bg) 60%);
}
.auth__card {
    width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 1.8rem 1.5rem; box-shadow: var(--shadow-lg);
}
.auth__logo {
    text-align: center; margin-bottom: 1.4rem;
}
.auth__logo b {
    display: inline-block; font-size: 1.9rem; letter-spacing: .28em; padding-left: .28em;
    color: var(--brand); font-weight: 800;
}
.auth__logo span { display: block; color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.auth__switch { text-align: center; margin-top: 1.1rem; color: var(--muted); font-size: .9rem; }

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

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem 1rem; padding-top: max(.7rem, env(safe-area-inset-top));
    background: var(--brand); color: #fff;
    box-shadow: 0 1px 12px rgba(0,0,0,.12);
}
.topbar__title { font-size: 1.05rem; font-weight: 650; flex: 1; min-width: 0; }
.topbar__title small { display: block; font-weight: 400; font-size: .76rem; opacity: .8; }
.topbar__back,
.topbar__user {
    background: rgba(255,255,255,.16); color: #fff; border: 0; cursor: pointer;
    border-radius: 999px; font: inherit; font-size: .85rem; padding: .35rem .8rem;
}
.topbar__back { padding: .35rem .7rem; font-size: 1rem; line-height: 1; }
.topbar__user:hover, .topbar__back:hover { background: rgba(255,255,255,.28); }

.main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 1rem 1rem 6rem; }

/* bottom tabs (mobile) */
.tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
    display: grid; justify-items: center; gap: .15rem; padding: .5rem .2rem .55rem;
    color: var(--muted); font-size: .68rem; text-align: center;
}
.tabs a.is-active { color: var(--brand); font-weight: 600; }
.tabs svg { width: 21px; height: 21px; }

@media (min-width: 900px) {
    .shell { flex-direction: row; }
    .tabs {
        position: sticky; top: 0; bottom: auto; left: auto; right: auto;
        width: 228px; height: 100vh; flex: 0 0 228px;
        grid-template-columns: 1fr; grid-auto-rows: max-content; gap: .15rem;
        align-content: start; padding: 1.4rem .7rem;
        border-top: 0; border-right: 1px solid var(--border);
    }
    .tabs a {
        grid-template-columns: 24px 1fr; justify-items: start; align-items: center;
        gap: .7rem; padding: .65rem .8rem; border-radius: var(--radius-sm); font-size: .92rem;
    }
    .tabs a.is-active { background: var(--brand-soft); }
    .tabs__brand {
        font-weight: 800; letter-spacing: .25em; color: var(--brand);
        padding: 0 .9rem 1.1rem; font-size: 1.15rem;
    }
    .shell > div:last-child { flex: 1; min-width: 0; display: flex; flex-direction: column; }
    .main { padding-bottom: 2.5rem; }
}
.tabs__brand { display: none; }
@media (min-width: 900px) { .tabs__brand { display: block; } }

/* =========================================================
   BUILDING BLOCKS
   ========================================================= */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem;
}
.card + .card { margin-top: .85rem; }
.card__head {
    display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem;
}
.card__head h3 { font-size: 1rem; flex: 1; }

.section-title {
    display: flex; align-items: center; gap: .6rem; margin: 1.4rem 0 .7rem;
    font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.section-title:first-child { margin-top: 0; }
.section-title > :last-child { margin-left: auto; text-transform: none; letter-spacing: 0; }

.grid { display: grid; gap: .85rem; }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.row--tight { gap: .35rem; }
.spacer { flex: 1; }

/* stat tiles */
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .85rem .9rem; box-shadow: var(--shadow);
}
.stat__label { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat__value { font-size: 1.35rem; font-weight: 700; margin-top: .2rem; letter-spacing: -.01em; }
.stat__hint  { font-size: .76rem; color: var(--muted); margin-top: .1rem; }
.stat--in  .stat__value { color: var(--in); }
.stat--out .stat__value { color: var(--out); }

/* buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer;
    padding: .6rem 1rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    transition: filter .15s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--ghost   { background: transparent; border-color: transparent; color: var(--brand); padding-inline: .5rem; }
.btn--danger  { background: transparent; border-color: var(--border); color: var(--danger); }
.btn--block   { width: 100%; }
.btn--sm      { padding: .35rem .65rem; font-size: .82rem; }

.fab {
    position: fixed; right: 1rem; bottom: calc(4.6rem + env(safe-area-inset-bottom)); z-index: 25;
    width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--brand); color: #fff; font-size: 1.7rem; line-height: 1;
    box-shadow: 0 6px 20px rgba(166,28,60,.42);
}
@media (min-width: 900px) { .fab { bottom: 1.5rem; right: 1.5rem; } }

/* chips & badges */
.chip {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .15rem .55rem; border-radius: 999px; font-size: .73rem; font-weight: 600;
    background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip--in    { background: var(--in-soft);    color: var(--in); }
.chip--out   { background: var(--out-soft);   color: var(--out); }
.chip--gold  { background: var(--gold-soft);  color: var(--gold); }
.chip--brand { background: var(--brand-soft); color: var(--brand); }

/* forms */
.field { margin-bottom: .85rem; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .3rem; color: var(--muted); }
.field input, .field select, .field textarea {
    width: 100%; font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .62rem .7rem;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.field textarea { min-height: 70px; resize: vertical; }
.field .err { display: block; color: var(--danger); font-size: .78rem; margin-top: .25rem; }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.field__hint { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.form-grid { display: grid; gap: 0 .8rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .span-2 { grid-column: 1 / -1; }

.search {
    display: flex; align-items: center; gap: .5rem; background: var(--surface);
    border: 1px solid var(--border); border-radius: 999px; padding: .1rem .5rem .1rem .85rem;
    box-shadow: var(--shadow);
}
.search input { flex: 1; border: 0; background: transparent; font: inherit; color: var(--text); padding: .55rem 0; }
.search input:focus { outline: none; }

/* lists */
.list { display: grid; gap: .5rem; }
.item {
    display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .75rem .85rem; box-shadow: var(--shadow); cursor: pointer; font: inherit; color: inherit;
}
.item:hover { border-color: var(--brand); }
.item--plain { cursor: default; }
.item--plain:hover { border-color: var(--border); }
.item__avatar {
    flex: 0 0 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
    background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .95rem;
}
.item__body { flex: 1; min-width: 0; }
.item__title { font-weight: 600; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.item__sub   { font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.item__end   { text-align: right; flex: 0 0 auto; }
.item__amt   { font-weight: 700; font-size: 1rem; }
.amt--in  { color: var(--in); }
.amt--out { color: var(--out); }

.empty {
    text-align: center; padding: 2.4rem 1rem; color: var(--muted);
    border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.empty__icon { font-size: 2rem; }
.empty h4 { margin: .5rem 0 .25rem; color: var(--text); }

/* table (desktop reports) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 540px; }
table.data th, table.data td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.is-clickable { cursor: pointer; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }

/* balance banner on the person ledger */
.balance {
    border-radius: var(--radius); padding: .9rem 1rem; display: flex; align-items: center; gap: .8rem;
    border: 1px solid var(--border); background: var(--surface-2);
}
.balance strong { font-size: 1.15rem; }
.balance--in  { background: var(--in-soft);  border-color: transparent; color: var(--in); }
.balance--out { background: var(--out-soft); border-color: transparent; color: var(--out); }
.balance--even { background: var(--surface-2); color: var(--muted); }

/* two-column ledger on wide screens */
.ledger-cols { display: grid; gap: .85rem; }
@media (min-width: 860px) { .ledger-cols { grid-template-columns: 1fr 1fr; align-items: start; } }

/* =========================================================
   MODAL + TOAST
   ========================================================= */
.modal {
    position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center;
    background: rgba(28,18,16,.45); backdrop-filter: blur(2px); padding: 0;
    animation: fade .16s ease;
}
@media (min-width: 640px) { .modal { align-items: center; padding: 1.5rem; } }
.modal__box {
    background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); animation: rise .2s ease;
}
@media (min-width: 640px) { .modal__box { border-radius: 18px; } }
.modal__head {
    position: sticky; top: 0; background: var(--surface); z-index: 1;
    display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem .7rem;
    border-bottom: 1px solid var(--border);
}
.modal__head h3 { flex: 1; font-size: 1.05rem; }
.modal__body { padding: 1rem 1.1rem; }
.modal__foot {
    display: flex; gap: .6rem; padding: .3rem 1.1rem 1.2rem;
    padding-bottom: max(1.2rem, env(safe-area-inset-bottom));
}
.modal__foot .btn { flex: 1; }
.icon-btn {
    border: 0; background: var(--surface-2); color: var(--muted); cursor: pointer;
    width: 30px; height: 30px; border-radius: 50%; font-size: 1.1rem; line-height: 1; font-family: inherit;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

.toast-host {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(5.4rem + env(safe-area-inset-bottom));
    z-index: 80; display: grid; gap: .4rem; width: max-content; max-width: 92vw;
}
@media (min-width: 900px) { .toast-host { bottom: 1.5rem; } }
.toast {
    background: #2C1F1C; color: #fff; padding: .6rem 1rem; border-radius: 999px;
    font-size: .88rem; box-shadow: var(--shadow-lg); animation: rise .18s ease;
}
.toast--error { background: var(--danger); }
.toast--ok    { background: var(--in); }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; }
.hidden { display: none !important; }

@media print {
    .topbar, .tabs, .fab, .btn, .search { display: none !important; }
    .main { padding: 0; max-width: none; }
    .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
