/* ═══════════════════════════════════════════════════════════════════════════
 * BUDGET CALCULATOR — budget-calc.css
 * Namespace: .bdc-* / #bdc-* (Budget Calculator)
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ── LOCAL TOKENS ────────────────────────────────────────────────────────── */
#bdc-main,
#bdc-container {
    --bdc-accent:         #0ea5e9;
    --bdc-accent-dark:    #0369a1;
    --bdc-accent-light:   #e0f2fe;
    --bdc-accent-hover:   #bae6fd;
    --bdc-interest:       #fbbf24;
    --bdc-teal:           #14b8a6;
    --bdc-green:          #22c55e;
    --bdc-green-bg:       #f0fdf4;
    --bdc-green-brd:      #bbf7d0;
    --bdc-green-dark:     #166534;
    --bdc-red:            #ef4444;
    --bdc-red-bg:         #fef2f2;
    --bdc-red-brd:        #fecaca;
    --bdc-red-dark:       #991b1b;
    --bdc-warning-text:   #b45309;
    --bdc-warning-bg:     #fffbeb;
    --bdc-warning-brd:    #fde68a;
    --bdc-bg:             #ffffff;
    --bdc-bg-soft:        #f8fafc;
    --bdc-bg-muted:       #f1f5f9;
    --bdc-text-primary:   #0f172a;
    --bdc-text-secondary: #475569;
    --bdc-text-muted:     #94a3b8;
    --bdc-border:         #e2e8f0;
    --bdc-border-soft:    #f1f5f9;
    --bdc-shadow-focus:   0 0 0 4px rgba(14,165,233,0.15);
    --bdc-radius:         10px;
    --bdc-radius-sm:      6px;
    --bdc-tr:             150ms ease;
    /* category accent colors */
    --bdc-c-income:  #0ea5e9;
    --bdc-c-needs:   #8b5cf6;
    --bdc-c-wants:   #f97316;
    --bdc-c-savings: #22c55e;
}

/* ── WRAPPER ─────────────────────────────────────────────────────────────── */
#bdc-main.bdc-wrap {
    width: 100%;
    font-family: inherit;
    color: var(--bdc-text-primary);
}

/* ── HEADER ROW ──────────────────────────────────────────────────────────── */
.bdc-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.bdc-heading {
    font-size: 1.18rem;
    font-weight: 700;
    color: var(--bdc-text-primary);
    margin: 0 0 2px;
}

.bdc-sub {
    font-size: 0.8rem;
    color: var(--bdc-text-secondary);
    margin: 0;
}

.bdc-actions-top {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.bdc-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 16px;
    height: 36px;
    border-radius: var(--bdc-radius-sm);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background var(--bdc-tr), color var(--bdc-tr), border-color var(--bdc-tr);
    white-space: nowrap;
    line-height: 1;
}

.bdc-btn--primary {
    background: var(--bdc-accent);
    color: #fff;
    border-color: var(--bdc-accent);
}
.bdc-btn--primary:hover  { background: var(--bdc-accent-dark); border-color: var(--bdc-accent-dark); }
.bdc-btn--primary:focus-visible { outline: none; box-shadow: var(--bdc-shadow-focus); }

.bdc-btn--ghost {
    background: var(--bdc-bg-soft);
    color: var(--bdc-text-secondary);
    border-color: var(--bdc-border);
}
.bdc-btn--ghost:hover { background: var(--bdc-bg-muted); color: var(--bdc-text-primary); }

/* ── BODY LAYOUT ─────────────────────────────────────────────────────────── */
.bdc-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

@media (max-width: 960px) {
    .bdc-body { grid-template-columns: 1fr; }
}

/* ── INPUT SECTIONS ──────────────────────────────────────────────────────── */
.bdc-inputs-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bdc-section {
    border: 1.5px solid var(--bdc-border);
    border-radius: var(--bdc-radius-sm);
    overflow: hidden;
}

.bdc-section-hd {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 12px;
    border-bottom: 1.5px solid var(--bdc-border);
    background: var(--bdc-bg-soft);
}

.bdc-section-hd--income { border-left: 3px solid var(--bdc-c-income); }
.bdc-section-hd--needs  { border-left: 3px solid var(--bdc-c-needs); }
.bdc-section-hd--wants  { border-left: 3px solid var(--bdc-c-wants); }
.bdc-section-hd--savings{ border-left: 3px solid var(--bdc-c-savings); }

.bdc-section-icon { font-size: 0.95rem; line-height: 1; }

.bdc-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--bdc-text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.bdc-rule-tag {
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--bdc-text-muted);
    background: var(--bdc-bg-muted);
    padding: 1px 6px;
    border-radius: 99px;
}

.bdc-section-total {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--bdc-text-primary);
    margin-left: auto;
    white-space: nowrap;
}

/* Fields container */
.bdc-fields {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bdc-fields--grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 12px;
}

@media (max-width: 480px) {
    .bdc-fields--grid { grid-template-columns: 1fr; }
}

.bdc-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.bdc-label {
    font-size: 0.73rem;
    font-weight: 600;
    color: var(--bdc-text-secondary);
    line-height: 1.3;
}

.bdc-fw {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--bdc-border);
    border-radius: var(--bdc-radius-sm);
    background: var(--bdc-bg);
    overflow: hidden;
    transition: border-color var(--bdc-tr), box-shadow var(--bdc-tr);
}

.bdc-fw:focus-within {
    border-color: var(--bdc-accent);
    box-shadow: var(--bdc-shadow-focus);
}

.bdc-pre {
    padding: 0 7px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bdc-text-muted);
    background: var(--bdc-bg-soft);
    border-right: 1.5px solid var(--bdc-border-soft);
    line-height: 32px;
    flex-shrink: 0;
    user-select: none;
}

.bdc-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 0 7px;
    height: 32px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--bdc-text-primary);
    min-width: 0;
    width: 100%;
    -moz-appearance: textfield;
}

.bdc-input::-webkit-outer-spin-button,
.bdc-input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ── RESULTS COLUMN ──────────────────────────────────────────────────────── */
.bdc-results-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: sticky;
    top: 16px;
}

@media (max-width: 960px) {
    .bdc-results-col { position: static; }
}

/* ── CASH FLOW BANNER ────────────────────────────────────────────────────── */
.bdc-cashflow-banner {
    border-radius: var(--bdc-radius-sm);
    border: 1.5px solid var(--bdc-border);
    background: var(--bdc-bg-soft);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color var(--bdc-tr), background var(--bdc-tr);
}

.bdc-cashflow-banner.bdc-positive {
    background: var(--bdc-green-bg);
    border-color: var(--bdc-green-brd);
}

.bdc-cashflow-banner.bdc-negative {
    background: var(--bdc-red-bg);
    border-color: var(--bdc-red-brd);
}

.bdc-cf-main {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.bdc-cf-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--bdc-text-muted);
}

.bdc-cf-val {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--bdc-text-primary);
    transition: color var(--bdc-tr);
}

.bdc-cashflow-banner.bdc-positive .bdc-cf-val { color: var(--bdc-green-dark); }
.bdc-cashflow-banner.bdc-negative .bdc-cf-val { color: var(--bdc-red-dark); }

.bdc-cf-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    border-top: 1px solid var(--bdc-border-soft);
    padding-top: 10px;
}

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

.bdc-cf-stat-lbl {
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--bdc-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.bdc-cf-stat-val {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--bdc-text-primary);
    letter-spacing: -0.01em;
}

/* ── 50/30/20 TRACKER ────────────────────────────────────────────────────── */
.bdc-rule-box {
    border: 1.5px solid var(--bdc-border);
    border-radius: var(--bdc-radius-sm);
    background: var(--bdc-bg-soft);
    padding: 11px 13px;
}

.bdc-rule-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--bdc-text-secondary);
    margin: 0 0 10px;
}

.bdc-rule-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bdc-rule-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bdc-rule-row-top {
    display: flex;
    align-items: center;
    gap: 6px;
}

.bdc-rule-lbl {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bdc-text-primary);
    flex: 1;
}

.bdc-rule-pct {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--bdc-text-primary);
    min-width: 36px;
    text-align: right;
}

.bdc-rule-badge {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.bdc-badge-ok  { background: #dcfce7; color: #166534; }
.bdc-badge-over{ background: #fee2e2; color: #991b1b; }
.bdc-badge-low { background: #fef9c3; color: #854d0e; }
.bdc-badge-na  { background: var(--bdc-bg-muted); color: var(--bdc-text-muted); }

/* Progress track */
.bdc-rule-track {
    position: relative;
    height: 7px;
    background: var(--bdc-bg-muted);
    border-radius: 99px;
    overflow: hidden;
}

.bdc-rule-target {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(0,0,0,0.18);
    z-index: 2;
    transform: translateX(-50%);
}

.bdc-rule-bar {
    height: 100%;
    border-radius: 99px;
    transition: width 380ms cubic-bezier(.4,0,.2,1);
    max-width: 100%;
}

.bdc-rule-bar--needs   { background: var(--bdc-c-needs); }
.bdc-rule-bar--wants   { background: var(--bdc-c-wants); }
.bdc-rule-bar--savings { background: var(--bdc-c-savings); }

.bdc-rule-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.67rem;
    color: var(--bdc-text-muted);
}

/* ── CHART BOX ───────────────────────────────────────────────────────────── */
.bdc-chart-box,
.bdc-bar-box {
    border: 1.5px solid var(--bdc-border);
    border-radius: var(--bdc-radius-sm);
    background: var(--bdc-bg-soft);
    padding: 11px 13px;
}

.bdc-chart-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--bdc-text-secondary);
    margin: 0 0 10px;
}

.bdc-chart-inner {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 12px;
    align-items: center;
}

@media (max-width: 400px) {
    .bdc-chart-inner { grid-template-columns: 1fr; }
}

/* Donut */
.bdc-donut-wrap {
    position: relative;
    width: 120px;
    height: 120px;
    flex-shrink: 0;
}

.bdc-donut-wrap canvas {
    width: 120px !important;
    height: 120px !important;
    display: block;
}

.bdc-donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.bdc-donut-val {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--bdc-text-primary);
    line-height: 1;
    letter-spacing: -0.02em;
}

.bdc-donut-lbl {
    font-size: 0.59rem;
    color: var(--bdc-text-muted);
    margin-top: 2px;
}

/* Donut legend */
.bdc-donut-legend {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.bdc-legend-row {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.67rem;
    color: var(--bdc-text-secondary);
    min-width: 0;
}

.bdc-legend-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.bdc-legend-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bdc-legend-val {
    font-weight: 600;
    color: var(--bdc-text-primary);
    white-space: nowrap;
}

/* Bar chart */
.bdc-bar-wrap {
    position: relative;
    /* height set dynamically by JS */
}

.bdc-bar-wrap canvas {
    width: 100% !important;
    display: block;
}

/* ── SUMMARY TABLE ───────────────────────────────────────────────────────── */
.bdc-table-wrap {
    border: 1.5px solid var(--bdc-border);
    border-radius: var(--bdc-radius-sm);
    overflow: hidden;
}

.bdc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76rem;
}

.bdc-table th {
    background: var(--bdc-bg-muted);
    padding: 6px 10px;
    text-align: left;
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--bdc-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.bdc-table th:not(:first-child) { text-align: right; }

.bdc-table td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--bdc-border-soft);
    color: var(--bdc-text-secondary);
}

.bdc-table td:not(:first-child) { text-align: right; white-space: nowrap; }
.bdc-table tbody tr:last-child td { border-bottom: none; }
.bdc-table tbody tr:nth-child(even) td { background: var(--bdc-bg-soft); }
.bdc-table .bdc-row-total td { font-weight: 700; color: var(--bdc-text-primary); background: var(--bdc-bg-muted) !important; }

.bdc-table .bdc-cat-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}

/* ── ALERT ───────────────────────────────────────────────────────────────── */
.bdc-alert {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    background: var(--bdc-warning-bg);
    border: 1.5px solid var(--bdc-warning-brd);
    border-radius: var(--bdc-radius-sm);
    padding: 9px 12px;
}

.bdc-alert svg { flex-shrink: 0; margin-top: 1px; }

.bdc-alert p {
    margin: 0;
    font-size: 0.78rem;
    color: var(--bdc-warning-text);
    line-height: 1.5;
}

/* ── RESPONSIVE ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .bdc-heading          { font-size: 1.05rem; }
    .bdc-cf-val           { font-size: 1.15rem; }
    .bdc-cf-stats         { grid-template-columns: 1fr 1fr; }
    .bdc-btn              { flex: 1; justify-content: center; }
    .bdc-actions-top      { width: 100%; }
    .bdc-header-row       { flex-direction: column; align-items: stretch; }
}

@media (max-width: 360px) {
    .bdc-cf-stats         { grid-template-columns: 1fr; }
}
