/* Десктоп-only, целевая ширина 1920x1080 — без media query, без мобильной адаптации (§11.0) */

:root {
    --accent: #2d6cdf;
    --accent-dark: #1f52ab;
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --border: #dde3ec;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --readonly-bg: #eef1f5;
    --error-bg: #fdecea;
    --error-border: #f5c6cb;
    --error-text: #611a15;
    --success-bg: #eafaf0;
    --success-border: #b7ebc6;
    --success-text: #1e5631;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-width: 1200px;
}

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

/* --- Шапка (§11.2) --- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 24px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    padding: 0 24px;
    height: 56px;
}

.app-header .brand {
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
}

.app-nav {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow: hidden;
}

.app-nav a, .app-nav .nav-link {
    padding: 8px 14px;
    border-radius: 4px;
    color: var(--text);
    font-size: 14px;
    white-space: nowrap;
}

.app-nav a:hover { background: var(--readonly-bg); text-decoration: none; }
.app-nav a.active { background: var(--accent); color: #fff; }

.app-header .user-name {
    color: var(--text-muted);
    font-size: 14px;
    white-space: nowrap;
}

.app-header .btn-export {
    margin-left: auto;
}

.app-main {
    padding: 24px;
    max-width: 1880px;
    margin: 0 auto;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 24px;
    margin-bottom: 20px;
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 12px; }
h2:first-child { margin-top: 0; }

/* --- Кнопки --- */
.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 9px 18px;
    font-size: 14px;
    cursor: pointer;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--readonly-bg); color: var(--text); }
.btn-danger-icon {
    background: none;
    border: none;
    color: #b91c1c;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
}
.btn-row { margin-top: 16px; display: flex; gap: 12px; }

/* --- Формы: «Подпись: поле» в одну строку, не подпись сверху --- */
.field-row {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 12px;
}
.field-row label {
    flex: 0 0 320px;
    padding-top: 8px;
    font-size: 14px;
    color: var(--text-muted);
    text-align: right;
}
.field-row-control { flex: 1; min-width: 0; }
.field-row input[type=text],
.field-row input[type=email],
.field-row input[type=number],
.field-row input[type=password],
.field-row select,
.field-row textarea {
    width: 100%;
    max-width: 480px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    color: #000;
    background: #fff;
}
.field-row textarea { max-width: 640px; }
.field-row .errorlist { color: var(--error-text); font-size: 12px; padding: 0; margin: 4px 0 0; list-style: none; }

/* Поля внутри таблиц (formset-строки, строки оборудования) — тот же стиль без обёртки .field-row */
table.grid input[type=text],
table.grid input[type=email],
table.grid input[type=number],
table.grid select,
table.grid textarea {
    padding: 5px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    color: #000;
    background: #fff;
    width: 100%;
    box-sizing: border-box;
}
table.grid .errorlist { color: var(--error-text); font-size: 11px; padding: 0; margin: 2px 0 0; list-style: none; }
table.grid textarea { resize: vertical; min-height: 44px; font-family: inherit; }

/* --- Коечный фонд (2.3/2.4) — 2 колонки, как в исходном файле-анкете --- */
.two-col {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.two-col > table { flex: 1; min-width: 0; }

/* --- 5.3 — группы в 3 колонки, прижаты влево, без растяжения на всю ширину --- */
.three-col {
    display: flex;
    gap: 48px;
    align-items: flex-start;
}
.three-col > table { flex: 1; min-width: 0; }
.three-col > div { flex: 0 0 auto; }
.three-col .field-row { margin-bottom: 0; }
.three-col .field-row label { flex-basis: auto; text-align: left; }

/* --- Несколько полей в одну строку (§5.2/§5.1 — короткие соседние поля) --- */
.row-fields {
    display: flex;
    gap: 40px;
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.row-fields .field-row { margin-bottom: 0; flex: 0 0 auto; }
/* Первое поле в строке держит общую колонку подписей (выравнивание с остальной формой);
   последующие поля в той же строке — компактная подпись рядом со своим полем. */
.row-fields .field-row:first-child label { flex: 0 0 320px; text-align: right; }
.row-fields .field-row:not(:first-child) label { flex-basis: auto; text-align: left; }
.row-fields .field-row-control input[type=text] { width: 320px; }

/* --- Числовой спиннер (§11.0.3) --- */
.numfield {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    width: 90px;
    overflow: hidden;
}
.numfield input[type=number] {
    border: none;
    width: 100%;
    padding: 6px 6px;
    font-size: 14px;
    color: #000;
    -moz-appearance: textfield;
}
.numfield input[type=number]::-webkit-inner-spin-button,
.numfield input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.numfield .spin {
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    width: 18px;
}
.numfield .spin button {
    flex: 1;
    border: none;
    background: var(--readonly-bg);
    cursor: pointer;
    font-size: 8px;
    line-height: 1;
    padding: 0;
}
.numfield .spin button:hover { background: var(--border); }
.numfield.invalid input[type=number] { background: var(--error-bg); }

/* --- Таблицы --- */
table.grid {
    border-collapse: collapse;
    width: 100%;
}
table.grid th, table.grid td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    font-size: 14px;
    text-align: left;
    vertical-align: middle;
}
table.grid thead {
    position: sticky;
    top: 56px;
    z-index: 10;
}
table.grid thead th {
    background: #f8f9fb;
    font-weight: 600;
}
table.grid td.readonly, table.grid td.ro { background: var(--readonly-bg); color: #444; }
table.grid td.col-narrow, table.grid th.col-narrow { width: 56px; text-align: center; }
table.grid td.col-wrap, table.grid th.col-wrap { white-space: normal; word-break: normal; }
table.grid tr.dim { opacity: 0.55; }
table.grid td.spacer-col, table.grid th.spacer-col {
    width: 18px;
    border-top: none;
    border-bottom: none;
    background: var(--bg);
    padding: 0;
}

/* Вкладки оборудования (§11.6) — пропорции колонок как в исходном файле-анкете */
table.equipment-grid { table-layout: fixed; }
table.equipment-grid td.col-narrow, table.equipment-grid th.col-narrow { width: auto; padding-left: 3px; padding-right: 3px; }
table.equipment-grid .numfield { width: 50px; }
table.equipment-grid .numfield input[type=number] { padding: 6px 3px; }
table.equipment-grid .numfield .spin { width: 13px; }

/* --- Toast (§11.0.2) --- */
.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.toast {
    padding: 12px 40px 12px 16px;
    border-radius: 4px;
    max-width: 420px;
    font-size: 14px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.toast-error { background: var(--error-bg); color: var(--error-text); border: 1px solid var(--error-border); }
.toast-success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.toast button {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: inherit;
}

/* --- Логин (§11.1) --- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.login-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px;
    width: 400px;
}
.login-card h1 { text-align: center; margin-bottom: 24px; }
.login-card .btn { width: 100%; margin-top: 8px; }
/* Карточка входа узкая (400px) — здесь подпись остаётся над полем, а не сбоку
   (в отличие от общего .field-row на страницах данных, §11.5). */
.login-card .field-row { display: block; }
.login-card .field-row label {
    display: block;
    flex: none;
    text-align: left;
    padding-top: 0;
    margin-bottom: 4px;
}
.login-card .field-row-control,
.login-card .field-row input {
    width: 100%;
    max-width: none;
}

/* --- Список субъектов/МО --- */
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover { background: #f2f6fd; }

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
}
.status-not_filled { background: #fdecea; color: #611a15; }
.status-in_progress { background: #fff6e0; color: #7a5b00; }
.status-filled { background: var(--success-bg); color: var(--success-text); }
