/* THEME VARIABLES */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #ffffff;
    --bg-card: #fbfbfb;
    --accent: #526258;
    --accent-hover: #3f4742;
    --accent-secondary: #EFF7EC;
    --accent-secondary-hover: #dfebda;
    --text-primary: #1a1d27;
    --text-secondary: #5a6380;
    --border: #dde1f0;
    --success: #78d0aa;
    --danger: #e05555;
    --sidebar-width: 240px;
}

/* RESET & BASE */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s ease;
}

/* LAYOUT */

#app {
    display: flex;
    min-height: 100vh;
}

#app.hidden {
    display: none !important;
}

/* SIDEBAR */

#sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background-color: #EFF7EC;
    border-right: 1px solid #d4e6cf;
    display: flex;
    flex-direction: column;
    padding: 24px 0 0;
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
}

/* LOGO */

#logo {
    padding: 24px;
    border-bottom: 1px solid var(--border);
    background-color: #EFF7EC;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app-title {
    font-family: 'League Spartan', sans-serif;
    font-weight: 700;
    font-size: 1.8rem;
    color: #526258;
    letter-spacing: -2.0px;
}

/* Brand wordmark rendered from assets/logo.png via a recolorable mask, so it
   matches the real logo exactly. Falls back to the League Spartan text above
   on browsers without CSS mask support. */
@supports ((-webkit-mask-image: url(x.png)) or (mask-image: url(x.png))) {
    #app-title {
        width: 103px;
        height: 26px;
        font-size: 0;
        color: transparent;
        background-color: #526258;
        -webkit-mask: url(assets/logo-mask.png) no-repeat center / contain;
        mask: url(assets/logo-mask.png) no-repeat center / contain;
    }
}

/* NAVIGATION */

#main-nav {
    flex: 1;
    padding: 24px 0;
}

#main-nav ul {
    list-style: none;
}

#main-nav li {
    margin-bottom: 4px;
}

.nav-link {
    display: block;
    padding: 10px 24px;
    color: #526258;
    text-decoration: none;
    border-radius: 8px;
    margin: 0 12px;
    font-size: 0.95rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.nav-link:hover {
    background-color: #d4e6cf;
    color: #526258;
}

.nav-link.active {
    background-color: #526258;
    color: #EFF7EC;
}

/* ── MAIN CONTENT ── */

#content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    padding: 40px;
    min-height: 100vh;
}

/* ── SECTIONS ── */

.section {
    display: none;
}

.section.active {
    display: block;
}

/* ── PAGE HEADER ── */
.section h2 {
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.5px;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.section p.subtitle {
    color: var(--text-secondary);
    margin-bottom: 28px;
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: 0;
}

/* ── CARDS ── */

.card {
    background-color: var(--bg-card);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.02);
}

.card .value {
    font-size: 2rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.card .value.positive {
    color: var(--success);
}

.card .value.negative {
    color: var(--danger);
    font-weight: 400;
}

.card .value.bold {
    font-weight: 700;
    color: var(--text-primary);
}

.card .value.bold.positive {
    font-weight: 700;
    color: var(--success);
}

/* ── CARD GRID ── */

.card-grid {
    display: grid;
    /* Fluid: as many equal columns as fit; reflows on its own at any width,
       so it never overflows in the gap between desktop and the 768px breakpoint.
       min(100%, …) keeps a single column from demanding more than the container
       on very narrow screens. */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

/* ── SUMMARY STRIP ── */
.summary-strip {
    display: flex;
    flex-wrap: wrap;          /* groups drop to a new row instead of squishing */
    gap: 12px;
    margin-bottom: 32px;
}

.summary-group {
    display: flex;
    align-items: center;
    /* Never shrink below the natural width of the values inside. Without this the
       group squeezes and the nowrap .summary-value bleeds into its neighbour
       (the overlap seen when narrowing the window); with it the whole group wraps
       to the next row instead. */
    min-width: max-content;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.summary-group--income  { flex: 3; }
.summary-group--expenses { flex: 1; }
.summary-group--savings  { flex: 2; }

/* Fixed-width summary cards (expenses KPI strip) on desktop. The mobile rule
   (.summary-group { width: 100% }) overrides this, so on a phone they stretch
   to full width instead of sitting at 220px hugging the left edge. */
.summary-group-fixed { width: 220px; }

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 24px;
    flex: 1;
    min-width: 0;
    text-align: center;
}

.summary-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    white-space: nowrap;
    margin-bottom: 6px;
}

.summary-value {
    font-size: 1.35rem;
    font-weight: 300;
    color: var(--text-secondary);
    white-space: nowrap;
    letter-spacing: -0.5px;
}

.summary-value.bold {
    font-weight: 600;
    color: var(--text-primary);
}

.summary-value.accent {
    color: #526258;
}

.summary-value.positive {
    color: var(--success);
}

.summary-value.bold.positive {
    font-weight: 700;
    color: var(--success);
}

.summary-value.savings-positive {
    color: #789c6c;
}

.summary-value.bold.savings-positive {
    font-weight: 700;
    color: #789c6c;
}

.summary-value.negative {
    color: var(--danger);
}

.summary-divider {
    width: 1px;
    height: 48px;
    background-color: var(--border);
    flex-shrink: 0;
}

/* ── INCOME PANEL ROW ── */

.income-panel-row {
    display: flex;
    flex-wrap: wrap;          /* the two panels stack once they no longer fit */
    align-items: stretch;
    gap: 24px;
    margin-bottom: 0;
}

.income-panel-left {
    flex: 1 1 320px;         /* grow/shrink, but wrap below ~320px each */
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.income-panel-left .card {
    flex: 1;
}

.income-panel-right {
    flex: 1 1 320px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.income-panel-right .card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.income-pie-header h3 {
    margin: 0;
}

.income-pie-toggle {
    flex-shrink: 0;
}

.income-pie-wrapper {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#income-breakdown-pie-chart {
    width: 340px !important;
    height: 340px !important;
}

/* ── CHART CONTAINER ── */

.chart-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.chart-container canvas {
    min-height: 300px;
}

#expenses-donut-chart {
    max-height: 300px;
}

#income-expenses-bar-chart {
    max-height: 300px;
}

/* ── SCROLLBAR ── */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* ── RESPONSIVE ──
   All responsive overrides live in one block at the END of this file. They must
   come last because media queries don't add specificity — a later same-specificity
   rule elsewhere in the file would otherwise win over a mid-file breakpoint. */

/* ── UTILITY ── */

.text-success {
    color: var(--success);
}

.text-savings {
    color: #789c6c;
}

.text-danger {
    color: var(--danger) !important;
}

.text-warning {
    color: #b45309;
}

.data-issue-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background-color: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #92400e;
}

/* ── CONFIRM MODAL ── */
.confirm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: confirm-overlay-fade-in 0.15s ease;
}

@keyframes confirm-overlay-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.confirm-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 28px 24px;
    max-width: 420px;
    width: calc(100% - 40px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    animation: confirm-modal-slide-in 0.15s ease;
}

@keyframes confirm-modal-slide-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.confirm-modal-message {
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--text-primary);
    margin: 0 0 24px;
}

.confirm-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.text-accent {
    color: #526258;
}

.text-secondary {
    color: var(--text-secondary);
}

.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }

/* ── INTRO TOUR (first-login spotlight) ── */
/* ── WHAT'S NEW MODAL ── */
.whatsnew-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5);
    animation: confirm-overlay-fade-in 0.15s ease;
}

.whatsnew-modal {
    width: 100%;
    max-width: 440px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
    padding: 28px;
    text-align: center;
}

.whatsnew-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent);
    margin-bottom: 10px;
}

.whatsnew-feature {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin: 0 0 18px;
}

.whatsnew-list {
    text-align: left;
    margin: 0 0 24px;
    padding-left: 20px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.whatsnew-list li {
    margin-bottom: 8px;
}

.whatsnew-btn {
    width: 100%;
}

.intro-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: auto; /* swallow clicks so the app can't be touched mid-tour */
    animation: confirm-overlay-fade-in 0.15s ease;
}

.intro-highlight {
    position: fixed;
    border-radius: 8px;
    pointer-events: none;
    /* Ring around the target + a huge spread shadow that dims everything else */
    box-shadow: 0 0 0 3px var(--accent), 0 0 0 9999px rgba(0, 0, 0, 0.55);
    transition: top 0.25s ease, left 0.25s ease, width 0.25s ease, height 0.25s ease;
}

/* Centered step (no target): keep the dim, drop the ring */
.intro-highlight--hidden {
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    border-radius: 0;
}

.intro-tooltip {
    position: fixed;
    z-index: 10001;
    width: 300px;
    max-width: calc(100vw - 16px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 18px 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    pointer-events: auto;
    transition: top 0.25s ease, left 0.25s ease;
}

/* Centered card sits dead-centre regardless of any target */
.intro-tooltip--centered {
    transform: translate(-50%, -50%);
}

.intro-progress {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.intro-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px;
}

.intro-body {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-secondary);
    margin: 0 0 16px;
}

.intro-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.intro-spacer {
    flex: 1;
}

.intro-skip {
    background: none;
    border: none;
    padding: 4px 2px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: underline;
}

.intro-skip:hover {
    color: var(--text-primary);
}

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

.form-grid--mortgage {
    /* Was repeat(2, 220px) fixed — overflowed its card on intermediate widths */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
}

.form-grid--mortgage .currency-input-wrapper {
    width: 100%;
}

.form-grid--projection {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    column-gap: 24px;
}

.form-grid--projection .currency-input-wrapper {
    width: 100%;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group input,
.form-group select {
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.2s ease;
    outline: none;
    height: 44px;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    min-width: 0;            /* allow shrinking inside narrow grid/flex cells */
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
}

.form-group input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* ── TAX PREVIEW ── */
.tax-preview {
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    transition: all 0.2s ease;
}

.tax-preview-active {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── BUTTONS ── */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--accent);
    color: #ffffff;
}

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

.btn-danger {
    background-color: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background-color: var(--danger);
    color: #ffffff;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
}

/* ── INCOME LIST ── */
.group-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 16px 0 8px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.income-list {
    margin-bottom: 8px;
}

.income-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.income-item:last-child {
    border-bottom: none;
}

.income-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.income-item-name {
    font-weight: 500;
    color: var(--text-primary);
}

.income-item-tax {
    font-size: 0.8rem;
}

.income-item-amounts {
    display: flex;
    gap: 16px;
    font-size: 0.9rem;
}

.group-summary {
    display: flex;
    gap: 24px;
    padding: 12px 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

/* ── EMPTY STATE ── */
.empty-state {
    color: var(--text-secondary);
    font-size: 0.95rem;
    padding: 24px 0;
    text-align: center;
}

.form-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 8px;
}

.settings-danger-zone {
    border: 1px solid var(--danger) !important;
}

.delete-account-warning {
    color: var(--danger);
    font-size: 0.875rem;
    margin: 0;
}

.form-success {
    color: var(--accent);
    font-size: 0.875rem;
    margin-top: 8px;
}

/* ── INACTIVITY WARNING BANNER ── */
#inactivity-warning {
    position: fixed;
    bottom: -80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 9999;
    transition: bottom 0.3s ease;
    white-space: nowrap;
}

#inactivity-warning.visible {
    bottom: 32px;
}

#inactivity-stay-btn {
    background: #fff;
    color: var(--danger);
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

#inactivity-stay-btn:hover {
    background: rgba(255,255,255,0.85);
}

/* ── SIDEBAR BOTTOM ── */
#sidebar-bottom {
    padding: 12px 0 0;
}

.settings-link {
    display: block;
    padding: 10px 24px;
    color: #526258;
    text-decoration: none;
    border-radius: 8px;
    margin: 0 12px;
    font-size: 0.95rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.settings-link:hover {
    background-color: #d4e6cf;
    color: #526258;
}

.settings-link.active {
    background-color: #526258;
    color: #EFF7EC;
}

#logout-btn {
    display: flex;
    align-items: center;
    width: calc(100% - 24px);
    padding: 10px 24px;
    background: none;
    border: none;
    border-radius: 8px;
    margin: 4px 12px 24px;
    color: var(--danger);
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#logout-btn:hover {
    background-color: #fdeaea;
}

/* ── SETTINGS ── */
.settings-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.form-grid-single {
    grid-template-columns: 1fr;
    max-width: 400px;
}

/* A form-group that spans the full width of a 2-column form grid */
.form-group--full {
    grid-column: 1 / -1;
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-item {
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.category-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.category-name {
    font-weight: 500;
    color: var(--text-primary);
}

.category-item-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-secondary {
    background-color: var(--accent-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: var(--accent-secondary-hover);
    color: var(--text-primary);
}

.subcategories-panel {
    border-top: 1px solid var(--border);
    padding: 16px;
    background-color: var(--bg-secondary);
}

.add-subcategory-form {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.subcategory-input {
    flex: 1;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}

.subcategory-input:focus {
    border-color: var(--accent);
}

.subcategory-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.subcategory-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background-color: var(--bg-card);
    border-radius: 6px;
}

.subcategory-name {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.empty-subcategory {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 8px 0;
}

/* ── SETTINGS LAYOUT ── */
.settings-layout {
    display: grid;
    /* minmax(0, 1fr) lets the content track shrink below its content size — a
       plain 1fr has min-width:auto and would push the layout past the viewport.
       The side-nav stacks on top once the window is narrow (see media query). */
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 32px;
    align-items: start;
}

/* With the 240px sidebar eating into the width, the settings side-nav + content
   pair gets too cramped well before the global 768px breakpoint, so stack the
   nav on top earlier. */
@media (max-width: 900px) {
    .settings-layout {
        grid-template-columns: 1fr;
    }

    .settings-nav {
        position: static;
    }
}

.settings-nav {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 0;
    position: sticky;
    top: 24px;
}

.settings-nav-group {
    margin-bottom: 8px;
}

.settings-nav-group:last-child {
    margin-bottom: 0;
}

.settings-nav-group-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #526258;
    padding: 12px 16px 6px 16px;
    border-top: 1px solid var(--border);
}

.settings-nav-group:first-child .settings-nav-group-label {
    border-top: none;
    padding-top: 4px;
}

.settings-nav-link {
    display: block;
    padding: 10px 16px;
    margin: 2px 8px;
    font-size: 0.9rem;
    color: #526258;
    text-decoration: none;
    border-radius: 8px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.settings-nav-link:hover {
    background-color: #d4e6cf;
    color: #526258;
}

.settings-nav-link.active {
    background-color: #526258;
    color: #EFF7EC;
    font-weight: 600;
}

/* ── SETTINGS PAGES ── */
.settings-page {
    display: none;
}

.settings-page.active {
    display: block;
}

/* ── SETTINGS FORM ── */
.settings-section-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.settings-section-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.settings-field-group {
    display: grid;
    /* Two fields side by side, collapsing to one when the settings content panel
       is too narrow (otherwise e.g. the language select clips its option text). */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 16px;
    margin-bottom: 16px;
    max-width: 600px;
}

.settings-field-group.full-width {
    grid-template-columns: 1fr;
    max-width: 480px;
}

.settings-save-btn {
    margin-top: 8px;
    max-width: 600px;
}

/* ── SETTINGS PREVIEW ── */
.settings-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
    max-width: 400px;
}

.settings-preview-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

#settings-preview-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #526258;
}

/* ── YEARLY SUMMARY ── */
.yearly-summary-section {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 2px solid var(--border);
}

.group-summary {
    display: flex;
    gap: 24px;
    padding: 12px 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

/* ── FLATPICKR CUSTOM STYLES ── */
.flatpickr-calendar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.flatpickr-months {
    background: var(--bg-card);
    border-radius: 12px 12px 0 0;
    padding: 8px 0;
}

.flatpickr-month {
    color: var(--text-primary);
}

.flatpickr-current-month {
    color: var(--text-primary);
}

.flatpickr-current-month select {
    color: var(--text-primary);
    background: var(--bg-card);
}

.flatpickr-prev-month svg,
.flatpickr-next-month svg {
    fill: var(--text-secondary);
}

.flatpickr-prev-month:hover svg,
.flatpickr-next-month:hover svg {
    fill: var(--accent);
}

.flatpickr-monthSelect-months {
    background: var(--bg-card);
    padding: 8px;
}

.flatpickr-monthSelect-month {
    color: var(--text-primary);
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.flatpickr-monthSelect-month:hover {
    background: var(--bg-primary);
    color: var(--accent);
}

.flatpickr-monthSelect-month.selected,
.flatpickr-monthSelect-month.selected:hover {
    background: #526258 !important;
    border-color: #526258 !important;
    color: #ffffff !important;
}

.flatpickr-day.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

/* Hide flatpickr year spinner arrows */
.flatpickr-calendar .arrowUp,
.flatpickr-calendar .arrowDown {
    display: none !important;
}

/* ── EXPENSES ── */
.expense-list {
    margin-bottom: 8px;
}

/* The expense transactions card stays readable rather than stretching across a
   wide monitor, but goes full width once the container is narrower than the cap —
   so it never gets squeezed so thin that its rows overflow (was a fixed 50%). */
.expense-list-card {
    width: 100%;
    max-width: 640px;
}

.expense-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.expense-item:last-child {
    border-bottom: none;
}

.expense-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.expense-item-description {
    font-weight: 500;
    color: var(--text-primary);
}

.expense-item-category {
    font-size: 0.8rem;
}

.expense-item-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.expense-item-amount {
    font-weight: 400;
    font-size: 1rem;
}

.income-tx-amounts {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 0.85rem;
}

.income-tx-net {
    font-weight: 500;
}

.expense-item-editing {
    background-color: var(--bg-primary);
    border-radius: 8px;
    padding: 4px 0;
}

.expense-edit-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 4px;
    width: 100%;
}

.expense-edit-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.expense-edit-row select,
.expense-edit-row input[type="text"]:not(.balance-input) {
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 10px;
    font-size: 0.875rem;
    color: var(--text-primary);
    background-color: var(--bg-card);
    outline: none;
}

.expense-edit-row select:focus,
.expense-edit-row input[type="text"]:not(.balance-input):focus {
    border-color: var(--accent);
}

.expense-edit-category  { flex: 1.5; min-width: 120px; }
.expense-edit-subcategory { flex: 1.2; min-width: 110px; }
.expense-edit-description { flex: 2; min-width: 140px; }

.expense-edit-row .currency-input-wrapper {
    width: 130px;
    height: 36px;
    flex-shrink: 0;
}

.expense-edit-actions {
    display: flex;
    gap: 8px;
}

/* ── SUBSECTION TABS ── */
.subsection-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 32px;
    border-bottom: 2px solid var(--border);
}

.tab-btn {
    background: none !important;
    border: none !important;
    border-bottom: 3px solid transparent !important;
    padding: 12px 24px !important;
    font-size: 1rem !important;
    font-weight: 500 !important;
    color: var(--text-secondary) !important;
    cursor: pointer !important;
    margin-bottom: -2px !important;
    transition: color 0.2s ease, border-bottom-color 0.2s ease !important;
    border-radius: 0 !important;
    letter-spacing: 0 !important;
}

.tab-btn:hover {
    color: var(--text-primary) !important;
    background: none !important;
}

.tab-btn.active {
    color: #526258 !important;
    border-bottom: 3px solid #526258 !important;
    background: none !important;
}

/* ── TAB CONTENT ── */
.tab-content {
    display: none;
}

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

/* ── SECONDARY TABS ── */
.subsection-tabs-secondary {
    margin-bottom: 24px;
    margin-top: -8px;
}

.tab-btn-secondary {
    background: none !important;
    border: none !important;
    border-bottom: 2px solid transparent !important;
    padding: 8px 16px !important;
    font-size: 0.9rem !important;
    font-weight: 500 !important;
    color: var(--text-secondary) !important;
    cursor: pointer !important;
    margin-bottom: -2px !important;
    transition: color 0.2s ease, border-bottom-color 0.2s ease !important;
    border-radius: 0 !important;
}

.tab-btn-secondary:hover {
    color: var(--text-primary) !important;
    background: none !important;
}

.tab-btn-secondary.active {
    color: #526258 !important;
    border-bottom: 2px solid #526258 !important;
    background: none !important;
}

/* ── SUBTAB CONTENT ── */
.subtab-content {
    display: none;
}

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

/* ── DASHBOARD ── */
.dashboard-header {
    margin-bottom: 24px;
}

.dashboard-month {
    font-size: 1.2rem;
    color: var(--text-primary);
    font-weight: 600;
}

/* ── CHART CONTAINERS ── */
.chart-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.chart-container-donut {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.chart-header h3 {
    margin-bottom: 0;
}

.chart-container h3,
.chart-container-donut h3,
.card h3 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

#expenses-donut-chart {
    max-height: 320px;
    max-width: 100%;
}

#income-expenses-bar-chart {
    max-height: 320px;
}

/* ── DATA TABLE ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table td {
    padding: 11px 12px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    color: var(--text-primary);
    font-size: 0.875rem;
    white-space: nowrap;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-primary);
    white-space: nowrap;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.category-row td {
    font-weight: 600;
}

.detail-row td {
    font-size: 0.85rem;
}

.data-table tfoot td {
    font-weight: 700;
    border-top: 2px solid var(--border);
    padding-top: 12px;
}

.total-row td {
    font-weight: 700;
    text-align: center;
}

.total-row td:first-child {
    text-align: center;
}

/* ── BALANCE SHEET ── */
.balance-equation-layout {
    display: flex;
    flex-wrap: wrap;          /* breakdown + chart stack when space runs out */
    align-items: flex-start;
    gap: 24px;
}

.balance-card {
    flex: 1 1 300px;
    min-width: 0;
}

.balance-equation-chart-card {
    flex: 1 1 300px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.balance-equation-chart-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 0;
}

#balance-equation-chart {
    max-width: 340px !important;
    max-height: 340px !important;
}

.balance-equation-legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px 0;
    padding-top: 12px;
}

.balance-eq-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-primary);
    padding: 0 8px;
}

.balance-eq-legend-swatch {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Balance breakdown ("Desglose del balance") and monthly expenses breakdown
   ("Desglose de gastos mensuales") legends: rounded-rectangle markers with larger
   labels, matching the budget radar's rectRounded legend. */
.balance-equation-chart-card .balance-equation-legend,
.expenses-breakdown-chart-card .balance-equation-legend {
    gap: 8px 0;
    padding-top: 14px;
}

.balance-equation-chart-card .balance-eq-legend-item,
.expenses-breakdown-chart-card .balance-eq-legend-item {
    gap: 8px;
    font-size: 13px;
    padding: 0 14px;
}

.balance-equation-chart-card .balance-eq-legend-swatch,
.expenses-breakdown-chart-card .balance-eq-legend-swatch {
    width: 16px;
    height: 16px;
    border-radius: 5px;
}

.balance-kpi-strip {
    margin-top: 20px;
    margin-bottom: 28px;
}

.balance-grid {
    display: grid;
    /* Assets / liabilities columns reflow to a single column when narrow */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 32px;
    margin-bottom: 24px;
}

.balance-section-header {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 16px;
    padding: 10px 14px;
    border-radius: 8px;
    text-align: center;
}

.balance-section-header--asset {
    color: #526258;
    border-left-color: #526258;
    background-color: var(--accent-secondary);
}

.balance-section-header--liability {
    color: var(--danger);
    border-left-color: var(--danger);
    background-color: rgba(224, 85, 85, 0.06);
}

.add-balance-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.networth-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background-color: var(--bg-primary);
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.1rem;
}

/* ── BALANCE SHEET FORM ── */
.balance-category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 7px 12px;
    border-radius: 6px;
    border-bottom: none;
    margin-top: 10px;
    margin-bottom: 2px;
}

.balance-category-header span:first-child {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.balance-category-header span:last-child {
    flex-shrink: 0;
    width: 160px;
    text-align: center;
}

.balance-category-header--asset span:last-child {
    color: #526258;
}

.balance-category-header--asset {
    background-color: var(--accent-secondary);
    color: #526258;
}

.balance-category-header--liability {
    background-color: rgba(224, 85, 85, 0.06);
    color: var(--danger);
}

.balance-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    gap: 16px;
}

.balance-row-sub {
    padding-left: 16px;
}

.balance-row-label {
    font-size: 0.9rem;
    color: var(--text-primary);
    flex: 1;
}

/* ── CURRENCY INPUT ── */
.currency-input-wrapper {
    display: flex;
    align-items: stretch;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s ease;
    width: 160px;
    height: 44px;
}

.currency-input-wrapper:focus-within {
    border-color: var(--accent);
}

.currency-input-wrapper input {
    border-radius: 0 8px 8px 0 !important;
    background-color: var(--bg-primary) !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.currency-symbol {
    display: flex;
    align-items: center;
    padding: 0 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-right: 1px solid var(--border);
    background-color: var(--bg-secondary);
    user-select: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.balance-input {
    width: 100%;
    background: transparent;
    border: none;
    padding: 0 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    text-align: right;
    height: 100%;
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
}

.balance-input:focus {
    border-color: var(--accent);
}

.balance-section-total {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 12px 0;
    margin-top: 8px;
    border-top: 2px solid var(--border);
}

.balance-section-total span:first-child {
    flex: 1;
    text-align: center;
}

.balance-section-total span:last-child {
    width: 160px;
    text-align: center;
    flex-shrink: 0;
}

/* ── HIDE NUMBER INPUT SPINNERS ── */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* ── LIST HEADER ── */
.list-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 16px;
}

.list-header-total {
    font-size: 1.1rem;
    font-weight: 700;
}

/* ── COLOUR PICKER ── */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
}

input[type="color"] {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
    background: var(--bg-primary);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
    border-radius: 6px;
    border: none;
}

.color-picker-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: monospace;
}

.category-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    opacity: 0.4;
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
    user-select: none;
    transition: opacity 0.15s;
}

.drag-handle:hover {
    opacity: 0.9;
}

.drag-handle:active {
    cursor: grabbing;
}

.sortable-ghost {
    opacity: 0.35;
    background-color: var(--bg-secondary);
    border-radius: 8px;
}

.category-color-swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

/* ── EDIT PANEL ── */
.edit-panel {
    padding: 16px;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.edit-panel-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.subcategory-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ── INCOME FORM TABLE ── */
.income-form-table {
    width: 100%;
}

.income-form-table th {
    background-color: transparent;
    border-bottom: 2px solid var(--border);
}

.income-form-table th:first-child {
    width: 40%;
    text-align: center;
}

.income-form-table th:nth-child(2),
.income-form-table th:nth-child(3) {
    width: 22%;
    text-align: center;
}

.income-form-table th:last-child {
    width: 16%;
    text-align: center;
}

.expenses-breakdown-layout {
    display: flex;
    flex-wrap: wrap;          /* table + donut stack when space runs out */
    align-items: flex-start;
    gap: 24px;
}

.expenses-breakdown-card {
    /* Higher basis than other two-up layouts: the breakdown table needs more
       room than the donut beside it, so the pair drops to a single column until
       there is genuinely space for both. */
    flex: 1 1 360px;
    min-width: 0;
}

.expenses-breakdown-chart-card {
    flex: 1 1 360px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.expenses-breakdown-chart-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 0;
    width: 100%;
}

#expenses-breakdown-donut-chart {
    max-width: 400px !important;
    max-height: 400px !important;
}

/* ── MONTHLY BUDGET ──
   Rows are block-based (label/input on one wrapping line, then a full-width
   progress bar, then a meta line), so they reflow on any width with no overflow. */
.budget-summary-strip {
    margin-top: 4px;
    justify-content: center;
}

/* Uniform-width KPI cards (overrides the content-width .summary-group default).
   210px fits the longest label on one line; they stay centred and wrap as the
   window narrows, and go full width on phones. */
.budget-summary-strip .summary-group {
    flex: 0 0 auto;
    width: 240px;          /* wide enough for the savings cards' "€X (Y%)" value */
    min-width: 0;
}

@media (max-width: 480px) {
    .budget-summary-strip .summary-group {
        width: 100%;
    }
}

.budget-prefill-note {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 16px;
}

/* Overall budget-used progress bar — centred, above the list + chart columns */
.budget-total {
    max-width: 720px;
    margin: 4px auto 28px;
}

.budget-total-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 8px;
}

.budget-total-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
}

.budget-total-amounts {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.budget-total-amounts .negative {
    color: var(--danger);
}

.budget-total-bar {
    height: 10px;
    margin-top: 0;
}

/* Category list (left) + radar chart (right), each taking half on desktop and
   stacking to full width once the window is too narrow. */
.budget-main-layout {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 24px;
}

.budget-list-card,
.budget-chart-card {
    flex: 1 1 360px;
    min-width: 0;
}

.budget-chart-card {
    display: flex;
    flex-direction: column;
}

/* Square, capped container so the radar always keeps a 1:1 aspect regardless of
   how wide the card gets. The canvas fills this box (Chart.js maintainAspectRatio
   is off), so capping the WRAPPER — not the canvas — avoids the width/height
   mismatch that stretched the chart. */
.budget-chart-wrapper {
    position: relative;
    width: 100%;
    max-width: 700px;
    aspect-ratio: 1 / 1;
    margin: 8px auto;
}

.budget-list {
    display: flex;
    flex-direction: column;
}

.budget-row {
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
}

.budget-row:last-child {
    border-bottom: none;
}

.budget-row--cat {
    padding-top: 11px;
}

/* Category head line: label + amounts/input on one row */
.budget-cat-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Subcategory rows: a single compact line, no bar */
.budget-row--sub {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
}

.budget-row-label {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    color: var(--text-primary);
}

.budget-row--cat .budget-row-label {
    font-weight: 600;
}

.budget-row--sub .budget-row-label {
    font-weight: 400;
}

/* Actual-spent amount (and the header's "actual / budget" roll-up) */
.budget-actual,
.budget-cat-amounts {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.budget-actual.negative,
.budget-cat-amounts .negative {
    color: var(--danger);
}

.budget-unbudgeted-tag {
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Compact budget input */
.budget-input-wrapper {
    width: 120px;
    height: 34px;
    flex-shrink: 0;
}

/* Indent the subcategory rows under their category header */
.budget-subrows {
    padding-left: 14px;
}

/* Category-level progress bar — thin track with a coloured fill */
.budget-bar {
    height: 6px;
    border-radius: 999px;
    background: var(--bg-secondary);
    overflow: hidden;
    margin-top: 8px;
}

.budget-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}

.budget-bar--under .budget-bar-fill {
    background: #789c6c;          /* same green as positive savings */
}

.budget-bar--approaching .budget-bar-fill {
    background: #e0a838;          /* amber: nearing the limit */
}

.budget-bar--over .budget-bar-fill {
    background: var(--danger);
}

.budget-bar--none {
    background: var(--bg-secondary);
}

.budget-row--unbudgeted .budget-row-label {
    color: var(--text-secondary);
}

.expenses-breakdown-table {
    border-collapse: separate;
    border-spacing: 0;
}

.expenses-breakdown-table th {
    text-align: center;
    background-color: transparent;
    border-bottom: 2px solid var(--border);
}

.category-row--collapsible {
    cursor: pointer;
    user-select: none;
}

td.category-row-tinted {
    background-color: var(--cat-bg, transparent);
    color: var(--cat-color, var(--text-primary));
}

td.category-row-tinted:first-child {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

td.category-row-tinted:last-child {
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

.category-row--collapsible:hover td.category-row-tinted {
    filter: brightness(0.96);
}


.expenses-breakdown-table td:nth-child(2),
.expenses-breakdown-table td:nth-child(3) {
    text-align: center;
}

.expenses-breakdown-table tfoot td {
    text-align: center;
}

.income-category-header-row td {
    padding: 8px 12px;
    height: 60px;
    background-color: transparent;
    border-radius: 4px;
    vertical-align: middle;
}

.income-sub-row td {
    padding: 6px 12px;
}

.income-form-row td {
    padding: 8px 12px;
    vertical-align: middle;
    text-align: center;
}

.income-form-row td:first-child {
    text-align: left;
}

.income-form-row td .currency-input-wrapper {
    margin: 0 auto;
}

.tax-rate-cell {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: center;
}

/* ── UNCATEGORISED ROW ── */
.uncategorised-row td {
    background-color: #fff8e6;
    color: #92600a;
}

/* ── HISTORICAL TABLE ── */
.historical-header {
    display: flex;
    flex-wrap: wrap;          /* title + control drop to two rows when they don't fit */
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 24px;
}

/* ── SLIDING TOGGLE ── */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── MORTGAGE CALCULATOR ── */
.mortgage-top-layout {
    display: flex;
    flex-wrap: wrap;          /* configurator + results stack when narrow */
    gap: 24px;
    align-items: flex-start;
    margin-bottom: 0;
}

.mortgage-top-layout > .card {
    flex: 1 1 320px;
    min-width: 0;
}

.mortgage-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.result-item {
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.result-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.result-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: #526258;
}

.mortgage-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mortgage-item {
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.mortgage-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.mortgage-header strong {
    font-size: 1.1rem;
    color: var(--text-primary);
}

.mortgage-category {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    background-color: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 4px;
}

.mortgage-details {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 48px;
    row-gap: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.mortgage-detail-row {
    display: contents;
}

.mortgage-item-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ── MORTGAGE SETTLEMENT ── */
.mortgage-settled-header {
    margin: 20px 0 4px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
}

.mortgage-item--settled {
    opacity: 0.85;
}

.mortgage-settled-badge {
    display: inline-block;
    margin-top: 6px;
    margin-bottom: 12px;
    padding: 2px 10px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
}

.mortgage-settle-panel {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settle-field {
    max-width: 240px;
}

.settle-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
}

.settle-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* ── PARTIAL AMORTISATION ── */
.mortgage-prepay-panel {
    gap: 18px;
    padding-top: 20px;
}

.prepay-fields {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.prepay-fields .currency-input-wrapper {
    width: 100%;
}

.prepay-mode-toggle {
    align-self: flex-start;
    margin: 10px 0 2px;
}

.mortgage-prepay-list {
    margin-top: 16px;
    padding: 12px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mortgage-prepay-list-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.mortgage-prepay-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.mortgage-prepay-row + .mortgage-prepay-row {
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* ── EDITOR EVENTS BANNER ── */
.mortgage-edit-events {
    margin: 16px 0;
    padding: 16px 18px;
    background: rgba(119, 156, 108, 0.08);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.mortgage-edit-events-title {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.mortgage-edit-event-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.mortgage-edit-event-row:last-child {
    margin-bottom: 0;
}

.mortgage-edit-event-tag {
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(119, 156, 108, 0.18);
    color: #526258;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.mortgage-edit-event-tag--settled {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-secondary);
}

.mortgage-prepay-remove {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

/* ── MORTGAGE AMORTISATION TABLE ── */
.amortization-table {
    min-width: 760px;
}

/* Soft highlight for months where a partial amortisation takes place */
.amort-prepaid-row > td {
    background: rgba(119, 156, 108, 0.12);
}

.amort-payments-group {
    background-color: rgba(239, 247, 236, 0.4);
}

.amort-remainder-group {
    background-color: rgba(82, 98, 88, 0.08);
}

.amort-num {
    text-align: right;
}

.amort-bold {
    font-weight: 600;
}

.amort-year-row .expand-toggle {
    display: none;
}

.amortization-table .historical-header-row-1 th {
    background-color: transparent;
}

.amortization-table .historical-header-row-2 th {
    background-color: transparent;
}

/* ── MORTGAGE AMORTISATION CHART ── */
.mortgage-chart-title {
    margin-top: 24px;
    margin-bottom: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.mortgage-chart-wrapper {
    overflow-x: auto;
    height: 280px;
}

.mortgage-chart-wrapper canvas {
    height: 280px !important;
}

/* ── FORM ACTIONS ── */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.toggle-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sliding-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sliding-toggle-label {
    font-weight: 500;
    transition: color 0.2s ease;
}

.sliding-toggle-label.active {
    color: var(--text-primary);
    font-weight: 600;
}

.switch {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.switch-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--accent);
    border-radius: 24px;
    transition: background-color 0.2s ease;
}

.switch-thumb {
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.switch input:checked ~ .switch-track {
    background-color: var(--accent);
}

.switch input:checked ~ .switch-thumb {
    transform: translateX(20px);
}

.table-wrapper {
    overflow-x: auto;
}

.historical-table {
    min-width: 800px;
}

.historical-table td {
    text-align: center;
}

.historical-table td.period-cell {
    text-align: left;
}

.historical-footer-row td.period-cell {
    text-align: center;
}

.historical-table .group-header-cell {
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.historical-table .period-col.group-header-cell,
.historical-table .networth-col.group-header-cell {
    border-bottom: none;
    vertical-align: middle;
}

.income-group {
    background-color: rgba(110, 168, 254, 0.08);
}

.savings-group {
    background-color: rgba(61, 207, 142, 0.08);
}

.separator-col {
    width: 24px;
    min-width: 24px;
    border: none !important;
    background-color: var(--bg-card) !important;
    padding: 0 !important;
}

.period-col {
    min-width: 140px;
}

/* No line wrapping — income historical table */
.income-hist-table th,
.income-hist-table td {
    white-space: nowrap;
}

/* Sticky Period column + its separator — shared by income and expenses historical tables */
.income-hist-table th.period-col,  .income-hist-table td.period-cell,
.expenses-hist-table th.period-col, .expenses-hist-table td.period-cell {
    position: sticky;
    left: 0;
    z-index: 2;
    background-color: var(--bg-card);
}

.income-hist-table th.period-sep,  .income-hist-table td.period-sep,
.expenses-hist-table th.period-sep, .expenses-hist-table td.period-sep {
    position: sticky;
    left: 140px;
    z-index: 2;
    background-color: var(--bg-card) !important;
    box-shadow: none;
    transition: box-shadow 0.2s ease;
}

.income-hist-table.is-scrolled th.period-sep,  .income-hist-table.is-scrolled td.period-sep,
.expenses-hist-table.is-scrolled th.period-sep, .expenses-hist-table.is-scrolled td.period-sep {
    box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.08);
}

.income-hist-table thead th.period-col,  .income-hist-table thead th.period-sep,
.expenses-hist-table thead th.period-col, .expenses-hist-table thead th.period-sep {
    z-index: 3;
}

.income-hist-table .year-row td.period-cell,  .income-hist-table .year-row td.period-sep,
.expenses-hist-table .year-row td.period-cell, .expenses-hist-table .year-row td.period-sep {
    background-color: var(--bg-primary);
}

.income-hist-table .year-row:hover td.period-cell,  .income-hist-table .year-row:hover td.period-sep,
.expenses-hist-table .year-row:hover td.period-cell, .expenses-hist-table .year-row:hover td.period-sep {
    background-color: var(--border);
}

.income-hist-table .current-month-row td.period-cell,  .income-hist-table .current-month-row td.period-sep,
.expenses-hist-table .current-month-row td.period-cell, .expenses-hist-table .current-month-row td.period-sep {
    background: linear-gradient(rgba(79, 142, 247, 0.06), rgba(79, 142, 247, 0.06)), var(--bg-card);
}

.income-hist-table .month-row:hover td.period-cell,  .income-hist-table .month-row:hover td.period-sep,
.expenses-hist-table .month-row:hover td.period-cell, .expenses-hist-table .month-row:hover td.period-sep {
    background-color: var(--bg-primary);
}

/* Sticky Period column + its separator — net worth historical table (same mechanism) */
.networth-hist-table th.period-col,
.networth-hist-table td.period-cell {
    position: sticky;
    left: 0;
    z-index: 2;
    background-color: var(--bg-card);
}

.networth-hist-table th.period-sep,
.networth-hist-table td.period-sep {
    position: sticky;
    left: 140px;
    z-index: 2;
    background-color: var(--bg-card) !important;
    box-shadow: none;
    transition: box-shadow 0.2s ease;
}

.networth-hist-table.is-scrolled th.period-sep,
.networth-hist-table.is-scrolled td.period-sep {
    box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.08);
}

.networth-hist-table thead th.period-col,
.networth-hist-table thead th.period-sep {
    z-index: 3;
}

.networth-hist-table .year-row td.period-cell,
.networth-hist-table .year-row td.period-sep {
    background-color: var(--bg-primary);
}

.networth-hist-table .year-row:hover td.period-cell,
.networth-hist-table .year-row:hover td.period-sep {
    background-color: var(--border);
}

.networth-hist-table .current-month-row td.period-cell,
.networth-hist-table .current-month-row td.period-sep {
    background: linear-gradient(rgba(79, 142, 247, 0.06), rgba(79, 142, 247, 0.06)), var(--bg-card);
}

.networth-hist-table .month-row:hover td.period-cell,
.networth-hist-table .month-row:hover td.period-sep {
    background-color: var(--bg-primary);
}

/* No line wrapping — expenses historical table */
.expenses-hist-table th,
.expenses-hist-table td {
    white-space: nowrap;
}


.networth-col {
    min-width: 120px;
}


/* ── HISTORICAL KPI CARDS ── */
.hist-kpi-grid {
    display: grid;
    /* Fluid: equal columns that reflow to fewer rows as the window narrows,
       instead of the fixed 2fr/1fr tracks that overflowed at intermediate widths.
       300px comfortably fits the two-column KPI cards (their headers wrap). */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 16px;
}

.hist-kpi-grid--income {
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
}

.hist-kpi-grid--groups {
    /* Group cards are single-column and narrower, so they can pack tighter */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}

.kpi-card-with-info {
    position: relative;
}

.kpi-info-icon {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: default;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.15s ease;
    user-select: none;
}

.kpi-info-icon:hover {
    opacity: 1;
    color: #526258;
}

.kpi-group-tooltip {
    display: none;
    position: fixed;
    z-index: 9999;
    width: 260px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 10px 14px;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
    pointer-events: none;
}


.hist-kpi-centered {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 16px;
    max-width: 60%;
    margin-left: auto;
    margin-right: auto;
}

.hist-kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
    display: flex;
    flex-wrap: wrap;          /* two-column cards stack their columns when the
                                 grid cell is too narrow, instead of overflowing */
    align-items: stretch;
    padding: 14px;
    gap: 8px 0;
}

.hist-kpi-col {
    /* No min-width:0 here on purpose: the column must keep its content width so
       the card wraps its two columns (and they stack full-width) rather than
       shrinking until the nowrap value spills past the card border. */
    flex: 1 1 130px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 6px;
}

.hist-kpi-col-sep {
    width: 1px;
    background: var(--border);
    flex-shrink: 0;
    align-self: stretch;
    margin: 6px 8px;
}

.hist-kpi-col-header {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    text-align: center;
    /* Allowed to wrap so a long header (e.g. "Cumulative income") never forces
       its two-column card wider than a narrow grid cell. */
    white-space: normal;
    padding: 2px 0 4px;
}

.hist-kpi-mini-card {
    flex: 1;
    min-width: 0;            /* shrink within its column instead of overflowing */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px 16px;
    gap: 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.hist-kpi-sublabel {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    white-space: normal;     /* wrap a long sublabel rather than force overflow */
}

.hist-kpi-value {
    font-size: 1.35rem;
    font-weight: 300;
    color: var(--text-secondary);
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.hist-kpi-weight {
    font-size: 0.75rem;
    text-align: center;
}

.hist-kpi-value.accent          { color: #526258; }
.hist-kpi-value.savings-positive { color: #789c6c; }
.hist-kpi-value.negative         { color: var(--danger); }
.hist-kpi-value.bold             { font-weight: 700; }

.kpi-var-positive {
    font-size: 0.8rem;
    font-weight: 400;
    color: #789c6c;
}
.kpi-var-negative {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--danger);
}

/* ── YEAR / MONTH ROWS ── */
.year-row {
    cursor: pointer;
    background-color: var(--bg-primary);
}

.year-row:hover {
    background-color: var(--border);
}

.year-row--separator td {
    border-top: 2px solid var(--border) !important;
}

.year-row .period-cell {
    box-shadow: inset 3px 0 0 var(--accent);
    padding-left: 13px !important;
}

.year-cell {
    font-size: 0.95rem;
}

.month-row {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.month-row:hover {
    background-color: var(--bg-primary);
}

.month-cell {
    padding-left: 32px !important;
}

.month-link {
    color: var(--accent);
    font-size: 0.9rem;
}

.month-link:hover {
    text-decoration: underline;
}

.current-month-row {
    background-color: rgba(79, 142, 247, 0.06) !important;
}

.current-month-row:hover {
    background-color: rgba(79, 142, 247, 0.1) !important;
}

.hidden {
    display: none !important;
}

.historical-header-row-1 th,
.historical-header-row-2 th {
    background-color: var(--bg-card);
}

/* ── HISTORICAL FOOTER ── */
.historical-footer-row td {
    border-top: 2px solid var(--border);
    padding: 12px;
    background-color: var(--bg-primary);
    font-weight: 400 !important;
}

.historical-footer-row td.period-cell,
.historical-footer-row td.exp-footer-bold {
    font-weight: 700 !important;
}

.historical-total-row td {
    font-size: 0.875rem;
}

.historical-avg-row td {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ── MONTH NAVIGATOR ── */
.month-navigator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    margin-bottom: 24px;
}

.month-navigator-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.month-nav-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.month-nav-btn:hover:not(.disabled) {
    background-color: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.month-nav-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.month-picker-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.month-picker-wrapper:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(79, 142, 247, 0.12);
}

.month-picker-wrapper::before {
    content: '📅';
    font-size: 0.9rem;
}

.month-picker-wrapper input {
    background: transparent;
    border: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    text-align: center;
    width: 150px;
    outline: none;
    font-weight: 500;
}

/* ── HISTORICAL INCOME TABLE HEADERS ── */
.historical-table thead th {
    text-align: center;
    vertical-align: middle;
    background-color: transparent;
}

.historical-table thead th:first-child {
    text-align: center;
    vertical-align: middle;
}

.year-summary-bold {
    font-weight: 700 !important;
}

.year-row td {
    font-weight: 400;
}

.year-row td.amort-bold {
    font-weight: 600;
}

.year-row td.year-rate-cell {
    font-weight: 400 !important;
}

/* ── CHART CONTROLS ── */
.chart-controls {
    display: flex;
    gap: 24px;
    align-items: center;
}

/* ── LOGO ── */
#app-logo {
    width: 120px;
    height: auto;
    display: block;
}

/* ── DUAL CHART ROW ── */
.dual-chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: 32px;
    margin-top: 24px;
}

.dual-chart-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.dual-chart-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

#income-pie-gross-chart,
#income-pie-net-chart {
    max-height: 400px;
    max-width: 400px;
}

/* ── EXPENSES TREND ── */
.exp-trend-full {
    height: 320px;
}

/* ── EXPENSES PIE ── */
.exp-pie-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 72px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.exp-pie-wrapper {
    display: flex;
    justify-content: center;
}

.exp-pie-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 180px;
    max-width: 260px;
}

.exp-pie-legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.exp-pie-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.exp-pie-legend-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.exp-pie-legend-value {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

#expenses-pie-chart {
    width: 440px !important;
    height: 440px !important;
}

/* ── CATEGORY CHARTS ── */
.category-chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 12px;
    margin-bottom: 20px;
}

.category-chart-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: none;
    letter-spacing: 0;
}

.category-bar-full {
    height: 320px;
}

/* ── AUTH SCREEN ── */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: #526258;
}

#auth-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

#auth-logo {
    font-family: 'League Spartan', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: #526258;
    text-align: center;
    margin-bottom: 4px;
    letter-spacing: -0.06em;
}

/* Brand wordmark rendered from assets/logo.png via a recolorable mask, so it
   matches the real logo exactly. Falls back to the League Spartan text above
   on browsers without CSS mask support. */
@supports ((-webkit-mask-image: url(x.png)) or (mask-image: url(x.png))) {
    #auth-logo {
        width: 119px;
        height: 30px;
        margin: 0 auto 4px;
        font-size: 0;
        color: transparent;
        background-color: #526258;
        -webkit-mask: url(assets/logo-mask.png) no-repeat center / contain;
        mask: url(assets/logo-mask.png) no-repeat center / contain;
    }
}

#auth-tagline {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 32px;
}

#auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 28px;
}

.auth-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s ease;
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    color: #526258;
    border-bottom-color: #526258;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.auth-field label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.auth-field input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.15s ease;
    outline: none;
}

.auth-field input:focus {
    border-color: #526258;
}

.auth-submit {
    background-color: #526258;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 11px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
    transition: opacity 0.15s ease;
}

.auth-submit:hover {
    opacity: 0.9;
}

.auth-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

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

.auth-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: auth-spin 0.7s linear infinite;
    vertical-align: middle;
}

.auth-error {
    font-size: 0.825rem;
    color: #e05555;
    min-height: 18px;
}

.auth-success {
    font-size: 0.825rem;
    color: #526258;
    min-height: 18px;
}

.auth-link-row {
    text-align: center;
    font-size: 0.825rem;
}

.auth-link-row a {
    color: #526258;
    text-decoration: none;
}

.auth-link-row a:hover {
    text-decoration: underline;
}

.auth-consent {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.auth-consent input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.auth-consent label {
    cursor: pointer;
    line-height: 1.5;
}

.auth-consent a {
    color: var(--accent);
    text-decoration: none;
}

.auth-consent a:hover {
    text-decoration: underline;
}

.auth-legal-links {
    text-align: center;
    font-size: 0.775rem;
    margin-top: 24px;
    color: var(--text-muted);
}

.auth-legal-links a {
    color: var(--text-muted);
    text-decoration: none;
}

.auth-legal-links a:hover {
    text-decoration: underline;
}

.auth-reset-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* ── DOCUMENTS ── */
.documents-card {
    max-width: 640px;
}

.documents-text {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.5;
    margin-bottom: 8px;
}

.documents-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin-bottom: 16px;
}

/* ════════════════════════════════════════════════════════════════════════
   RESPONSIVE / MOBILE
   Kept at the end of the file so these overrides win over the same-specificity
   desktop rules above (media queries add no specificity — only source order
   breaks the tie). Two breakpoints: 768px (tablet & large phones) collapses the
   layout to a single column; 480px (phones) tightens spacing and type.
   ════════════════════════════════════════════════════════════════════════ */

/* Global safety net: media and tables never push the page wider than the screen.
   Wide data tables keep their own horizontal scroll via .table-wrapper. */
img,
svg,
canvas {
    max-width: 100%;
}

@media (max-width: 768px) {

    /* ── App shell: stack the sidebar on top of the content ──
       The desktop layout is a fixed 240px sidebar + margin-left content. On
       mobile we turn #app into a column so the sidebar becomes a top bar and
       the content takes the full width. */
    #app {
        flex-direction: column;
    }

    #sidebar {
        position: static;
        width: 100%;
        min-height: auto;
        flex-direction: column;
        gap: 8px;
        padding: 12px 16px;
        border-right: none;
        border-bottom: 1px solid #d4e6cf;
    }

    #logo {
        padding: 4px 0;
        border-bottom: none;
        justify-content: flex-start;
    }

    #main-nav {
        flex: none;
        padding: 0;
    }

    #main-nav ul {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }

    #main-nav li {
        margin-bottom: 0;
    }

    .nav-link,
    .settings-link {
        margin: 0;
        padding: 8px 14px;
    }

    #sidebar-bottom {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 0;
        margin-top: 4px;
    }

    #logout-btn {
        width: auto;
        margin: 0;
        padding: 8px 14px;
    }

    #content {
        margin-left: 0;
        min-height: 0;
        padding: 24px 16px;
        overflow-x: hidden; /* catch any stray element that still overflows */
    }

    /* ── Collapse every multi-column grid to a single column ── */
    .card-grid,
    .form-grid,
    .form-grid--mortgage,
    .form-grid--projection,
    .settings-field-group,
    .balance-grid,
    .dual-chart-row {
        grid-template-columns: 1fr;
    }

    /* Historical KPI grids: single column and drop the centring max-widths */
    .hist-kpi-grid,
    .hist-kpi-grid--income,
    .hist-kpi-grid--networth,
    .hist-kpi-grid--groups,
    .hist-kpi-centered {
        grid-template-columns: 1fr;
        max-width: none;
    }

    /* Settings two-column layout → stacked; unstick the nav while scrolling */
    .settings-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .settings-nav {
        position: static;
    }

    /* ── Stack horizontal flex panels vertically ── */
    .income-panel-row,
    .balance-equation-layout,
    .mortgage-top-layout,
    .expenses-breakdown-layout,
    .summary-strip {
        flex-direction: column;
    }

    .summary-group {
        width: 100%;
    }

    /* The expense transactions card is half-width on desktop — full width here */
    .expense-list-card {
        width: 100%;
    }

    .chart-controls {
        flex-wrap: wrap;
        gap: 12px;
    }

    .exp-pie-row {
        gap: 24px;
    }

    /* ── Cap fixed-pixel charts so they never overflow the viewport ──
       max-width clamps the width; height:auto preserves the canvas aspect
       ratio from its width/height attributes. */
    #income-breakdown-pie-chart,
    #expenses-pie-chart {
        max-width: 100% !important;
        height: auto !important;
    }

    /* ── Let the unwrapped wide tables scroll instead of breaking the page ──
       (Historical tables already scroll inside their own .table-wrapper.) */
    #mortgage-amortization-table,
    .expenses-breakdown-card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .section h2 {
        font-size: 1.4rem;
    }
}

@media (max-width: 480px) {

    #content {
        padding: 20px 12px;
    }

    .card,
    .chart-container,
    .chart-container-donut {
        padding: 16px;
    }

    .section h2 {
        font-size: 1.3rem;
    }

    /* Tab rows can be wider than the screen — let them scroll sideways.
       Hide the scrollbar: on a touch device the bar is a thick, permanently
       visible gray strip under the tabs; swiping the tabs is the affordance. */
    .subsection-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;          /* Firefox */
    }

    .subsection-tabs::-webkit-scrollbar {
        display: none;                  /* Chrome, Safari, Edge */
    }

    .tab-btn,
    .tab-btn-secondary {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Headers with a title + control: wrap instead of overflowing */
    .chart-header,
    .historical-header,
    .list-header,
    .income-pie-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .summary-item {
        padding: 14px 12px;
    }

    .month-navigator {
        gap: 16px;
    }

    /* Inactivity toast: allow wrapping so it never exceeds the viewport width */
    #inactivity-warning {
        white-space: normal;
        max-width: calc(100vw - 24px);
    }

    /* Auth card: breathing room from the screen edges */
    #auth-screen {
        padding: 16px;
    }

    #auth-card {
        padding: 28px 22px;
    }

    /* ── Transaction rows (income + expenses) ──
       The desktop row is a single non-wrapping flex line: description/category
       on the left, amount(s) + Edit/Delete on the right. On a phone that line is
       wider than the card, so the action buttons overflow and get clipped. Let
       the row wrap: the description takes the first line full-width, and the
       amount + buttons sit on a second full-width line (amount pinned left,
       buttons grouped right via the auto margin). */
    .expense-item {
        flex-wrap: wrap;
        gap: 8px 16px;
    }

    .expense-item-info {
        flex-basis: 100%;
    }

    .expense-item-right {
        width: 100%;
    }

    .expense-item-right > :first-child {
        margin-right: auto;
    }

    /* Income amounts read left-to-right once they sit at the start of the row */
    .income-tx-amounts {
        align-items: flex-start;
    }

    /* ── Settings category rows ──
       Same problem as the transaction rows: name + "Subcategories (n)" + Edit +
       Delete is too wide for a phone, clipping Delete. Wrap so the name takes the
       first line and the action buttons sit on a second line below it. */
    .category-item-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    .category-name-row {
        flex-basis: 100%;
    }

    .category-item-actions {
        width: 100%;
    }

    .category-item-actions > :first-child {
        margin-right: auto;
    }

    /* ── Historical KPI cards ──
       A KPI card can hold two side-by-side columns (e.g. "Monthly average" +
       "Cumulative income"). On a phone the pair overflows the card, clipping the
       second column. Stack the columns and turn the vertical divider into a
       horizontal one. */
    .hist-kpi-card {
        flex-direction: column;
    }

    .hist-kpi-col-sep {
        width: auto;
        height: 1px;
        margin: 8px 6px;
    }
}
