:root {
    /* Stripe-inspired palette */
    --bg: #f6f9fc;
    --surface: #ffffff;
    --surface-2: #f7fafc;
    --line: #e3e8ee;
    --line-strong: #d5dbe5;
    --text: #1a1f36;
    --text-2: #4f566b;
    --muted: #8792a2;
    --accent: #635bff;
    --accent-hover: #5851ec;
    --accent-soft: #f0eeff;
    --green: #1a7f4b;
    --green-soft: #e6f6ed;
    --red: #df1b41;
    --red-soft: #fcebef;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm:
        0 1px 1px rgba(60, 66, 87, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow:
        0 0 0 1px rgba(60, 66, 87, 0.04), 0 2px 5px rgba(60, 66, 87, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-pop:
        0 0 0 1px rgba(60, 66, 87, 0.06), 0 7px 14px rgba(60, 66, 87, 0.1),
        0 3px 6px rgba(0, 0, 0, 0.06);
    --ring: 0 0 0 3px rgba(99, 91, 255, 0.25);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family:
        "Inter",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom);
}

.hidden {
    display: none !important;
}
.error {
    color: var(--red);
    min-height: 1.2em;
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
}

h1,
h2,
h3 {
    letter-spacing: -0.01em;
}

/* ---- Login ---- */
.login {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(
            1200px 500px at 50% -10%,
            #efeefe 0%,
            rgba(246, 249, 252, 0) 60%
        ),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 360px;
    padding: 2rem 1.75rem;
    box-shadow: var(--shadow-pop);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.login-card h1 {
    text-align: center;
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
}
.login-card button.primary {
    margin-top: 0.25rem;
    padding: 0.8rem;
    font-size: 1rem;
    letter-spacing: 0.01em;
    background: linear-gradient(180deg, #6d66ff 0%, var(--accent) 100%);
    box-shadow:
        0 1px 2px rgba(60, 66, 87, 0.12),
        0 4px 12px rgba(99, 91, 255, 0.35);
    transition:
        background 0.12s,
        box-shadow 0.15s,
        transform 0.08s;
}
.login-card button.primary:hover {
    background: linear-gradient(180deg, #6d66ff 0%, var(--accent-hover) 100%);
    box-shadow:
        0 1px 2px rgba(60, 66, 87, 0.12),
        0 6px 18px rgba(99, 91, 255, 0.45);
    transform: translateY(-1px);
}
.login-card button.primary:active {
    transform: translateY(0);
    box-shadow:
        0 1px 2px rgba(60, 66, 87, 0.12),
        0 2px 6px rgba(99, 91, 255, 0.3);
}
.login-card .error {
    margin: 0;
    text-align: center;
}

/* ---- Top bar ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(10px);
    padding: max(env(safe-area-inset-top), 0.65rem) 1rem 0.65rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border-bottom: 1px solid var(--line);
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #7a5cff, #635bff);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    box-shadow: var(--shadow-sm);
}
.brand-name {
    font-weight: 600;
    font-size: 1rem;
}
.user-box {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.78rem;
    color: var(--muted);
}
.user-box #user-name {
    font-weight: 600;
    color: var(--text-2);
}
.link {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
}
.link:hover {
    color: var(--accent-hover);
}
.user-actions {
    display: flex;
    gap: 0.7rem;
}
.form-msg {
    min-height: 1.2em;
    margin: 0.1rem 0 0;
    font-size: 0.85rem;
}
.form-msg.err {
    color: var(--red);
}
.form-msg.ok {
    color: var(--green);
}

/* ---- Toolbar (tabs + month nav) ---- */
.toolbar {
    position: sticky;
    top: 3.45rem;
    z-index: 19;
    background: rgba(246, 249, 252, 0.9);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    flex-wrap: wrap;
    padding: 0.55rem 1rem;
}

/* Segmented tabs */
.tabs {
    display: flex;
    gap: 0.15rem;
    overflow-x: auto;
    background: #eef1f6;
    padding: 0.25rem;
    border-radius: 10px;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
    display: none;
}
.tabs button {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: var(--text-2);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background 0.12s,
        color 0.12s;
}
.tabs button:hover {
    color: var(--text);
}
.tabs button.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* Month stepper */
.month-nav {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 9px;
    box-shadow: var(--shadow-sm);
    padding: 2px;
}
.month-nav span {
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 7.5rem;
    text-align: center;
    color: var(--text);
}
.month-nav button {
    background: transparent;
    border: none;
    color: var(--text-2);
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 7px;
    font-size: 1.1rem;
    cursor: pointer;
}
.month-nav button:hover {
    background: var(--surface-2);
    color: var(--text);
}

/* ---- Views ---- */
main {
    padding: 1.1rem 1rem 2.5rem;
    max-width: 760px;
    margin: 0 auto;
}
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    padding: 1.1rem;
    margin-bottom: 1.1rem;
}
.card h2 {
    margin: 0 0 0.9rem;
    font-size: 1rem;
    font-weight: 600;
}
.card h3 {
    margin: 1.2rem 0 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-2);
    font-weight: 500;
    margin-bottom: 0.3rem;
}
input,
select {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    color: var(--text);
    padding: 0.6rem 0.7rem;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    box-shadow: var(--shadow-sm);
    transition:
        border-color 0.12s,
        box-shadow 0.12s;
    appearance: none;
    -webkit-appearance: none;
}
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238792a2' d='M3 4.5L6 8l3-3.5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    padding-right: 1.8rem;
}
input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}
input::placeholder {
    color: #aab3c2;
}

button {
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
}
button.primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.7rem;
    border-radius: 8px;
    font-weight: 600;
    width: 100%;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
    transition:
        background 0.12s,
        transform 0.04s;
}
button.primary:hover {
    background: var(--accent-hover);
}
button.primary:active {
    transform: translateY(1px);
}
.row {
    display: flex;
    gap: 0.6rem;
}
.row > * {
    flex: 1;
    min-width: 0;
}
.field {
    margin-bottom: 0.7rem;
}

/* lists */
.list {
    list-style: none;
    padding: 0;
    margin: 0.6rem 0 0;
}
.list li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0;
    border-top: 1px solid var(--line);
}
.list li .grow {
    flex: 1;
    min-width: 0;
}
.list .d {
    font-size: 0.82rem;
    color: var(--muted);
}
.list .amt {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.list .note {
    font-size: 0.85rem;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.del {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1rem;
    padding: 0.25rem 0.45rem;
    border-radius: 7px;
    line-height: 1;
    cursor: pointer;
}
.del:hover {
    background: var(--red-soft);
    color: var(--red);
}
.edit {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 0.95rem;
    padding: 0.25rem 0.45rem;
    border-radius: 7px;
    line-height: 1;
    cursor: pointer;
}
.edit:hover {
    background: var(--accent-soft);
    color: var(--accent);
}
.by {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.3rem;
    font-size: 0.7rem;
    color: var(--text-2);
}
.by-who {
    font-weight: 600;
    color: var(--text);
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
}
.by-when {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.ghost {
    background: none;
    border: 1px solid var(--line-strong);
    color: var(--text-2);
    width: 100%;
    padding: 0.6rem;
    border-radius: 8px;
    font-weight: 500;
    margin-top: 0.5rem;
    cursor: pointer;
}
.ghost:hover {
    background: var(--surface-2);
}
.tag {
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
}

/* summary rows */
.sum-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-top: 1px solid var(--line);
}
.sum-row:first-of-type {
    border-top: none;
}
.sum-row > span:first-child {
    color: var(--text-2);
    font-size: 0.9rem;
}
.sum-row .v {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.pos {
    color: var(--green);
}
.neg {
    color: var(--red);
}
.muted {
    color: var(--muted);
}

/* KPI block */
.kpi {
    text-align: center;
    padding: 1.2rem 0 0.4rem;
    margin-top: 0.6rem;
    border-top: 1px solid var(--line);
}
.kpi .label {
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}
.kpi .value {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    margin-top: 0.2rem;
}

/* Stat cards (Stripe-style metric tiles) */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
    margin-bottom: 1.1rem;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 0.9rem;
}
.stat .label {
    color: var(--muted);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.stat .value {
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    margin-top: 0.35rem;
}
@media (max-width: 560px) {
    /* Stack into compact full-width rows: label left, value right. */
    .stat-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .stat {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.7rem 0.95rem;
    }
    .stat .label {
        font-size: 0.7rem;
    }
    .stat .value {
        font-size: 1.2rem;
        margin-top: 0;
        white-space: nowrap;
    }
}

/* Info tooltip */
.info-wrap {
    position: relative;
    display: inline-flex;
    vertical-align: middle;
}
.info {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    font-style: italic;
    margin-left: 0.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}
.info:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.tip {
    position: absolute;
    z-index: 30;
    top: 150%;
    left: -4px;
    width: min(280px, 76vw);
    background: var(--text);
    color: #fff;
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    font-size: 0.8rem;
    line-height: 1.55;
    font-weight: 450;
    letter-spacing: 0;
    text-transform: none;
    box-shadow: var(--shadow-pop);
}
.tip::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 9px;
    border: 6px solid transparent;
    border-bottom-color: var(--text);
}
.tip[hidden] {
    display: none;
}

.slider-val {
    font-weight: 600;
    color: var(--accent);
}
/* Range slider — custom track + thumb (global appearance:none strips the native one) */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: var(--line);
    box-shadow: none;
    margin-top: 0.7rem;
    cursor: pointer;
}
input[type="range"]:focus {
    outline: none;
    box-shadow: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}
input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: var(--ring);
}
input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 999px;
    background: var(--line);
}
input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}
small.hint {
    color: var(--muted);
    font-size: 0.78rem;
    display: block;
    margin-top: 0.5rem;
    line-height: 1.5;
}

/* ---- Action buttons (add revenue / add expense) ---- */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-bottom: 1.1rem;
}
.action-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.7rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.1rem;
    min-height: 116px;
    text-align: left;
    cursor: pointer;
    transition:
        box-shadow 0.14s,
        border-color 0.14s,
        transform 0.04s;
}
.action-btn:hover {
    box-shadow: var(--shadow-pop);
}
.action-btn:active {
    transform: translateY(1px);
}
.action-ico {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 11px;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}
.action-btn.rev {
    border-top: 3px solid var(--green);
}
.action-btn.exp {
    border-top: 3px solid var(--red);
}
.action-btn.rev .action-ico {
    background: var(--green-soft);
    color: var(--green);
}
.action-btn.exp .action-ico {
    background: var(--red-soft);
    color: var(--red);
}
.action-label {
    font-weight: 600;
    font-size: 1.02rem;
    color: var(--text);
}

/* ---- Drawer / modal ---- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.overlay.open {
    opacity: 1;
}
.drawer {
    width: 100%;
    max-width: 540px;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-radius: 20px 20px 0 0;
    box-shadow: var(--shadow-pop);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom);
}
.overlay.open .drawer {
    transform: translateY(0);
}
.drawer-head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1.1rem 1.1rem 0.7rem;
    border-bottom: 1px solid var(--line);
}
.drawer-head h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}
.drawer-grabber {
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: var(--line-strong);
}
.drawer-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.3rem 0.45rem;
    border-radius: 8px;
    cursor: pointer;
}
.drawer-close:hover {
    background: var(--surface-2);
    color: var(--text);
}
.drawer-body {
    padding: 1.1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.drawer-body .list {
    margin-top: 1rem;
    border-top: 1px solid var(--line);
}

@media (min-width: 600px) {
    .overlay {
        align-items: center;
    }
    .drawer {
        border-radius: 18px;
        max-height: 86dvh;
        transform: translateY(24px) scale(0.98);
        opacity: 0;
        transition:
            transform 0.22s ease,
            opacity 0.22s ease;
    }
    .overlay.open .drawer {
        transform: none;
        opacity: 1;
    }
    .drawer-grabber {
        display: none;
    }
}
