:root {
    color-scheme: light dark;
    --bg: #f7f7f5;
    --surface: #ffffff;
    --border: #e2e2df;
    --text: #1c1c1a;
    --text-muted: #6b6b66;
    --accent: #2f6f4f;
    --danger: #a4372c;
    --warning: #9a6700;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}

.site-header nav {
    display: flex;
    gap: 1rem;
}

.site-header nav a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

main {
    max-width: 60rem;
    margin: 0 auto;
    padding: 1.5rem;
}

.flash {
    max-width: 60rem;
    margin: 1rem auto 0;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
}

.flash-success {
    background-color: #e4f3ea;
    color: var(--accent);
}

.flash-error {
    background-color: #f8e6e3;
    color: var(--danger);
}

.banner-warning {
    background-color: #f8e6e3;
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
}

.collapsible-section {
    margin-bottom: 1.5rem;
}

.collapsible-section summary {
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.summary-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    flex: 1;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
}

.summary-card h2 {
    margin: 0 0 0.25rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.summary-card .amount {
    font-size: 1.5rem;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-muted);
}

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

th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    color: var(--text);
}

th.sortable::after {
    content: '\2195';
    display: inline-block;
    margin-left: 0.3rem;
    opacity: 0.4;
}

th.sortable[data-sort-direction="asc"]::after {
    content: '\2191';
    opacity: 1;
}

th.sortable[data-sort-direction="desc"]::after {
    content: '\2193';
    opacity: 1;
}

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

.amount-positive {
    color: var(--accent);
}

.amount-warning {
    color: var(--warning);
}

.category-remaining.amount-negative {
    font-weight: 700;
}

.row-pending {
    color: var(--text-muted);
    font-style: italic;
}

/* Marks a forecast row as a predicted budget spend, not a real scheduled
   bill or pending transaction - a light tint of --warning, the same hue
   already used for "approaching budget" elsewhere, ties it visually to
   "budget" without implying anything's actually wrong. */
.row-budget-estimate {
    background-color: #fdf3d9;
    font-style: italic;
}

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

/* Shrinks a column (the trailing icon-actions one) to fit its content
   instead of it soaking up whatever width the other columns don't need -
   without that, a short icon column leaves the table's one free-text
   column stretched out with a lot of empty space after its content. */
.actions-col {
    width: 1%;
    white-space: nowrap;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    color: var(--text-muted);
    vertical-align: middle;
}

.icon-button + .icon-button {
    margin-left: 0.25rem;
}

.icon-button:hover {
    background-color: var(--bg);
    border-color: var(--border);
}

.icon-button--edit:hover {
    color: var(--accent);
}

.icon-button--delete:hover {
    color: var(--danger);
}

.icon-button--report:hover {
    color: var(--accent);
}

.icon-button--confirm {
    color: var(--accent);
}

.icon-button--confirm:hover {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.icon-warning {
    display: inline-flex;
    vertical-align: middle;
    margin-left: 0.35rem;
    color: var(--danger);
}

.icon-warning--caution {
    color: var(--warning);
}

.transactions-table .date-divider td {
    background-color: var(--bg);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    padding: 0.45rem 0.85rem;
    border-top: 1px solid var(--border);
}

.transactions-table .date-divider:first-child td {
    border-top: none;
}

.trend-table {
    table-layout: fixed;
}

.trend-table th:first-child,
.trend-table td:first-child {
    width: 30%;
}

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

.trend-table th:nth-child(even),
.trend-table td:nth-child(even) {
    background-color: var(--bg);
}

.trend-table td:first-child {
    font-weight: 600;
    font-size: 0.8rem;
}

.trend-table th:last-child,
.trend-table td:last-child {
    border-left: 2px solid var(--border);
    font-weight: 600;
}

.trend-table tbody tr:last-child td {
    border-bottom: 1px solid var(--border);
}

.trend-table tfoot td {
    font-weight: 700;
    border-top: 2px solid var(--border);
    border-bottom: none;
}

.category-table td:first-child {
    font-weight: 600;
}

.category-table tbody tr:last-child td {
    border-bottom: 1px solid var(--border);
}

.category-table tfoot td {
    font-weight: 700;
    border-top: 2px solid var(--border);
    border-bottom: none;
}

/* Sets the Remaining column off as the summary figure, the same way
   trend-table's last (avg) column is set off - :nth-last-child(2) rather
   than :last-child because the actions icon column comes after it here. */
.category-table th:nth-last-child(2),
.category-table td:nth-last-child(2) {
    border-left: 2px solid var(--border);
}

form {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
    max-width: 30rem;
}

form > div {
    margin-bottom: 1rem;
}

form label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

/* A checkbox field's label comes just before its input in the markup -
   keep them on one line, tickbox at the end of the text, instead of the
   block label forcing the checkbox onto its own line underneath. */
form label:has(+ input[type="checkbox"]) {
    display: inline;
    margin: 0 0.5rem 0 0;
}

form input[type="checkbox"] {
    vertical-align: middle;
}

form input[type="text"],
form input[type="password"],
form input[type="number"],
form input[type="date"],
form select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 1rem;
}

form .help,
form .help-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/*
 * Expanded ChoiceType fields (radio buttons/checkboxes, e.g. Direction,
 * Holiday shift) render as a wrapper div with alternating input/label
 * pairs and no per-choice container. A 2-column grid pairs each input
 * with its label on one row without needing extra markup.
 */
form > div > div:not(.help-text) {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0.35rem 0.5rem;
}

form > div > div:not(.help-text) input[type="radio"],
form > div > div:not(.help-text) input[type="checkbox"] {
    margin: 0;
}

form > div > div:not(.help-text) label {
    display: inline;
    font-weight: 400;
    margin: 0;
}

form div > ul {
    color: var(--danger);
    font-size: 0.85rem;
    margin: 0.25rem 0 0;
    padding-left: 1.1rem;
}

button, .button {
    display: inline-block;
    background-color: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    border-radius: 0.375rem;
    padding: 0.55rem 1rem;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
}

.button.secondary {
    background-color: transparent;
    color: var(--accent);
}

.button.danger {
    background-color: var(--danger);
    border-color: var(--danger);
}

.button-row {
    display: flex;
    gap: 0.5rem;
}

fieldset.split-rows {
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin: 0 0 1rem;
}

fieldset.split-rows legend {
    font-weight: 500;
    padding: 0 0.25rem;
}

.split-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.quick-add-category {
    margin: 0.5rem 0;
}

.quick-add-category input[type="text"] {
    width: auto;
    display: inline-block;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.9rem;
}

.quick-add-category .button {
    padding: 0.35rem 0.75rem;
    font-size: 0.9rem;
}

.quick-add-category .error:not([hidden]) {
    display: block;
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.split-row select,
.split-row input {
    flex: 1;
}

.filter-row {
    max-width: none;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.filter-row div {
    margin-bottom: 0;
    min-width: 16rem;
}

.chart-card {
    position: relative;
    height: 260px;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

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