/* ============================================
   Savings Page — Restructured Layout
   ============================================ */

/* ── Summary Bar (full-width KPI strip) ── */
.savings-summary-bar {
    margin-bottom: var(--spacing-lg);
    text-align: center;
}

.savings-summary-month {
    color: var(--text-primary);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-lg);
    margin: 0 0 var(--spacing-md) 0;
    letter-spacing: 0.3px;
}

.savings-kpi-row {
    display: flex;
    justify-content: center;
    gap: var(--spacing-xl);
    flex-wrap: wrap;
}

.savings-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: 10px;
    min-width: 140px;
}

.savings-kpi--highlight {
    background-color: rgba(180, 100, 255, 0.08);
    border: 1px solid rgba(180, 100, 255, 0.2);
}

.savings-kpi-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.savings-kpi-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: var(--line-height-tight);
}

/* Monthly Savings KPI - Red for negative, Green for positive */
.savings-kpi:first-child .savings-kpi-value {
    color: var(--brand-red);
}

.savings-kpi:first-child .savings-kpi-value.positive {
    color: var(--brand-green);
}

/* Available to Allocate KPI - Purple highlight */
.savings-kpi.savings-kpi--highlight .savings-kpi-value {
    color: var(--brand-purple);
}

/* Already Allocated KPI - Green */
.savings-kpi:last-child .savings-kpi-value {
    color: var(--brand-green);
}

/* ── Section Headers (shared across all savings cards) ── */
.savings-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.savings-section-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.savings-auto-allocate-btn {
    font-size: 0.875rem;
    white-space: nowrap;
    background-color: rgba(180, 100, 255, 0.1);
    border: 1px solid var(--brand-purple);
    color: var(--brand-purple);
    transition: all 0.2s ease;
}

.savings-auto-allocate-btn:hover {
    background-color: var(--brand-purple);
    border-color: var(--brand-purple);
    color: white;
}

.savings-section-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    position: relative;
    padding-left: 12px;
}

.savings-section-title::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 16px;
    background: linear-gradient(180deg, var(--brand-purple) 0%, var(--brand-purple-hover) 100%);
    border-radius: 2px;
}

/* Amount to allocate inside Allocate to Goals card — same style as summary bar KPI */
.savings-allocation-card-amount-row {
    margin-bottom: var(--spacing-md);
    text-align: center;
}
.savings-allocation-card-amount-row.savings-kpi {
    min-width: unset;
    width: 100%;
}

.savings-section-subtitle {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin: calc(-1 * var(--spacing-xs)) 0 var(--spacing-md) 0;
}

.savings-help-btn {
    background: none;
    border: none;
    color: var(--brand-purple);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s, background-color 0.15s;
}

.savings-help-btn:hover {
    color: var(--brand-purple-hover);
    background-color: var(--bg-hover);
}

/* ── Desktop Two-Column Layout (Option B: left = charts 7/12, right = allocation 5/12) ── */
@media (min-width: 992px) {
    .savings-sections-row {
        display: flex;
        gap: var(--spacing-lg);
        align-items: stretch;
    }

    .savings-left-col,
    .savings-charts-col {
        flex: 7;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: var(--spacing-lg);
    }

    .savings-right-col {
        flex: 5;
        min-width: 0;
        display: flex;
        flex-direction: column;
    }

    .savings-goals-list {
        flex: 1;
        overflow-y: auto;
        padding-right: var(--spacing-xs);
    }

    .savings-goals-list::-webkit-scrollbar {
        width: 4px;
    }
    .savings-goals-list::-webkit-scrollbar-thumb {
        background: var(--border-secondary);
        border-radius: 2px;
    }

    .savings-allocation-content {
        flex: 1;
        display: flex;
        flex-direction: column;
    }
}

/* ── Mobile / Tablet: Stack ── */
@media (max-width: 991px) {
    .savings-sections-row {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-lg);
    }

    .savings-right-col {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-lg);
    }

    .savings-goals-list {
        overflow-y: auto;
    }
}

/* ── Allocation Section (parent card) ── */
.savings-allocation-section {
    background-color: var(--bg-secondary) !important;
    border-left: 3px solid var(--brand-purple);
}

/* Info icons - brand purple */
.savings-kpi i,
.savings-kpi svg,
.savings-section-header i,
.savings-section-header svg {
    color: var(--brand-purple);
}

/* Positive/negative amount indicators */
.amount-positive {
    color: var(--brand-green) !important;
}

.amount-negative {
    color: var(--brand-red) !important;
}

.amount-neutral {
    color: var(--brand-purple) !important;
}

/* ── Allocation Goal Cards ── */
.savings-goals-list {
    padding: var(--spacing-sm) 0;
}

.allocation-goal-card {
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border-ui) !important;
    border-radius: 0;
    transition: all 0.15s ease;
    box-shadow: none;
}

.allocation-goal-card:hover {
    border-color: var(--brand-purple) !important;
    box-shadow: 0 0 0 1px rgba(180, 100, 255, 0.2) !important;
}

.allocation-input {
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border-ui) !important;
    color: var(--text-primary) !important;
    border-radius: 8px !important;
    transition: all 0.15s ease !important;
    font-size: var(--font-size-sm) !important;
}

.allocation-input:focus {
    border-color: var(--brand-purple) !important;
    box-shadow: 0 0 0 2px rgba(180, 100, 255, 0.15) !important;
    background-color: var(--bg-secondary) !important;
    outline: none !important;
}

.allocation-input::placeholder {
    color: var(--text-secondary) !important;
}

/* ── Goal Card Internal Layout ── */
.goal-card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-ui);
    border-radius: 0;
    padding: var(--card-padding);
    position: relative;
    transition: border-color 0.2s ease;
}

.goal-card:hover {
    border-color: var(--brand-purple);
    box-shadow: 0 2px 8px rgba(180, 100, 255, 0.12);
}

/* Delete/Archive buttons */
.goal-card .btn-danger,
.goal-card .btn-outline-danger {
    background-color: rgba(220, 38, 38, 0.1);
    border-color: var(--brand-red);
    color: var(--brand-red);
}

.goal-card .btn-danger:hover,
.goal-card .btn-outline-danger:hover {
    background-color: var(--brand-red);
    border-color: var(--brand-red);
    color: white;
}

/* Edit/Configure buttons */
.goal-card .btn-primary,
.goal-card .btn-outline-primary {
    background-color: rgba(180, 100, 255, 0.1);
    border-color: var(--brand-purple);
    color: var(--brand-purple);
}

.goal-card .btn-primary:hover,
.goal-card .btn-outline-primary:hover {
    background-color: var(--brand-purple);
    border-color: var(--brand-purple);
    color: white;
}

/* Success/Confirm buttons */
.goal-card .btn-success,
.goal-card .btn-outline-success {
    background-color: rgba(5, 150, 105, 0.1);
    border-color: var(--brand-green);
    color: var(--brand-green);
}

.goal-card .btn-success:hover,
.goal-card .btn-outline-success:hover {
    background-color: var(--brand-green);
    border-color: var(--brand-green);
    color: white;
}

.goal-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 0;
    font-size: 0.65rem;
    font-weight: var(--font-weight-semibold);
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.goal-status-badge--at-risk {
    background-color: rgba(220, 38, 38, 0.15);
    color: var(--brand-red);
}

.goal-status-badge--on-track {
    background-color: rgba(5, 150, 105, 0.15);
    color: var(--brand-green);
}

.goal-status-badge--completed {
    background-color: rgba(5, 150, 105, 0.15);
    color: var(--brand-green);
}

.goal-status-badge--overdue {
    background-color: rgba(220, 38, 38, 0.15);
    color: var(--brand-red);
}

.goal-status-badge--ongoing {
    background-color: rgba(180, 100, 255, 0.15);
    color: var(--brand-purple);
}

.goal-progress-bar {
    height: 8px;
    border-radius: 4px;
    background-color: rgba(180, 100, 255, 0.15);
    overflow: hidden;
}

.goal-progress-bar .progress-bar {
    background: linear-gradient(90deg, var(--brand-purple) 0%, var(--brand-purple-hover) 100%);
}

.goal-progress-bar .progress-bar.completed {
    background: linear-gradient(90deg, var(--brand-green) 0%, var(--brand-green-hover) 100%);
}

.goal-progress-bar .progress-bar.at-risk {
    background: linear-gradient(90deg, var(--brand-red) 0%, var(--brand-red-hover) 100%);
}

/* ── Registered Account Cards ── */
.registered-account-card {
    padding: 0.75rem;
    border: 1px solid var(--border-ui);
    border-radius: 0;
    background-color: var(--bg-primary);
    position: relative;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    min-height: 100%;
}

.registered-account-card--configured::before {
    content: "";
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 2px;
    background: var(--account-color, var(--brand-green));
}

.registered-account-card--unconfigured {
    background-color: var(--bg-secondary);
}

.registered-account-card--unconfigured::before {
    content: "";
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 2px;
    background: var(--account-color, var(--brand-red));
}

.registered-account-card--untracked {
    opacity: 0.8;
}

.registered-account-card--untracked.registered-account-card--ineligible {
    opacity: 0.6;
}

.registered-account-card:hover {
    box-shadow: var(--card-hover-shadow);
}

.account-balance-badge {
    font-weight: var(--font-weight-medium);
    font-size: 0.85rem;
    color: var(--brand-green);
    background-color: rgba(5, 150, 105, 0.15);
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.account-balance-badge.negative {
    color: var(--brand-red);
    background-color: rgba(220, 38, 38, 0.15);
}

/* ── Save Button (standard Bootstrap primary) ── */
.savings-save-row {
    display: flex;
    justify-content: center;
    padding-top: var(--spacing-md);
}

#save-allocations-button {
    background: linear-gradient(135deg, var(--brand-purple) 0%, var(--brand-purple-hover) 100%);
    border-color: var(--brand-purple);
    color: white;
    font-weight: var(--font-weight-semibold);
    transition: all 0.2s ease;
}

#save-allocations-button:hover {
    background: linear-gradient(135deg, var(--brand-purple-hover) 0%, var(--brand-purple-active) 100%);
    border-color: var(--brand-purple-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(180, 100, 255, 0.3);
}

#save-allocations-button:active {
    transform: translateY(0);
}

#save-allocations-button:disabled {
    background: var(--bg-quaternary);
    border-color: var(--border-ui);
    color: var(--text-muted);
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Goal Status & Time Charts ── */
.savings-goal-status-card,
.savings-time-chart-card {
    margin-bottom: 0;
}

.savings-time-chart-card {
    margin-top: 0;
}

.savings-accounts-card {
    margin-bottom: var(--spacing-lg);
    margin-top: 0;
}

/* ── Mobile Optimizations ── */
@media (max-width: 768px) {
    /* Goal Status heatmap: ensure horizontal scroll (card uses .heatmap-scrollable from chart_generation) */
    .savings-goal-status-card .heatmap-scrollable,
    .savings-goal-status-card #savings-goal-status-card-content .heatmap-scrollable {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* Savings Over Time chart: prevent compression on mobile tap (flex + chart-active was causing shrink) */
    .savings-time-chart-card {
        min-height: 420px !important;
    }
    .savings-time-chart-card #savings-time-bar-chart-wrap,
    .savings-time-chart-card .chart-animate-wrap {
        min-height: 350px !important;
        flex: none !important;
    }
    .savings-time-chart-card .dash-graph {
        min-height: 350px !important;
        flex: none !important;
    }

    .savings-kpi-row {
        gap: var(--spacing-sm);
    }

    .savings-kpi {
        min-width: 100px;
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    .savings-kpi-value {
        font-size: var(--font-size-xl);
    }

    .savings-section-title {
        font-size: var(--font-size-base);
    }

    #save-allocations-button {
        width: 100% !important;
    }

    .card-title {
        font-size: 1.1rem !important;
        margin-bottom: 0.5rem !important;
    }

    .card-text {
        font-size: 0.875rem !important;
    }

    .card-body p {
        font-size: 0.875rem !important;
        margin-bottom: 0.5rem !important;
    }

    .card-body label {
        font-size: 0.875rem !important;
        margin-bottom: 0.25rem !important;
    }

    .allocation-input {
        font-size: 0.875rem !important;
        padding: 0.375rem 0.5rem !important;
        height: auto !important;
    }

    .progress {
        height: 0.75rem !important;
        margin-bottom: 0.5rem !important;
    }

    .metric-card .card-body {
        padding: 0.75rem !important;
    }
}

@media (max-width: 576px) {
    .savings-kpi-row {
        flex-direction: column;
        align-items: center;
        gap: var(--spacing-xs);
    }

    .savings-kpi {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        padding: var(--spacing-xs) var(--spacing-md);
        border-bottom: 1px solid var(--border-subtle);
    }

    .savings-kpi:last-child {
        border-bottom: none;
    }

    .savings-kpi--highlight {
        border-radius: 6px;
    }

    /* Stack goal card columns vertically */
    .card-body .row .col-4 {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 0.75rem !important;
    }

    .card-body .row .col-4 > * {
        text-align: center !important;
    }

    .card-body .row .g-0.align-items-center {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        gap: 0.5rem !important;
    }

    .card-body .row .g-0 .col-8 {
        flex: 1 !important;
        width: auto !important;
        max-width: 70% !important;
    }

    .card-body .row .g-0 .col-4 {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: 25% !important;
    }

    #save-allocations-button {
        width: 100% !important;
        display: block !important;
    }
}

/* ── Transaction Allocation Rows ── */
.transaction-row {
    transition: background-color 0.15s ease;
}

@media (max-width: 768px) {
    .transaction-row {
        display: flex !important;
        flex-wrap: wrap !important;
        padding: 0.75rem !important;
        gap: 0.5rem !important;
        align-items: center !important;
        font-size: 0.875rem !important;
    }

    .transaction-row > div:nth-child(1) {
        display: none !important;
    }

    .transaction-row > div:nth-child(3) {
        order: 1 !important;
        flex: 0 0 100% !important;
        width: 100% !important;
        margin-bottom: 0.25rem !important;
    }

    .transaction-row > div:nth-child(3) > div > div {
        display: inline !important;
    }

    .transaction-row > div:nth-child(3) > div > div:first-child {
        font-size: 0.95rem !important;
        display: inline !important;
        margin-right: 0.5rem !important;
    }

    .transaction-row > div:nth-child(3) > div > div:last-child {
        font-size: 0.85rem !important;
        display: inline !important;
    }

    .transaction-row > div:nth-child(3) > div > div:last-child::before {
        content: "- " !important;
        color: var(--text-slate) !important;
    }

    .transaction-row > div:nth-child(2) {
        order: 2 !important;
        flex: 0 0 auto !important;
    }

    .transaction-row > div:nth-child(2) > div {
        font-size: 0.8rem !important;
        color: var(--text-slate) !important;
    }

    .transaction-row > div:nth-child(4) {
        order: 3 !important;
        flex: 0 0 auto !important;
        margin-left: 0.5rem !important;
    }

    .transaction-row > div:nth-child(4) > div {
        font-size: 0.95rem !important;
        font-weight: bold !important;
    }

    .transaction-row > div:nth-child(5) {
        order: 4 !important;
        flex: 1 !important;
        min-width: 120px !important;
        max-width: 100% !important;
        margin-left: auto !important;
    }

    .transaction-row > div:nth-child(5) > div:first-child {
        display: none !important;
    }

    .transaction-row .Select-control,
    .transaction-row .Select__control,
    .transaction-row select,
    .transaction-row .dropdown,
    .transaction-row dcc-dropdown {
        font-size: 0.75rem !important;
        min-height: 32px !important;
        padding: 0.25rem 0.5rem !important;
        min-width: 120px !important;
        width: 100% !important;
    }

    .transaction-row [id*="transaction-allocation-dropdown"] {
        width: 100% !important;
        min-width: 120px !important;
        max-width: 100% !important;
    }

    .transaction-row > div:nth-child(5) > div:last-child {
        width: 100% !important;
        min-width: 120px !important;
        max-width: 100% !important;
    }

    #savings-transactions-container h5 {
        font-size: 1rem !important;
        margin-bottom: 0.75rem !important;
    }

    #savings-transactions-container p {
        font-size: 0.75rem !important;
        margin-bottom: 0.75rem !important;
    }
}

/* ── Tablet ── */
@media (min-width: 769px) and (max-width: 1024px) {
    .card-title { font-size: 1.25rem !important; }
    .card-text, .card-body p, .card-body label { font-size: 0.9rem !important; }
    .transaction-row { font-size: 0.9rem !important; }
}
