/* Rahim Family Hub
   Indigo + violet-blue, with sky blue for contributions, on soft lavender paper.
   One family: Plus Jakarta Sans. (Token names kept from the first palette.) */

:root {
    --paper: #F4F3FA;
    --surface: #FFFFFF;
    --sunk: #EBE9F6;
    --ink: #1E1B3A;
    --ink-2: #4D4A6B;
    --muted: #7E7B98;
    --line: #E0DEEE;
    --palm: #5B4BDB;        /* primary: violet-blue */
    --palm-deep: #2B2570;   /* sidebar and Tabung panel: deep indigo */
    --palm-soft: #E8E5FC;
    --gold: #3B8BEB;        /* contributions: sky blue */
    --gold-ink: #1D5FB5;
    --gold-soft: #E2EEFD;
    --on-gold: #FFFFFF;
    --clay: #D23F5B;
    --clay-soft: #FBE3E8;
    --monsoon: #0E9C82;     /* events: teal, distinct from both blues */
    --monsoon-soft: #DCF3EE;
    --on-palm: #F4F3FA;

    --r-lg: 22px;
    --r-md: 14px;
    --r-sm: 10px;
    --shadow: 0 1px 0 rgba(40, 30, 110, .04), 0 10px 30px -18px rgba(40, 30, 110, .35);
    --side: 236px;
    --font: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #13121F; --surface: #1B1A2B; --sunk: #232136; --ink: #ECEAF7; --ink-2: #C0BDD8; --muted: #8E8BAA; --line: #2F2C47;
        --palm: #9A8CFF; --palm-deep: #221E52; --palm-soft: #2A2652;
        --gold: #6AA8F5; --gold-ink: #9CC6FA; --gold-soft: #1C2B45; --on-gold: #0E1426;
        --clay: #FF8DA1; --clay-soft: #42202B; --monsoon: #5DD3B9; --monsoon-soft: #163530;
        --on-palm: #13121F;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.55 var(--font); font-feature-settings: "tnum" 0; }
a { color: var(--palm); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2.5px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { margin: 0 0 .35em; line-height: 1.15; letter-spacing: -.02em; font-weight: 800; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.1rem); }
h2 { font-size: 1.12rem; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 1rem; font-weight: 700; }
img { max-width: 100%; display: block; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num, .amt, .money { font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: .85rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- Shell ---------- */
.sidebar { display: none; }
.mobile-top { display: none; }
.main { min-height: 100vh; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 2rem 2rem 4rem; }

.brand { display: flex; align-items: center; gap: .65rem; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 40px; height: 40px; display: block; flex: none; }
.brand-mark .logo { width: 100%; height: 100%; display: block; }
.sidebar .brand-mark .logo { border-radius: 9px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .22); }
.brand-text strong { display: block; font-size: 1.02rem; font-weight: 800; letter-spacing: -.015em; line-height: 1.15; }
.brand-text small { font-size: .74rem; opacity: .75; }

.is-auth .sidebar {
    display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: var(--side);
    background: var(--palm-deep); color: var(--on-palm); padding: 1.4rem 1rem; z-index: 20;
}
@media (prefers-color-scheme: dark) { .is-auth .sidebar { background: #0F0E1C; border-right: 1px solid var(--line); color: var(--ink); } }
.is-auth .main { margin-left: var(--side); }
.side-nav { display: grid; gap: 2px; margin-top: 2rem; }
.side-nav a, .side-link {
    display: flex; align-items: center; gap: .8rem; padding: .62rem .8rem; border-radius: 12px;
    color: inherit; opacity: .78; font-weight: 600; font: 600 .95rem var(--font); background: none; border: 0; width: 100%; cursor: pointer; text-align: left;
}
.side-nav a:hover, .side-link:hover { opacity: 1; background: rgba(255, 255, 255, .07); text-decoration: none; }
.side-nav a.active { opacity: 1; background: rgba(255, 255, 255, .12); box-shadow: inset 3px 0 0 var(--gold); }
.side-foot { margin-top: auto; display: grid; gap: 2px; padding-top: 1rem; border-top: 1px solid rgba(255, 255, 255, .12); }
.side-foot form { margin: 0; }
.me { display: flex; align-items: center; gap: .7rem; padding: .55rem .8rem; color: inherit; font-weight: 700; }
.me:hover { text-decoration: none; }

.avatar {
    --av: var(--palm);
    width: 34px; height: 34px; border-radius: 50%; background: var(--av); color: #fff;
    display: inline-grid; place-items: center; font-weight: 800; font-size: .78rem; letter-spacing: .02em; flex: none;
    box-shadow: 0 0 0 2px var(--surface);
}
a.avatar:hover { text-decoration: none; }
.avatar-lg { width: 46px; height: 46px; font-size: .95rem; }

.fab, .tabbar { display: none; }
.is-auth .fab {
    display: grid; place-items: center; position: fixed; right: 1.6rem; bottom: 1.6rem; width: 58px; height: 58px; border-radius: 20px;
    background: var(--gold); color: var(--on-gold); border: 0; cursor: pointer; box-shadow: 0 12px 28px -10px rgba(30, 80, 170, .55); z-index: 30;
    transition: transform .15s ease;
}
.fab:hover { transform: translateY(-2px); }
.fab .ico { width: 28px; height: 28px; stroke-width: 2.4; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head p { margin: 0; color: var(--ink-2); }
.page-head h1 { margin-bottom: .15rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.section-head h2 { margin: 0; }
.section-head a { font-weight: 600; font-size: .9rem; }
.section-head .actions { flex-wrap: nowrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.35rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.grid > .card + .card, .grid > * + .card { margin-top: 0; }
.card.flat { box-shadow: none; background: transparent; border-style: dashed; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack-gap > * + * { margin-top: 1rem; }

.stat { padding: 1.1rem 1.25rem; }
.stat .label { color: var(--ink-2); font-size: .85rem; font-weight: 600; }
.stat .value { font-size: 1.65rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-link { color: var(--ink); display: block; }
.stat-link:hover { text-decoration: none; border-color: var(--palm); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .62rem 1.05rem; border-radius: 12px;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 .93rem var(--font); cursor: pointer; white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; border-color: var(--palm); }
.btn .ico { width: 18px; height: 18px; }
.btn-primary { background: var(--palm); border-color: var(--palm); color: var(--on-palm); }
.btn-primary:hover { background: var(--palm-deep); border-color: var(--palm-deep); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }
.btn-gold:hover { border-color: var(--gold-ink); }
.btn-small { padding: .36rem .7rem; font-size: .84rem; border-radius: 10px; }
.btn-danger { color: var(--clay); }
.btn-danger:hover { border-color: var(--clay); }
.btn-green { color: var(--palm); background: var(--palm-soft); border-color: transparent; }
.btn-green:hover { border-color: var(--palm); }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--palm); cursor: pointer; }

/* ---------- Tabs, chips, badges ---------- */
.tabs { display: flex; gap: .3rem; padding: .3rem; background: var(--sunk); border-radius: 14px; width: fit-content; max-width: 100%; overflow-x: auto; margin-bottom: 1.1rem; }
.tabs a { padding: .48rem .95rem; border-radius: 10px; color: var(--ink-2); font-weight: 600; font-size: .92rem; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { padding: .36rem .85rem; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); font-size: .87rem; font-weight: 600; background: var(--surface); }
.chip:hover { text-decoration: none; border-color: var(--palm); color: var(--ink); }
.chip.active { background: var(--palm); border-color: var(--palm); color: var(--on-palm); }

.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .14rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700; background: var(--sunk); color: var(--ink-2); white-space: nowrap; }
.badge-red { background: var(--clay-soft); color: var(--clay); }
.badge-amber { background: var(--gold-soft); color: var(--gold-ink); }
.badge-green { background: var(--palm-soft); color: var(--palm); }
.badge-blue { background: var(--monsoon-soft); color: var(--monsoon); }
a.badge:hover { text-decoration: none; }

/* ---------- Lists & tables ---------- */
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .45rem .6rem; border-bottom: 1px solid var(--line); }
.list td { padding: .8rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr:hover td { background: color-mix(in srgb, var(--sunk) 55%, transparent); }
.list .num { text-align: right; white-space: nowrap; }
.list .row-actions { text-align: right; white-space: nowrap; }
.list .row-actions form { display: inline; }

.mini-list { list-style: none; padding: 0; margin: 0; }
.mini-list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list li.archived { opacity: .55; }
.empty { color: var(--muted); padding: 1.1rem 0; text-align: center; }

/* ---------- Forms ---------- */
form.stack { display: grid; gap: 1.05rem; max-width: 660px; }
form.stack > *, .row > * { min-width: 0; }
.field label { display: block; font-weight: 600; margin-bottom: .32rem; font-size: .9rem; }
.field .hint { color: var(--muted); font-size: .82rem; margin-top: .3rem; }
.field .error { color: var(--clay); font-size: .85rem; margin-top: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=month], input[type=search], select, textarea {
    width: 100%; padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font: 500 .95rem var(--font);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--palm); box-shadow: 0 0 0 3px color-mix(in srgb, var(--palm) 22%, transparent); background: var(--surface); }
input[type=file] { font: inherit; color: var(--ink-2); }
textarea { min-height: 96px; resize: vertical; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.checkbox { display: flex; align-items: center; gap: .55rem; font-size: .92rem; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--palm); }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .5rem; }

.segmented { display: inline-flex; padding: .3rem; background: var(--sunk); border-radius: 14px; width: fit-content; max-width: 100%; gap: .2rem; }
.segmented label { margin: 0; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; align-items: center; gap: .4rem; padding: .5rem 1rem; font-weight: 700; color: var(--ink-2); border-radius: 10px; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.segmented input[value=income]:checked + span { background: var(--gold); color: var(--on-gold); }
.segmented input[value=expense]:checked + span { background: var(--palm); color: var(--on-palm); }
.segmented input:focus-visible + span { outline: 2.5px solid var(--gold); }

/* ---------- Feedback ---------- */
.toast {
    position: fixed; left: 50%; top: 1.2rem; transform: translateX(-50%); z-index: 60;
    display: flex; align-items: center; gap: .55rem; padding: .75rem 1.1rem; border-radius: 14px;
    background: var(--ink); color: var(--paper); font-weight: 600; box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .4);
    max-width: calc(100vw - 2rem); animation: toast-in .35s cubic-bezier(.2, .8, .2, 1);
}
.toast .ico { color: var(--gold); width: 20px; height: 20px; stroke-width: 2.4; }
.toast.hide { opacity: 0; transform: translate(-50%, -10px); transition: .4s; pointer-events: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -12px); } }
.alert { background: var(--clay-soft); color: var(--clay); border-radius: var(--r-md); padding: .85rem 1.05rem; margin-bottom: 1.2rem; font-weight: 600; }
.flash { background: var(--palm-soft); color: var(--palm); border-radius: var(--r-md); padding: .8rem 1rem; margin-bottom: 1.2rem; font-weight: 600; }

/* ---------- Sheets (quick add, more) ---------- */
dialog.sheet {
    border: 0; padding: 1.3rem; border-radius: 24px; background: var(--surface); color: var(--ink);
    width: min(560px, calc(100vw - 2rem)); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45);
}
dialog.sheet::backdrop { background: rgba(20, 16, 50, .5); backdrop-filter: blur(2px); }
dialog.sheet[open] { animation: sheet-in .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.sheet-head h2 { margin: 0; }
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.quick { display: grid; gap: .15rem; padding: .95rem; border-radius: 16px; background: var(--paper); border: 1px solid var(--line); color: var(--ink); }
.quick:hover { text-decoration: none; border-color: var(--palm); }
.quick .ico { color: var(--palm); margin-bottom: .3rem; }
.quick span { color: var(--muted); font-size: .82rem; }
.quick.q-gold { background: var(--gold-soft); border-color: transparent; }
.quick.q-gold .ico { color: var(--gold-ink); }
.quick.q-green { background: var(--palm-soft); border-color: transparent; }
.quick.q-blue { background: var(--monsoon-soft); border-color: transparent; }
.quick.q-blue .ico { color: var(--monsoon); }
.more-list { display: grid; }
.more-list a, .more-list button { display: flex; align-items: center; gap: .85rem; padding: .85rem .4rem; color: var(--ink); font: 600 1rem var(--font); border: 0; border-bottom: 1px solid var(--line); background: none; width: 100%; cursor: pointer; }
.more-list a:hover { text-decoration: none; color: var(--palm); }
.more-list form { margin: 0; }
.more-list .ico { color: var(--palm); }

/* ---------- Dashboard: greeting + week planner ---------- */
.hello { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.hello h1 { margin: 0; }
.hello p { margin: .2rem 0 0; color: var(--ink-2); font-weight: 500; }

.week { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.week-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .4rem; }
.day-btn {
    display: grid; justify-items: center; gap: .15rem; padding: .6rem .2rem .55rem; border-radius: 16px; border: 1px solid transparent;
    background: var(--paper); color: var(--ink); cursor: pointer; font: inherit;
}
.day-btn:hover { border-color: var(--line); }
.day-btn .dow { font-size: .75rem; color: var(--muted); font-weight: 600; }
.day-btn .dnum { font-size: 1.25rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.day-btn .dots { display: flex; gap: 3px; height: 6px; }
.day-btn .dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.dot-event { background: var(--monsoon); }
.dot-bill { background: var(--gold); }
.dot-renewal { background: var(--clay); }
.day-btn.today .dnum { color: var(--palm); }
.day-btn[aria-pressed="true"] { background: var(--palm); color: var(--on-palm); }
.day-btn[aria-pressed="true"] .dow { color: inherit; opacity: .8; }
.day-btn[aria-pressed="true"] .dnum { color: inherit; }
.day-panel { margin-top: .9rem; padding: .2rem .3rem 0; }
.day-panel h3 { margin-bottom: .4rem; }
.agenda { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.agenda li { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 12px; background: var(--paper); }
.agenda li a { color: var(--ink); font-weight: 600; flex: 1; min-width: 0; }
.agenda .kind { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.agenda .when { color: var(--muted); font-size: .82rem; font-weight: 600; white-space: nowrap; }

.attention li { align-items: center; }
.due-chip { min-width: 52px; text-align: center; padding: .3rem .4rem; border-radius: 12px; background: var(--sunk); line-height: 1.1; flex: none; }
.due-chip b { display: block; font-size: 1.05rem; font-weight: 800; }
.due-chip small { font-size: .7rem; font-weight: 700; color: var(--muted); }
.due-chip.late { background: var(--clay-soft); color: var(--clay); }
.due-chip.late small { color: var(--clay); }
.due-chip.soon { background: var(--gold-soft); color: var(--gold-ink); }
.due-chip.soon small { color: var(--gold-ink); }
.attention .what { flex: 1; min-width: 0; }
.attention .what strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tabung ---------- */
.tabung-hero {
    display: grid; grid-template-columns: 170px 1fr; gap: 1.6rem; align-items: center;
    background: var(--palm-deep); color: var(--on-palm); border-radius: 28px; padding: 1.6rem 1.8rem; margin-bottom: 1rem; position: relative; overflow: hidden;
}
@media (prefers-color-scheme: dark) { .tabung-hero { background: var(--palm-deep); color: var(--ink); } }
.tabung-hero .label { font-weight: 600; opacity: .8; }
.tabung-hero .balance { font-size: clamp(2.2rem, 1.6rem + 2.4vw, 3.3rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.tabung-hero .balance small { font-size: .45em; font-weight: 700; opacity: .7; margin-right: .2em; }
.tabung-hero .runway { margin-top: .35rem; font-weight: 600; opacity: .9; }
.tabung-hero .month-pair { display: flex; gap: 1.6rem; margin-top: 1.1rem; flex-wrap: wrap; }
.tabung-hero .month-pair div { display: grid; }
.tabung-hero .month-pair span { font-size: .82rem; opacity: .75; font-weight: 600; }
.tabung-hero .month-pair strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tabung-hero .in { color: #9CC8FF; }
.tabung-hero .hero-actions { margin-top: 1.2rem; }
.tabung-hero .btn { border-color: rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .08); color: inherit; }
.tabung-hero .btn:hover { border-color: rgba(255, 255, 255, .6); }
.tabung-hero .btn-gold { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }

.jar { width: 100%; max-width: 170px; }
.jar .glass { fill: rgba(255, 255, 255, .08); stroke: rgba(255, 255, 255, .55); stroke-width: 3; }
.jar .lid { fill: var(--gold); }
.jar .fill { fill: var(--gold); }
.jar .wave { fill: #7FB6F7; }
.jar .shine { fill: none; stroke: rgba(255, 255, 255, .35); stroke-width: 4; stroke-linecap: round; }
.jar .coin { fill: #D6E8FD; stroke: #1D5FB5; stroke-width: 1.5; }
@media (prefers-reduced-motion: no-preference) {
    .jar .wave { animation: wave 4s ease-in-out infinite; }
    .jar .fill-group { animation: rise 1.1s cubic-bezier(.2, .8, .2, 1) both; }
}
@keyframes wave { 50% { transform: translateX(-14px); } }
@keyframes rise { from { transform: translateY(100%); } }

.contributors { display: grid; gap: .55rem; }
.contributor { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem; }
.contributor .name { font-weight: 700; }
.contributor .bar { margin-top: .3rem; }
.contributor .amount { font-weight: 800; font-variant-numeric: tabular-nums; }

.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font: 600 11px var(--font); }
.chart .in { fill: var(--gold); }
.chart .out { fill: var(--palm); }
.chart rect { transition: opacity .15s; }
.chart g.month:hover rect { opacity: .8; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--ink-2); font-weight: 600; margin-top: .6rem; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .4rem; vertical-align: -1px; }
.legend .l-in::before { background: var(--gold); }
.legend .l-out::before { background: var(--palm); }
.legend .l-event::before { background: var(--monsoon); }
.legend .l-bill::before { background: var(--gold); }
.legend .l-paid::before { background: var(--palm); }
.legend .l-renewal::before { background: var(--clay); }

.amt { font-weight: 700; white-space: nowrap; }
.amt-in { color: var(--gold-ink); }
.amt-out { color: var(--ink); }
.amt-neg { color: var(--clay); }
.bar { height: 8px; background: var(--sunk); border-radius: 999px; overflow: hidden; margin-top: .4rem; }
.bar span { display: block; height: 100%; background: var(--palm); border-radius: 999px; }
.bar span.gold { background: var(--gold); }
.bar span.warn { background: var(--gold); }
.bar span.over { background: var(--clay); }
.bar span.none { background: var(--muted); opacity: .3; }
.budget-total { margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.budget-total .bar { height: 12px; }
.budget-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; }
.budget-line { display: flex; justify-content: space-between; gap: .75rem; font-weight: 600; }
.budget-line a { color: var(--ink); }
.budget-input { max-width: 150px; text-align: right; margin-left: auto; display: block; }
.tx-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--palm-soft); color: var(--palm); }
.tx-icon.in { background: var(--gold-soft); color: var(--gold-ink); }
.tx-icon .ico { width: 19px; height: 19px; }
.tx-row { display: flex; align-items: center; gap: .75rem; }
.tx-row .what { flex: 1; min-width: 0; }
.tx-row .what strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters select, .filters input { width: auto; padding: .48rem .7rem; font-size: .9rem; }
.filters input[type=search] { min-width: 180px; flex: 1; }
.pay-form { display: inline-flex !important; gap: .35rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.mini-select, .mini-input { width: auto !important; padding: .32rem .5rem !important; font-size: .8rem !important; border-radius: 9px !important; }
.mini-input { max-width: 100px; }

/* ---------- Photos ---------- */
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.album-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; color: var(--ink); box-shadow: var(--shadow); }
.album-card:hover { text-decoration: none; border-color: var(--palm); }
.album-cover { aspect-ratio: 4/3; background: var(--palm-soft); display: grid; place-items: center; color: var(--palm); overflow: hidden; }
.album-cover .ico { width: 40px; height: 40px; opacity: .6; }
.album-cover img { width: 100%; height: 100%; object-fit: cover; }
.album-card .meta { padding: .8rem 1rem; }
.album-card .meta strong { display: block; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem; }
.photo { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: var(--sunk); }
.photo img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.photo .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: .45rem .6rem; font-size: .76rem; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); }
.lightbox { position: fixed; inset: 0; background: rgba(14, 12, 30, .94); display: none; align-items: center; justify-content: center; z-index: 70; padding: 1rem; flex-direction: column; gap: .8rem; }
.lightbox.open { display: flex; }
.lightbox img { max-height: 78vh; max-width: 95vw; border-radius: 10px; }
.lightbox .lb-bar { display: flex; gap: .5rem; align-items: center; color: #eee; flex-wrap: wrap; justify-content: center; }
.lightbox .lb-bar input { width: 260px; background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .2); }
.lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, .12); color: #fff; border: 0; font-size: 1.6rem; width: 48px; height: 48px; border-radius: 50%; cursor: pointer; }
.lightbox .lb-prev { left: 1rem; }
.lightbox .lb-next { right: 1rem; }
.lightbox .lb-close { position: absolute; top: 1rem; right: 1rem; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.cal .dow { padding: .55rem; font-size: .8rem; font-weight: 700; color: var(--muted); background: var(--paper); border-bottom: 1px solid var(--line); text-align: center; }
.cal .day { min-height: 112px; padding: .4rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); position: relative; }
.cal .day:nth-child(7n) { border-right: 0; }
.cal .day.out { background: var(--paper); }
.cal .day.out .dnum { opacity: .45; }
.cal .dnum { font-size: .85rem; font-weight: 700; color: var(--ink-2); display: flex; justify-content: space-between; align-items: center; }
.cal .dnum a { color: var(--muted); opacity: 0; font-size: 1.05rem; padding: 0 .25rem; }
.cal .day:hover .dnum a, .cal .dnum a:focus { opacity: 1; }
.cal .today .dnum span { background: var(--palm); color: var(--on-palm); border-radius: 999px; padding: .05rem .5rem; }
.cal .item { display: block; font-size: .74rem; font-weight: 600; padding: .14rem .45rem; border-radius: 7px; margin-top: .22rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.cal .item:hover { text-decoration: none; filter: brightness(.96); }
.item.event { background: var(--monsoon-soft); color: var(--monsoon); }
.item.bill { background: var(--gold-soft); color: var(--gold-ink); }
.item.bill-paid { background: var(--palm-soft); color: var(--palm); text-decoration: line-through; }
.item.renewal { background: var(--clay-soft); color: var(--clay); }

/* ---------- Misc ---------- */
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; font-size: .9rem; font-weight: 600; }
.login-wrap { min-height: 88vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { justify-content: center; margin-bottom: 1.3rem; }
.login-card .brand-mark { width: 60px; height: 60px; }
address { font-style: normal; margin-bottom: .8rem; line-height: 1.55; color: var(--ink-2); }
.home-stats { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.home-stats a { display: block; padding: .7rem .8rem; border-radius: 14px; background: var(--paper); color: var(--ink); }
.home-stats a:hover { text-decoration: none; outline: 1px solid var(--palm); }
.home-stats strong { display: block; font-variant-numeric: tabular-nums; }
.steps { padding-left: 1.2rem; margin: 0 0 .75rem; display: grid; gap: .5rem; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: 2.6rem 1rem; border: 2px dashed var(--line); border-radius: var(--r-lg); cursor: pointer; text-align: center; background: var(--paper); position: relative; }
.dropzone:hover { border-color: var(--palm); }
.dropzone input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.dropzone .ico { width: 36px; height: 36px; color: var(--palm); }
.dropzone.busy { opacity: .6; pointer-events: none; }
.dropzone.busy strong::after { content: " (reading…)"; }
.scan-note { background: var(--palm-soft); color: var(--ink); border-radius: var(--r-md); padding: .9rem 1.05rem; margin-bottom: 1rem; }
.scan-note-warn { background: var(--gold-soft); }
.scan-note form { display: inline; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .is-auth .sidebar { display: none; }
    .is-auth .main { margin-left: 0; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
    .is-auth .mobile-top {
        display: flex; align-items: center; justify-content: space-between; padding: .7rem 1rem; padding-top: max(.7rem, env(safe-area-inset-top));
        background: var(--paper); position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line);
    }
    .is-auth .tabbar {
        display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
        background: var(--surface); border-top: 1px solid var(--line); padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
    }
    .tabbar a, .tabbar button {
        display: grid; justify-items: center; gap: 2px; padding: .35rem 0; color: var(--muted); font: 700 .7rem var(--font); background: none; border: 0; cursor: pointer;
    }
    .tabbar a:hover { text-decoration: none; }
    .tabbar .active { color: var(--palm); }
    .tabbar .active .ico { stroke-width: 2.3; }
    .is-auth .fab { right: 1rem; bottom: calc(84px + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 18px; }
    .wrap { padding: 1.2rem 1rem 3rem; }
    .tabung-hero { grid-template-columns: 110px 1fr; gap: 1rem; padding: 1.2rem; border-radius: 24px; }
    dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 24px 24px 0 0; padding-bottom: calc(1.3rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4, .row { grid-template-columns: minmax(0, 1fr); }
    .grid-4.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .list .hide-sm { display: none; }
    .stat .value { font-size: 1.35rem; }
    .cal .day { min-height: 70px; padding: .2rem; }
    .cal .item { font-size: 0; height: 6px; padding: 0; margin-top: 3px; }
    .cal .dow { font-size: .68rem; padding: .35rem .1rem; }
    .week { padding: .7rem; }
    .week-days { gap: .25rem; }
    .day-btn { padding: .5rem 0; border-radius: 12px; }
    .day-btn .dnum { font-size: 1.05rem; }
    .tabung-hero { grid-template-columns: 64px minmax(0, 1fr); align-items: start; gap: .9rem; padding: 1.1rem; }
    .tabung-hero .jar { max-width: 64px; margin-top: .3rem; }
    .tabung-hero .month-pair { gap: 1rem; }
    .tabung-hero .hero-actions .btn { flex: 1 1 auto; }
    .segmented span { padding: .45rem .7rem; font-size: .9rem; }
    .tabs a { padding: .45rem .7rem; font-size: .88rem; }
    .attention li { flex-wrap: wrap; row-gap: .4rem; }
    .attention .what { flex: 1 1 calc(100% - 70px); }
    .attention li > .amt { margin-left: 64px; margin-right: auto; }
    .attention li > form, .attention li > .btn { margin-left: auto; }
    .attention li > .due-chip + .what + form, .attention li > .due-chip + .what + .btn { margin-left: 64px; }
    .section-head { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Type switcher fits narrow screens */
.segmented label { min-width: 0; }
@media (max-width: 640px) {
    .segmented { display: flex; width: 100%; }
    .segmented label { flex: 1 1 0; }
    .segmented span { justify-content: center; padding: .5rem .3rem; }
    .segmented .ico { display: none; }
}

/* Bills list: on phones each bill becomes a stacked card that stays inside its box */
@media (max-width: 640px) {
    .bills-list thead { display: none; }
    .bills-list, .bills-list tbody { display: block; }
    .bills-list tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "main amt" "due due" "act act";
        gap: .35rem .75rem; padding: .9rem 0; border-bottom: 1px solid var(--line);
    }
    .bills-list tr:last-child { border-bottom: 0; }
    .bills-list td { display: block; padding: 0; border: 0; }
    .bills-list tbody tr:hover td { background: none; }
    .bills-list .c-main { grid-area: main; min-width: 0; }
    .bills-list .c-amt { grid-area: amt; font-weight: 800; font-size: 1.05rem; }
    .bills-list .c-due { grid-area: due; color: var(--ink-2); font-size: .9rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
    .bills-list .c-due div { display: inline; }
    .bills-list .row-actions { grid-area: act; text-align: left; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; white-space: normal; margin-top: .25rem; }
    .bills-list .pay-form { display: flex !important; flex: 1 1 100%; justify-content: flex-start; }
    .bills-list .pay-form .mini-select { flex: 1 1 auto; min-width: 0; }
}

/* Family page: last login line */
.what .sub { display: block; }
.what .seen { margin-top: .15rem; font-size: .8rem; }
