:root {
    --ink: #1d1d1d;
    --ink-soft: #262a2b;
    --paper: #f5f5f5;
    --paper-card: #ffffff;
    --line: #dcdcdc;
    --brand: #d90818;
    --brand-dark: #b30714;
    --copper: #d90818;
    --copper-dark: #b30714;
    --teal: #13612e;
    --rose: #d90818;
    --muted: #4a4a4a;
    --shadow: 0 12px 30px rgba(29, 29, 29, 0.08);
    --radius: 16px;
    --sidebar: 272px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family: "Montserrat", "Segoe UI", sans-serif;
}

a { color: inherit; }

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar);
    background: var(--ink);
    color: #ffffff;
    padding: 28px 20px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 8px;
    text-decoration: none;
}

.brand-logo {
    display: block;
    width: min(168px, 100%);
    height: auto;
    object-fit: contain;
}

.brand-name {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--brand);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 18px;
}

.brand strong { display: block; font-size: 15px; }
.brand small { color: #c4c4c4; font-size: 12px; }

.nav-group { display: flex; flex-direction: column; gap: 6px; }
.nav-label {
    font-size: 11px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #9aa3ab;
    padding: 12px 12px 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    color: #f5f5f5;
    text-decoration: none;
    font-size: 14px;
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover,
.nav-link.is-active {
    background: rgba(255, 253, 248, .08);
    color: #fff;
}

.nav-link.is-active { background: var(--brand); }

.sidebar-footer {
    margin-top: auto;
    padding: 14px 12px;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: 13px;
    color: #c4c4c4;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 28px 32px 48px;
}

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

.page-kicker {
    font-size: 12px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 6px;
}

.page-title {
    font-family: "Montserrat", "Segoe UI", sans-serif;
    font-size: 32px;
    font-weight: 800;
    line-height: 1.1;
    margin: 0;
}

.page-subtitle { margin: 8px 0 0; color: var(--muted); }

.context-form {
    display: flex;
    gap: 10px;
    align-items: end;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    box-shadow: var(--shadow);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label,
.form-grid label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

select, input, textarea {
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    min-width: 0;
}

select:focus, input:focus, textarea:focus {
    outline: 2px solid rgba(217, 8, 24, .25);
    border-color: var(--brand);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary { background: var(--ink); color: #fff; }
.btn-accent { background: var(--brand); color: #fff; }
.btn-accent:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: #fde8e6; color: var(--rose); }
.btn-small { padding: 7px 10px; font-size: 13px; }

.cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.card span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.card strong {
    font-family: "Montserrat", "Segoe UI", sans-serif;
    font-size: 26px;
    font-weight: 800;
}

.panel {
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

th {
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    background: #f5f5f5;
}

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.muted { color: var(--muted); }
tr.total td { font-weight: 800; background: #f5f5f5; }

.is-positive { color: var(--teal); font-weight: 700; }
.is-negative { color: var(--rose); font-weight: 700; }
.is-neutral { color: var(--muted); }

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 600;
}

.flash-success { background: #e6f4ef; color: var(--teal); }
.flash-error { background: #fde8e6; color: var(--rose); }

.form-card {
    max-width: 820px;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.error { color: var(--rose); font-size: 12px; margin-top: 4px; }

.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    background: var(--paper);
}

.login-aside {
    background: var(--ink);
    color: #ffffff;
    padding: 56px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 6px solid var(--brand);
}

.login-aside h1 {
    font-family: "Montserrat", "Segoe UI", sans-serif;
    font-size: 42px;
    font-weight: 800;
    line-height: 1.1;
    max-width: 10ch;
}

.login-panel {
    display: grid;
    place-items: center;
    padding: 32px;
}

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

.login-card h2 {
    font-family: "Montserrat", "Segoe UI", sans-serif;
    margin: 0 0 8px;
    font-weight: 800;
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.user-chip { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.actions { display: flex; gap: 8px; }

.menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 20;
}

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

@media (max-width: 1100px) {
    .cards { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        z-index: 15;
        transform: translateX(-110%);
        transition: transform .2s ease;
    }
    .sidebar.is-open { transform: none; }
    .menu-toggle { display: inline-flex; }
    .main { padding: 72px 16px 32px; }
    .topbar, .form-grid, .login-page, .cards { grid-template-columns: 1fr; display: grid; }
    .login-aside { display: none; }
    .context-form { flex-wrap: wrap; }
}
