:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #eeeeee;
    --text: #14151a;
    --text-muted: #6b6d78;
    --text-faint: #9d9fa8;
    --accent: #4f46e5;
    --accent-soft: #eef0fd;
    --accent-contrast: #ffffff;
    --danger: #e0455b;
    --income: #16a34a;
    --income-soft: #eefbf3;
    --expense: #e0455b;
    --expense-soft: #fdeef1;
    --warning: #b45309;
    --warning-soft: #fef3e2;
    --series-1: #4f46e5;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(20, 21, 26, 0.04), 0 8px 24px rgba(20, 21, 26, 0.05);
    --header-height: 65px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #101114;
        --surface: #1a1b20;
        --border: #2b2c33;
        --text: #f5f5f7;
        --text-muted: #a7a8b3;
        --text-faint: #75767f;
        --accent: #7c74ea;
        --accent-soft: #262449;
        --accent-contrast: #101114;
        --danger: #ef6b7d;
        --income: #34c46f;
        --income-soft: #123322;
        --expense: #ef6b7d;
        --expense-soft: #3a1e24;
        --warning: #f0b155;
        --warning-soft: #3a2c14;
        --series-1: #7c74ea;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.3);
    }
}

:root[data-theme="dark"] {
    --bg: #101114;
    --surface: #1a1b20;
    --border: #2b2c33;
    --text: #f5f5f7;
    --text-muted: #a7a8b3;
    --text-faint: #75767f;
    --accent: #7c74ea;
    --accent-soft: #262449;
    --accent-contrast: #101114;
    --danger: #ef6b7d;
    --income: #34c46f;
    --income-soft: #123322;
    --expense: #ef6b7d;
    --expense-soft: #3a1e24;
    --warning: #f0b155;
    --warning-soft: #3a2c14;
    --series-1: #7c74ea;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
    display: flex;
    align-items: center;
    gap: 28px;
    height: var(--header-height);
    padding: 0 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-header__brand { display: flex; align-items: center; }
.app-header__logo { height: 30px; width: auto; display: none; }
.app-header__logo--light { display: block; }

:root[data-theme="dark"] .app-header__logo--light { display: none; }
:root[data-theme="dark"] .app-header__logo--dark { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .app-header__logo--light { display: none; }
    :root:not([data-theme="light"]) .app-header__logo--dark { display: block; }
}

.app-nav { display: flex; gap: 24px; flex: 1; }
.app-nav a { color: var(--text-muted); font-size: 14px; font-weight: 500; padding: 6px 0; position: relative; }
.app-nav a:hover { text-decoration: none; color: var(--text); }
.app-nav a.is-active { color: var(--text); font-weight: 600; }
.app-nav a.is-active::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -19px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

.app-header__actions { display: flex; align-items: center; gap: 14px; }
.app-header__actions > a { color: var(--text-faint); font-size: 14px; }

.household-switcher select {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

/* Generic small dropdown panel — language menu, avatar menu. Opened/closed
   via app.js's initDropdowns(), which toggles this same display:none/block
   on whatever panel follows a [data-dropdown-toggle] button. */
.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 6px;
    min-width: 150px;
}
.dropdown-menu--right { left: auto; right: 0; }
.dropdown-menu a, .dropdown-menu__button {
    display: block;
    padding: 8px 10px;
    border-radius: 6px;
    color: var(--text) !important;
    font-size: 14px !important;
    font-weight: 500;
}
.dropdown-menu a:hover, .dropdown-menu__button:hover { background: var(--bg); text-decoration: none; }
.dropdown-menu a.is-active { color: var(--accent) !important; font-weight: 700; }
/* Logout is a <form><button> (POST, CSRF-protected) rather than a plain
   link — reset it to look identical to the <a> rows around it. */
.dropdown-menu form { margin: 0; }
.dropdown-menu__button {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    font: inherit;
    cursor: pointer;
}

.lang-switcher, .avatar-menu { position: relative; }
.lang-switcher__current {
    border: 1px solid var(--border);
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
}
.lang-switcher__current:hover { border-color: var(--accent); color: var(--accent); }

.theme-toggle {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 6px;
    border-radius: 8px;
    display: flex;
}
.theme-toggle:hover { background: var(--bg); }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: inline; }
}

.avatar-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.avatar-btn svg { width: 18px; height: 18px; }
.avatar-btn:hover { border-color: var(--accent); }
.avatar-menu--guest { display: flex; align-items: center; gap: 8px; color: var(--text-faint) !important; font-size: 14px; }
.avatar-btn--guest { background: var(--bg); color: var(--text-faint); cursor: default; }
.avatar-menu--guest:hover .avatar-btn--guest { border-color: var(--border); }

.app-main { max-width: 1080px; margin: 0 auto; padding: 40px 32px 80px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 24px;
}

.card h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; margin-top: 0; }
.card h2 { font-size: 16px; font-weight: 700; margin: 0 0 4px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; color: var(--text-muted); }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}
.form-group input[type="checkbox"],
.form-group input[type="radio"] {
    width: auto;
    padding: 0;
    border: none;
    background: none;
    accent-color: var(--accent);
}

/* Checkbox first, label text right after it, same row — for every
   <label class="checkbox-label"><input type="checkbox"> Text</label>
   pair (rule active/recurring toggles, template "make global", etc).
   Plain .form-group label + a bare checkbox inherited the block/bold
   text-label styling meant for <input>/<select> labels, which stretched
   the checkbox to the row's full width via the generic .form-group input
   rule above — this class opts out of that entirely. Qualified with
   .form-group (matching that rule's own specificity) so its font-size/weight
   actually win instead of silently losing to the plainer .checkbox-label
   selector — a checkbox's own label reads as normal body text, not the
   small muted caption style meant for text-input labels. */
.form-group .checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; flex-shrink: 0; }

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

.btn {
    display: inline-flex;
    align-items: center;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}
.btn:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); color: var(--text); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn-primary:hover { color: var(--accent-contrast); opacity: 0.92; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); font-size: 13px; padding: 6px 10px; }
.btn-ghost:hover { border-color: transparent; }

.btn#add-condition {
    margin-top: -5px;
    margin-bottom: 10px;
}

/* Square icon-only button (e.g. the "view details" magnifying glass) — same
   footprint as the datepicker toggle, much smaller than a text .btn. Its
   label lives in data-tooltip (see initTooltips() in app.js), not title. */
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; font-size: 14px; line-height: 1; }

/* Custom hover tooltip driven by data-tooltip (see initTooltips() in app.js)
   — appears immediately on hover, unlike the native title attribute's ~1s
   dwell delay, so it works even on an icon-only button. */
.js-tooltip {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 300;
    background: var(--text);
    color: var(--bg);
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.1s ease;
}
.js-tooltip.is-visible { opacity: 1; visibility: visible; }

.badge { display: inline-block; font-weight: 600; font-size: 12px; color: var(--text-faint); background: var(--bg); padding: 4px 10px; border-radius: 999px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }
.pagination__info { font-size: 13px; color: var(--text-muted); }
.pagination span.btn[aria-disabled="true"] { opacity: 0.4; cursor: default; pointer-events: none; }

/* Section header inside a card: title on the left, one or more actions on
   the right — replaces ad hoc float:right on <h1>/<h2>. */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.card-head h1, .card-head h2 { margin: 0; }
.card-head__actions { display: flex; align-items: center; gap: 10px; }

/* Two cards side by side (e.g. expense/income breakdown) — stacks on narrow viewports. */
.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) {
    .grid-two { grid-template-columns: 1fr; }
}

.filter-row { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; }

.summary-row { display: flex; gap: 24px; color: var(--text-muted); font-size: 13px; margin: 8px 0 22px; }
.summary-row .amount-income, .summary-row .amount-expense { font-weight: 700; }

table { width: 100%; border-collapse: collapse; }

/* Bare inline-edit inputs/selects inside table cells (e.g. the categories
   table's per-row rename/reparent controls) aren't wrapped in .form-group,
   so they'd otherwise fall back to the browser's default white styling
   regardless of theme. */
table input[type="text"],
table select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
table input[type="text"]:focus,
table select:focus { outline: none; border-color: var(--accent); }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); }
th {
    color: var(--text-faint); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
    position: sticky; top: var(--header-height); z-index: 5; background: var(--surface); box-shadow: 0 1px 0 var(--border);
}
tr:last-child td { border-bottom: none; }

.amount-income { color: var(--income); font-weight: 700; }
.amount-expense { color: var(--expense); font-weight: 700; }

.empty-state { text-align: center; padding: 48px 0; color: var(--text-muted); }

/* Small caption under a form field/checkbox (priority hint, recurring hint,
   etc) — deliberately smaller/quieter than the field's own label so the two
   can't be confused for equally-important text. */
.field-hint { margin: 4px 0 0; font-size: 12px; color: var(--text-faint); text-align: left; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; font-weight: 500; }
.alert-error { background: var(--expense-soft); color: var(--expense); }
.alert-success { background: var(--income-soft); color: var(--income); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }

.form-narrow { max-width: 360px; margin: 48px auto; }

/* Wider than .form-narrow (single-field auth forms) but still capped well
   short of .app-main's 1080px — for pages with several grouped fields (e.g.
   the tabbed profile page) that look cramped at 360px on desktop but
   shouldn't stretch text inputs edge-to-edge either. Still shrinks fine on
   mobile since it's just a max-width with no fixed width of its own. */
.form-medium { max-width: 640px; margin: 48px auto; }

/* Generic tab strip — pairs with initTabs() in app.js, which toggles
   [hidden] on the matching [data-tab-panel] sibling and persists the active
   tab in the URL hash so a same-page form POST (e.g. the profile forms,
   whose <form action> carries the hash) lands back on the right tab. */
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--border); margin: 20px 0 24px; }
.tab-btn {
    border: none;
    background: none;
    cursor: pointer;
    padding: 0 0 10px;
    margin-bottom: -1px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active { color: var(--text); border-bottom-color: var(--accent); }

.stat-tile__label { color: var(--text-muted); font-size: 13px; font-weight: 500; margin-bottom: 10px; }
.stat-tile__value { font-size: 52px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat-tile__delta { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 700; margin-top: 14px; padding: 5px 10px; border-radius: 999px; }
.stat-tile__delta.amount-income { background: var(--income-soft); }
.stat-tile__delta.amount-expense { background: var(--expense-soft); }

.chart { width: 100%; }
.chart-axis-label { fill: var(--text-faint); font-size: 11px; }
.chart-net-label { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }

.chart-legend { display: flex; gap: 20px; margin: 4px 0 12px; }
.chart-legend__item { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-muted); }
.chart-legend__dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.chart-tooltip {
    position: absolute;
    display: none;
    z-index: 100;
    background: var(--text);
    color: var(--bg);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    pointer-events: none;
    max-width: 220px;
}

/* Category breakdown rows (dashboard "expense/income by category") — two
   lines per row so nothing shifts around depending on label length: swatch
   + name top-left, amount + % of the filtered period's total top-right,
   then a full-width track below filled to that %. The unfilled remainder
   of the track is a flat neutral tint, standing in for "0 to 100%" so every
   bar starts at the same visual baseline. */
.cat-row { padding: 13px 0; border-bottom: 1px solid var(--border); }
.cat-row:first-child { padding-top: 0; }
.cat-row:last-child { border-bottom: none; padding-bottom: 0; }
.cat-row--child { padding-left: 19px; }
.cat-row__top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 9px; }
.cat-row__label { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; min-width: 0; }
.cat-row--child .cat-row__label { font-weight: 500; font-size: 13px; color: var(--text-muted); }
.cat-row__label .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.cat-row__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-row__arrow {
    border: none; background: none; padding: 0; margin: 0;
    color: var(--accent); font-size: 13px; font-weight: 700; cursor: pointer; line-height: 1;
}
.cat-row__amt { display: flex; align-items: baseline; gap: 7px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.cat-row__amt .val { font-weight: 700; font-size: 14px; }
.cat-row--child .cat-row__amt .val { font-weight: 600; font-size: 13px; }
.cat-row__amt .pct { font-weight: 600; font-size: 12px; color: var(--text-faint); background: var(--bg); padding: 2px 7px; border-radius: 999px; }
.cat-row__track { height: 8px; border-radius: 5px; background: #eeeef0; overflow: hidden; }
:root[data-theme="dark"] .cat-row__track { background: #26272e; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .cat-row__track { background: #26272e; }
}
.cat-row--child .cat-row__track { height: 6px; }
.cat-row__fill { height: 100%; border-radius: 5px; }

.forecast-list { list-style: none; margin: 0; padding: 0; }
.forecast-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.forecast-list li:first-child { padding-top: 0; }
.forecast-list li:last-child { border-bottom: none; padding-bottom: 0; }
.forecast-list .confidence { color: var(--text-faint); font-size: 12px; }

.datepicker-wrap { position: relative; display: inline-flex; align-items: center; }
.datepicker-wrap input.date-input { padding-right: 26px; }
.datepicker-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    border: none; background: none; padding: 0; margin: 0;
    font-size: 13px; line-height: 1; cursor: pointer; opacity: 0.65;
}
.datepicker-toggle:hover { opacity: 1; }
.datepicker-panel {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow); padding: 10px; width: 216px;
}
.datepicker-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.datepicker-header button { border: none; background: none; color: var(--text-muted); font-size: 15px; cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.datepicker-header button:hover { background: var(--bg); color: var(--text); }
.datepicker-month-label { font-size: 12px; font-weight: 700; text-transform: capitalize; color: var(--text); }
.datepicker-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.datepicker-weekdays { margin-bottom: 2px; }
.datepicker-weekdays span { font-size: 10px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; }
.datepicker-day { border: none; background: none; padding: 5px 0; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--text); }
.datepicker-day:hover { background: var(--bg); }
.datepicker-day.is-today { border: 1px solid var(--accent); }
.datepicker-day.is-selected { background: var(--accent); color: var(--accent-contrast); }

.column-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 10;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    box-shadow: var(--shadow);
    white-space: nowrap;
}
.column-menu label { display: flex; align-items: center; gap: 8px; font-weight: normal; padding: 3px 0; cursor: pointer; user-select: none; }
.column-menu input { width: auto; margin: 0; accent-color: var(--accent); }

/* Searchable category combobox (see category-select.js) — a look-alike
   <select> replacement. The real <select> it enhances stays in the DOM,
   just visually hidden; only .combo/.combo-* below are ever seen. */
.combo { position: relative; display: inline-block; width: 100%; }
.combo-select { display: none; }
.combo-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}
.combo-trigger:hover { border-color: var(--accent); }
.combo-trigger:focus, .combo-trigger.is-open { outline: none; border-color: var(--accent); }
.combo-trigger__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-trigger__label.is-placeholder { color: var(--text-faint); }
.combo-trigger__arrow { flex-shrink: 0; font-size: 11px; color: var(--text-faint); }
.combo-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    width: max-content;
    min-width: 100%;
    max-width: 320px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 8px;
}
.combo-panel input[type="text"] {
    width: 100%;
    margin-bottom: 6px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}
.combo-panel input[type="text"]:focus { outline: none; border-color: var(--accent); }
.combo-options { max-height: 240px; overflow-y: auto; }
.combo-option {
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.combo-option:hover, .combo-option.is-active { background: var(--bg); }
.combo-option.is-selected { font-weight: 700; color: var(--accent); }
.combo-option--child { padding-left: 22px; }
.combo-option--empty { color: var(--text-faint); text-align: center; cursor: default; }
.combo-option--empty:hover { background: none; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 21, 26, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
}
.modal-box {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    max-width: 460px;
    width: 100%;
    /* Grow with content up to the overlay's own available height (its 24px
       padding on every side, doubled) before scrolling internally — a short
       modal (detail/split) just never reaches it, a tall one (the rule
       popup with several conditions) gets to use the full viewport instead
       of scrolling well before it needed to. */
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}
.modal-box h2 { margin-top: 0; }

/* The rule-creation popup carries the same condition-builder as the
   standalone Rules page (multiple field/op/value/min/max controls per row)
   — the default 460px modal is too narrow for that, so it gets more room. */
#rule-modal .modal-box { max-width: 640px; }

/* One rule condition's field/operator/value/min/max controls, side by side.
   Wraps onto multiple lines rather than squeezing every control down to an
   unreadable width — matters most in the narrower rule-creation popup, but
   helps the standalone Rules page on small viewports too. */
.cond-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cond-row > select, .cond-row > input { width: auto; flex: 1 1 130px; }
.cond-row > .cond-remove { flex: 0 0 auto; }
.modal-close {
    position: absolute;
    top: 14px;
    right: 18px;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-faint);
}
.modal-close:hover { color: var(--text); }
.modal-box dl { margin: 0; }
.modal-box dt { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); margin-top: 16px; }
.modal-box dt:first-child { margin-top: 0; }
.modal-box dd { margin: 3px 0 0; font-size: 15px; }

.bulk-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 16px;
}
.bulk-bar select { width: auto; }
.bulk-bar .combo { width: auto; min-width: 200px; }

/* The review queue's category picker sits inline with several action
   buttons in a nowrap cell — keep it compact instead of stretching to fill
   the row like the Moviments table's dedicated category column does. */
#review-table .combo { width: auto; min-width: 160px; max-width: 220px; }
.bulk-bar #bulk-count { font-weight: 700; }

.row-status { margin-left: 8px; color: var(--income); font-weight: 700; font-size: 13px; }
.row-status.is-error { color: var(--danger); }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable .sort-arrow { display: inline-block; width: 1em; opacity: 0.5; }
th.sortable.sort-asc .sort-arrow, th.sortable.sort-desc .sort-arrow { opacity: 1; }
