@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap");

:root {
    --ink: #0c1222;
    --muted: rgba(12, 18, 34, 0.58);
    --line: rgba(255, 255, 255, 0.42);
    --glass: rgba(255, 255, 255, 0.42);
    --glass-strong: rgba(255, 255, 255, 0.58);
    --glass-border: rgba(255, 255, 255, 0.55);
    --accent: #2dd4a8;
    --accent-2: #5b8cff;
    --danger: #ff5c7a;
    --ok: #1fbf75;
    --shadow: 0 18px 50px rgba(20, 36, 70, 0.16);
    --blur: 22px;
    --radius: 22px;
    --tap: 46px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    min-height: 100%;
    background:
        radial-gradient(1200px 700px at 8% -10%, rgba(93, 214, 255, 0.55), transparent 55%),
        radial-gradient(900px 600px at 92% 8%, rgba(120, 110, 255, 0.42), transparent 50%),
        radial-gradient(800px 500px at 50% 110%, rgba(45, 212, 168, 0.35), transparent 45%),
        linear-gradient(160deg, #dbe7ff 0%, #eef2ff 42%, #e8fff7 100%);
    background-attachment: fixed;
}

body {
    margin: 0;
    min-height: 100%;
    min-height: 100dvh;
    position: relative;
    isolation: isolate;
    font-family: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
    color: var(--ink);
    line-height: 1.45;
    background: transparent;
}

a {
    color: inherit;
}

/* Diagonal flying money / coins — full viewport layer */
.money-bg {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.money-fx {
    position: absolute;
    top: var(--fx-start, -16vh);
    left: var(--fx-left);
    font-size: var(--fx-size);
    line-height: 1;
    font-weight: 700;
    color: rgba(34, 78, 160, 0.55);
    opacity: var(--fx-opacity);
    text-shadow: 0 8px 18px rgba(40, 70, 140, 0.18);
    will-change: transform, opacity;
    animation: money-fly-diag var(--fx-duration) linear infinite;
    animation-delay: var(--fx-delay);
    transform: rotate(var(--fx-rotate));
    user-select: none;
}

.money-fx--coin {
    display: grid;
    place-items: center;
    width: calc(var(--fx-size) * 1.35);
    height: calc(var(--fx-size) * 1.35);
    border-radius: 50%;
    color: #7a4f00;
    background:
        radial-gradient(circle at 30% 28%, #ffe9a8 0%, #f0c14b 42%, #d4a017 78%, #b8860b 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        inset 0 -2px 4px rgba(120, 70, 0, 0.25),
        0 8px 14px rgba(180, 120, 20, 0.22);
    font-size: calc(var(--fx-size) * 0.72);
}

.money-fx--coin i {
    font-style: normal;
    font-weight: 800;
    line-height: 1;
}

.money-fx--cash {
    color: rgba(16, 110, 78, 0.48);
    font-weight: 800;
    letter-spacing: -0.02em;
}

@keyframes money-fly-diag {
    0% {
        transform: translate3d(0, 0, 0) rotate(var(--fx-rotate));
        opacity: 0;
    }
    8% {
        opacity: var(--fx-opacity);
    }
    92% {
        opacity: var(--fx-opacity);
    }
    100% {
        transform: translate3d(var(--fx-drift), 130vh, 0) rotate(calc(var(--fx-rotate) + 55deg));
        opacity: 0;
    }
}

.site-header,
.page,
.auth-card {
    position: relative;
    z-index: 1;
}

.undo-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100vw - 32px);
    padding: 12px 14px 12px 18px;
    border-radius: 16px;
    transform: translateX(-50%);
    font-size: 14px;
    font-weight: 600;
}

.undo-toast[hidden] {
    display: none !important;
}

.undo-toast-btn {
    min-height: 38px;
    padding: 0 14px;
    color: #0b5cab;
}

.undo-toast-timer {
    min-width: 1.5em;
    text-align: center;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
    .money-fx {
        animation: none;
        opacity: 0.14;
        top: auto;
        bottom: 12%;
    }

    .tab-indicator,
    .data-cards,
    .header-debt,
    .data-cards.is-entering .column,
    .data-cards.is-entering .card-container,
    .data-cards.is-entering .stats > div,
    .header-debt.is-entering {
        transition: none !important;
        animation: none !important;
    }
}

.glass {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(var(--blur)) saturate(160%);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 18px;
    border-radius: 999px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    color: #041511;
    background: linear-gradient(135deg, #7dffe0 0%, #2dd4a8 55%, #1fb8c9 100%);
    box-shadow: 0 10px 28px rgba(45, 212, 168, 0.35);
    border-color: rgba(255, 255, 255, 0.45);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 14px 32px rgba(45, 212, 168, 0.45);
}

.btn-compensate {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.55);
    border-color: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.btn-ghost {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(255, 255, 255, 0.45);
}

.btn-block {
    width: 100%;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
}

.field > span {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.field input,
.field textarea {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 16px;
    padding: 13px 15px;
    font: inherit;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field textarea:focus {
    border-color: rgba(45, 212, 168, 0.8);
    box-shadow: 0 0 0 4px rgba(45, 212, 168, 0.18);
}

.field textarea {
    resize: vertical;
    min-height: 104px;
}

/* Switch */
.switch {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    cursor: pointer;
    user-select: none;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.switch-ui {
    position: relative;
    width: 52px;
    height: 32px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: rgba(12, 18, 34, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.45);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.45);
    transition: background 0.2s ease;
}

.switch-ui::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(180deg, #fff, #f2f5ff);
    box-shadow: 0 4px 12px rgba(20, 36, 70, 0.25);
    transition: transform 0.2s ease;
}

.switch input:checked + .switch-ui {
    background: linear-gradient(135deg, #7dffe0, #2dd4a8);
}

.switch input:checked + .switch-ui::after {
    transform: translateX(20px);
}

.switch input:focus-visible + .switch-ui {
    box-shadow: 0 0 0 4px rgba(45, 212, 168, 0.25);
}

.switch-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

/* Auth */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 16px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    border-radius: 28px;
    padding: 32px 28px;
}

.auth-card h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.auth-lead {
    margin: 8px 0 22px;
    color: var(--muted);
}

.auth-error {
    background: rgba(255, 92, 122, 0.12);
    color: #b42318;
    border: 1px solid rgba(255, 92, 122, 0.28);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* App shell */
.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 14px 16px 0;
}

.header-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 14px 18px;
    border-radius: 22px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 18px;
}

.header-user {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.greeting {
    color: var(--muted);
    font-weight: 500;
}

.user-name {
    font-size: 1.08rem;
    font-weight: 700;
}

.header-debt {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.header-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-left: auto;
    flex: 0 0 auto;
}

.page {
    max-width: 1120px;
    margin: 0 auto;
    padding: 18px 16px 56px;
}

.panel {
    border-radius: var(--radius);
    padding: 18px 18px 12px;
    margin-bottom: 16px;
}

.panel-title {
    margin: 0 0 14px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.tab {
    position: relative;
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.45);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.35);
}

.tab-indicator {
    position: absolute;
    top: 4px;
    left: 4px;
    height: calc(100% - 8px);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 8px 20px rgba(20, 36, 70, 0.12);
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform, width;
    pointer-events: none;
    z-index: 0;
}

.tablinks {
    position: relative;
    z-index: 1;
    min-height: 42px;
    min-width: 88px;
    padding: 0 22px;
    border-radius: 999px;
    border: 0;
    background: transparent;
    font: inherit;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.25s ease;
}

.tablinks.active {
    color: var(--ink);
}

.header-debt {
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.header-debt.is-leaving {
    opacity: 0;
    transform: translateY(-6px);
}

.header-debt.is-entering {
    animation: content-enter 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.outcome-form .form-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
    margin-bottom: 4px;
}

.data-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.data-cards.is-leaving {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.data-cards.is-entering .column {
    animation: content-enter 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.data-cards.is-entering .column.roma {
    animation-delay: 0.02s;
}

.data-cards.is-entering .column.sanya {
    animation-delay: 0.08s;
}

.data-cards.is-entering .card-container {
    animation: card-enter 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
    animation-delay: calc(0.06s + var(--enter-i, 0) * 0.045s);
}

.data-cards.is-entering .stats > div {
    animation: content-enter 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
    animation-delay: calc(0.04s + var(--enter-i, 0) * 0.03s);
}

@keyframes content-enter {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes card-enter {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.column {
    border-radius: var(--radius);
    padding: 18px;
    min-width: 0;
}

.column-toggle {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0;
    margin: 0 0 14px;
    border: 0;
    background: transparent;
    font: inherit;
    color: inherit;
    cursor: default;
    text-align: left;
    pointer-events: none;
}

.column-toggle-main {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
}

.column-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.column-spent {
    display: none;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--danger);
    letter-spacing: -0.02em;
}

.column-chevron {
    display: none;
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.7);
    position: relative;
}

.column-chevron::before {
    content: "";
    position: absolute;
    top: 10px;
    left: 9px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--ink);
    border-bottom: 2px solid var(--ink);
    transform: rotate(45deg);
    transition: transform 0.18s ease;
}

.column.is-open .column-chevron::before {
    top: 12px;
    transform: rotate(-135deg);
}

.column-body {
    display: block;
}

.stats {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(12, 18, 34, 0.08);
    font-size: 14px;
}

.stats .spent {
    color: var(--danger);
    font-weight: 700;
    font-size: 1.55rem;
    letter-spacing: -0.03em;
}

.stats .income {
    color: var(--ok);
    margin-top: 8px;
    font-weight: 600;
}

.stats .comp {
    color: var(--accent-2);
    margin-top: 6px;
    font-weight: 600;
}

.cards-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card-container {
    border-radius: 18px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.48);
    border: 1px solid rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.card-container.compensation {
    border-color: rgba(91, 140, 255, 0.45);
    background: rgba(91, 140, 255, 0.12);
}

.card-container.incoming {
    border-color: rgba(31, 191, 117, 0.45);
    background: rgba(31, 191, 117, 0.12);
}

.card-container .date {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

.card-actions {
    display: inline-flex;
    gap: 10px;
    align-items: center;
}

.card-action {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.42);
    padding: 0;
    margin: 0;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    cursor: pointer;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.card-action svg {
    display: block;
}

.card-action:hover {
    background: rgba(255, 255, 255, 0.72);
}

.card-action:active {
    transform: scale(0.96);
}

.edit-button {
    color: var(--accent-2);
}

.close-button {
    color: var(--danger);
}

.edit-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    z-index: 50;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 0;
    width: min(420px, calc(100vw - 28px));
    max-height: min(90vh, 640px);
    overflow: auto;
    background: var(--glass-strong);
    box-shadow: var(--shadow);
    backdrop-filter: blur(var(--blur)) saturate(160%);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
    color: var(--ink);
}

.edit-dialog::backdrop {
    background: rgba(12, 18, 34, 0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.edit-form {
    padding: 22px 20px 18px;
}

.edit-title {
    margin: 0 0 16px;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.edit-hint {
    margin: 10px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.edit-dialog .btn-ghost {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.55);
}

.card-container .howmuch {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.card-container .details {
    font-size: 14px;
    color: var(--muted);
    word-break: break-word;
}

.card-container .details a {
    color: var(--accent-2);
}

@media (max-width: 768px) {
    :root {
        --tap: 38px;
    }

    .site-header {
        padding: 8px 10px 0;
    }

    .header-inner {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "user actions"
            "debt debt";
        align-items: center;
        column-gap: 8px;
        row-gap: 6px;
        padding: 10px 12px;
        border-radius: 16px;
    }

    .header-user {
        grid-area: user;
        min-width: 0;
    }

    .greeting {
        font-size: 13px;
    }

    .user-name {
        font-size: 0.95rem;
    }

    .header-debt {
        grid-area: debt;
        flex: none;
        font-size: 0.95rem;
        line-height: 1.25;
        padding: 0;
        margin: 0;
    }

    .header-actions {
        grid-area: actions;
        margin-left: 0;
        width: auto;
        gap: 6px;
    }

    .header-actions .btn {
        flex: 0 0 auto;
        min-height: 34px;
        padding: 0 12px;
        font-size: 13px;
    }

    .page {
        padding: 12px 10px 40px;
    }

    .panel {
        padding: 14px 14px 10px;
        margin-bottom: 12px;
        border-radius: 18px;
    }

    .data-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .column {
        padding: 12px 14px;
        border-radius: 18px;
    }

    .column-toggle {
        margin: 0;
        min-height: 52px;
        cursor: pointer;
        pointer-events: auto;
    }

    .column-toggle .column-title {
        font-size: 1.1rem;
    }

    .column-spent {
        display: block;
    }

    .column-chevron {
        display: block;
    }

    .column-body {
        display: none;
        padding-top: 12px;
        margin-top: 10px;
        border-top: 1px solid rgba(12, 18, 34, 0.08);
    }

    .column.is-open .column-body {
        display: block;
    }

    .column.is-open .column-spent {
        display: none;
    }

    .tab {
        display: flex;
        width: 100%;
    }

    .tablinks {
        flex: 1;
        min-width: 0;
        min-height: 38px;
        padding: 0 12px;
    }

    .auth-card {
        padding: 26px 20px;
        border-radius: 24px;
    }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .glass,
    .header-inner,
    .panel,
    .column,
    .auth-card,
    .card-container,
    .field input,
    .field textarea {
        background: rgba(255, 255, 255, 0.88);
    }
}
