/* ========================================
   Finik - Credit Tracker
   Dark theme, glassmorphism, elegant animations
   ======================================== */

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

:root {
    /* --- Dark Theme (default) --- */
    --bg: #07070d;
    --bg-elevated: #0e0e18;
    --surface: rgba(255, 255, 255, 0.035);
    --surface-hover: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.07);
    --border-light: rgba(255, 255, 255, 0.04);

    --text: #e8e8ed;
    --text-secondary: rgba(255, 255, 255, 0.45);
    --text-tertiary: rgba(255, 255, 255, 0.25);

    --accent: #818cf8;
    --accent-dim: rgba(129, 140, 248, 0.15);
    --success: #34d399;
    --success-dim: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --warning-dim: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-dim: rgba(248, 113, 113, 0.12);

    --pin-dot-border: rgba(255, 255, 255, 0.2);
    --progress-track: rgba(255, 255, 255, 0.06);
    --overlay-bg: rgba(0, 0, 0, 0.6);
    --handle-bg: rgba(255, 255, 255, 0.15);
    --card-shadow: rgba(0, 0, 0, 0.25);
    --card-hover-border: rgba(255, 255, 255, 0.1);
    --scrollbar-thumb: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(255, 255, 255, 0.03);
    --input-focus-bg: rgba(129, 140, 248, 0.04);
    --fab-shadow: rgba(129, 140, 248, 0.35);

    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;

    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);

    color-scheme: dark;
}

/* --- Light Theme --- */
:root[data-theme="light"] {
    --bg: #f4f4f8;
    --bg-elevated: #ffffff;
    --surface: rgba(0, 0, 0, 0.03);
    --surface-hover: rgba(0, 0, 0, 0.06);
    --border: rgba(0, 0, 0, 0.08);
    --border-light: rgba(0, 0, 0, 0.04);

    --text: #1a1a2e;
    --text-secondary: rgba(0, 0, 0, 0.5);
    --text-tertiary: rgba(0, 0, 0, 0.3);

    --accent: #6366f1;
    --accent-dim: rgba(99, 102, 241, 0.1);
    --success: #16a34a;
    --success-dim: rgba(22, 163, 74, 0.1);
    --warning: #d97706;
    --warning-dim: rgba(217, 119, 6, 0.08);
    --danger: #dc2626;
    --danger-dim: rgba(220, 38, 38, 0.08);

    --pin-dot-border: rgba(0, 0, 0, 0.18);
    --progress-track: rgba(0, 0, 0, 0.06);
    --overlay-bg: rgba(0, 0, 0, 0.3);
    --handle-bg: rgba(0, 0, 0, 0.12);
    --card-shadow: rgba(0, 0, 0, 0.06);
    --card-hover-border: rgba(0, 0, 0, 0.12);
    --scrollbar-thumb: rgba(0, 0, 0, 0.1);
    --input-bg: rgba(0, 0, 0, 0.02);
    --input-focus-bg: rgba(99, 102, 241, 0.05);
    --fab-shadow: rgba(99, 102, 241, 0.3);

    color-scheme: light;
}

/* Auto-detect system preference when no explicit theme is set */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) {
        --bg: #f4f4f8;
        --bg-elevated: #ffffff;
        --surface: rgba(0, 0, 0, 0.03);
        --surface-hover: rgba(0, 0, 0, 0.06);
        --border: rgba(0, 0, 0, 0.08);
        --border-light: rgba(0, 0, 0, 0.04);

        --text: #1a1a2e;
        --text-secondary: rgba(0, 0, 0, 0.5);
        --text-tertiary: rgba(0, 0, 0, 0.3);

        --accent: #6366f1;
        --accent-dim: rgba(99, 102, 241, 0.1);
        --success: #16a34a;
        --success-dim: rgba(22, 163, 74, 0.1);
        --warning: #d97706;
        --warning-dim: rgba(217, 119, 6, 0.08);
        --danger: #dc2626;
        --danger-dim: rgba(220, 38, 38, 0.08);

        --pin-dot-border: rgba(0, 0, 0, 0.18);
        --progress-track: rgba(0, 0, 0, 0.06);
        --overlay-bg: rgba(0, 0, 0, 0.3);
        --handle-bg: rgba(0, 0, 0, 0.12);
        --card-shadow: rgba(0, 0, 0, 0.06);
        --card-hover-border: rgba(0, 0, 0, 0.12);
        --scrollbar-thumb: rgba(0, 0, 0, 0.1);
        --input-bg: rgba(0, 0, 0, 0.02);
        --input-focus-bg: rgba(99, 102, 241, 0.05);
        --fab-shadow: rgba(99, 102, 241, 0.3);

        color-scheme: light;
    }
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    transition: background-color 0.3s ease, color 0.3s ease;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    font-feature-settings: 'cv01' 1, 'cv02' 1, 'ss01' 1;
    font-optical-sizing: auto;
    color: var(--text);
    background: var(--bg);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[x-cloak] { display: none !important; }

/* --- Loading Screen --- */
.loading-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    gap: 24px;
}

.loading-logo {
    font-size: 48px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -2px;
}

.loading-pulse {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--accent);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scaleX(0.6); }
    50% { opacity: 1; transform: scaleX(1); }
}

/* --- PIN Screen --- */
.pin-screen {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 20px;
}

.pin-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 320px;
}

.pin-logo {
    font-size: 56px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -3px;
    margin-bottom: 8px;
    user-select: none;
}

.pin-title {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.pin-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 16px;
}

.pin-dots {
    display: flex;
    gap: 16px;
    margin: 16px 0 8px;
}

.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--pin-dot-border);
    transition: all 0.2s var(--ease-out-expo);
}

.pin-dot.filled {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.15);
}

.pin-dots.shake {
    animation: shake 0.5s var(--ease-out-expo);
}

.pin-dots.shake .pin-dot.filled {
    background: var(--danger);
    border-color: var(--danger);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-12px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(4px); }
}

.pin-error {
    color: var(--danger);
    font-size: 13px;
    min-height: 20px;
}

.pin-keypad {
    display: grid;
    grid-template-columns: repeat(3, 72px);
    gap: 12px;
    margin-top: 12px;
}

.pin-key {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    color: var(--text);
    font-size: 24px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.pin-key:active:not(:disabled) {
    background: var(--accent-dim);
    transform: scale(0.92);
}

.pin-key--empty {
    background: transparent;
    pointer-events: none;
}

.pin-key--del {
    background: transparent;
    color: var(--text-secondary);
}

.pin-key--del:active {
    color: var(--text);
    background: transparent !important;
}

.pin-key:disabled {
    opacity: 0.3;
}

.pin-key-icon {
    display: flex;
    align-items: center;
}

.pin-hint {
    color: var(--text-tertiary);
    font-size: 12px;
    margin-top: 24px;
}

/* --- Readonly Badge --- */
.header-title-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.readonly-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    background: var(--warning-dim);
    color: var(--warning);
    white-space: nowrap;
    line-height: 1;
}

.readonly-badge svg {
    flex-shrink: 0;
}

.readonly-settings-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: var(--warning-dim);
    color: var(--warning);
    font-size: 13px;
    font-weight: 500;
}

.settings-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.5;
}

.readonly-pin-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.readonly-pin-status--active {
    color: var(--success);
}

/* --- App Shell --- */
.app {
    min-height: 100dvh;
    padding-bottom: calc(80px + var(--safe-bottom));
}

/* --- Header --- */
.header {
    padding: calc(var(--safe-top) + 16px) 16px 0;
    background: linear-gradient(180deg, var(--bg-elevated) 0%, transparent 100%);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.header-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Theme toggle: dark = show sun, light = show moon */
.btn-theme .icon-moon { display: none; }
.btn-theme .icon-sun { display: block; }

:root[data-theme="light"] .btn-theme .icon-sun { display: none; }
:root[data-theme="light"] .btn-theme .icon-moon { display: block; }

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) .btn-theme .icon-sun { display: none; }
    :root:not([data-theme="dark"]):not([data-theme="light"]) .btn-theme .icon-moon { display: block; }
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon:active {
    transform: scale(0.92);
    background: var(--surface-hover);
}

/* --- Summary Cards --- */
.summary-scroll {
    overflow-x: auto;
    margin: 0 -16px;
    padding: 0 16px 16px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.summary-scroll::-webkit-scrollbar { display: none; }

.summary-cards {
    display: flex;
    gap: 10px;
    min-width: min-content;
}

.summary-card {
    flex: 0 0 auto;
    min-width: 160px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 4px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.summary-card--primary {
    background: var(--accent-dim);
    border-color: rgba(129, 140, 248, 0.15);
}

.summary-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.summary-value {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.summary-card--primary .summary-value {
    color: var(--accent);
}

.summary-sub {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* --- Tabs --- */
.tabs {
    display: flex;
    padding: 4px 16px;
    gap: 4px;
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--bg);
}

.tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.25s var(--ease-out-expo);
    -webkit-tap-highlight-color: transparent;
}

.tab--active {
    background: var(--surface);
    color: var(--text);
}

.tab-badge {
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
    min-width: 20px;
    text-align: center;
}

.tab--active .tab-badge {
    background: var(--accent);
    color: var(--bg);
}

/* --- Credits List --- */
.credits-list {
    padding: 8px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* --- Credit Card --- */
.credit-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: transform 0.3s var(--ease-out-expo),
                box-shadow 0.3s var(--ease-out-expo),
                opacity 0.3s ease;

    /* Staggered entrance animation */
    opacity: 0;
    transform: translateY(16px);
    animation: card-enter 0.5s var(--ease-out-expo) forwards;
    animation-delay: var(--delay, 0s);
}

.credit-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--rate-color, var(--accent));
    border-radius: 3px 0 0 3px;
}

.credit-card--closed {
    opacity: 0.6;
}

.credit-card--closed::before {
    background: var(--success);
}

@keyframes card-enter {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (hover: hover) {
    .credit-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 32px var(--card-shadow);
        border-color: var(--card-hover-border);
    }
}

/* Card Header */
.credit-header {
    margin-bottom: 12px;
}

.credit-name-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.credit-name {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.credit-rate {
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.credit-status-row {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.credit-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.credit-badge--active {
    background: var(--accent-dim);
    color: var(--accent);
}

.credit-badge--closed {
    background: var(--success-dim);
    color: var(--success);
}

.credit-badge--mortgage {
    background: var(--warning-dim);
    color: var(--warning);
}

/* Card Body */
.credit-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.credit-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.credit-stat-label {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.credit-stat-value {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Progress Bar */
.credit-progress {
    margin-bottom: 4px;
}

.credit-progress-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--progress-track);
    overflow: hidden;
}

.credit-progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.8s var(--ease-out-expo);
    min-width: 2px;
}

.credit-progress-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-tertiary);
}

/* Card Actions */
.credit-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.credit-actions-right {
    display: flex;
    gap: 4px;
}

.credit-action {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.credit-action:active {
    transform: scale(0.93);
}

.credit-action:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.credit-action--active {
    background: var(--accent-dim);
    color: var(--accent);
}

.credit-action--success:hover {
    background: var(--success-dim);
    color: var(--success);
}

.credit-action--danger:hover {
    background: var(--danger-dim);
    color: var(--danger);
}

/* --- History Timeline --- */
.credit-history {
    overflow: hidden;
    border-top: 1px solid var(--border-light);
    margin-top: 10px;
    padding-top: 12px;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.history-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.history-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.history-form-actions {
    display: flex;
    gap: 8px;
}

/* Timeline */
.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 4px;
    bottom: 4px;
    width: 1px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 14px;
    display: flex;
    align-items: flex-start;
    gap: 0;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--text-tertiary);
    z-index: 1;
}

.timeline-item--created .timeline-dot { border-color: var(--accent); background: var(--accent-dim); }
.timeline-item--closed .timeline-dot { border-color: var(--success); background: var(--success-dim); }
.timeline-item--partial_payment .timeline-dot { border-color: var(--warning); background: var(--warning-dim); }
.timeline-item--rate_change .timeline-dot { border-color: #a78bfa; background: rgba(167, 139, 250, 0.12); }
.timeline-item--note .timeline-dot { border-color: var(--text-secondary); }

.timeline-content {
    flex: 1;
    min-width: 0;
}

.timeline-text {
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
    word-break: break-word;
}

.timeline-meta {
    display: flex;
    gap: 8px;
    margin-top: 2px;
}

.timeline-date, .timeline-type {
    font-size: 11px;
    color: var(--text-tertiary);
}

.timeline-type {
    padding: 0 6px;
    background: var(--surface);
    border-radius: 4px;
}

.timeline-delete {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.15s ease;
}

.timeline-item:hover .timeline-delete {
    opacity: 1;
}

.timeline-delete:hover {
    background: var(--danger-dim);
    color: var(--danger);
}

/* Mobile: always show delete */
@media (hover: none) {
    .timeline-delete { opacity: 0.5; }
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
    font-size: 14px;
}

/* --- FAB --- */
.fab {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px var(--fab-shadow);
    transition: all 0.2s var(--ease-out-expo);
    z-index: 60;
    -webkit-tap-highlight-color: transparent;
}

.fab:active {
    transform: scale(0.9);
}

@media (hover: hover) {
    .fab:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 30px var(--fab-shadow);
    }
}

/* --- Bottom Sheet / Modal --- */
.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 0;
}

.sheet {
    width: 100%;
    max-width: 480px;
    max-height: 90dvh;
    overflow-y: auto;
    background: var(--bg-elevated);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 12px 20px calc(20px + var(--safe-bottom));
    border: 1px solid var(--border);
    border-bottom: none;
}

.sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--handle-bg);
    margin: 0 auto 16px;
}

.sheet-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
    margin-bottom: 20px;
}

/* Desktop: center modal */
@media (min-width: 640px) {
    .sheet-overlay {
        align-items: center;
        padding: 20px;
    }

    .sheet {
        border-radius: var(--radius);
        border-bottom: 1px solid var(--border);
        max-height: 85vh;
        padding-bottom: 24px;
    }
}

/* --- Form Elements --- */
.sheet-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}

.form-input, .form-select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--input-bg);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s ease;
    outline: none;
    -webkit-appearance: none;
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.form-input:focus, .form-select:focus {
    border-color: var(--accent);
    background: var(--input-focus-bg);
}

.form-select {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-select option {
    background: var(--bg-elevated);
    color: var(--text);
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    user-select: none;
}

.form-checkbox input {
    display: none;
}

.form-checkbox-mark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 5px;
    flex-shrink: 0;
    transition: all 0.2s ease;
    position: relative;
}

.form-checkbox input:checked + .form-checkbox-mark {
    background: var(--accent);
    border-color: var(--accent);
}

.form-checkbox input:checked + .form-checkbox-mark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

/* --- Buttons --- */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    background: var(--surface);
    color: var(--text-secondary);
    flex: 1;
    text-align: center;
}

.btn--primary {
    background: var(--accent);
    color: white;
}

.btn--primary:active {
    background: #6366f1;
    transform: scale(0.97);
}

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

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

.btn:disabled {
    opacity: 0.4;
    pointer-events: none;
}

.btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: none;
    border-radius: var(--radius-xs);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-sm:active {
    transform: scale(0.95);
}

.btn-sm--primary {
    background: var(--accent-dim);
    color: var(--accent);
}

.btn-sm:disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* --- Settings --- */
.settings-section {
    padding: 16px 0;
    border-bottom: 1px solid var(--border-light);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-heading {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

.settings-section .form-group {
    margin-bottom: 10px;
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: calc(90px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 8px 30px var(--card-shadow);
    white-space: nowrap;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.toast--success { border-color: rgba(52, 211, 153, 0.3); }
.toast--error { border-color: rgba(248, 113, 113, 0.3); color: var(--danger); }

/* --- Transitions (Alpine.js) --- */
.transition-fade { transition: opacity 0.25s ease; }
.transition-fade-up { transition: all 0.35s var(--ease-out-expo); }
.transition-sheet-up { transition: transform 0.35s var(--ease-out-expo); }
.transition-slide-down { transition: all 0.3s var(--ease-out-expo); }
.transition-toast { transition: all 0.3s var(--ease-out-expo); }

.opacity-0 { opacity: 0; }
.opacity-1 { opacity: 1; }
.translate-up { transform: translateY(20px); }
.translate-0 { transform: translateY(0); }
.translate-sheet-down { transform: translateY(100%); }
.translate-toast-down { transform: translateX(-50%) translateY(20px); }
.max-h-0 { max-height: 0; overflow: hidden; }
.max-h-full { max-height: 1200px; }

/* --- Desktop Layout --- */
@media (min-width: 768px) {
    .credits-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
        gap: 12px;
        max-width: 1100px;
        margin: 0 auto;
        padding: 12px 24px 24px;
    }

    .header {
        padding-left: 24px;
        padding-right: 24px;
        max-width: 1148px;
        margin: 0 auto;
    }

    .tabs {
        padding: 4px 24px;
        max-width: 1148px;
        margin: 0 auto;
    }

    .summary-scroll {
        margin: 0 -24px;
        padding: 0 24px 16px;
    }

    .summary-card {
        min-width: 180px;
    }

    .credit-stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .summary-cards {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        width: 100%;
    }

    .summary-card {
        min-width: auto;
    }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 2px;
}

/* --- Selection --- */
::selection {
    background: var(--accent-dim);
    color: var(--text);
}

/* --- Light Theme card refinements --- */
:root[data-theme="light"] .credit-card,
:root[data-theme="light"] .summary-card,
:root[data-theme="light"] .sheet {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
}

:root[data-theme="light"] .credit-card--closed {
    opacity: 0.7;
}

:root[data-theme="light"] .fab {
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.25);
}

:root[data-theme="light"] .toast {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) .credit-card,
    :root:not([data-theme="dark"]):not([data-theme="light"]) .summary-card,
    :root:not([data-theme="dark"]):not([data-theme="light"]) .sheet {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
    }

    :root:not([data-theme="dark"]):not([data-theme="light"]) .credit-card--closed {
        opacity: 0.7;
    }

    :root:not([data-theme="dark"]):not([data-theme="light"]) .fab {
        box-shadow: 0 4px 16px rgba(99, 102, 241, 0.25);
    }

    :root:not([data-theme="dark"]):not([data-theme="light"]) .toast {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    }
}

/* --- Number input arrows removal --- */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}
