:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --line: #e2e5ea;
    --text: #1c2330;
    --muted: #6b7585;
    --accent: #1f6feb;
    --accent-dark: #1859c2;
    --ok-bg: #e7f6ec;
    --ok-text: #17603a;
    --bad-bg: #fdecec;
    --bad-text: #a12626;
    --warn-bg: #fff5d9;
    --warn-text: #7a5a00;
    --radius: 8px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* ---------- каркас ---------- */

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

.side {
    width: 220px;
    flex: none;
    background: #18202c;
    color: #c9d1dc;
    padding: 16px 0;
    display: flex;
    flex-direction: column;
}

.side .brand { color: #fff; font-weight: 700; font-size: 18px; padding: 0 20px 14px; }
.side .group { margin: 14px 20px 6px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: #7d8898; }
.side a { display: block; padding: 8px 20px; color: inherit; }
.side a:hover { background: #222c3b; text-decoration: none; color: #fff; }
.side a.on { background: #2a3648; color: #fff; box-shadow: inset 3px 0 0 var(--accent); }

.side .who { margin-top: auto; padding: 14px 20px 0; border-top: 1px solid #2a3648; font-size: 13px; }
.side .who b { display: block; color: #fff; font-weight: 600; }
.side .who button { margin-top: 8px; background: none; border: 0; color: #9fb4d1; padding: 0; cursor: pointer; font: inherit; }
.side .who button:hover { color: #fff; text-decoration: underline; }

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

.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head .grow { flex: 1; }
.sub { color: var(--muted); font-size: 13px; }

/* ---------- блоки ---------- */

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}

.card.flush { padding: 0; overflow: hidden; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: inherit; display: block; }
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .num { font-size: 26px; font-weight: 700; }
.tile .cap { color: var(--muted); font-size: 13px; }
.tile.warn .num { color: #b26a00; }

.note { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.note.ok { background: var(--ok-bg); color: var(--ok-text); }
.note.bad { background: var(--bad-bg); color: var(--bad-text); }
.note.warn { background: var(--warn-bg); color: var(--warn-text); }
.note ul { margin: 0; padding-left: 18px; }

/* ---------- таблицы ---------- */

.scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfd; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.tight, th.tight { width: 1%; white-space: nowrap; }
td.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.neg { color: var(--bad-text); font-weight: 600; }
.dim { color: var(--muted); }
.small { font-size: 13px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eceff3; color: #47505e; white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok-text); }
.tag.bad { background: var(--bad-bg); color: var(--bad-text); }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); }

/* ---------- формы ---------- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cdd3dc;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

input:focus, select:focus, textarea:focus { outline: 2px solid #b7d2ff; border-color: var(--accent); }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: #f3f4f6; color: #555; }
textarea { min-height: 96px; resize: vertical; }

/* без min-width:0 широкая таблица внутри fieldset растягивает всю страницу */
fieldset { min-width: 0; border: 0; padding: 0; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 18px; }
.field.wide { grid-column: 1 / -1; }
.field .err { color: var(--bad-text); font-size: 13px; margin-top: 4px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 15px; color: var(--text); margin: 0 0 6px; }
.check input { margin-top: 3px; }

.btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid #cdd3dc;
    background: #fff;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover { background: #f3f5f8; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--bad-text); border-color: #e9b9b9; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.sm { padding: 4px 10px; font-size: 13px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 18px; }
.actions .grow { flex: 1; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { width: 320px; max-width: 100%; }
.filters select { width: auto; }
.filters .check { margin: 0; }

.inline { display: flex; gap: 8px; align-items: center; }
.inline input { min-width: 0; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px; color: var(--muted); font-size: 13px; }

/* ---------- строки документа ---------- */

.finder { position: relative; margin-bottom: 12px; }
.finder .list {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 5;
    background: #fff; border: 1px solid var(--line); border-radius: 6px;
    box-shadow: 0 8px 24px rgba(20, 30, 50, .12); margin-top: 4px; max-height: 320px; overflow: auto;
}
.finder .list[hidden] { display: none; }
.finder .list button { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; font: inherit; cursor: pointer; }
.finder .list button:hover, .finder .list button:focus { background: #eef4ff; outline: 0; }
.finder .list .none { padding: 10px 12px; color: var(--muted); }

.lines input { width: 110px; text-align: right; }
.lines td.name { min-width: 220px; }
.total { text-align: right; font-size: 17px; font-weight: 700; padding: 12px; }

/* ---------- вход ---------- */

.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate .card { width: 100%; max-width: 420px; padding: 26px; }
.gate h1 { margin-bottom: 4px; }
.gate .field { margin-top: 14px; }
.gate .btn { width: 100%; margin-top: 18px; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .side { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; }
    .side .brand { padding: 4px 10px; }
    .side .group { display: none; }
    .side a { padding: 6px 10px; border-radius: 6px; }
    .side a.on { box-shadow: none; }
    .side .who { margin: 0 0 0 auto; border: 0; padding: 4px 10px; }
    .side .who b { display: none; }
    .side .who button { margin: 0; }
    .main { padding: 16px; }
}
