/* ==============================
   Budget Bank — Design System
   ============================== */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --dark: #1e293b;
    --darker: #0f172a;
    --light: #f8fafc;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--darker);
    color: var(--light);
    font-family: "Inter", sans-serif;
    line-height: 1.6;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

h3 {
    font-size: 1.4rem;
}

.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* ==============================
   Buttons
   ============================== */

button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border-radius: 8px;
    font-weight: 500;
    font-size: 1rem;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

button:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

button.secondary {
    background-color: var(--dark);
}

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

button.small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* ==============================
   Inputs
   ============================== */

input,
select {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.75rem;
    margin: 0.5rem 0;
    width: 100%;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

label {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 0.25rem;
    display: block;
}

/* ==============================
   Cards
   ============================== */

.card {
    background-color: var(--dark);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--primary);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-bank {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

.card-bank i {
    font-size: 1.25rem;
    color: var(--primary);
}

.card-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.7);
}

.card-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.card.expanded .card-content {
    max-height: 2000px;
    transition: max-height 0.5s ease-in;
}

.card-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.card-detail {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.card-detail-label {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.7);
}

.card-detail-value {
    font-weight: 500;
    font-size: 1.1rem;
}

.card-detail-value.danger {
    color: #e74c3c !important;
    font-weight: 700;
}

.card-detail-value.warning {
    color: var(--warning) !important;
    font-weight: 700;
}

.card-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

/* Link styled as button — for navigation from card-actions */
.btn-link {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border-radius: 8px;
    font-weight: 500;
    font-size: 1rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.btn-link:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
    color: white;
}

/* ==============================
   Debt progress bar
   ============================== */

.debt-progress {
    height: 8px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin: 2rem 0;
    overflow: hidden;
}

.debt-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ==============================
   Payments
   ============================== */

.payment-item {
    background-color: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.payment-item:last-child {
    margin-bottom: 0;
}

.payment-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.payment-date {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
}

.payment-amount {
    font-weight: 500;
}

.no-payments {
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

/* ==============================
   Summary
   ============================== */

.summary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.5s ease;
}

.summary-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
}

.title-main {
    display: flex;
    align-items: center;
    gap: 7px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.summary-item {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 8px;
    backdrop-filter: blur(5px);
}

.summary-item-label {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: rgba(255, 255, 255, 0.8);
}

.summary-item-value {
    font-size: 1.1rem;
    font-weight: 600;
}

.summary-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.badge-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    font-weight: 500;
    color: #fff;
    text-decoration: none;
    background: rgba(79, 134, 247, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    white-space: nowrap;
    transition: background 0.2s, border-color 0.2s;
}

.badge-link:hover {
    background: rgba(79, 134, 247, 0.3);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
}

.badge-link i {
    font-size: 0.6rem;
}

/* ==============================
   Modals
   ============================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal {
    background-color: var(--dark);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    padding: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    transform: translateY(20px);
    transition: transform 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.modal-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-left: auto;
    transition: color 0.2s ease;
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
    transform: none;
    box-shadow: none;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* ==============================
   Radio group
   ============================== */

.radio-group {
    display: flex;
    gap: 1rem;
    margin: 0.5rem 0;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.radio-option input {
    width: auto;
    margin: 0;
}

/* ==============================
   History items
   ============================== */

.history-item {
    padding: 1rem;
    margin-bottom: 0.5rem;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    font-size: 0.9rem;
}

.history-item .date {
    color: #ffffff99;
    display: block;
    margin-bottom: 0.25rem;
}

.history-item.income .amount { color: var(--success); }
.history-item.expense .amount { color: var(--danger); }
.history-item.payment .amount { color: var(--primary); }
.history-item.payment_edit .amount { color: var(--warning); }
.history-item.payment_paid .amount { color: var(--success); }

/* ==============================
   Form errors
   ============================== */

.form-errors {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    color: var(--danger);
    font-size: 0.875rem;
}

.form-errors ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.field-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: -0.25rem;
}

.error-message {
    color: #ff4444;
    margin: 10px 0;
    min-height: 20px;
}

/* ==============================
   Alerts
   ============================== */

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--success);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    color: var(--success);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-info {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    color: var(--primary);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ==============================
   Landing page — Split layout
   ============================== */

.landing-page {
    display: flex;
    min-height: 100vh;
}

.landing-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 4rem 3rem;
    background: var(--darker);
}

.landing-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 4rem 3rem;
    background: var(--dark);
}

.landing-logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.landing-logo i {
    font-size: 2.5rem;
    color: var(--primary);
}

.landing-logo h1 {
    font-size: 2rem;
}

.landing-description {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 2.5rem;
    line-height: 1.8;
}

.feature-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border-left: 3px solid var(--primary);
    transition: all 0.3s;
}

.feature-item:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateX(5px);
}

.feature-item i {
    font-size: 1.25rem;
    color: var(--primary);
    width: 2rem;
    text-align: center;
}

.feature-item span {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
}

/* ==============================
   Auth card (login / register)
   ============================== */

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-card h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    color: rgba(255, 255, 255, 0.6);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.auth-links {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.auth-links a {
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    font-size: 0.875rem;
}

.auth-links a:hover {
    color: var(--primary);
}

.auth-description {
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 1.5rem;
}

/* Auth page (password reset, etc.) */
.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.auth-page .auth-card {
    background: var(--dark);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

/* ==============================
   Outline buttons (upcoming payments)
   ============================== */

.outline-btn {
    border: 1px solid var(--primary);
    background: none;
    color: var(--primary);
    padding: 0.3em 1em;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
    transition: background 0.15s;
}

.outline-btn.active-outline,
.outline-btn:hover {
    background: var(--primary);
    color: #fff;
}

/* ==============================
   Animations
   ============================== */

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

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.pulse {
    animation: pulse 2s infinite;
}

/* ==============================
   Spinner / Loading
   ============================== */

.loading-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ==============================
   HTMX indicator
   ============================== */

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

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

@media (max-width: 768px) {
    .landing-page {
        flex-direction: column;
    }

    .landing-left,
    .landing-right {
        padding: 2rem 1.5rem;
    }

    .landing-left {
        padding-bottom: 1rem;
    }

    .landing-right {
        padding-top: 1rem;
    }

    .summary-title button {
        width: 15%;
        text-align: right;
    }

    .title-main {
        width: 85%;
    }

    .container {
        padding: 0 1rem;
    }

    .card-details {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-close {
        width: 2rem;
        height: 2rem;
        font-size: 1.3rem;
    }

    button {
        width: 100%;
        justify-content: center;
    }

    .btn-link {
        width: 100%;
        justify-content: center;
    }
}


/* ==============================
   Upcoming Payments Page
   ============================== */

.page-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
    transition: opacity 0.2s;
}

.page-back:hover {
    opacity: 0.8;
}

.page-back i {
    font-size: 1.1rem;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
}

.page-header i {
    font-size: 1.3rem;
    color: var(--primary);
}

/* Period filter buttons */
.period-filter {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.period-btn {
    padding: 0.5rem 1.2rem;
    border-radius: 8px;
    background: var(--darker);
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.period-btn:hover {
    background: var(--dark);
    color: white;
}

.period-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Payment rows */
.payment-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 10px;
    margin-bottom: 0.5rem;
    border-left: 4px solid var(--primary);
}

.payment-row-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    flex: 1;
}

.payment-row-date {
    font-size: 1rem;
    font-weight: 600;
}

.payment-row-card {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.payment-row-card img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.payment-row-sum {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
    margin-left: 1rem;
}

/* Total */
.payments-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    margin-top: 1rem;
    background: var(--darker);
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
}

.payments-total-sum {
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: 700;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: rgba(255, 255, 255, 0.5);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

.empty-state p {
    font-size: 1.1rem;
}

/* ==============================
   History Page
   ============================== */

.history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    background: var(--card-bg);
    border-radius: 10px;
    margin-bottom: 0.5rem;
    border-left: 4px solid var(--primary);
}

.history-row--success { border-left-color: var(--success); }
.history-row--danger  { border-left-color: var(--danger); }
.history-row--primary { border-left-color: var(--primary); }

.history-row-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
    flex: 1;
}

.history-row-comment {
    font-size: 0.95rem;
    font-weight: 500;
}

.history-row-date {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.45);
}

.history-row-amount {
    font-size: 1.05rem;
    font-weight: 700;
    white-space: nowrap;
    margin-left: 1rem;
}

.history-amount--success { color: var(--success); }
.history-amount--danger  { color: var(--danger); }
.history-amount--primary { color: var(--primary); }

/* ==============================
   Pull-to-refresh / top spinner
   ============================== */

.ptr-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    pointer-events: none;
}

/* Thin progress shimmer while loading */
.ptr-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -60%;
    width: 60%;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--primary), var(--success), transparent);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s;
}

.ptr-bar.loading::after {
    opacity: 1;
    animation: shimmer 1s linear infinite;
}

/* Pull indicator circle */
.ptr-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--primary);
    border-right-color: var(--success);
    border-radius: 50%;
    background: var(--bg-card);
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 10000;
}

.ptr-bar.pulling .ptr-spinner {
    opacity: 1;
    transform: scale(1);
}

.ptr-bar.loading .ptr-spinner {
    opacity: 1;
    transform: scale(1);
    animation: spin 0.75s linear infinite;
}

@keyframes shimmer {
    to { left: 160%; }
}

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