:root {
    --bg: #f3efe7;
    --surface: #fffdf8;
    --surface-strong: #f7f0e5;
    --line: #d9cbb7;
    --text: #1f2933;
    --muted: #64748b;
    --primary: #8f4d2e;
    --primary-dark: #6f351b;
    --accent: #d4a373;
    --income: #117a65;
    --expense: #c0392b;
    --shadow: 0 18px 40px rgba(68, 44, 22, 0.08);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Trebuchet MS", sans-serif;
    background:
        radial-gradient(circle at top right, rgba(212, 163, 115, 0.22), transparent 28%),
        linear-gradient(180deg, #f9f5ef 0%, #f0e7db 100%);
    color: var(--text);
}

h1,
h2,
h3 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
}

p {
    margin-top: 0;
}

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

ul {
    margin: 0;
    padding-left: 1rem;
}

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

.sidebar {
    padding: 2rem 1.5rem;
    background: linear-gradient(180deg, #2e2a27 0%, #1e1b19 100%);
    color: #f5eee4;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sidebar h1 {
    font-size: 1.9rem;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.76rem;
    color: var(--accent);
    margin-bottom: 0.55rem;
}

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

.sidebar .muted,
.sidebar-label {
    color: rgba(245, 238, 228, 0.76);
}

.nav-links {
    display: grid;
    gap: 0.65rem;
}

.nav-links a {
    padding: 0.8rem 1rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    transition: transform 0.18s ease, background 0.18s ease;
}

.nav-links a:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-card {
    margin-top: auto;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
}

.content {
    padding: 2rem;
}

.page-header,
.panel-heading,
.header-actions,
.form-actions,
.metric-row,
.list-card,
.trend-row,
.totals-card,
.trend-values {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.page-header {
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.header-actions {
    flex-wrap: wrap;
}

.button,
.inline-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.button {
    padding: 0.78rem 1.2rem;
    background: var(--primary);
    color: white;
}

.button:hover,
.inline-button:hover {
    transform: translateY(-1px);
    opacity: 0.92;
}

.button.secondary {
    background: #efe3d3;
    color: var(--primary-dark);
}

.button.ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
}

.inline-button {
    padding: 0.55rem 0.85rem;
    background: #ece4d8;
    color: var(--text);
}

.inline-button.danger {
    background: #fde7e4;
    color: var(--expense);
}

.text-link {
    color: var(--primary-dark);
    font-weight: 600;
}

.panel,
.metric-card {
    background: var(--surface);
    border: 1px solid rgba(143, 77, 46, 0.12);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    padding: 1.35rem;
    margin-bottom: 1.5rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

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

.metric-card {
    padding: 1.2rem;
}

.metric-period {
    margin-bottom: 0.55rem;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.metric-row {
    padding-top: 0.45rem;
    border-top: 1px solid rgba(143, 77, 46, 0.08);
    margin-top: 0.45rem;
}

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

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

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

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

th,
td {
    text-align: left;
    padding: 0.82rem 0.7rem;
    border-bottom: 1px solid rgba(143, 77, 46, 0.1);
    vertical-align: top;
}

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

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

.compact-form {
    margin-bottom: 1rem;
}

label {
    display: grid;
    gap: 0.5rem;
    font-weight: 600;
}

label span {
    font-size: 0.92rem;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fffdfa;
    color: var(--text);
    padding: 0.85rem 0.95rem;
    font: inherit;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(143, 77, 46, 0.18);
    border-color: var(--primary);
}

.full-width {
    grid-column: 1 / -1;
}

.flash-stack {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.flash {
    padding: 0.95rem 1rem;
    border-radius: 14px;
    border: 1px solid transparent;
    font-weight: 600;
}

.flash-success {
    background: #e7f8f1;
    color: #0c6a4d;
    border-color: #bfe6d7;
}

.flash-danger {
    background: #fdeceb;
    color: #9c2f25;
    border-color: #f7c7c2;
}

.flash-warning {
    background: #fff4de;
    color: #9d6700;
    border-color: #f2d79c;
}

.flash-info {
    background: #e8f2fb;
    color: #20598f;
    border-color: #bdd7ee;
}

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

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

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

.stack-list,
.trend-list {
    display: grid;
    gap: 0.9rem;
}

.list-card,
.trend-row,
.totals-card {
    padding: 1rem;
    border: 1px solid rgba(143, 77, 46, 0.1);
    border-radius: 16px;
    background: var(--surface-strong);
}

.totals-card {
    margin-top: 1rem;
    flex-wrap: wrap;
}

.totals-card div {
    min-width: 140px;
}

.trend-values {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.empty-state {
    padding: 1rem;
    border-radius: 14px;
    background: var(--surface-strong);
    color: var(--muted);
}

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

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

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

    .sidebar {
        padding-bottom: 1.5rem;
    }

    .two-column,
    .form-grid,
    .metrics-grid,
    .metrics-grid.three-up {
        grid-template-columns: 1fr;
    }

    .content {
        padding: 1.25rem;
    }

    .list-card,
    .trend-row,
    .totals-card,
    .page-header,
    .panel-heading,
    .header-actions,
    .trend-values {
        align-items: flex-start;
        flex-direction: column;
    }

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