:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-muted: #f0f3f5;
    --line: #d9e0e6;
    --text: #1d252d;
    --muted: #64717d;
    --primary: #126b6f;
    --primary-strong: #0c5559;
    --accent: #2f6fb2;
    --success: #23784a;
    --warning: #9a6200;
    --danger: #b53a35;
    --radius: 8px;
    --shadow: 0 12px 32px rgba(35, 45, 58, 0.08);
    --content-max: 1360px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

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

a:hover {
    text-decoration: underline;
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 22px 18px;
    background: #20272f;
    color: #f8fafc;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
    margin-bottom: 28px;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: #e4b64b;
    color: #20272f;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #b9c3cc;
    font-size: 12px;
}

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

.nav a {
    display: flex;
    align-items: center;
    min-height: 40px;
    padding: 9px 11px;
    border-radius: 8px;
    color: #dfe7ee;
    text-decoration: none;
}

.nav a:hover,
.nav a.active {
    background: #34404a;
    color: #ffffff;
}

.main {
    min-width: 0;
    padding: clamp(20px, 2.1vw, 34px);
}

.main-frame {
    width: min(100%, var(--content-max));
    margin-inline: auto;
}

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

.topbar h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
    font-weight: 800;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

.topbar-actions form {
    display: inline-flex;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    max-width: 100%;
    padding: 8px 13px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 750;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.button:hover {
    text-decoration: none;
}

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

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

.button.secondary {
    border-color: var(--line);
    background: #ffffff;
}

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

.button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.button.tiny {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 13px;
}

body.auth-page {
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(18, 107, 111, 0.12), rgba(47, 111, 178, 0.10)),
        var(--bg);
}

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

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

body.auth-page .login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

body.auth-page .login-brand strong,
body.auth-page .login-brand small {
    display: block;
}

body.auth-page .login-brand small {
    color: var(--muted);
}

body.auth-page .login-panel h1 {
    margin: 0 0 18px;
    font-size: 28px;
    line-height: 1.15;
}

body.auth-page .login-form {
    display: grid;
    gap: 14px;
}

body.auth-page .login-form .button {
    width: 100%;
}

.alert {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.alert ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

.alert.success {
    width: fit-content;
    min-width: min(100%, 320px);
    max-width: 100%;
    padding-block: 10px;
    border-color: #9bd3b8;
    background: #eef9f3;
    color: #165b38;
}

.alert.danger {
    border-color: #efaaa6;
    background: #fff1f0;
    color: #8a2926;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

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

.stat-card {
    min-height: 106px;
    padding: 18px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin-top: 10px;
    font-size: 32px;
    line-height: 1;
}

.stat-card.warning {
    border-color: #edcf85;
}

.stat-card.danger {
    border-color: #efaaa6;
}

.grid {
    display: grid;
    gap: 18px;
    margin-bottom: 18px;
}

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

.align-start {
    align-items: start;
}

.panel {
    padding: 18px;
}

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

.panel-heading h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.25;
}

.money-list,
.category-list {
    display: grid;
    gap: 10px;
}

.money-row,
.category-list div {
    display: grid;
    grid-template-columns: 72px repeat(3, minmax(0, 1fr));
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-muted);
}

.category-list div {
    grid-template-columns: minmax(0, 1fr) auto;
}

.profit {
    color: var(--success);
    font-weight: 800;
}

.filters {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 180px auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
}

.filters.wide {
    grid-template-columns: minmax(260px, 1.35fr) minmax(220px, 0.95fr) minmax(116px, 0.42fr) minmax(130px, 0.48fr) minmax(130px, 0.48fr) auto;
}

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

label {
    display: grid;
    gap: 6px;
    min-width: 0;
}

label > span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 10px;
    border: 1px solid #cbd5dc;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
}

textarea {
    min-height: 104px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(18, 107, 111, 0.22);
    border-color: var(--primary);
}

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

.check input {
    width: 18px;
    height: 18px;
    min-height: 18px;
}

.span-3 {
    grid-column: span 3;
}

.span-4 {
    grid-column: span 4;
}

.span-6 {
    grid-column: span 6;
}

.span-12 {
    grid-column: span 12;
}

.form-actions,
.danger-zone {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.form-actions {
    padding-top: 6px;
}

.form-actions.between {
    justify-content: space-between;
}

.danger-zone {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

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

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

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

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

td strong,
td small {
    display: block;
}

td small {
    margin-top: 2px;
    color: var(--muted);
}

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

.actions-cell form {
    display: inline-flex;
    margin-left: 7px;
}

.actions-cell .button {
    margin-left: 7px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    max-width: 100%;
    padding: 4px 8px;
    border-radius: 999px;
    background: #ecf0f3;
    color: #38444f;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
}

.badge.ok {
    background: #e8f5ee;
    color: #1b6840;
}

.badge.annual-ok {
    background: #e8f5ee;
    color: #1b6840;
}

.badge.annual-warning {
    background: #fff4d7;
    color: #7a4d00;
}

.badge.annual-urgent {
    background: #ffebe9;
    color: #9d2f2a;
}

.badge.soon,
.badge.warning {
    background: #fff4d7;
    color: #7a4d00;
}

.badge.urgent,
.badge.today {
    background: #ffe6cf;
    color: #934d05;
}

.badge.expired,
.badge.danger {
    background: #ffebe9;
    color: #9d2f2a;
}

.badge.inactive,
.badge.neutral {
    background: #eceff2;
    color: #4d5965;
}

.empty {
    color: var(--muted);
    text-align: center;
}

.detail-list {
    display: grid;
    gap: 10px;
    margin: 0;
}

.detail-list div {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.detail-list dt {
    color: var(--muted);
    font-weight: 800;
}

.detail-list dd {
    margin: 0;
}

.notes {
    margin: 16px 0 0;
    padding: 12px;
    border-radius: 8px;
    background: var(--surface-muted);
    color: #39444e;
    white-space: pre-wrap;
}

nav[role="navigation"] {
    margin-top: 16px;
}

nav[role="navigation"] > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
}

nav[role="navigation"] svg {
    width: 18px;
    height: 18px;
}

nav[role="navigation"] a,
nav[role="navigation"] span {
    border-radius: 8px;
}

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

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

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

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

    .sidebar {
        position: static;
        height: auto;
        padding: 12px;
    }

    .brand {
        margin-bottom: 12px;
    }

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

    .nav a {
        justify-content: center;
        padding: 8px;
        font-size: 13px;
        text-align: center;
    }

    .main {
        padding: 16px 12px;
    }

    .topbar {
        display: grid;
        gap: 12px;
        margin-bottom: 16px;
    }

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

    .stat-grid,
    .two-columns,
    .filters,
    .filters.wide {
        grid-template-columns: 1fr;
    }

    .span-3,
    .span-4,
    .span-6 {
        grid-column: span 12;
    }

    .money-row {
        grid-template-columns: 1fr;
    }

    .panel-heading {
        align-items: flex-start;
    }

    .detail-list div {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .table-wrap {
        overflow: visible;
    }

    table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    table thead {
        display: none;
    }

    table tbody {
        display: grid;
        gap: 12px;
    }

    table tr {
        display: grid;
        padding: 12px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface);
    }

    table td {
        display: grid;
        grid-template-columns: minmax(86px, 34%) minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        padding: 8px 0;
        border-bottom: 1px solid #edf1f4;
        overflow-wrap: anywhere;
    }

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

    table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 850;
        line-height: 1.25;
        text-transform: uppercase;
    }

    table td.empty,
    table td[colspan] {
        display: block;
        border-bottom: 0;
        text-align: center;
    }

    table td.empty::before,
    table td[colspan]::before {
        content: none;
    }

    .actions-cell {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        text-align: left;
        white-space: normal;
    }

    .actions-cell::before {
        grid-column: 1 / -1;
    }

    .actions-cell form,
    .actions-cell .button {
        width: 100%;
        margin-left: 0;
    }

    .actions-cell form {
        display: flex;
    }

    .actions-cell .button {
        min-height: 36px;
    }

    .badge {
        white-space: normal;
    }
}

@media (max-width: 520px) {
    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar h1 {
        font-size: 24px;
    }

    .stat-grid {
        gap: 10px;
    }

    .stat-card {
        min-height: 88px;
    }

    .stat-card strong {
        font-size: 28px;
    }

    .panel,
    .stat-card {
        padding: 12px;
    }

    .button {
        width: 100%;
    }

    .topbar-actions form,
    .user-pill {
        width: 100%;
    }

    .topbar-actions form .button {
        width: 100%;
    }

    .actions-cell .button,
    .actions-cell form {
        width: 100%;
        margin-left: 0;
    }

    .actions-cell form .button {
        width: 100%;
    }

    table td,
    .actions-cell {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    table td::before,
    .actions-cell::before {
        margin-bottom: 1px;
    }

    body.auth-page .login-shell {
        padding: 14px;
    }

    body.auth-page .login-panel {
        padding: 20px;
    }
}
