:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-soft: #f9fbfd;
    --text: #17202a;
    --muted: #657386;
    --line: #dfe6ee;
    --teal: #0f9f8f;
    --teal-dark: #08776c;
    --green: #198754;
    --amber: #d97706;
    --red: #dc2626;
    --blue: #177ddc;
    --shadow: 0 18px 45px rgba(22, 34, 51, 0.08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

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

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

.sidebar-toggle-input {
    position: fixed;
    opacity: 0;
    pointer-events: none;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    flex-direction: column;
    gap: 28px;
    border-right: 1px solid var(--line);
    background: var(--surface);
    padding: 28px 20px;
}

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 800;
}

.brand-text {
    white-space: nowrap;
}

.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 8px;
    background: var(--teal);
    color: white;
}

.sidebar-toggle-button {
    display: inline-grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    cursor: pointer;
    padding: 7px;
}

.sidebar-toggle-button span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: var(--muted);
}

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

.nav a {
    border-radius: 8px;
    color: var(--muted);
    font-size: 15px;
    font-weight: 700;
    padding: 12px 14px;
}

.nav a.active,
.nav a:hover {
    background: #eaf7f5;
    color: var(--teal-dark);
}

.sidebar-footer {
    display: grid;
    gap: 8px;
    margin-top: auto;
    color: var(--muted);
    font-size: 14px;
}

.sidebar-toggle-input:checked + .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
}

.sidebar-toggle-input:checked + .app-shell .sidebar {
    padding-inline: 14px;
}

.sidebar-toggle-input:checked + .app-shell .sidebar-top {
    justify-content: center;
}

.sidebar-toggle-input:checked + .app-shell .brand-text,
.sidebar-toggle-input:checked + .app-shell .sidebar-footer span {
    display: none;
}

.sidebar-toggle-input:checked + .app-shell .brand {
    justify-content: center;
}

.sidebar-toggle-input:checked + .app-shell .sidebar-toggle-button {
    position: absolute;
    top: 66px;
}

.sidebar-toggle-input:checked + .app-shell .nav {
    margin-top: 44px;
}

.sidebar-toggle-input:checked + .app-shell .nav a {
    overflow: hidden;
    padding-inline: 8px;
    text-align: center;
    text-overflow: clip;
    white-space: nowrap;
}

.sidebar-toggle-input:checked + .app-shell .sidebar-footer {
    justify-items: center;
}

.main {
    min-width: 0;
    padding: 32px;
}

.section-block {
    margin-bottom: 20px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.section-title span {
    width: 4px;
    height: 22px;
    border-radius: 999px;
    background: var(--teal);
}

.section-title h2 {
    color: var(--text);
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 34px;
    line-height: 1.1;
}

.title-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.account-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid #b7eee5;
    border-radius: 999px;
    background: #ecfbf8;
    color: var(--teal-dark);
    font-size: 13px;
    font-weight: 900;
    padding: 7px 10px;
}

.account-badge.compact {
    font-size: 12px;
    padding: 5px 9px;
}

h2 {
    font-size: 20px;
}

.muted,
.panel-heading p {
    color: var(--muted);
    font-size: 14px;
}

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

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

select[multiple] {
    min-height: 150px;
}

.toolbar input,
.toolbar select {
    width: auto;
}

.button,
button.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-weight: 800;
    padding: 10px 14px;
}

.button.primary {
    border-color: var(--teal);
    background: var(--teal);
    color: white;
}

.button.danger {
    border-color: #fee2e2;
    background: #fff1f2;
    color: var(--red);
}

.link-button {
    border: 0;
    background: transparent;
    color: var(--teal-dark);
    cursor: pointer;
    padding: 0;
    text-align: left;
}

.link-button.warning {
    color: var(--amber);
}

.link-button.danger-text,
.danger-text {
    color: var(--red);
}

.flash {
    border: 1px solid #b7eee5;
    border-radius: 8px;
    background: #ecfbf8;
    color: #075e55;
    margin-bottom: 18px;
    padding: 12px 14px;
}

.flash.error {
    border-color: #fecaca;
    background: #fff1f2;
    color: #991b1b;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 14px;
}

.metric,
.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric {
    display: grid;
    gap: 10px;
    padding: 18px;
}

.metric span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.metric strong {
    font-size: 24px;
    line-height: 1.1;
}

.metric.income {
    border-top: 4px solid var(--teal);
}

.metric.paid {
    border-top: 4px solid var(--green);
}

.metric.due {
    border-top: 4px solid var(--amber);
}

.metric.expense {
    border-top: 4px solid var(--red);
}

.metric.net {
    border-top: 4px solid var(--blue);
}

.overdue-panel {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    border: 1px solid #fecaca;
    border-left: 4px solid var(--red);
    border-radius: 8px;
    background: #fff7f7;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    padding: 18px;
}

.overdue-panel p {
    color: #991b1b;
    font-size: 14px;
    margin-top: 4px;
}

.overdue-list {
    display: grid;
    gap: 8px;
}

.overdue-tabs {
    justify-content: flex-start;
    margin-bottom: 16px;
}

.overdue-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: white;
    padding: 10px 12px;
}

.overdue-item small {
    display: block;
    color: #991b1b;
    margin-top: 3px;
}

.overdue-item b {
    color: var(--red);
    white-space: nowrap;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
}

.panel {
    padding: 18px;
}

.panel.wide {
    min-width: 0;
}

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

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

.filter-tabs a {
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
    padding: 8px 10px;
}

.filter-tabs a.active,
.filter-tabs a:hover {
    border-color: #b7eee5;
    background: #ecfbf8;
    color: var(--teal-dark);
}

.table-wrap {
    overflow-x: auto;
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

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

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

td small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

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

.pill,
.status {
    display: inline-flex;
    align-items: center;
    border: 0;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
    padding: 6px 10px;
}

.pill.income,
.income {
    color: var(--teal-dark);
}

.pill.expense,
.expense {
    color: var(--red);
}

.pill.income {
    background: #eaf7f5;
}

.pill.expense {
    background: #fff1f2;
}

.status.paid {
    background: #eaf7ee;
    color: var(--green);
}

.status.due {
    background: #fff7ed;
    color: var(--amber);
}

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

.action-stack {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.action-stack form {
    margin: 0;
}

.row-actions a {
    color: var(--teal-dark);
    font-weight: 800;
}

.mini-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.mini-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.mini-item span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.color-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--swatch);
    margin-right: 8px;
    vertical-align: -2px;
}

.category-form {
    margin-top: 16px;
}

.empty {
    color: var(--muted);
    padding: 22px 10px;
    text-align: center;
}

.form-panel {
    max-width: 900px;
}

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

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.full,
.form-actions {
    grid-column: 1 / -1;
}

.form-section {
    border-top: 1px solid var(--line);
    margin-top: 6px;
    padding-top: 16px;
}

.form-section h2 {
    margin-bottom: 4px;
}

.form-section p {
    color: var(--muted);
    font-size: 14px;
}

.password-panel {
    margin-top: 24px;
}

.compact-form {
    margin-top: 16px;
}

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

.check-row input {
    width: auto;
}

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

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

.login-card {
    width: min(460px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    box-shadow: var(--shadow);
    padding: 32px;
}

.login-brand {
    margin-bottom: 24px;
}

.login-card h1 {
    margin-bottom: 8px;
}

.login-card p {
    color: var(--muted);
    margin-bottom: 22px;
}

.stack {
    display: grid;
    gap: 16px;
}

@media (max-width: 1100px) {
    .summary-grid {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    .overdue-panel {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    body {
        font-size: 14px;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar-toggle-input:checked + .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        gap: 14px;
        overflow: hidden;
        padding: 12px;
    }

    .sidebar-toggle-button {
        display: none;
    }

    .brand {
        font-size: 17px;
    }

    .brand-mark {
        width: 30px;
        height: 30px;
    }

    .nav {
        display: flex;
        gap: 8px;
        margin-inline: -12px;
        overflow-x: auto;
        padding: 0 12px 4px;
        scrollbar-width: thin;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .sidebar-toggle-input:checked + .app-shell .nav {
        margin-top: 0;
    }

    .nav a {
        flex: 0 0 auto;
        min-height: 38px;
        padding: 9px 8px;
        scroll-snap-align: start;
        text-align: center;
        font-size: 12px;
        white-space: nowrap;
    }

    .sidebar-footer {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        font-size: 12px;
    }

    .main {
        padding: 12px;
    }

    .page-header,
    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar input,
    .toolbar select,
    .toolbar .button {
        width: 100%;
    }

    .toolbar {
        gap: 7px;
    }

    .summary-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 23px;
    }

    h2 {
        font-size: 17px;
    }

    .muted,
    .panel-heading p {
        font-size: 12px;
    }

    .button,
    button.button,
    input,
    select,
    textarea {
        min-height: 38px;
        padding: 9px 10px;
        font-size: 13px;
    }

    .section-block {
        border-top: 1px solid var(--line);
        margin-bottom: 14px;
        padding-top: 12px;
    }

    .section-title {
        margin-bottom: 8px;
    }

    .summary-grid {
        gap: 8px;
    }

    .metric {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        padding: 12px;
    }

    .metric span {
        font-size: 11px;
    }

    .metric strong {
        font-size: 18px;
        text-align: right;
    }

    .overdue-panel,
    .panel {
        padding: 12px;
    }

    .overdue-item,
    .mini-item {
        align-items: flex-start;
        font-size: 13px;
    }

    .content-grid {
        gap: 12px;
    }

    .panel-heading {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .filter-tabs {
        justify-content: flex-start;
        gap: 5px;
    }

    .filter-tabs a {
        flex: 1 1 auto;
        padding: 7px 8px;
        text-align: center;
        font-size: 11px;
    }

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

    table {
        min-width: 0;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
        width: 100%;
    }

    thead {
        display: none;
    }

    tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface-soft);
        margin-bottom: 10px;
        padding: 8px 10px;
    }

    td {
        display: grid;
        grid-template-columns: minmax(82px, 36%) minmax(0, 1fr);
        gap: 8px;
        align-items: center;
        border-bottom: 1px solid #edf1f5;
        padding: 8px 0;
        font-size: 13px;
        text-align: right;
        word-break: break-word;
    }

    td:last-child {
        border-bottom: 0;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 900;
        text-align: left;
        text-transform: uppercase;
    }

    td:not([data-label])::before {
        content: "";
    }

    td small {
        font-size: 12px;
    }

    .amount,
    .row-actions {
        text-align: right;
    }

    .row-actions,
    .action-stack {
        justify-content: flex-end;
    }

    .pill,
    .status {
        justify-self: end;
        padding: 5px 8px;
        font-size: 11px;
    }

    .empty {
        display: block;
        padding: 16px 6px;
        text-align: center;
    }

    .empty::before {
        content: "";
    }
}

@media (max-width: 420px) {
    td {
        grid-template-columns: minmax(72px, 34%) minmax(0, 1fr);
        font-size: 12px;
    }

    .metric strong {
        font-size: 17px;
    }
}
