/* Контроль ремонтов: оформление без сборки и внешних библиотек.
   Цвета — переменные; тёмная тема — по настройке системы. */

:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b2330;
  --muted: #5a6575;
  --border: #d4dae2;
  --accent: #1d5bb8;
  --accent-hover: #174a96;
  --accent-text: #ffffff;
  --accent-soft: #e5edfa;
  --danger: #b3261e;
  --danger-soft: #fcebea;
  --success: #17703d;
  --success-soft: #e3f3e8;
  --warning: #855400;
  --warning-soft: #fff3d6;
  --focus: #2a78e4;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 2px 6px rgb(16 24 40 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2028;
    --surface-2: #222a34;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --border: #333d4a;
    --accent: #6ea2f0;
    --accent-hover: #8db6f4;
    --accent-text: #0d1724;
    --accent-soft: #1d2d45;
    --danger: #f08a82;
    --danger-soft: #3a1f1d;
    --success: #6fcf97;
    --success-soft: #17301f;
    --warning: #f2c46b;
    --warning-soft: #33280f;
    --focus: #8db6f4;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .9em; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus, h1:focus { outline: none; }

.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 30;
  background: var(--surface); padding: 8px 12px; border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- Верхняя панель и меню ------------------------------------------ */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  display: block; padding: 6px 12px; border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.who-name { color: var(--muted); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-name:hover { color: var(--text); }
.topbar .menu-toggle { display: none; }

/* Меню сворачивается под кнопку, когда пункты не помещаются в одну строку. */
@media (max-width: 1100px) {
  .topbar-inner { gap: 8px 12px; }
  .who { order: 2; }
  .topbar .menu-toggle { display: inline-flex; order: 3; }
  .nav { order: 4; flex-basis: 100%; display: none; padding-bottom: 4px; }
  .nav.open { display: block; }
  .nav ul { flex-direction: column; }
}

@media (max-width: 520px) {
  .brand { flex-basis: 100%; }
  .who { margin-left: 0; flex: 1; }
  .who-name { flex: 1; }
}

/* --- Содержимое ------------------------------------------------------ */

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.boot { color: var(--muted); }

.screen-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.screen-head h1 { margin: 0; margin-right: auto; }
.lead { color: var(--muted); max-width: 70ch; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 14px; color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.toolbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .field { margin: 0; }
.toolbar .grow { flex: 1 1 220px; }

.muted { color: var(--muted); }
.small { font-size: .875em; }
.nowrap { white-space: nowrap; }

/* --- Кнопки ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: .875rem; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Поля форм ------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label, .field-label { font-weight: 600; font-size: .9rem; }
.hint { color: var(--muted); font-size: .85rem; }
input[type="text"], input[type="password"], input[type="search"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; min-height: 38px; width: 100%; max-width: 100%;
}
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
input[aria-invalid="true"] { border-color: var(--danger); }
.check { display: flex; align-items: flex-start; gap: 8px; margin: 4px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; }
.check.disabled { color: var(--muted); cursor: default; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 14px; min-width: 0; }
legend { font-weight: 700; padding: 0 6px; }
.checklist { max-height: 380px; overflow: auto; padding: 4px 2px; }
.columns-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.inline-add { display: flex; gap: 8px; margin-top: 6px; }
.inline-add input { flex: 1; }

.form-error {
  background: var(--danger-soft); color: var(--danger); border-radius: var(--radius);
  padding: 8px 12px; margin: 0 0 12px;
}
.note {
  background: var(--accent-soft); border-radius: var(--radius); padding: 8px 12px; margin: 0 0 12px;
}
.note.warn { background: var(--warning-soft); color: var(--warning); }

/* --- Метки состояния ------------------------------------------------- */

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.readiness { list-style: none; padding: 0; margin: 0; }
.readiness li { padding: 2px 0; }
.readiness li::before { content: "✗ "; color: var(--danger); font-weight: 700; }
.readiness li.done::before { content: "✓ "; color: var(--success); }

/* --- Таблицы --------------------------------------------------------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tr.inactive td { color: var(--muted); }
.empty { padding: 16px; color: var(--muted); text-align: center; }
.sub { display: block; color: var(--muted); font-size: .85em; }

@media (max-width: 640px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.responsive tr:last-child { border-bottom: none; }
  table.responsive td { border: none; padding: 4px 12px; }
  table.responsive td[data-label]::before {
    content: attr(data-label); display: block; font-size: .78rem; color: var(--muted); font-weight: 600;
  }
}

.pager { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.narrow { max-width: 560px; }

@media (max-width: 640px) {
  .details { grid-template-columns: 1fr; gap: 0; }
  .details dd { margin-bottom: 8px; }
}

/* --- Вход ------------------------------------------------------------ */

.login { max-width: 380px; margin: 8vh auto 0; }
.login h1 { font-size: 1.35rem; }
.login .btn { width: 100%; }

/* --- Диалоги и уведомления ------------------------------------------ */

dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; color: var(--text);
  background: var(--surface); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  box-shadow: 0 12px 40px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(10 15 25 / 45%); }
.dialog-form { padding: 18px 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* Полоса копии (instance.banner): тестовую копию не спутать с пилотом. */
.instance-banner {
  background: var(--warning-soft); color: var(--warning); border-bottom: 2px solid var(--warning);
  padding: 6px 16px; text-align: center; font-weight: 600;
}

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 40; max-width: calc(100vw - 32px); }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius);
  box-shadow: var(--shadow); max-width: 420px;
}
.toast.error { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }

@media (max-width: 640px) {
  main { padding: 14px 16px 40px; }
  .screen-head .btn { width: 100%; }
  .toolbar > * { flex: 1 1 100%; }
  .toasts { left: 16px; right: 16px; }
}
