:root {
    color-scheme: light;
    --bg: #f4f7f4;
    --ink: #18201b;
    --muted: #657165;
    --line: #d8dfd6;
    --surface: #ffffff;
    --surface-soft: #eef4ee;
    --accent: #0d6b57;
    --accent-strong: #095140;
    --accent-soft: #dcefe9;
    --warn: #b75f2b;
    --danger: #a33a2b;
    --shadow: 0 18px 48px rgba(24, 32, 27, 0.08);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

[data-transfer-field]:not(.is-transfer-visible) {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(13, 107, 87, 0.08), transparent 36rem),
        var(--bg);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
input,
select,
textarea {
    font: inherit;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 5vw, 3.3rem);
    line-height: 1;
}

h2 {
    margin-bottom: 0;
    font-size: 1.15rem;
}

.app-frame {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns 180ms ease;
}

.app-frame.sidebar-collapsed {
    grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar-toggle {
    position: fixed;
    z-index: 40;
    top: 14px;
    left: 14px;
    display: inline-grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.94);
    color: var(--accent-strong);
    cursor: pointer;
    padding: 0;
    box-shadow: 0 12px 28px rgba(24, 32, 27, 0.12);
}

.sidebar-toggle-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.sidebar-toggle .menu-closed {
    display: none;
}

.sidebar-collapsed .sidebar-toggle .menu-open {
    display: none;
}

.sidebar-collapsed .sidebar-toggle .menu-closed {
    display: block;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 28px;
    border-right: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    padding: 64px 18px 28px;
    overflow: hidden;
    transition: border-color 180ms ease, padding 180ms ease, visibility 180ms ease;
}

.sidebar-collapsed .sidebar {
    visibility: hidden;
    border-color: transparent;
    padding-right: 0;
    padding-left: 0;
}

.brand {
    display: grid;
    gap: 4px;
    color: var(--ink);
    font-weight: 800;
}

.brand span {
    font-size: 1.35rem;
}

.brand small {
    color: var(--muted);
    font-size: 0.85rem;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav-heading {
    margin: 14px 12px 2px;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.nav-heading:first-child {
    margin-top: 0;
}

.nav a,
.logout-form button,
.button {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--ink);
}

.nav a {
    display: block;
}

.nav a.active,
.nav a:hover {
    border-color: var(--line);
    background: var(--surface-soft);
}

.logout-form {
    margin-top: auto;
}

.logout-form button {
    width: 100%;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    text-align: left;
}

.content {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 48px;
}

.page-header,
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 24px;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
}

.muted {
    color: var(--muted);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-color: var(--line);
    background: var(--surface);
    cursor: pointer;
    font-weight: 700;
}

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

.button.primary:hover {
    background: var(--accent-strong);
}

.button.icon-only {
    width: 42px;
    min-width: 42px;
    padding: 0;
}

.button.icon-only svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.add-record-button {
    border-radius: 12px;
}

.button.small {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.86rem;
}

.button.danger {
    border-color: rgba(163, 58, 43, 0.25);
    background: #fff1ee;
    color: var(--danger);
}

.button.wide {
    width: 100%;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 24px;
}

.metric {
    min-height: 132px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 20px;
    box-shadow: var(--shadow);
}

.metric.compact {
    min-height: 104px;
    box-shadow: none;
}

.metric span,
.summary-list dt,
table small {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
}

.metric strong {
    display: block;
    margin-top: 18px;
    font-size: clamp(1.65rem, 4vw, 2.45rem);
    line-height: 1;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.8fr);
    gap: 18px;
    margin-top: 18px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 22px;
}

.panel.narrow {
    max-width: 860px;
}

.accent-panel {
    border-left: 4px solid var(--accent);
    background: var(--accent-soft);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.filter-actions {
    display: flex;
    align-items: end;
    gap: 10px;
}

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

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

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

.number {
    text-align: right;
    white-space: nowrap;
}

.actions {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.compact-actions {
    justify-content: flex-start;
}

.actions form {
    margin: 0;
}

.icon-button {
    display: inline-grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--accent-strong);
    cursor: pointer;
    padding: 0;
}

.icon-button:hover {
    background: var(--surface-soft);
}

.icon-button.danger {
    border-color: rgba(163, 58, 43, 0.22);
    background: #fff8f6;
    color: var(--danger);
}

.icon-button.danger:hover {
    background: #fff1ee;
}

.icon-button svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.summary-list {
    display: grid;
    gap: 12px;
    margin: 18px 0 0;
}

.summary-list div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-top: 1px solid rgba(13, 107, 87, 0.18);
    padding-top: 12px;
}

.summary-list dd {
    margin: 0;
    font-weight: 800;
}

.report-split {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
}

.bar-report {
    display: grid;
    gap: 16px;
}

.bar-row {
    display: grid;
    gap: 8px;
}

.bar-row strong {
    color: var(--ink);
}

.bar-row span {
    display: block;
    color: var(--muted);
    font-size: 0.86rem;
}

.bar {
    display: block;
    width: max(4px, var(--bar-width));
    height: 10px;
    border-radius: 999px;
}

.bar.income {
    background: var(--accent);
}

.bar.expense {
    background: var(--warn);
}

.year-panel {
    align-self: start;
}

.chart-total {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.year-chart {
    display: grid;
    gap: 12px;
}

.chart-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 90px;
    align-items: center;
    gap: 10px;
}

.chart-month,
.chart-amount {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

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

.chart-bars {
    display: grid;
    gap: 4px;
}

.chart-bar {
    display: block;
    width: max(4px, var(--bar-width));
    height: 8px;
    border-radius: 999px;
}

.chart-bar.income {
    background: var(--accent);
}

.chart-bar.expense {
    background: var(--warn);
}

.opening-row {
    background: var(--surface-soft);
    font-weight: 800;
}

.pagination-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 18px;
}

.pagination-summary {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.page-link {
    display: inline-flex;
    min-width: 34px;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    padding: 7px 10px;
    font-size: 0.9rem;
    font-weight: 800;
}

.page-link.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.page-link.disabled {
    color: var(--muted);
    opacity: 0.55;
}

.form-grid,
.form-stack {
    display: grid;
    gap: 16px;
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-weight: 700;
}

.required-field {
    position: relative;
}

.required-indicator {
    position: absolute;
    top: 0;
    right: 0;
    display: inline-grid;
    width: 18px;
    height: 18px;
    place-items: center;
    border: 1px solid rgba(163, 58, 43, 0.22);
    border-radius: 50%;
    background: #fff1ee;
    color: var(--danger);
    font-size: 0.78rem;
    font-weight: 900;
    line-height: 1;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 11px 12px;
}

.native-select-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.combo {
    position: relative;
}

.combo-input {
    padding-right: 34px;
}

.combo::after {
    position: absolute;
    top: 50%;
    right: 12px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    content: "";
    pointer-events: none;
    transform: translateY(-65%) rotate(45deg);
}

.combo-list {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 6px;
}

.combo-option,
.combo-empty {
    display: block;
    width: 100%;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    padding: 9px 10px;
    text-align: left;
}

.combo-option {
    cursor: pointer;
}

.combo-option:hover,
.combo-option.selected {
    background: var(--surface-soft);
}

.combo-empty {
    color: var(--muted);
}

textarea {
    resize: vertical;
}

.span-2,
.form-action {
    grid-column: 1 / -1;
}

.form-action {
    justify-self: start;
}

.checkline {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkline input {
    width: auto;
}

.role-grid {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.role-card {
    align-items: flex-start;
    grid-template-columns: auto minmax(0, 1fr);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    padding: 12px;
}

.role-card input {
    width: auto;
    margin-top: 4px;
}

.role-card strong,
.role-card small,
.role-card em {
    display: block;
}

.role-card small {
    color: var(--muted);
    font-weight: 600;
}

.role-card em {
    margin-top: 6px;
    color: var(--accent-strong);
    font-size: 0.82rem;
    font-style: normal;
    font-weight: 700;
}

.flash,
.error-box {
    border-radius: 8px;
    margin-bottom: 18px;
    padding: 12px 14px;
}

.flash {
    border: 1px solid rgba(13, 107, 87, 0.24);
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.error-box {
    border: 1px solid rgba(163, 58, 43, 0.25);
    background: #fff1ee;
    color: var(--danger);
}

.error-box ul {
    margin-bottom: 0;
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.auth-panel {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 28px;
}

.pill,
.line-chip {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 0.78rem;
    font-weight: 800;
}

.pill {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.pill.type-income {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.pill.type-expense {
    background: #fff1e7;
    color: var(--warn);
}

.pill.type-transfer {
    background: #e9eef7;
    color: #37506f;
}

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

.line-chip {
    margin: 0 4px 4px 0;
    background: var(--surface-soft);
    color: var(--muted);
}

@media (max-width: 900px) {
    .app-frame {
        grid-template-columns: 1fr;
    }

    .app-frame.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .sidebar-collapsed .sidebar {
        display: none;
    }

    .nav {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .nav-heading {
        grid-column: 1 / -1;
        margin-top: 10px;
    }

    .split,
    .metrics,
    .form-grid,
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .page-header,
    .topbar,
    .pagination-wrap {
        align-items: flex-start;
        flex-direction: column;
    }

    .pagination {
        justify-content: flex-start;
    }
}

@media (max-width: 560px) {
    .content {
        width: min(100% - 20px, 1180px);
        padding-top: 20px;
    }

    .sidebar {
        padding: 58px 12px 18px;
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-row {
        grid-template-columns: 36px minmax(0, 1fr);
    }

    .chart-amount {
        grid-column: 2;
        text-align: left;
    }

    .panel,
    .metric,
    .auth-panel {
        padding: 16px;
    }
}
