/* Import Design Tokens */
@import url('design-tokens.css');

/* ===== GLOBAL RESET & TYPOGRAPHY ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    /* Prevent rubber-banding on body */
    overscroll-behavior-y: none;
}


/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--system-gray-3);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--system-gray-2);
}

/* ===== UTILITY CLASSES ===== */
.screen {
    display: none;
    width: 100%;
    height: 100vh;
    overflow-y: auto;
}

.screen.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

#dashboard-screen.active {
    display: block;
    padding-top: calc(80px + var(--safe-top)); /* Space for sticky nav */
    padding-bottom: var(--safe-bottom);
}


/* ===== COMPONENTS ===== */

/* 1. Navigation Bar (Sticky, Blurred) */
.dashboard-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(60px + var(--safe-top));
    padding-top: var(--safe-top);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: var(--material-regular);
    -webkit-backdrop-filter: var(--material-regular);
    border-bottom: 0.5px solid var(--separator);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: max(var(--space-6), var(--safe-left));
    padding-right: max(var(--space-6), var(--safe-right));
}

@media (prefers-color-scheme: dark) {
    .dashboard-header {
        background: rgba(28, 28, 30, 0.7);
    }
}


.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.header-left h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.logo-icon-small {
    font-size: 24px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.user-badge {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* 2. Cards (Floating, Rounded) */
.glass-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2);
    border: 0.5px solid var(--separator);
    padding: var(--space-6);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.glass-card:hover {
    box-shadow: var(--shadow-3);
    transform: scale(1.005);
}

/* 3. Inputs (Apple-style Glossy) */
input[type="text"],
input[type="number"],
input[type="password"],
select {
    width: 100%;
    height: 44px; /* Apple standard touch target */
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 0 var(--space-4);
    font-size: 17px;
    color: var(--text-primary);
    transition: all 0.2s ease;
    outline: none;
}

input:focus,
select:focus {
    background: var(--bg-card);
    border-color: var(--color-blue);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15); /* Glossy ring */
}

/* 4. Buttons (Vibrant, Rounded) */
.btn {
    height: 44px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 17px;
    font-weight: 600;
    padding: 0 var(--space-6);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.btn:active {
    transform: scale(0.96);
    opacity: 0.9;
}

.btn-primary {
    background: var(--color-blue);
    color: white;
}

.btn-primary:hover {
    background: #0062CC; /* Darker blue */
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--color-blue);
}

.btn-secondary:hover {
    background: rgba(118, 118, 128, 0.2);
}

.btn-icon {
    font-weight: 700;
}

.btn-small {
    height: 32px;
    font-size: 13px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
}

/* ===== SPECIFIC LAYOUTS ===== */

/* Login Screen */
.login-container {
    width: 100%;
    max-width: 400px;
    text-align: center;
    animation: floatUp 0.6s ease-out;
}

@keyframes floatUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.logo-section {
    margin-bottom: var(--space-8);
}

.logo-icon {
    font-size: 80px;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.1));
}

.app-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: var(--space-2);
}

.app-subtitle {
    font-size: 17px;
    color: var(--text-secondary);
}

.login-form {
    text-align: left;
}

/* Dashboard Layout */
.dashboard-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: var(--space-6);
    padding-left: max(var(--space-6), var(--safe-left));
    padding-right: max(var(--space-6), var(--safe-right));
}


.balance-card {
    margin-bottom: var(--space-6);
    text-align: center;
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(255,255,255,0.8) 100%);
}

@media (prefers-color-scheme: dark) {
    .balance-card {
        background: linear-gradient(135deg, var(--bg-card) 0%, rgba(28,28,30,0.8) 100%);
    }
}

.balance-header h2 {
    font-size: 17px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.balance-amount {
    font-size: 64px;
    font-weight: 700;
    font-variant-numeric: tabular-nums; /* Monospace numbers for stability */
    letter-spacing: -2px;
    margin: var(--space-2) 0;
}

.balance-amount.positive { color: var(--color-green); }
.balance-amount.negative { color: var(--color-red); }

.balance-status {
    font-size: 17px;
    color: var(--text-secondary);
}

/* Pay Debt Section */
.clear-balance-section {
    margin-top: var(--space-6);
}

.pay-debt-button {
    background: var(--color-green);
    color: white;
    width: 100%;
    height: 50px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(52, 199, 89, 0.3);
    transition: all 0.2s ease;
}

.pay-debt-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(52, 199, 89, 0.4);
}

.pay-debt-button:active {
    transform: scale(0.98);
}

/* Two Column Layout */
.two-column-layout {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: var(--space-6);
}

@media (max-width: 768px) {
    .two-column-layout {
        grid-template-columns: 1fr;
    }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 0.5px solid var(--separator);
}

.card-header h2 {
    font-size: 17px;
    font-weight: 600;
}

/* Forms */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Checkbox (Apple Switch) */
.checkbox-group {
    display: flex;
    flex-direction: column;
}

.checkbox-group .checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    gap: var(--space-3);
    position: relative;
    /* Reset generic label styles */
    margin-bottom: 0;
    text-transform: none;
    font-weight: normal;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkbox-custom {
    display: block;
    width: 50px;
    height: 30px;
    flex-shrink: 0; /* Prevent shrinking */
    background: var(--system-gray-5);
    border-radius: 15px;
    position: relative;
    transition: background 0.3s;
}

.checkbox-custom::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 26px;
    height: 26px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

input[type="checkbox"]:checked + .checkbox-custom {
    background: var(--color-green);
}

input[type="checkbox"]:checked + .checkbox-custom::after {
    transform: translateX(20px);
}

.checkbox-text {
    font-size: 17px;
}

.help-text {
    margin-top: var(--space-2);
    font-size: 13px;
    color: var(--text-tertiary);
}

/* Transaction Log */
.transaction-log {
    max-height: 400px;
    overflow-y: auto;
}

.transaction-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 0.5px solid var(--separator);
}

.transaction-item:last-child {
    border-bottom: none;
}

.transaction-main {
    flex: 1;
    min-width: 0; /* Allow text truncation */
    padding-right: var(--space-3);
}

.transaction-note {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.transaction-amount-display {
    text-align: right;
    font-weight: 600;
    font-size: 17px;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.transaction-date {
    font-size: 13px;
    color: var(--text-tertiary);
}

.transaction-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    margin-left: 8px;
}

.badge-split { background: rgba(0, 122, 255, 0.1); color: var(--color-blue); }
.badge-full { background: rgba(255, 45, 85, 0.1); color: var(--color-pink); }

/* Payment Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-container {
    width: 90%;
    max-width: 400px;
    background: var(--bg-modal);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-floating);
    padding: var(--space-6);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-container {
    transform: scale(1);
}

.payment-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin: var(--space-6) 0;
}

.option-card {
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    background: var(--system-gray-6);
    padding: var(--space-4);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

input[type="radio"]:checked + .option-card {
    border-color: var(--color-blue);
    background: rgba(0, 122, 255, 0.1);
}

.option-icon { font-size: 32px; margin-bottom: 8px; }
.option-label { font-weight: 600; font-size: 15px; }

/* Toast */
.toast {
    position: fixed;
    bottom: calc(20px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);

    background: rgba(0,0,0,0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-weight: 500;
    box-shadow: var(--shadow-3);
    z-index: 3000;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ===== MISSING UTILITIES ===== */
.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-6);
    color: var(--text-tertiary);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: var(--space-2);
    opacity: 0.5;
}

.empty-subtitle {
    margin-top: var(--space-2);
    font-size: 15px;
}

.balance-icon, .card-icon {
    font-size: 24px;
}
