/* =====================================================
   FinManager — visual gaming charcoal (dark + light)
   ===================================================== */

:root,
html[data-theme="dark"] {
    color-scheme: dark;

    --bg: #121418;
    --bg-2: #181b21;
    --bg-3: #22262e;
    --header: #16191f;
    --surface: #1e2026;
    --surface-2: #282c35;
    --line: rgba(255, 255, 255, .07);
    --text: #ffffff;
    --text-dim: #a0a0a0;
    --muted: #7a8090;
    --icon: #9aa3b5;

    --primary: #3d5afe;
    --primary-2: #85c1ff;
    --primary-soft: rgba(61, 90, 254, .18);
    --success: #78d68c;
    --success-soft: rgba(120, 214, 140, .14);
    --warn: #c6934b;
    --warn-soft: rgba(198, 147, 75, .16);
    --danger: #ef5350;
    --danger-soft: rgba(239, 83, 80, .14);
    --orange: #ffad60;
    --blue: #3d5afe;
    --pink: #ec4899;
    --purple: #a855f7;
    --teal: #489e9e;

    --on-accent: #121418;
    --on-accent-muted: rgba(18, 20, 24, .75);
    --overlay: rgba(255, 255, 255, .06);
    --overlay-2: rgba(255, 255, 255, .1);
    --overlay-3: rgba(255, 255, 255, .16);
    --backdrop: rgba(0, 0, 0, .6);
    --input-bg: rgba(255, 255, 255, .05);
    --toast-bg: #2a2e38;
    --muted-icon: #4a505c;
    --action-grad: linear-gradient(180deg, #2a3144, #1c2230);
    --expense: #ffad60;
    --shadow: 0 8px 24px rgba(0, 0, 0, .4);
    --shadow-soft: 0 2px 12px rgba(0, 0, 0, .28);

    --radius: 18px;
    --radius-lg: 28px;
    --theme-meta: #121418;
}

html[data-theme="light"] {
    color-scheme: light;

    --bg: #eef0f3;
    --bg-2: #ffffff;
    --bg-3: #e4e7ec;
    --header: #ffffff;
    --surface: #ffffff;
    --surface-2: #e8ebf0;
    --line: rgba(18, 20, 24, .08);
    --text: #121418;
    --text-dim: #5c6370;
    --muted: #8b919a;
    --icon: #5c6578;

    --primary: #3d5afe;
    --primary-2: #2f6fdb;
    --primary-soft: rgba(61, 90, 254, .12);
    --success: #2f9e4f;
    --success-soft: rgba(47, 158, 79, .12);
    --warn: #c6934b;
    --warn-soft: rgba(198, 147, 75, .14);
    --danger: #e53935;
    --danger-soft: rgba(229, 57, 53, .12);
    --orange: #e0893a;
    --blue: #3d5afe;
    --pink: #db2777;
    --purple: #9333ea;
    --teal: #3d8585;

    --on-accent: #121418;
    --on-accent-muted: rgba(18, 20, 24, .7);
    --overlay: rgba(18, 20, 24, .04);
    --overlay-2: rgba(18, 20, 24, .07);
    --overlay-3: rgba(18, 20, 24, .12);
    --backdrop: rgba(18, 20, 24, .4);
    --input-bg: rgba(18, 20, 24, .04);
    --toast-bg: #2a2e38;
    --muted-icon: #9aa3b2;
    --action-grad: linear-gradient(180deg, #e8ecf6, #d9e0ef);
    --expense: #d97706;
    --shadow: 0 8px 24px rgba(18, 20, 24, .08);
    --shadow-soft: 0 2px 10px rgba(18, 20, 24, .06);

    --theme-meta: #eef0f3;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Outfit", "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

input, textarea, select, button {
    font-family: inherit;
}

input, textarea, select {
    user-select: text;
    -webkit-user-select: text;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    background: var(--bg);
    overflow-x: hidden;
}

/* ======= SCREENS ======= */
.screen {
    display: none;
    min-height: 100vh;
    padding-bottom: 24px;
    animation: fadein .15s ease;
}
.screen.active {
    display: block;
}
@keyframes fadein {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

/* ======= TOP BAR ======= */
.top-bar {
    background: var(--header);
    height: 60px;
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
    padding: 0 6px;
    color: var(--text);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-soft);
    border-bottom: 1px solid var(--line);
}
.top-bar .title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    text-align: left;
    padding-left: 4px;
    letter-spacing: .2px;
}
.icon-btn {
    background: transparent;
    border: 0;
    color: var(--icon);
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.icon-btn:hover, .icon-btn:active {
    background: var(--overlay);
    color: var(--text);
}

/* Account pill in top bar */
.account-pill {
    background: var(--overlay);
    border: 1px solid var(--line);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 15px;
    font-weight: 600;
    margin: 0 auto;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 999px;
}
.account-pill .chev {
    opacity: .8;
}

/* ======= BALANCE ======= */
.balance-block {
    background: var(--header);
    text-align: center;
    padding: 4px 16px 18px;
}
.balance-amount {
    font-size: 30px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: .2px;
}

/* ======= TABS ======= */
.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--header);
    position: relative;
    border-bottom: 1px solid var(--line);
}
.tab {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 14px;
    padding: 14px 0;
    cursor: pointer;
    position: relative;
    letter-spacing: .8px;
}
.tab.active {
    color: var(--text);
}
.tab.active::after {
    content: '';
    position: absolute;
    left: 16%;
    right: 16%;
    bottom: 0;
    height: 3px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
    box-shadow: 0 0 10px rgba(61, 90, 254, .45);
}

/* ======= PERIOD ======= */
.period-bar {
    display: flex;
    gap: 22px;
    padding: 14px 18px 6px;
    background: var(--bg);
    overflow-x: auto;
    scrollbar-width: none;
}
.period-bar::-webkit-scrollbar { display: none; }
.period {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 400;
    padding: 4px 2px;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
}
.period.active {
    color: var(--warn);
}
.period.active::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -4px;
    height: 1px;
    background: var(--warn);
}

.period-nav {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    padding: 4px 8px;
}
.period-label {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-color: var(--overlay-3);
    color: var(--text);
}

/* ======= CHART ======= */
.chart-wrap {
    position: relative;
    margin: 8px auto 16px;
    width: 260px;
    height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.donut {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.donut-track {
    fill: none;
    stroke: var(--surface);
    stroke-width: 26;
}
.donut-dashed {
    fill: none;
    stroke: var(--overlay-3);
    stroke-width: 1.5;
    stroke-dasharray: 4 4;
}
.donut-segment {
    fill: none;
    stroke-width: 26;
    stroke-linecap: butt;
    transition: stroke-width .15s;
}
.chart-center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.chart-amount {
    font-size: 28px;
    font-weight: 700;
}
.fab {
    position: absolute;
    right: -10px;
    bottom: 14px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 0;
    background: var(--warn);
    color: var(--on-accent);
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .12s;
}
.fab:active { transform: scale(.95); }

.fab-bottom {
    position: fixed;
    right: 50%;
    bottom: 22px;
    transform: translateX(220px);
    z-index: 80;
}
@media (max-width: 480px) {
    .fab-bottom {
        right: 22px;
        transform: none;
    }
}

/* ======= LIST (categories / accounts / transactions) ======= */
.list {
    padding: 8px 12px 100px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.row-item {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 40px 1fr auto auto;
    gap: 12px;
    align-items: center;
    cursor: pointer;
    transition: background .12s;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
}
.row-item:active {
    background: var(--surface-2);
}
.row-item .pct {
    color: var(--text-dim);
    font-size: 14px;
    min-width: 38px;
    text-align: right;
}
.row-item .amt {
    font-weight: 600;
    font-size: 15px;
    min-width: 80px;
    text-align: right;
}
.row-item .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
}
.cat-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
}
.cat-icon.sm { width: 32px; height: 32px; }
.cat-icon svg { width: 22px; height: 22px; }

/* Per-list extras */
.transaction-row {
    grid-template-columns: 40px 1fr auto;
}
.transaction-row .meta {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 2px;
}
.transaction-row .amt.income { color: var(--success); }
.transaction-row .amt.expense { color: var(--expense); }

/* ======= ACCOUNTS SCREEN ======= */
.accounts-total {
    text-align: center;
    padding: 22px 16px 12px;
}
.accounts-total .muted {
    color: var(--text-dim);
    margin-bottom: 4px;
    font-size: 14px;
}
.accounts-total .big-amount {
    font-size: 30px;
    font-weight: 600;
}
.accounts-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0 16px 18px;
}
.action-card {
    background: transparent;
    border: 0;
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px;
    font-size: 13px;
    line-height: 1.2;
    text-align: center;
}
.action-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.action-icon.green {
    background: var(--action-grad);
    color: var(--primary-2);
    border-radius: 18px;
}

/* ======= DRAWER ======= */
.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: var(--bg-2);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.2,.7,.3,1);
    display: flex;
    flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
    background: var(--header);
    padding: 22px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.drawer-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--overlay);
    color: var(--icon);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
}
.drawer-avatar .cat-icon {
    width: 56px;
    height: 56px;
}
.drawer-avatar img,
.cat-icon img,
.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}
.cat-icon.has-photo {
    padding: 2px;
    overflow: hidden;
}
.avatar-editor {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.avatar-preview {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--overlay);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.avatar-preview .cat-icon {
    width: 72px;
    height: 72px;
}
.avatar-preview .cat-icon svg {
    width: 34px;
    height: 34px;
}
.avatar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.btn-chip {
    border: 0;
    background: var(--overlay);
    color: var(--text);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
}
.btn-chip:hover { filter: brightness(1.08); }
.btn-chip.ghost {
    background: transparent;
    border: 1px solid var(--border, rgba(127,127,127,.35));
    color: var(--text-dim);
}
.funko-stage {
    display: flex;
    justify-content: center;
    padding: 8px 16px 4px;
}
.funko-preview {
    width: 168px;
    height: 168px;
    border-radius: 28px;
    background:
        radial-gradient(circle at 50% 20%, rgba(255,255,255,.08), transparent 55%),
        var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.funko-preview svg,
.funko-preview img {
    width: 150px;
    height: 150px;
    display: block;
}
.funko-options {
    max-height: 42vh;
    padding: 8px 16px 4px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.funko-group-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.funko-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.funko-chip {
    border: 1px solid transparent;
    background: var(--bg-2, var(--overlay));
    color: var(--text);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    min-height: 36px;
}
.funko-chip.active {
    border-color: var(--primary, #78d68c);
    box-shadow: 0 0 0 1px var(--primary, #78d68c);
}
.funko-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    padding: 0;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}
.funko-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--primary, #78d68c);
}
.drawer-title { font-weight: 700; }
.drawer-sub { color: var(--text-dim); font-size: 12px; }
.drawer-nav { padding: 8px 0; flex: 1; overflow-y: auto; }
.drawer-nav button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: transparent;
    border: 0;
    color: var(--text);
    text-align: left;
    padding: 14px 18px;
    font-size: 15px;
    cursor: pointer;
}
.drawer-nav button:hover { background: var(--overlay); }
.dn-icon {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--icon);
    flex-shrink: 0;
}
.dn-icon svg { width: 20px; height: 20px; }
.drawer-theme {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
.drawer-theme-label {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-size: 15px;
}
.drawer-theme-label .dn-icon { color: var(--icon); }
.drawer-foot { padding: 14px 18px; color: var(--muted); font-size: 12px; }

.backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

/* ======= SHEET ======= */
.sheet {
    position: fixed;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    bottom: 0;
    width: 100%;
    max-width: 480px;
    background: var(--bg-2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 250;
    transition: transform .25s cubic-bezier(.2,.7,.3,1);
    padding: 8px 18px 22px;
    max-height: 85vh;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-bottom: 0;
}
.sheet.open { transform: translateX(-50%) translateY(0); }
.sheet.tall { max-height: 90vh; }
.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--overlay-3);
    border-radius: 2px;
    margin: 6px auto 12px;
}
.sheet-title {
    font-size: 16px;
    font-weight: 600;
    margin: 4px 0 14px;
}
.sheet-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 18px;
}
.btn-text {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    font-weight: 700;
    letter-spacing: .8px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    border-radius: 8px;
}
.btn-text:hover { background: var(--overlay); }
.btn-text.primary { color: var(--primary-2); }
.btn-text.danger { color: var(--danger); }

/* ======= ROW TOGGLE ======= */
.row-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 4px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-dim);
}
.toggle {
    position: relative;
    width: 36px;
    height: 20px;
    display: inline-block;
}
.toggle input { display: none; }
.toggle .track {
    position: absolute;
    inset: 0;
    background: var(--overlay-3);
    border-radius: 999px;
    transition: background .15s;
}
.toggle .track::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ddd;
    top: 2px;
    left: 2px;
    transition: transform .18s, background .18s;
}
.toggle input:checked + .track {
    background: var(--primary-soft);
}
.toggle input:checked + .track::after {
    transform: translateX(16px);
    background: var(--primary);
}

/* ======= PICKER LIST (radios) ======= */
.picker-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.picker-row {
    display: grid;
    grid-template-columns: 28px 36px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    cursor: pointer;
    border-radius: 10px;
}
.picker-row:hover { background: var(--overlay); }
.picker-row .radio-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--text-dim);
    position: relative;
    margin-left: 4px;
}
.picker-row.selected .radio-dot {
    border-color: var(--primary-2);
}
.picker-row.selected .radio-dot::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--primary-2);
}
.picker-row .name { font-size: 15px; }
.picker-row .meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.picker-row .amount { color: var(--text-dim); font-size: 13px; }

/* ======= TX FORM ======= */
.tx-form .field {
    padding: 14px 18px 8px;
    border-bottom: 1px solid var(--line);
}
.field-label {
    color: var(--text-dim);
    font-size: 13px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.field-label.section-title {
    padding: 16px 18px 0;
    color: var(--text-dim);
    font-size: 13px;
    margin-bottom: 8px;
}
.field-value {
    background: transparent;
    border: 0;
    color: var(--primary-2);
    font-size: 16px;
    text-align: left;
    padding: 0;
    cursor: pointer;
    width: 100%;
    font-family: inherit;
}
.field {
    padding: 14px 18px 8px;
}
.req { color: var(--danger); }
.link {
    background: transparent;
    border: 0;
    color: var(--primary-2);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

/* amount input */
.amount-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: end;
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--line);
}
.amount-input {
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--overlay-3);
    color: var(--text);
    font-size: 30px;
    text-align: right;
    width: 100%;
    padding: 4px 0;
    outline: none;
    font-family: inherit;
}
.amount-input:focus { border-bottom-color: var(--primary-2); }
.amount-currency {
    color: var(--primary-2);
    font-size: 16px;
    margin-bottom: 8px;
}

/* category grid */
.cat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px 8px;
    padding: 8px 14px 8px;
}
.cat-grid.scroll {
    max-height: min(52vh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: 12px;
    scrollbar-width: thin;
}
#category-icon-grid.cat-grid.scroll,
#account-icon-grid.cat-grid.scroll {
    max-height: min(48vh, 380px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    margin: 0 12px;
    padding: 12px 8px;
}
.cat-tile {
    background: transparent;
    border: 0;
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 6px 4px;
    cursor: pointer;
    border-radius: 12px;
    font-size: 12px;
    line-height: 1.1;
}
.cat-tile.selected {
    background: var(--overlay);
}
.cat-tile .cat-icon { width: 56px; height: 56px; }
.cat-tile .cat-icon svg { width: 28px; height: 28px; }
.cat-tile span { text-align: center; }
.cat-icon.muted { background: var(--muted-icon) !important; }
.cat-icon.gray { background: var(--muted-icon); }
.cat-icon.warn { background: var(--warn); color: var(--on-accent); }

/* date row */
.date-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 14px 14px 6px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    align-items: center;
}
.date-pill {
    background: transparent;
    border: 0;
    color: var(--text);
    padding: 10px 6px;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.2;
}
.date-pill .small { font-size: 11px; color: var(--text-dim); display: block; margin-top: 2px; }
.date-pill.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}
.date-pill.active .small { color: rgba(255, 255, 255, .8); }
.date-pill.calendar { display: flex; align-items: center; justify-content: center; }

/* ======= CALENDÁRIO (sheet data) ======= */
.cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}
.cal-month-label {
    font-size: 15px;
    font-weight: 600;
    text-transform: capitalize;
    flex: 1;
    text-align: center;
}
.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 6px;
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 600;
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.cal-day {
    aspect-ratio: 1;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.cal-day:hover { background: var(--overlay); }
.cal-day.outside { color: var(--text-dim); opacity: .45; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--primary); }
.cal-day.selected {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}
.cal-day.selected.today { box-shadow: none; }

/* tags */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 13px;
    background: var(--primary-soft);
    color: var(--primary-2);
    border: 1px dashed color-mix(in srgb, var(--primary-2) 55%, transparent);
    cursor: pointer;
}
.chip.solid {
    background: var(--overlay);
    color: var(--text);
    border: 1px solid transparent;
}
.chip .x {
    margin-left: 4px;
    cursor: pointer;
}

textarea, .text-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    resize: vertical;
    outline: none;
}
textarea:focus, .text-input:focus { border-color: var(--primary-2); }
.text-input.flat {
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--overlay-3);
    border-radius: 0;
    padding: 6px 2px;
}
.text-input.half { max-width: 180px; }
.char-count { text-align: right; color: var(--text-dim); font-size: 12px; margin-top: 4px; }

/* ======= BOTTOM CTA ======= */
.bottom-cta {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--warn);
    color: var(--on-accent);
    border: 0;
    width: calc(100% - 32px);
    max-width: 448px;
    padding: 14px 18px;
    border-radius: 999px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 60;
    font-family: inherit;
}
.bottom-cta:active { transform: translateX(-50%) scale(.99); }

/* ======= COLOR ROW ======= */
.color-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 6px 18px 18px;
}
.color-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
}
.color-dot.selected { border-color: var(--text); }
.color-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 12px;
    padding: 6px 4px;
}

/* ======= RADIO ROW ======= */
.radio-row {
    display: flex;
    gap: 24px;
    padding: 14px 18px 4px;
}
.radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}
.radio input { display: none; }
.radio .dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--text-dim);
    position: relative;
}
.radio input:checked ~ .dot { border-color: var(--primary-2); }
.radio input:checked ~ .dot::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--primary-2);
}

/* ======= ROW utility ======= */
.row { display: flex; gap: 12px; align-items: center; }
.muted { color: var(--text-dim); }
.bottom-spacer { height: 90px; }

.field.with-icon { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 10px; }
.field-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--overlay);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--icon);
}

/* ======= SEGMENTED CONTROL ======= */
.seg {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    background: var(--overlay);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 10px;
}
.seg button {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    padding: 8px 6px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
}
.seg button.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

/* ======= SPLIT EDITOR ROW ======= */
.split-row {
    display: grid;
    grid-template-columns: 36px 1fr 90px;
    gap: 10px;
    align-items: center;
    padding: 8px 4px;
    border-bottom: 1px solid var(--line);
}
.split-row .cat-icon { width: 32px; height: 32px; }
.split-row input[type="number"] {
    background: var(--input-bg);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 13px;
    text-align: right;
    width: 100%;
    font-family: inherit;
}
.split-row .check {
    width: 22px;
    height: 22px;
    border: 2px solid var(--text-dim);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.split-row.checked .check {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.split-total { padding: 6px 4px; font-size: 13px; }

/* ======= TOAST ======= */
.toast {
    position: fixed;
    left: 50%;
    bottom: 80px;
    transform: translateX(-50%) translateY(20px);
    background: var(--toast-bg);
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    box-shadow: var(--shadow);
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ======= FILTER SUMMARY ======= */
.filter-summary {
    padding: 8px 16px;
    color: var(--text-dim);
    font-size: 13px;
    background: var(--overlay);
}
.filter-summary:empty { display: none; }

/* date input fix */
input[type=date], input[type=number], select.text-input {
    color-scheme: inherit;
}

/* ======= ICONIFIED CATEGORY (icon + label inline for transactions) ======= */
.transaction-row .cat-icon { width: 40px; height: 40px; }

/* ======= LOADING OVERLAY ======= */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    justify-content: center;
    color: var(--text);
    transition: opacity .3s;
}
#loading-overlay.hide {
    opacity: 0;
    pointer-events: none;
}
.loading-gif {
    width: 180px;
    height: 180px;
    object-fit: contain;
    display: block;
    user-select: none;
    pointer-events: none;
}

/* family row */
.family-row {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
}
.family-row .icon-wrap {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--action-grad);
    color: var(--primary-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.family-row .name { font-size: 15px; }
.family-row .meta { color: var(--text-dim); font-size: 12px; }
.family-row .pill {
    background: var(--primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
}
.family-row .menu-btn {
    background: transparent; border: 0;
    color: var(--text-dim);
    cursor: pointer;
    padding: 6px;
}

/* income amounts */
.amount-input.income { color: var(--success); }

/* split warning */
.split-warn {
    color: var(--warn);
    font-size: 12px;
    padding: 4px 0;
}
.split-ok { color: var(--success); font-size: 12px; padding: 4px 0; }

/* small badge for splits in tx list */
.split-badge {
    display: inline-block;
    background: var(--success-soft);
    color: var(--success);
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 11px;
    margin-left: 4px;
}

.row-item .meta {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 2px;
}

/* ======= AUTH SCREENS ======= */
.auth-screen {
    background: linear-gradient(180deg, var(--header) 0%, var(--bg) 60%);
    min-height: 100vh;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px 24px;
}
.auth-screen.active { display: flex; }

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 22px 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}
.auth-logo {
    font-size: 34px;
    font-weight: 700;
    text-align: center;
    margin-top: 4px;
    letter-spacing: .12em;
}
.auth-sub {
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    margin: 4px 0 18px;
}
.auth-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    background: var(--overlay);
    border-radius: 999px;
    padding: 4px;
}
.auth-tab {
    flex: 1;
    background: transparent;
    border: 0;
    color: var(--text-dim);
    padding: 10px 8px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .3px;
    font-family: inherit;
}
.auth-tab.active {
    background: var(--primary);
    color: #fff;
}
.auth-pane { display: none; }
.auth-pane.active { display: block; }

.auth-pane .text-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 13px 14px;
    border-radius: 12px;
    margin-bottom: 10px;
    font-size: 15px;
    outline: none;
}
.auth-pane .text-input:focus { border-color: var(--primary); }

.auth-cta {
    margin-top: 6px;
    width: 100%;
    border-radius: 12px;
    padding: 14px;
}
.link-btn {
    display: block;
    width: 100%;
    background: transparent;
    border: 0;
    color: var(--primary-2);
    text-align: center;
    padding: 10px;
    cursor: pointer;
    font-size: 13px;
    margin-top: 8px;
}
.muted.small { font-size: 12px; }

.auth-magic-hint {
    background: var(--primary-soft);
    color: var(--primary-2);
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    margin-top: 12px;
    line-height: 1.5;
}

/* INVITE preview */
.invite-info {
    background: var(--overlay);
    padding: 14px;
    border-radius: 12px;
    margin: 8px 0 14px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
.invite-info b { color: var(--primary-2); }
.invite-error {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    margin: 8px 0;
}

/* SYNC dot indicator on menu button */
.icon-btn { position: relative; }
.sync-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-2);
    box-shadow: 0 0 0 2px var(--header);
}
.sync-dot.syncing {
    background: var(--warn);
    animation: pulse 1.2s ease-in-out infinite;
}
.sync-dot.error { background: var(--danger); }
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.25); opacity: .6; }
}

/* family manage list rows */
#family-members-list .family-row,
#family-invites-list .family-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.row-meta { color: var(--text-dim); font-size: 12px; }
.row-actions button {
    background: transparent; border: 0; color: var(--danger);
    cursor: pointer; font-size: 13px; padding: 6px 8px;
}
.row-badge {
    display: inline-block;
    background: var(--success-soft);
    color: var(--success);
    padding: 1px 8px;
    border-radius: 8px;
    font-size: 11px;
    margin-left: 6px;
}
.row-badge.warn { background: var(--warn-soft); color: var(--warn); }

#invite-email-input { flex: 1; }

/* theme toggle helper on light surfaces */
html[data-theme="light"] .top-bar,
html[data-theme="light"] .balance-block,
html[data-theme="light"] .tabs {
    border-color: var(--line);
}

html[data-theme="light"] .drawer {
    box-shadow: 8px 0 28px rgba(18, 20, 24, .08);
}

/* ===== Gamificação ===== */
.family-hud {
    margin: 0 16px 12px;
    display: grid;
    gap: 8px;
}
.family-hud-main {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    border-radius: 16px;
    padding: 12px 14px;
    text-align: left;
    cursor: pointer;
}
.family-hud-main:active { transform: scale(.99); }
.family-hud-mascot { font-size: 28px; line-height: 1; }
.family-hud-copy { flex: 1; min-width: 0; display: grid; gap: 2px; }
.family-hud-title { font-weight: 600; font-size: 14px; }
.family-hud-sub { color: var(--text-dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.family-hud-streak {
    min-width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--primary-soft);
    color: var(--primary-2);
    font-weight: 700;
    font-size: 14px;
}
.family-hud-quest,
.family-hud-budgets,
.family-hud-goal {
    border-radius: 14px;
    padding: 10px 12px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    font-size: 13px;
    color: var(--text-dim);
}
.hud-budget-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.hud-budget-bar {
    flex: 1;
    height: 6px;
    border-radius: 99px;
    background: var(--overlay);
    overflow: hidden;
}
.hud-budget-bar > span {
    display: block;
    height: 100%;
    border-radius: 99px;
    background: var(--success);
}
.hud-budget-bar.warn > span { background: var(--warn); }
.hud-budget-bar.over > span { background: var(--danger); }

.kind-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.kind-chip {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-dim);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
}
.kind-chip.active {
    background: var(--primary-soft);
    color: var(--primary-2);
    border-color: transparent;
    font-weight: 600;
}

.card-members-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: var(--surface);
}
.card-member-row {
    display: grid;
    grid-template-columns: 36px 1fr 28px;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
}
.card-member-row:last-child { border-bottom: none; }
.card-member-row .cat-icon { width: 32px; height: 32px; }
.card-member-row .check {
    width: 22px;
    height: 22px;
    border: 2px solid var(--text-dim);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}
.card-member-row.checked .check {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.card-members-list .empty-hint {
    padding: 14px 12px;
    text-align: center;
}

.play-tabs {
    display: flex;
    gap: 6px;
    padding: 0 16px 12px;
    overflow-x: auto;
}
.play-tab {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-dim);
    border-radius: 999px;
    padding: 8px 12px;
    white-space: nowrap;
    font-size: 13px;
}
.play-tab.active {
    background: var(--primary-soft);
    color: var(--primary-2);
    border-color: transparent;
    font-weight: 600;
}
.play-pane { display: none; padding: 0 16px; }
.play-pane.active { display: block; }
.play-hero {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    margin-bottom: 12px;
}
.play-mascot { font-size: 36px; }
.play-hero-title { color: var(--text-dim); font-size: 12px; }
.play-hero-value { font-size: 20px; font-weight: 700; }
.play-challenge {
    margin-top: 12px;
    padding: 12px;
    border-radius: 14px;
    background: var(--success-soft);
    color: var(--text);
    font-size: 13px;
}
.coins-pill {
    display: inline-flex;
    margin-bottom: 12px;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--warn-soft);
    color: var(--warn);
    font-weight: 600;
    font-size: 13px;
}
.kind-badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--overlay);
    color: var(--text-dim);
    margin-left: 6px;
    vertical-align: middle;
}
.row-item .sub {
    font-size: 12px;
    color: var(--text-dim);
}
.reward-actions {
    display: flex;
    gap: 6px;
}
.reward-actions button {
    border: 0;
    background: var(--primary-soft);
    color: var(--primary-2);
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
}
.goal-meter {
    height: 8px;
    border-radius: 99px;
    background: var(--overlay);
    overflow: hidden;
    margin-top: 8px;
}
.goal-meter > span {
    display: block;
    height: 100%;
    background: var(--success);
}

