:root {
    --bg: #f4f5f2;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #70766c;
    --line: #dfe3da;
    --green: #31715f;
    --green-dark: #214d42;
    --red: #b94735;
    --amber: #b5792a;
    --blue: #356f96;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
}

.auth-screen {
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #f4f5f2 0%, #e8efe9 100%);
}

.auth-card {
    width: min(440px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 18px 60px rgba(30, 45, 35, .12);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 248px;
    padding: 20px;
    background: #1f2c27;
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand-mark {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #e2b45b;
    color: #18221e;
    font-weight: 800;
}

.brand small,
.profile span,
small,
.muted {
    color: var(--muted);
}

.sidebar .brand small,
.sidebar .profile span {
    display: block;
    color: #afbbb3;
}

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

.sidebar nav a,
.profile a {
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 6px;
    color: #dce5df;
}

.sidebar nav a.active,
.sidebar nav a:hover {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

.profile {
    margin-top: auto;
    display: grid;
    gap: 4px;
}

.profile a {
    padding-left: 0;
    color: #e2b45b;
}

.main {
    margin-left: 248px;
    padding: 30px;
}

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

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

h1,
h2 {
    margin: 0;
    line-height: 1.15;
}

h1 {
    font-size: 32px;
}

h2 {
    font-size: 20px;
    margin-bottom: 16px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--green);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.button.primary {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
}

.button.small {
    min-height: 32px;
    padding: 0 10px;
    font-size: 13px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

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

.metric {
    padding: 18px;
}

.metric span {
    display: block;
    color: var(--muted);
    margin-bottom: 10px;
}

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

.metric small {
    display: block;
    margin-top: 8px;
    line-height: 1.35;
}

.metric.danger strong {
    color: var(--red);
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(320px, .85fr);
    gap: 20px;
    align-items: start;
}

.vision {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, .8fr);
    gap: 22px;
    align-items: center;
    padding: 22px;
    margin-bottom: 24px;
    border: 1px solid #cbd7cf;
    border-radius: 8px;
    background: #eaf1ec;
}

.vision h2 {
    max-width: 860px;
    margin-bottom: 0;
    font-size: 24px;
}

.vision p:last-child {
    margin: 0;
    color: #46524b;
    line-height: 1.5;
}

.panel {
    padding: 20px;
}

.panel.wide {
    max-width: none;
}

.section-gap {
    margin-top: 24px;
}

.table-wrap {
    overflow: auto;
}

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

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

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

td small {
    display: block;
    margin-top: 4px;
}

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

.strong-link {
    font-weight: 700;
    text-decoration: none;
}

.strong-link:hover {
    color: var(--green);
}

.status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #edf0ea;
    color: #394039;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.status.urgent,
.status.rejected {
    background: #fae6e1;
    color: var(--red);
}

.status.review {
    background: #f5ecda;
    color: var(--amber);
}

.status.approved,
.status.closed {
    background: #e2f0e9;
    color: var(--green-dark);
}

.status.in_purchase,
.status.accounting {
    background: #e2edf4;
    color: var(--blue);
}

.status.planned {
    background: #edf0ea;
    color: #394039;
}

.status.approval {
    background: #f5ecda;
    color: var(--amber);
}

.status.active,
.status.approved,
.status.paid,
.status.imported {
    background: #e2f0e9;
    color: var(--green-dark);
}

.status.partial {
    background: #f5ecda;
    color: var(--amber);
}

.status.error {
    background: #fae6e1;
    color: var(--red);
}

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

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

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

label {
    display: grid;
    gap: 6px;
    color: #3a4039;
    font-weight: 700;
}

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

textarea {
    resize: vertical;
}

.alert {
    padding: 12px;
    border-radius: 6px;
    background: #fae6e1;
    color: var(--red);
    font-weight: 700;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(320px, .6fr);
    gap: 20px;
    align-items: start;
}

.detail-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}

.facts {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 22px 0;
}

.facts div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

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

dd {
    margin: 5px 0 0;
    font-weight: 700;
}

.timeline {
    display: grid;
    gap: 14px;
    margin: 0;
    padding-left: 20px;
}

.timeline li span,
.timeline li small {
    display: block;
    margin-top: 4px;
}

.compact {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.inline-form {
    margin: 0;
}

.action-stack {
    margin-bottom: 6px;
}

.address-field {
    position: relative;
}

.suggestions {
    position: absolute;
    right: 0;
    left: 0;
    z-index: 30;
    display: grid;
    gap: 4px;
    max-height: 280px;
    overflow: auto;
    margin-top: 4px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 36px rgba(31, 44, 39, .14);
}

.suggestions[hidden] {
    display: none;
}

.suggestions button {
    padding: 10px 12px;
    border: 0;
    border-radius: 6px;
    background: #f7f8f5;
    color: var(--ink);
    font: inherit;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
}

.suggestions button:hover {
    background: #eaf1ec;
}

.empty {
    padding: 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.money-in {
    color: var(--green-dark);
    font-weight: 800;
}

.money-out {
    color: var(--red);
    font-weight: 800;
}

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

.process-grid div,
.action-grid div {
    display: grid;
    gap: 8px;
    min-height: 116px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
}

.process-grid span,
.action-grid span {
    color: var(--muted);
    line-height: 1.4;
}

.action-grid {
    margin-bottom: 24px;
}

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip-list.vertical {
    display: grid;
}

.chip-list span {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #edf0ea;
    color: #394039;
    font-size: 12px;
    font-weight: 700;
}

.employee-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    overflow: hidden;
    border-radius: 999px;
    background: #eaf1ec;
    color: var(--green-dark);
    font-weight: 800;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.check-grid {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.check-grid legend {
    padding: 0 6px;
    color: var(--muted);
    font-weight: 700;
}

.check-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

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

.workflow-card {
    margin-bottom: 16px;
}

.workflow-steps {
    display: grid;
    gap: 12px;
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
}

.workflow-steps li {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.workflow-steps li > span {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: var(--green);
    color: #fff;
    font-weight: 800;
}

.workflow-steps p {
    margin: 4px 0;
    color: #46524b;
}

code {
    white-space: pre-wrap;
}

@media (max-width: 980px) {
    body {
        padding-bottom: 74px;
    }

    .sidebar {
        position: fixed;
        inset: auto 0 0 0;
        width: auto;
        z-index: 20;
        padding: 8px 10px;
        border-top: 1px solid rgba(255, 255, 255, .12);
        gap: 0;
    }

    .main {
        margin-left: 0;
        padding: 16px;
    }

    .brand,
    .profile {
        display: none;
    }

    .sidebar nav {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .sidebar nav::-webkit-scrollbar {
        display: none;
    }

    .sidebar nav a {
        flex: 0 0 auto;
        min-width: 78px;
        padding: 10px 12px;
        text-align: center;
        font-size: 13px;
        white-space: nowrap;
    }

    .metric-grid,
    .split,
    .detail-grid,
    .facts,
    .form-grid,
    .form-grid.three,
    .vision,
    .process-grid,
    .action-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 10;
        flex-direction: column;
        gap: 12px;
        margin: -16px -16px 16px;
        padding: 14px 16px;
        border-bottom: 1px solid var(--line);
        background: rgba(244, 245, 242, .96);
        backdrop-filter: blur(8px);
    }

    .top-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
        justify-content: stretch;
    }

    .button {
        width: 100%;
        min-height: 48px;
    }

    .button.small {
        width: auto;
        min-height: 38px;
    }

    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 18px;
    }

    .auth-screen {
        align-items: start;
        padding: 16px;
    }

    .auth-card,
    .panel,
    .metric,
    .vision,
    .table-wrap {
        border-radius: 8px;
    }

    .panel,
    .auth-card,
    .vision {
        padding: 16px;
    }

    .vision h2 {
        font-size: 20px;
    }

    .metric-grid {
        gap: 10px;
        margin-bottom: 16px;
    }

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

    input,
    select,
    textarea {
        min-height: 48px;
        font-size: 16px;
        padding: 12px;
    }

    textarea {
        min-height: 120px;
    }

    label {
        font-size: 14px;
    }

    .table-wrap {
        overflow: visible;
        border: 0;
        background: transparent;
    }

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

    thead {
        display: none;
    }

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

    td {
        display: flex;
        justify-content: space-between;
        gap: 14px;
        padding: 9px 0;
        border-bottom: 1px solid #edf0ea;
        text-align: right;
    }

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

    td::before {
        content: attr(data-label);
        flex: 0 0 42%;
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
        text-align: left;
        text-transform: uppercase;
    }

    td[data-label="Заявка"],
    td[data-label="Платеж"],
    td[data-label="Договор"],
    td[data-label="Объект"],
    td[data-label="Payload"] {
        display: grid;
        gap: 5px;
        text-align: left;
    }

    td[data-label="Заявка"]::before,
    td[data-label="Платеж"]::before,
    td[data-label="Договор"]::before,
    td[data-label="Объект"]::before,
    td[data-label="Payload"]::before {
        flex: none;
    }

    .detail-head {
        display: grid;
    }

    .facts {
        margin: 16px 0;
    }

    .inline-form {
        display: flex;
        justify-content: flex-end;
    }
}

@media (max-width: 520px) {
    .main {
        padding: 12px;
    }

    .topbar {
        margin: -12px -12px 14px;
        padding: 12px;
    }

    .sidebar nav a {
        min-width: 72px;
        padding: 10px;
    }

    .action-grid div,
    .process-grid div {
        min-height: auto;
    }

    td {
        flex-direction: column;
        gap: 4px;
        text-align: left;
    }

    td::before {
        flex: none;
    }
}
