/* ============================================================
   BUDGETS — PREMIUM DASHBOARD  (scoped to #budgets-page)
   Uses global theme vars: --surface, --primary, --text,
   --text-muted, --border, --shadow, --radius, --success
   ============================================================ */

#budgets-page {
    --b-primary: var(--primary, #4A6CF7);
    --b-primary-2: #6C5CE7;
    --b-success: var(--success, #22c55e);
    --b-danger: #ef4444;
    --b-warn: #f59e0b;
    --b-border: var(--border, rgba(0,0,0,0.08));
    --b-radius: 18px;
    --b-radius-sm: 12px;
    --b-gap: 18px;

    display: flex;
    flex-direction: column;
    gap: var(--b-gap);
    padding: 8px 0 36px;
}

/* ---------------- HERO ---------------- */
#budgets-page .bg-hero {
    position: relative;
    overflow: hidden;
    border-radius: 22px;
    padding: 28px;
    background: linear-gradient(135deg, #4A6CF7 0%, #6C5CE7 55%, #8B5CF6 100%);
    box-shadow: 0 14px 40px rgba(74,108,247,0.28);
}

#budgets-page .bg-hero-glow {
    position: absolute;
    top: -90px; right: -50px;
    width: 300px; height: 300px;
    background: radial-gradient(circle, rgba(255,255,255,0.32) 0%, rgba(255,255,255,0) 70%);
    pointer-events: none;
}

#budgets-page .bg-hero-inner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

#budgets-page .bg-eyebrow {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    color: rgba(255,255,255,0.82);
    margin-bottom: 6px;
}

#budgets-page .bg-hero-text h1 {
    margin: 0;
    color: #fff;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

#budgets-page .bg-hero-text p {
    margin: 6px 0 0;
    color: rgba(255,255,255,0.9);
    font-size: 0.92rem;
}

/* ---------------- BUTTONS ---------------- */
#budgets-page .bg-btn,
#budgets-page .btn-action {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}

#budgets-page .bg-btn-light {
    background: #fff;
    color: var(--b-primary);
    box-shadow: 0 6px 18px rgba(0,0,0,0.14);
}
#budgets-page .bg-btn-light:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0,0,0,0.2); }

#budgets-page .bg-btn-primary {
    background: var(--b-primary);
    color: #fff;
    box-shadow: 0 6px 16px rgba(74,108,247,0.3);
}
#budgets-page .bg-btn-primary:hover { transform: translateY(-1px); background: var(--primary-hover, #3A56C9); }

#budgets-page .btn-icon { font-size: 1rem; line-height: 1; }

/* ---------------- SUMMARY KPIs ---------------- */
#budgets-page .budgets-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--b-gap);
}

#budgets-page .summary-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius);
    padding: 16px 18px;
    box-shadow: var(--shadow, 0 4px 20px rgba(0,0,0,0.05));
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#budgets-page .summary-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,0.1); }
#budgets-page .summary-card.empty { grid-column: span 3; }

#budgets-page .summary-ico {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    border-radius: 13px;
    display: grid; place-items: center;
    font-size: 1.25rem;
    background: color-mix(in srgb, var(--b-primary) 12%, transparent);
}
#budgets-page .ico-income  { background: color-mix(in srgb, var(--b-success) 16%, transparent); }
#budgets-page .ico-expense { background: color-mix(in srgb, var(--b-danger) 16%, transparent); }
#budgets-page .ico-limit   { background: color-mix(in srgb, #8b5cf6 16%, transparent); }

#budgets-page .summary-body { display: flex; flex-direction: column; min-width: 0; }
#budgets-page .summary-label { font-size: 0.76rem; color: var(--text-muted); font-weight: 500; }
#budgets-page .summary-value {
    font-size: 1.3rem; font-weight: 700; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#budgets-page .summary-value.positive { color: var(--b-success); }
#budgets-page .summary-value.negative { color: var(--b-danger); }

/* ---------------- MAIN GRID ---------------- */
#budgets-page .budgets-main-grid {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: var(--b-gap);
    align-items: start;
}
#budgets-page .budgets-left,
#budgets-page .budgets-right { display: flex; flex-direction: column; gap: var(--b-gap); min-width: 0; }

/* ---------------- CARDS ---------------- */
#budgets-page .budget-list-card,
#budgets-page .budget-details-card,
#budgets-page .chart-card,
#budgets-page .insights-card {
    background: var(--surface);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius);
    padding: 20px;
    box-shadow: var(--shadow, 0 4px 20px rgba(0,0,0,0.05));
}

#budgets-page .section-title {
    margin: 0 0 14px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

/* ---------------- BUDGET LIST ---------------- */
#budgets-page .budget-list { display: flex; flex-direction: column; gap: 10px; }

#budgets-page .budget-list-item {
    width: 100%;
    text-align: left;
    background: color-mix(in srgb, var(--b-primary) 3%, var(--surface));
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-sm);
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
#budgets-page .budget-list-item:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--b-primary) 40%, transparent);
    box-shadow: 0 8px 20px rgba(74,108,247,0.1);
}
#budgets-page .budget-list-item.selected {
    border-color: var(--b-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--b-primary) 30%, transparent);
    background: color-mix(in srgb, var(--b-primary) 8%, var(--surface));
}

#budgets-page .budget-list-main {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px;
}
#budgets-page .budget-list-name { font-weight: 700; color: var(--text); font-size: 0.96rem; }
#budgets-page .budget-list-pill {
    font-size: 0.72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
    background: color-mix(in srgb, var(--b-primary) 14%, transparent); color: var(--b-primary);
}
#budgets-page .budget-list-pill.high { background: color-mix(in srgb, var(--b-danger) 16%, transparent); color: var(--b-danger); }

#budgets-page .budget-list-progress { display: flex; align-items: center; gap: 10px; }
#budgets-page .progress-bar {
    flex: 1; height: 8px; border-radius: 999px;
    background: color-mix(in srgb, var(--text-muted) 18%, transparent); overflow: hidden;
}
#budgets-page .progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--b-primary), var(--b-primary-2)); transition: width 0.5s ease; }
#budgets-page .progress-fill.high { background: linear-gradient(90deg, #f59e0b, var(--b-danger)); }
#budgets-page .progress-label { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

/* ---------------- DETAILS ---------------- */
#budgets-page .budget-details-header {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px;
}
#budgets-page .budget-details-header .section-title { margin-bottom: 2px; }
#budgets-page .budget-details-subtitle { margin: 0; font-size: 0.8rem; color: var(--text-muted); }
#budgets-page .budget-details-actions { display: flex; gap: 8px; flex-shrink: 0; }

#budgets-page .btn-action {
    background: var(--surface); border: 1px solid var(--b-border); color: var(--text);
    padding: 7px 12px; font-size: 0.8rem;
}
#budgets-page .btn-action.edit-btn:hover { border-color: var(--b-primary); color: var(--b-primary); }
#budgets-page .btn-action.delete-btn:hover { border-color: var(--b-danger); color: var(--b-danger); }

#budgets-page #budget-details-summary {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px;
    padding: 16px; margin-bottom: 18px;
    border-radius: var(--b-radius-sm);
    background: color-mix(in srgb, var(--b-primary) 4%, var(--surface));
    border: 1px solid var(--b-border);
}
#budgets-page .summary-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#budgets-page .summary-row .label { font-size: 0.8rem; color: var(--text-muted); }
#budgets-page .summary-row .value { font-size: 0.92rem; font-weight: 700; color: var(--text); }
#budgets-page .summary-row .value.negative { color: var(--b-danger); }
#budgets-page .progress-text.high { color: var(--b-danger); }
#budgets-page .progress-text.normal { color: var(--b-success); }

/* ---------------- INCOME ALLOCATIONS ---------------- */
#budgets-page .income-allocation-section { margin-bottom: 20px; }
#budgets-page .income-allocation-section .section-title { margin-bottom: 2px; font-size: 0.98rem; }
#budgets-page .allocation-subtitle { margin: 0 0 12px; font-size: 0.78rem; color: var(--text-muted); }
#budgets-page .allocation-summary {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
    padding: 12px 14px; margin-bottom: 12px;
    border-radius: var(--b-radius-sm);
    background: color-mix(in srgb, var(--b-success) 7%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--b-success) 20%, transparent);
}
#budgets-page .allocation-summary .summary-row { flex-direction: column; align-items: flex-start; gap: 2px; }
#budgets-page .allocation-list { display: flex; flex-direction: column; gap: 8px; }
#budgets-page .allocation-item {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 14px; border-radius: var(--b-radius-sm);
    background: var(--surface); border: 1px solid var(--b-border);
}
#budgets-page .allocation-income-name { font-weight: 600; color: var(--text); font-size: 0.88rem; }
#budgets-page .allocation-percentage { font-size: 0.74rem; color: var(--text-muted); }
#budgets-page .allocation-amount { font-weight: 700; color: var(--b-primary); }

#budgets-page .allocation-warning {
    margin-top: 12px; padding: 10px 14px; border-radius: var(--b-radius-sm);
    font-size: 0.82rem; font-weight: 500;
}
#budgets-page .allocation-warning.underfunded { background: color-mix(in srgb, var(--b-warn) 12%, transparent); color: #b45309; border: 1px solid color-mix(in srgb, var(--b-warn) 30%, transparent); }
#budgets-page .allocation-warning.overfunded { background: color-mix(in srgb, var(--b-primary) 10%, transparent); color: var(--b-primary); border: 1px solid color-mix(in srgb, var(--b-primary) 28%, transparent); }
#budgets-page .text-warning { color: var(--b-warn) !important; }
#budgets-page .income-allocation-section.empty { padding: 14px; border-radius: var(--b-radius-sm); background: color-mix(in srgb, var(--b-warn) 8%, transparent); border: 1px dashed color-mix(in srgb, var(--b-warn) 35%, transparent); }

/* ---------------- CATEGORY BUDGETS ---------------- */
#budgets-page .category-header-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px;
}
#budgets-page .category-header-left .section-title { margin-bottom: 2px; font-size: 0.98rem; }
#budgets-page .category-subtitle { font-size: 0.76rem; color: var(--text-muted); }

#budgets-page .category-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px;
}

#budgets-page .category-card {
    display: flex; flex-direction: column; gap: 12px;
    padding: 14px; border-radius: var(--b-radius-sm);
    background: var(--surface); border: 1px solid var(--b-border);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#budgets-page .category-card:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(0,0,0,0.08); }

#budgets-page .category-left { display: flex; align-items: center; gap: 12px; }
#budgets-page .category-icon {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px;
    display: grid; place-items: center; font-size: 1.15rem; color: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.12);
}
#budgets-page .category-title { font-weight: 700; color: var(--text); font-size: 0.92rem; font-style: normal; }
#budgets-page .category-notes { font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; font-style: normal; }

#budgets-page .category-amounts { display: flex; justify-content: space-between; gap: 10px; }
#budgets-page .amount-row { display: flex; flex-direction: column; gap: 2px; }
#budgets-page .amount-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
#budgets-page .amount { font-weight: 700; font-size: 0.9rem; }
#budgets-page .amount.planned { color: var(--text); }
#budgets-page .amount.spent-safe { color: var(--b-success); }
#budgets-page .amount.spent-warning { color: var(--b-warn); }
#budgets-page .amount.spent-danger { color: var(--b-danger); }

#budgets-page .category-progress-track {
    height: 7px; border-radius: 999px;
    background: color-mix(in srgb, var(--text-muted) 18%, transparent); overflow: hidden;
}
#budgets-page .category-progress-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
#budgets-page .category-progress-fill.safe { background: linear-gradient(90deg, var(--b-success), #16a34a); }
#budgets-page .category-progress-fill.warning { background: linear-gradient(90deg, #fbbf24, var(--b-warn)); }
#budgets-page .category-progress-fill.danger { background: linear-gradient(90deg, #f87171, var(--b-danger)); }

#budgets-page .category-actions { display: flex; justify-content: flex-end; gap: 6px; }
#budgets-page .action-btn {
    border: 1px solid var(--b-border); background: var(--surface);
    width: 30px; height: 30px; border-radius: 9px; cursor: pointer; font-size: 0.8rem;
    display: grid; place-items: center; transition: border-color 0.15s ease, background 0.15s ease;
}
#budgets-page .action-btn.edit:hover { border-color: var(--b-primary); }
#budgets-page .action-btn.delete:hover { border-color: var(--b-danger); }

#budgets-page .no-categories-placeholder { max-width: 320px; text-align: right; }

/* ---------------- CHART CARDS ---------------- */
#budgets-page .chart-card .section-title { font-size: 0.95rem; }
#budgets-page .chart-definition { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; }
#budgets-page .def-item { font-size: 0.74rem; color: var(--text-muted); }
#budgets-page .def-item strong { color: var(--text); }

/* ---------------- INSIGHTS + HEALTH RING ---------------- */
#budgets-page .insights-card { background: linear-gradient(135deg, color-mix(in srgb, var(--b-primary) 8%, var(--surface)), var(--surface)); }
#budgets-page .insights-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
#budgets-page .insights-header-row .section-title { margin: 0; font-size: 0.98rem; }

#budgets-page .health-meter { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#budgets-page .health-ring {
    --value: 0;
    width: 60px; height: 60px; border-radius: 50%;
    display: grid; place-items: center; position: relative;
    background: conic-gradient(var(--b-primary) calc(var(--value) * 1%), color-mix(in srgb, var(--text-muted) 20%, transparent) 0);
}
#budgets-page .health-ring::before {
    content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--surface);
}
#budgets-page .health-ring span { position: relative; font-weight: 800; font-size: 1rem; color: var(--text); }
#budgets-page .health-text { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }

#budgets-page .insights-cards { display: flex; flex-direction: column; gap: 8px; }
#budgets-page .insight-card {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 10px 14px; border-radius: var(--b-radius-sm);
    background: var(--surface); border: 1px solid var(--b-border);
    font-size: 0.84rem; color: var(--text); line-height: 1.4;
}

/* ============================================================
   MODALS  (ids/classes preserved; .visible toggles display)
   ============================================================ */
#budgets-page .modal-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 1050;
    background: rgba(0,0,0,0.5);
    align-items: center; justify-content: center; padding: 16px;
}
#budgets-page .modal-overlay.visible { display: flex; animation: bgFade 0.18s ease; }
@keyframes bgFade { from { opacity: 0; } to { opacity: 1; } }

#budgets-page .modal {
    /* override Bootstrap's .modal (display:none; position:fixed; height:100%) */
    display: block;
    position: relative;
    inset: auto;
    margin: 0;
    width: 480px; max-width: 95vw;
    height: auto; max-height: 92vh; overflow-y: auto;
    background: var(--surface); color: var(--text);
    border: none;
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.3);
    animation: bgPop 0.2s ease;
}

/* Neutralise Bootstrap borders on the inner sections */
#budgets-page .modal-header,
#budgets-page .modal-footer { border: none; }
@keyframes bgPop { from { transform: translateY(12px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

#budgets-page .modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px 0;
}
#budgets-page .modal-header h2 { margin: 0; font-size: 1.2rem; font-weight: 700; }
#budgets-page .modal-close {
    border: none; background: color-mix(in srgb, var(--text-muted) 12%, transparent);
    width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
    font-size: 0.95rem; color: var(--text); display: grid; place-items: center;
    transition: background 0.15s ease, color 0.15s ease;
}
#budgets-page .modal-close:hover { background: color-mix(in srgb, var(--b-danger) 16%, transparent); color: var(--b-danger); }

#budgets-page .modal-body { padding: 18px 24px; display: flex; flex-direction: column; gap: 14px; }
#budgets-page .modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 22px; }

#budgets-page .form-group { display: flex; flex-direction: column; }
#budgets-page .form-group-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#budgets-page .form-group label,
#budgets-page .form-group-inline label {
    font-size: 0.78rem; color: var(--text-muted); font-weight: 500; margin-bottom: 5px;
}
#budgets-page .form-control {
    width: 100%;
    border: 1px solid var(--b-border); border-radius: 12px;
    padding: 10px 12px; background: var(--surface); color: var(--text);
    font-size: 0.9rem; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#budgets-page .form-control:focus {
    outline: none; border-color: var(--b-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--b-primary) 18%, transparent);
}
#budgets-page textarea.form-control { resize: vertical; min-height: 64px; }
#budgets-page .error-text { font-size: 0.74rem; color: var(--b-danger); margin-top: 5px; }
#budgets-page .error-text.d-none { display: none; }

/* Modal buttons */
#budgets-page .btn-primary {
    background: var(--b-primary); color: #fff; border: none;
    border-radius: 12px; padding: 10px 18px; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px;
}
#budgets-page .btn-primary:hover { background: var(--primary-hover, #3A56C9); }
#budgets-page .btn-secondary {
    background: transparent; color: var(--text); border: 1px solid var(--b-border);
    border-radius: 12px; padding: 10px 18px; font-weight: 600; cursor: pointer;
}
#budgets-page .btn-secondary:hover { border-color: var(--b-primary); color: var(--b-primary); }
#budgets-page .btn-danger {
    background: var(--b-danger); color: #fff; border: none;
    border-radius: 12px; padding: 10px 18px; font-weight: 600; cursor: pointer;
}
#budgets-page .btn-danger:hover { background: #dc2626; }

/* select2 rounding inside modals */
#budgets-page .select2-container--default .select2-selection--single {
    border-radius: 12px !important; border: 1px solid var(--b-border) !important;
    height: 42px !important; padding: 5px 8px !important;
}
#budgets-page .category-option-wrapper { display: inline-flex; align-items: center; gap: 8px; }
#budgets-page .category-option-icon {
    width: 22px; height: 22px; border-radius: 6px; display: inline-grid; place-items: center; font-size: 0.8rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
    #budgets-page .budgets-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #budgets-page .summary-card.empty { grid-column: span 1; }
    #budgets-page .budgets-main-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    #budgets-page .budgets-summary-grid { grid-template-columns: 1fr; }
    #budgets-page .bg-hero { padding: 22px 20px; }
    #budgets-page .bg-hero-text h1 { font-size: 1.6rem; }
    #budgets-page #budget-details-summary,
    #budgets-page .allocation-summary { grid-template-columns: 1fr; }
    #budgets-page .form-group-inline { grid-template-columns: 1fr; }
}
