:root {
    color-scheme: light;
    --bg: #f2e8d8;
    --paper: #fffaf2;
    --paper-2: #f7ecd9;
    --ink: #211916;
    --muted: #75685c;
    --line: #decbb0;
    --charcoal: #171412;
    --gold: #b88437;
    --gold-soft: #f4d996;
    --rust: #8e3129;
    --green: #18794e;
    --green-bg: #e7f4ec;
    --red: #b4232a;
    --red-bg: #fff0ee;
    --blue: #315f8c;
    --blue-bg: #e8f1fb;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(255, 250, 242, .92), rgba(242, 232, 216, .98)),
        radial-gradient(circle at 14% 0%, rgba(184, 132, 55, .18), transparent 26%),
        radial-gradient(circle at 90% 12%, rgba(49, 95, 140, .12), transparent 28%),
        var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
    border: 0;
    border-radius: 8px;
    min-height: 44px;
    padding: 11px 16px;
    background: linear-gradient(135deg, var(--charcoal), #3b2b20);
    color: #fff7e8;
    font-weight: 800;
    cursor: pointer;
}

button.secondary {
    width: 100%;
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--line);
}

button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-btn {
    width: 44px;
    padding: 0;
    display: grid;
    place-items: center;
    background: rgba(255, 250, 240, .1);
    color: #fff7e8;
    border: 1px solid rgba(255, 250, 240, .22);
}

.delete-btn {
    width: 34px;
    min-height: 34px;
    padding: 0;
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid #efb8b0;
}

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

input:focus,
select:focus,
textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(49, 95, 140, .14);
}

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

h1,
h2,
p {
    margin: 0;
}

.login-body {
    display: grid;
    place-items: center;
}

.login-shell {
    width: min(480px, calc(100% - 32px));
}

.login-card,
.workspace-card,
.balance-card,
.mini-card,
.week-card {
    background: rgba(255, 250, 242, .96);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(52, 34, 20, .12);
}

.login-card {
    padding: 30px;
    text-align: center;
}

.login-logo {
    width: min(220px, 70vw);
    aspect-ratio: 1;
    object-fit: contain;
    display: block;
    margin: 0 auto 18px;
    filter: drop-shadow(0 20px 28px rgba(52, 34, 20, .2));
}

.login-card h1 {
    font-size: 42px;
}

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

.login-card form {
    text-align: left;
}

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

.app-header {
    position: sticky;
    top: 0;
    z-index: 8;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px clamp(16px, 4vw, 42px);
    border-bottom: 1px solid rgba(255, 250, 240, .16);
    background: rgba(23, 20, 18, .96);
    backdrop-filter: blur(14px);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-badge {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--gold), #efd188);
    color: #211916;
    font-size: 22px;
    font-weight: 950;
    border: 1px solid rgba(255, 250, 240, .28);
}

.app-header strong {
    display: block;
    color: #fff7e8;
    font-size: 18px;
}

.app-header span {
    color: #d5c5ad;
    font-size: 13px;
}

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

.page {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 24px clamp(16px, 4vw, 34px) 52px;
}

.toast,
.alert {
    padding: 12px 14px;
    border: 1px solid #d6a251;
    background: #fff0c8;
    color: #6f4310;
    border-radius: 8px;
    margin-bottom: 16px;
}

.settings-drawer {
    position: fixed;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.settings-drawer.is-open {
    pointer-events: auto;
}

.settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(23, 20, 18, .42);
    opacity: 0;
    transition: opacity .18s ease;
}

.settings-drawer.is-open .settings-backdrop {
    opacity: 1;
}

.settings-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: min(460px, 100%);
    height: 100%;
    overflow-y: auto;
    padding: 22px;
    background: var(--paper);
    border-left: 1px solid var(--line);
    box-shadow: -22px 0 60px rgba(52, 34, 20, .2);
    transform: translateX(100%);
    transition: transform .18s ease;
}

.settings-drawer.is-open .settings-panel {
    transform: translateX(0);
}

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

.settings-head h2 {
    font-size: 24px;
}

.settings-head p {
    color: var(--muted);
    margin-top: 4px;
}

.drawer-close {
    width: 38px;
    min-height: 38px;
    padding: 0;
    background: var(--paper-2);
    color: var(--ink);
    border: 1px solid var(--line);
}

.overview {
    display: grid;
    grid-template-columns: minmax(280px, 1.4fr) repeat(3, minmax(160px, .7fr));
    gap: 14px;
    margin-bottom: 18px;
}

.balance-card,
.mini-card {
    padding: 18px;
}

.balance-card {
    background:
        linear-gradient(135deg, rgba(23, 20, 18, .96), rgba(58, 38, 26, .9)),
        radial-gradient(circle at 90% 0%, rgba(184, 132, 55, .34), transparent 34%);
    color: #fff7e8;
}

.balance-card span,
.mini-card span,
.week-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.balance-card span,
.balance-card p {
    color: #d5c5ad;
}

.balance-card strong {
    display: block;
    font-size: clamp(34px, 5vw, 56px);
    line-height: 1;
}

.balance-card p {
    margin-top: 10px;
}

.mini-card {
    position: relative;
    overflow: hidden;
}

.mini-card::after {
    content: "";
    position: absolute;
    width: 84px;
    height: 84px;
    right: -30px;
    top: -30px;
    border-radius: 50%;
}

.mini-card.revenue::after {
    background: var(--green-bg);
}

.mini-card.expense::after {
    background: var(--red-bg);
}

.mini-card.month::after {
    background: var(--blue-bg);
}

.mini-card strong {
    position: relative;
    z-index: 1;
    font-size: clamp(22px, 3vw, 30px);
}

.workspace-card {
    overflow: hidden;
}

.workspace-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    padding: 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 253, 248, .64);
}

.workspace-head h1 {
    font-size: 28px;
}

.workspace-head p {
    color: var(--muted);
    margin-top: 4px;
}

.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 4px;
    background: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-width: 330px;
}

.tab-button {
    min-height: 38px;
    padding: 8px 12px;
    background: transparent;
    color: var(--muted);
}

.tab-button.is-active {
    background: var(--charcoal);
    color: #fff7e8;
}

.tab-panel {
    display: none;
    padding: 18px;
}

.tab-panel.is-active {
    display: block;
}

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

.wide {
    grid-column: 1 / -1;
}

.segmented {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 4px;
    background: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.segmented label {
    display: block;
}

.segmented input {
    display: none;
}

.segmented span {
    display: grid;
    place-items: center;
    min-height: 44px;
    border-radius: 7px;
    color: var(--muted);
    cursor: pointer;
}

.segmented input:checked + span {
    color: #fff7e8;
    background: var(--charcoal);
}

.category-field {
    display: grid;
    gap: 10px;
}

.field-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    color: var(--muted);
    font-size: 13px;
}

.field-head strong {
    color: var(--rust);
    font-size: 13px;
}

.category-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.category-choice {
    min-height: 78px;
    text-align: left;
    background: #fffdf8;
    color: var(--ink);
    border: 1px solid var(--line);
    box-shadow: none;
}

.category-choice strong {
    display: block;
    font-size: 14px;
    margin-bottom: 6px;
}

.category-choice span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.category-choice.is-active {
    border-color: var(--rust);
    background: #fff2df;
    box-shadow: inset 0 0 0 2px rgba(142, 49, 41, .18);
}

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

.week-card {
    padding: 16px;
}

.week-card strong {
    font-size: 26px;
}

.inline-actions {
    margin-top: 12px;
}

.cron-box {
    display: grid;
    gap: 8px;
    margin-top: 14px;
    padding: 12px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 13px;
    background: var(--paper-2);
}

.cron-box code {
    display: block;
    overflow-wrap: anywhere;
    color: var(--ink);
    background: #fffdf8;
    border-radius: 6px;
    padding: 10px;
}

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

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

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

td:nth-child(4) {
    white-space: normal;
    min-width: 190px;
}

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

td {
    font-size: 14px;
}

.category-panel {
    display: grid;
    gap: 10px;
}

.category-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
}

.category-row strong {
    color: var(--ink);
    white-space: nowrap;
}

.good {
    color: var(--green);
}

.bad {
    color: var(--red);
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 960px) {
    .overview,
    .entry-form,
    .week-grid {
        grid-template-columns: 1fr;
    }

    .workspace-head {
        display: grid;
    }

    .tabs {
        min-width: 0;
        width: 100%;
    }

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

@media (max-width: 560px) {
    .workspace-head h1 {
        font-size: 24px;
    }

    .field-head {
        display: grid;
    }

    .tabs,
    .category-picker {
        grid-template-columns: 1fr;
    }

    .settings-panel {
        padding: 18px;
    }
}
