/* ===== Light Mode (default) ===== */
:root {
    --mha-bg: #ffffff;
    --mha-bg-secondary: #f7f8fc;
    --mha-bg-input: #fafbfe;
    --mha-bg-input-focus: #ffffff;
    --mha-bg-net: #eef0fb;
    --mha-bg-fun: #fff7e6;
    --mha-bg-progress: #eef0f5;
    --mha-shadow: rgba(20, 30, 60, 0.08);
    --mha-text-primary: #1f2433;
    --mha-text-secondary: #2c3142;
    --mha-text-muted: #6b7280;
    --mha-text-label: #444b5a;
    --mha-text-fun: #7a5b00;
    --mha-border: #e3e6ee;
    --mha-toggle-off: #d8dce6;
    --mha-accent: #5b3df0;
}

/* ===== Dark Mode ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --mha-bg: #1a1d2e;
        --mha-bg-secondary: #242740;
        --mha-bg-input: #2a2d42;
        --mha-bg-input-focus: #32364e;
        --mha-bg-net: #1f2a4a;
        --mha-bg-fun: #2a2200;
        --mha-bg-progress: #2a2d42;
        --mha-shadow: rgba(0, 0, 0, 0.4);
        --mha-text-primary: #e8eaf6;
        --mha-text-secondary: #c5c8e0;
        --mha-text-muted: #9399b2;
        --mha-text-label: #b0b5cc;
        --mha-text-fun: #f0c84a;
        --mha-border: #3a3d5c;
        --mha-toggle-off: #4a4e68;
        --mha-accent: #7c6af5;
    }
}

/* ===== Base Styles ===== */
.mha-calculator {
    max-width: 720px;
    margin: 20px auto;
    padding: 28px;
    background: var(--mha-bg);
    border-radius: 18px;
    box-shadow: 0 10px 30px var(--mha-shadow);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--mha-text-primary);
    box-sizing: border-box;
}
.mha-calculator * { box-sizing: border-box; }

.mha-header { text-align: center; margin-bottom: 22px; }
.mha-header h3 {
    margin: 0 0 6px;
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(90deg, #5b3df0, #00b8a9);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.mha-subtitle { margin: 0; color: var(--mha-text-muted); font-size: 14px; }

.mha-top-controls {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 14px;
    align-items: end;
    margin-bottom: 24px;
}
.mha-field { display: flex; flex-direction: column; gap: 6px; }
.mha-field label { font-size: 13px; font-weight: 600; color: var(--mha-text-label); }
.mha-field select,
.mha-field input[type="number"] {
    padding: 10px 12px;
    border: 1.5px solid var(--mha-border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--mha-bg-input);
    color: var(--mha-text-primary);
    transition: border-color .15s ease, background .15s ease;
}
.mha-field select:focus,
.mha-field input:focus { outline: none; border-color: var(--mha-accent); background: var(--mha-bg-input-focus); }

/* Fix select arrow color in dark mode */
.mha-field select {
    -webkit-appearance: auto;
    appearance: auto;
    color-scheme: light dark;
}

.mha-toggle-field {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
    padding-bottom: 8px;
}
.mha-toggle-text { font-size: 13px; font-weight: 600; color: var(--mha-text-label); white-space: nowrap; }

.mha-switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.mha-switch input { opacity: 0; width: 0; height: 0; }
.mha-slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--mha-toggle-off); transition: .2s; border-radius: 26px;
}
.mha-slider:before {
    position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px;
    background-color: white; transition: .2s; border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.mha-switch input:checked + .mha-slider { background-color: var(--mha-accent); }
.mha-switch input:checked + .mha-slider:before { transform: translateX(20px); }

.mha-expenses h4 { margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--mha-text-primary); }
.mha-expense-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 22px; }
.mha-expense-row {
    display: grid;
    grid-template-columns: 30px 1fr 130px;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--mha-bg-secondary);
}
.mha-expense-icon { font-size: 18px; text-align: center; }
.mha-expense-name { font-size: 14px; color: var(--mha-text-secondary); }
.mha-expense-input {
    padding: 8px 10px;
    border: 1.5px solid var(--mha-border);
    border-radius: 8px;
    font-size: 14px;
    text-align: right;
    background: var(--mha-bg-input-focus);
    color: var(--mha-text-primary);
}
.mha-expense-input:focus { outline: none; border-color: var(--mha-accent); }

.mha-results {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 18px;
}
.mha-result-box {
    background: var(--mha-bg-secondary);
    border-radius: 12px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mha-result-label { font-size: 12px; color: var(--mha-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.mha-result-value { font-size: 22px; font-weight: 700; color: var(--mha-text-primary); }
.mha-net-box { background: var(--mha-bg-net); }
.mha-net-box .mha-result-value.mha-positive { color: #0a9d6f; }
.mha-net-box .mha-result-value.mha-negative { color: #e0473e; }

.mha-progress-wrap { margin-bottom: 16px; }
.mha-progress-bar {
    width: 100%; height: 14px; background: var(--mha-bg-progress); border-radius: 20px; overflow: hidden; margin-bottom: 6px;
}
.mha-progress-fill {
    height: 100%; width: 0%; border-radius: 20px;
    background: #0a9d6f;
    transition: width .3s ease, background-color .3s ease;
}
.mha-fill-green { background: #0a9d6f; }
.mha-fill-yellow { background: #e0b400; }
.mha-fill-orange { background: #e08a23; }
.mha-fill-red { background: #e0473e; }
.mha-progress-label { font-size: 13px; color: var(--mha-text-muted); text-align: right; }

.mha-fun-message {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--mha-bg-fun);
    color: var(--mha-text-fun);
    margin-bottom: 18px;
    min-height: 20px;
}

.mha-breakdown { display: flex; flex-direction: column; gap: 8px; }
.mha-breakdown-row { display: grid; grid-template-columns: 160px 1fr 40px; align-items: center; gap: 10px; }
.mha-breakdown-name { font-size: 13px; color: var(--mha-text-label); }
.mha-breakdown-bar-wrap { height: 8px; background: var(--mha-bg-progress); border-radius: 10px; overflow: hidden; }
.mha-breakdown-bar { height: 100%; background: linear-gradient(90deg, #5b3df0, #00b8a9); border-radius: 10px; }
.mha-breakdown-pct { font-size: 12px; color: var(--mha-text-muted); text-align: right; }

@media (max-width: 600px) {
    .mha-top-controls { grid-template-columns: 1fr; }
    .mha-expense-row { grid-template-columns: 24px 1fr 100px; }
    .mha-breakdown-row { grid-template-columns: 110px 1fr 36px; }
    .mha-calculator { padding: 18px; }
}
