/* ==========================================================================
   Life Assistant — Premium Mobile-First Design System
   Inspired by: iOS Finance apps, Revolut, Wise, Apple HIG
   ========================================================================== */

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

:root {
    /* Deep dark palette — rich & warm */
    --bg: #0a0a0f;
    --surface-1: rgba(255,255,255,0.04);
    --surface-2: rgba(255,255,255,0.06);
    --surface-3: rgba(255,255,255,0.10);
    --surface-solid: #151519;
    --border: rgba(255,255,255,0.07);
    --border-focus: rgba(99,102,241,0.5);

    /* Accent — vibrant indigo-purple gradient feel */
    --accent: #818cf8;
    --accent-strong: #6366f1;
    --accent-soft: rgba(129,140,248,0.12);
    --accent-glow: rgba(129,140,248,0.25);

    /* Semantic */
    --green: #34d399;
    --green-soft: rgba(52,211,153,0.12);
    --green-glow: rgba(52,211,153,0.2);
    --amber: #fbbf24;
    --amber-soft: rgba(251,191,36,0.10);
    --red: #f87171;
    --red-soft: rgba(248,113,113,0.10);

    /* Type */
    --text-1: #f4f4f5;
    --text-2: #a1a1aa;
    --text-3: #63637a;

    /* Radius — rounder for mobile friendliness */
    --r-sm: 12px;
    --r-md: 16px;
    --r-lg: 20px;
    --r-xl: 24px;
    --r-full: 9999px;

    /* Spacing */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --sp-10: 40px;

    /* Shadows */
    --shadow-card: 0 2px 16px rgba(0,0,0,0.3), 0 0 1px rgba(255,255,255,0.05);
    --shadow-modal: 0 -8px 40px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);
}

/* Reset */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg);
    color: var(--text-1);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ==========================================================================
   Layout Shell — Full width on mobile
   ========================================================================== */

.glass-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 var(--sp-5) var(--sp-10);
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
}

/* ==========================================================================
   Header — Compact, sticky on mobile
   ========================================================================== */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) 0;
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(to bottom, var(--bg) 60%, transparent);
    padding-top: env(safe-area-inset-top, 16px);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.profile-img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--surface-3);
    transition: transform 0.2s ease;
}

.profile-img:active {
    transform: scale(0.95);
}

.header h1 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-1);
    line-height: 1.2;
}

.subtitle {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 500;
    margin-top: 2px;
    letter-spacing: 0.02em;
}

.status-indicator {
    width: 10px;
    height: 10px;
    background: var(--green);
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 8px var(--green-glow);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 8px var(--green-glow); }
    50% { box-shadow: 0 0 16px var(--green-glow), 0 0 24px rgba(52,211,153,0.1); }
}

/* ==========================================================================
   Summary Hero Card — Top-level financial overview
   ========================================================================== */

.summary-card {
    background: linear-gradient(135deg, rgba(99,102,241,0.08) 0%, rgba(129,140,248,0.04) 100%);
    border: 1px solid rgba(99,102,241,0.12);
    border-radius: var(--r-xl);
    padding: var(--sp-6);
    margin-bottom: var(--sp-6);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(129,140,248,0.08) 0%, transparent 70%);
    pointer-events: none;
}

.summary-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--sp-2);
}

.summary-amount {
    font-size: 38px;
    font-weight: 800;
    letter-spacing: -2px;
    line-height: 1.1;
    color: var(--text-1);
    position: relative;
}

.summary-sub {
    font-size: 13px;
    color: var(--text-2);
    margin-top: var(--sp-3);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sp-1);
}

/* Metrics row — horizontal scrolling on small screens */
.metric-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-3);
    margin-top: var(--sp-5);
}

.metric-item {
    background: rgba(255,255,255,0.04);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
    text-align: center;
    border: 1px solid var(--border);
    transition: background 0.2s;
}

.metric-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--sp-1);
}

.metric-value {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.3px;
}

/* Progress */
.progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--sp-5);
    margin-bottom: var(--sp-2);
}

.progress-label {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 500;
}

.progress-track {
    width: 100%;
    height: 6px;
    background: var(--surface-3);
    border-radius: var(--r-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-strong), var(--green));
    border-radius: var(--r-full);
    transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3));
    border-radius: var(--r-full);
}

.summary-status {
    font-size: 13px;
    margin-top: var(--sp-4);
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-weight: 500;
}

.summary-status svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.color-green { color: var(--green); }
.color-amber { color: var(--amber); }
.color-muted { color: var(--text-3); }

/* ==========================================================================
   Section / Widget
   ========================================================================== */

.widget {
    margin-bottom: var(--sp-8);
}

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-4);
    padding: 0 var(--sp-1);
}

.widget-header h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.01em;
}

/* ==========================================================================
   Buttons — Large touch targets (min 44px)
   ========================================================================== */

button {
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--r-sm);
    border: none;
    padding: 12px 18px;
    min-height: 44px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent));
    color: #fff;
    border: none;
    padding: 14px 22px;
    border-radius: var(--r-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(99,102,241,0.3);
    letter-spacing: -0.01em;
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(99,102,241,0.4); }
.btn-primary:active { transform: scale(0.97); box-shadow: 0 2px 8px rgba(99,102,241,0.2); }

.btn-ghost {
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: var(--r-full);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-height: 40px;
    transition: all 0.2s ease;
}
.btn-ghost:hover { background: var(--surface-3); color: var(--text-1); }
.btn-ghost:active { transform: scale(0.96); }

.btn-success {
    background: var(--green-soft);
    color: var(--green);
    border: 1px solid rgba(52,211,153,0.2);
    padding: 12px 18px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.2s ease;
}
.btn-success:hover { background: rgba(52,211,153,0.18); }
.btn-success:active { transform: scale(0.96); }

.btn-outline {
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
    padding: 14px 22px;
    border-radius: var(--r-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    transition: all 0.2s ease;
}
.btn-outline:hover { background: var(--surface-2); }
.btn-outline:active { transform: scale(0.97); }

.action-btn {
    background: var(--surface-2);
    color: var(--text-3);
    border: 1px solid var(--border);
    font-size: 16px;
    padding: 8px;
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.action-btn:hover { color: var(--text-1); background: var(--surface-3); }
.action-btn:active { transform: scale(0.92); }

/* ==========================================================================
   Cards / List Items — Touch-friendly, swipeable look
   ========================================================================== */

.debts-list, .cards-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

.debt-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-5);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.debt-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.debt-card:active {
    background: var(--surface-2);
}

.debt-card:active::before {
    opacity: 1;
}

.debt-card.paid-card {
    opacity: 0.6;
}

.debt-card.paid-card::before {
    background: var(--green);
    opacity: 1;
}

.debt-info {
    flex: 1;
    min-width: 0;
}

.debt-info h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.debt-amount {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.debt-due {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: var(--sp-1);
}

.debt-paid-badge {
    font-size: 12px;
    font-weight: 600;
    color: var(--green);
    background: var(--green-soft);
    padding: 6px 14px;
    border-radius: var(--r-full);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Payment channel card — with icon accent */
.payment-card {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-4) var(--sp-5);
    transition: all 0.2s ease;
}

.payment-card:active {
    background: var(--surface-2);
}

.payment-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--r-md);
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--accent);
    font-size: 18px;
    font-weight: 700;
}

.payment-card-info {
    flex: 1;
    min-width: 0;
}

.payment-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.payment-card-bank {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 500;
}

.payment-card-dates {
    display: flex;
    gap: var(--sp-3);
    margin-top: 4px;
}

.payment-card-date {
    font-size: 11px;
    color: var(--text-3);
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: var(--r-full);
    font-weight: 500;
}

/* ==========================================================================
   Loader
   ========================================================================== */

.init-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100px 0;
    gap: var(--sp-5);
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--surface-3);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Modal / Bottom Sheet — Native iOS feel
   ========================================================================== */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    padding: 0;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    width: 100%;
    max-width: 480px;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding: var(--sp-2) var(--sp-6) var(--sp-8);
    padding-bottom: calc(var(--sp-8) + env(safe-area-inset-bottom, 0px));
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    animation: slideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-modal);
    position: relative;
}

.modal-content::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--surface-3);
    border-radius: 4px;
    margin: var(--sp-3) auto var(--sp-5);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-content h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: var(--sp-2);
    color: var(--text-1);
    letter-spacing: -0.02em;
}

.modal-content .modal-desc {
    font-size: 14px;
    color: var(--text-3);
    margin-bottom: var(--sp-6);
    line-height: 1.6;
}

/* ==========================================================================
   Forms — Large, touch-friendly inputs
   ========================================================================== */

.form-group {
    margin-bottom: var(--sp-5);
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: var(--sp-2);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 14px 16px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-1);
    font-size: 16px; /* Prevents iOS zoom */
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    min-height: 50px;
}

.form-group input::placeholder {
    color: var(--text-3);
    font-weight: 400;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: rgba(255,255,255,0.06);
}

.row {
    display: flex;
    gap: var(--sp-3);
}

.half { flex: 1; }

.modal-actions {
    display: flex;
    gap: var(--sp-3);
    margin-top: var(--sp-6);
}

.modal-actions .btn-primary,
.modal-actions .btn-outline {
    flex: 1;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: var(--sp-10) var(--sp-4);
    color: var(--text-3);
    background: var(--surface-1);
    border: 1px dashed var(--border);
    border-radius: var(--r-lg);
}

.empty-state svg {
    width: 32px;
    height: 32px;
    margin-bottom: var(--sp-3);
    opacity: 0.4;
    stroke: currentColor;
}

.empty-state p {
    font-size: 14px;
    font-weight: 500;
}

/* ==========================================================================
   Utility
   ========================================================================== */

.text-center { text-align: center; }

/* Smooth fade-in for content sections */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

main .widget:nth-child(1) { animation: fadeInUp 0.4s ease 0.1s both; }
main .widget:nth-child(2) { animation: fadeInUp 0.4s ease 0.2s both; }
main .widget:nth-child(3) { animation: fadeInUp 0.4s ease 0.3s both; }

#dashboardSummary { animation: fadeInUp 0.5s ease both; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (min-width: 481px) {
    body {
        padding: var(--sp-8) var(--sp-4);
    }
    .glass-container {
        min-height: auto;
        border: 1px solid var(--border);
        border-radius: var(--r-xl);
        padding: var(--sp-4) var(--sp-8) var(--sp-8);
    }
    .modal {
        align-items: center;
    }
    .modal-content {
        border-radius: var(--r-xl);
        max-height: 80vh;
    }
}

/* Mobile-specific — stack vertically, full-width buttons */
@media (max-width: 480px) {
    .debt-card {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--sp-3);
    }

    .debt-card > div:last-child {
        width: 100%;
    }

    .debt-card > div:last-child .btn-success,
    .debt-card > div:last-child .btn-mark-paid {
        width: 100%;
        text-align: center;
        padding: 12px;
        min-height: 44px;
        border-radius: var(--r-sm);
    }

    .metric-row {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--sp-2);
    }

    .metric-item {
        padding: var(--sp-3) var(--sp-2);
    }

    .metric-value {
        font-size: 15px;
    }

    .row {
        gap: var(--sp-2);
    }
}

/* Safe area padding for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .glass-container {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Scrollbar styling (mobile usually hidden, desktop visible) */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 4px;
}
