/* ============================================================
   app.css — application-level component styles
   Extracted from index.html's inline <style> block.
   Loads after layout.css, before utilities.css and overrides.css,
   so overrides.css wins by cascade order alone (no !important needed).
   ============================================================ */

/* Header */
.header {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

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

.header h1 {
    color: var(--dark);
    font-size: 32px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Person selector */
.person-selector {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--light);
    padding: 6px;
    border-radius: 12px;
}

.person-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    background: transparent;
    color: var(--gray);
    display: flex;
    align-items: center;
    gap: 8px;
}

.person-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.person-btn.couple.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--white);
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 40px rgba(0,0,0,0.12);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
}

.stat-card .icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: 12px;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.stat-card .label {
    color: var(--gray);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-card .value {
    color: var(--dark);
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-card .change {
    font-size: 13px;
    color: var(--success);
    font-weight: 600;
}

.stat-card .sublabel {
    font-size: 11px;
    color: var(--gray);
    margin-top: 8px;
}

/* Tabs */
.tabs {
    background: var(--surface);
    border-radius: 12px;
    padding: 8px;
    margin-bottom: 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

.tab {
    padding: 12px 24px;
    border: none;
    background: transparent;
    color: var(--gray);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab.active {
    background: var(--primary);
    color: var(--white);
}

/* Content area */
.content-area {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    min-height: 400px;
}

.content-section {
    display: none;
}

.content-section.active {
    display: block;
}

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

.section-title {
    color: var(--dark);
    font-size: 24px;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

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

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s;
}

.btn-icon:hover {
    background: var(--light);
    transform: scale(1.1);
}

/* Repeated btn-success / btn-danger with explicit border/padding (from cards section) */
.btn-success {
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-danger {
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-secondary {
    background: #64748b;
}

.btn-secondary:hover {
    background: #475569;
}

/* Investment cards */
.investment-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    gap: 16px;
    align-items: stretch;
}

.investment-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    background: var(--surface);
}

.investment-card:hover {
    border-color: var(--primary-accent);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.investment-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.investment-title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 12px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.investment-title .investment-name {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 20px;
    line-height: 1.2;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.01em;
}

.investment-title .investment-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.investment-meta {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}

.investment-meta .sep {
    color: var(--text-subtle);
    user-select: none;
}

.investment-badge {
    padding: 4px 8px;
    border-radius: var(--r-sm);
    font-size: 11px;
    font-weight: 600;
    background: var(--surface-muted);
    color: var(--text-muted);
    white-space: nowrap;
}

.investment-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.detail-item {
    padding: 8px 10px;
    background: var(--surface-muted);
    border-radius: var(--r-sm);
}

.detail-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.detail-value.positive { color: var(--success); }
.detail-value.negative { color: var(--danger); }

.investment-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    justify-content: flex-start;
}

.investment-actions .action-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.investment-actions .action-group--secondary {
    margin-left: auto;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    margin-bottom: 24px;
}

.modal-title {
    color: var(--dark);
    font-size: 24px;
    font-weight: 600;
}

/* Forms */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    color: var(--dark);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s;
}

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

textarea.form-input {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Charts */
.chart-container {
    margin-top: 24px;
    padding: 20px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    background: var(--surface);
}

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

.chart-title {
    color: var(--dark);
    font-size: 18px;
    font-weight: 600;
}

.chart-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--gray);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.chart {
    height: 300px;
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chart-bar {
    flex: 1;
    background: linear-gradient(to top, var(--primary), var(--info));
    border-radius: 4px 4px 0 0;
    position: relative;
    transition: all 0.3s;
    cursor: pointer;
}

.chart-bar:hover {
    opacity: 0.8;
    transform: translateY(-4px);
}

.chart-bar::after {
    content: attr(data-label);
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--gray);
    white-space: nowrap;
}

.chart-bar::before {
    content: attr(data-value);
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-weight: 600;
    color: var(--dark);
    white-space: nowrap;
}

/* Cashflow timeline */
.cashflow-timeline {
    margin-top: 24px;
    padding: 20px;
    background: var(--light);
    border-radius: 12px;
    overflow-x: auto;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.timeline-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--dark);
}

.timeline-grid {
    display: grid;
    grid-template-columns: 120px repeat(12, minmax(100px, 1fr));
    gap: 8px;
    min-width: 800px;
}

.timeline-row {
    display: contents;
}

.timeline-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--dark);
    padding: 8px;
    background: var(--surface);
    border-radius: 6px;
    display: flex;
    align-items: center;
}

.timeline-cell {
    padding: 8px;
    background: var(--surface);
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
    transition: all 0.3s;
}

.timeline-cell.positive {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    font-weight: 600;
}

.timeline-cell.negative {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    font-weight: 600;
}

.timeline-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Liquidity */
.liquidity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.liquidity-card {
    background: linear-gradient(135deg, var(--surface-muted) 0%, var(--surface) 100%);
    border-radius: 12px;
    padding: 20px;
    border: 2px solid #e5e7eb;
}

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

.liquidity-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--dark);
}

.liquidity-amount {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

.liquidity-items {
    display: grid;
    gap: 8px;
}

.liquidity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: var(--surface);
    border-radius: 6px;
    font-size: 13px;
}

.liquidity-item-name {
    color: var(--gray);
}

.liquidity-item-value {
    font-weight: 600;
    color: var(--dark);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--gray);
}

.empty-icon {
    font-size: 64px;
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-text {
    margin-bottom: 20px;
    font-size: 16px;
}

/* Setup (inline on index.html's setup container, separate from setup.html) */
.setup-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 8px;
    text-align: center;
}

.setup-subtitle {
    font-size: 16px;
    color: var(--gray);
    text-align: center;
    margin-bottom: 32px;
}

.person-form {
    padding: 24px;
    background: var(--light);
    border-radius: 12px;
    margin-bottom: 20px;
}

.person-form-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Credit cards and bills */
#creditCardsList {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
    align-items: stretch;
}

.card-item,
.bill-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.card-item:hover,
.bill-item:hover {
    border-color: var(--primary-accent);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.bills-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
    align-items: stretch;
}

/* Tooltips */
.tooltip {
    position: relative;
    cursor: help;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: var(--dark);
    color: var(--white);
    font-size: 12px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    margin-bottom: 8px;
}

.tooltip:hover::after {
    opacity: 1;
}

/* Progress ring */
.progress-ring {
    width: 120px;
    height: 120px;
    margin: 20px auto;
}

.progress-ring-circle {
    stroke: var(--primary);
    stroke-width: 8;
    fill: none;
    stroke-dasharray: 339.292;
    stroke-dashoffset: 339.292;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 1s ease-in-out;
}

.progress-ring-bg {
    stroke: var(--light);
    stroke-width: 8;
    fill: none;
}

.progress-ring-text {
    font-size: 24px;
    font-weight: 700;
    fill: var(--dark);
    text-anchor: middle;
    alignment-baseline: middle;
}

/* Screenshot upload */
.screenshot-upload-area {
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: #f8fafc;
}

.screenshot-upload-area:hover {
    border-color: #6366f1;
    background: #f1f5f9;
}

.screenshot-upload-area.has-file {
    border-color: #10b981;
    background: #f0fdf4;
}

/* Spinner */
.spinner {
    border: 3px solid #f3f4f6;
    border-top: 3px solid #6366f1;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: spin 1s linear infinite;
}

/* Animations */
@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.fade-in {
    animation: slideIn 0.5s ease-out;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: var(--white);
    animation: spin 1s ease-in-out infinite;
}

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

/* Responsive — consolidated to 640px to match the design system breakpoint */
@media (max-width: 640px) {
    .header-top {
        flex-direction: column;
        align-items: flex-start;
    }

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

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

    .form-row {
        grid-template-columns: 1fr;
    }

    .tabs {
        overflow-x: auto;
    }
}
