:root {
    --bg: #0f1117;
    --surface: #1a1d29;
    --surface-2: #242836;
    --border: #2f3548;
    --text: #eef0f6;
    --text-muted: #9aa3b8;
    --primary: #4f8cff;
    --primary-hover: #3d7aef;
    --success: #34c759;
    --danger: #ff5a5f;
    --warning: #ffb020;
    --radius: 14px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --header-h: 140px;
    --total-bar-h: 72px;
    --fab-size: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

input,
select,
button {
    font: inherit;
}

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 24px 16px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 24px;
    box-shadow: var(--shadow);
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 1.6rem;
}

.auth-subtitle {
    margin: 0 0 24px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.auth-form label {
    display: block;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.auth-form input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
}

.auth-form input:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

.auth-footer {
    margin: 20px 0 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-icon {
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1.4rem;
    line-height: 1;
}

/* Alerts */
.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(255, 90, 95, 0.15);
    color: #ff8a8e;
    border: 1px solid rgba(255, 90, 95, 0.3);
}

.alert-success {
    background: rgba(52, 199, 89, 0.15);
    color: #6ee78a;
    border: 1px solid rgba(52, 199, 89, 0.3);
}

/* App layout */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 16px 12px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.header-top h1 {
    margin: 0;
    font-size: 1.25rem;
}

.month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.month-label {
    flex: 1;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
}

.stats-bar {
    margin-top: 10px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.app-main {
    padding: 12px 16px calc(var(--total-bar-h) + var(--fab-size) + 32px + var(--safe-bottom));
    max-width: 640px;
    margin: 0 auto;
}

.payment-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.payment-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    min-height: 64px;
}

.payment-item:active {
    background: var(--surface-2);
}

.payment-item.is-paid {
    opacity: 0.75;
    border-color: rgba(52, 199, 89, 0.35);
}

.payment-item.is-overdue {
    border-color: rgba(255, 176, 32, 0.5);
    background: rgba(255, 176, 32, 0.06);
}

.payment-check {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: transparent;
    transition: all 0.15s;
}

.payment-item.is-paid .payment-check {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.payment-body {
    flex: 1;
    min-width: 0;
}

.payment-name {
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.payment-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.payment-amount {
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--success);
    text-align: right;
}

.payment-item:not(.is-paid) .payment-amount {
    color: var(--text-muted);
    font-weight: 500;
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-hint {
    font-size: 0.9rem;
    margin-top: 8px;
}

/* Total bar */
.total-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px calc(16px + var(--safe-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
}

.total-bar span {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.total-bar strong {
    font-size: 1.25rem;
    color: var(--success);
}

/* FAB */
.fab {
    position: fixed;
    right: 20px;
    bottom: calc(var(--total-bar-h) + 16px + var(--safe-bottom));
    z-index: 25;
    width: var(--fab-size);
    height: var(--fab-size);
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.15s, background 0.15s;
}

.fab:active {
    transform: scale(0.95);
}

/* Modal */
.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: 90dvh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px 20px calc(24px + var(--safe-bottom));
    border-top: 1px solid var(--border);
}

.modal-content h2 {
    margin: 0 0 8px;
    font-size: 1.2rem;
}

.modal-subtitle {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.modal-content label {
    display: block;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.modal-content input,
.modal-content select {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    min-height: 44px;
}

.modal-content input:focus,
.modal-content select:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}

.modal-actions-stack {
    flex-direction: column;
}

.modal-actions .btn {
    flex: 1;
}

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--total-bar-h) + 24px + var(--safe-bottom));
    transform: translateX(-50%);
    z-index: 200;
    padding: 12px 20px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.9rem;
    box-shadow: var(--shadow);
    max-width: calc(100% - 32px);
    text-align: center;
}

.toast[hidden] {
    display: none;
}

.toast.is-error {
    border-color: rgba(255, 90, 95, 0.4);
    color: #ff8a8e;
}

/* Desktop */
@media (min-width: 640px) {
    .modal {
        align-items: center;
        padding: 24px;
    }

    .modal-content {
        border-radius: var(--radius);
        border: 1px solid var(--border);
    }

    .app-main {
        padding-bottom: calc(var(--total-bar-h) + 24px + var(--safe-bottom));
    }

    .fab {
        bottom: calc(var(--total-bar-h) + 24px + var(--safe-bottom));
    }
}
