/* Autotronik — оформлення. Одна тема в двох станах, перемикач у підвалі меню.
   Планшет у майстерні: великі цілі дотику, високий контраст, нічого дрібного. */

:root {
  --bg: #0f1216;
  --bg-soft: #161b22;
  --panel: #1b222c;
  --panel-2: #212a35;
  --line: #2c3644;
  --text: #e6edf3;
  --muted: #8d9bab;
  --accent: #f5a524;
  --accent-2: #38bdf8;
  --ok: #35c07f;
  --warn: #f0b429;
  --bad: #ef5f5f;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

body.light {
  --bg: #f3f5f8;
  --bg-soft: #e9edf3;
  --panel: #ffffff;
  --panel-2: #f4f7fa;
  --line: #d8dfe8;
  --text: #17212b;
  --muted: #5d6b7a;
  --accent: #b8700a;
  --accent-2: #0b6fa4;
  --ok: #17784f;
  --warn: #9a6b06;
  --bad: #b3382f;
  --shadow: 0 8px 24px rgba(20, 34, 48, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Мусить стояти тут і з !important: авторський стиль перебиває браузерне
   правило [hidden]{display:none}, і .modal-root із display:grid лишалася
   розтягнутою на весь екран — невидима панель, яка ковтала всі кліки. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 .8em; }
a { color: var(--accent-2); }
code { font-family: Consolas, ui-monospace, monospace; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }

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

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

.side {
  width: 232px;
  flex: 0 0 232px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px; border-bottom: 1px solid var(--line); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #d97706);
  color: #14181d; font-weight: 800; font-size: 13px;
  display: grid; place-items: center; letter-spacing: .5px;
}
.brand-name { font-weight: 700; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.nav { flex: 1; overflow-y: auto; padding: 8px 8px 16px; }
.nav button {
  width: 100%; text-align: left; display: flex; gap: 10px; align-items: center;
  background: none; border: 0; color: var(--muted); cursor: pointer;
  padding: 10px 10px; border-radius: 9px; font: inherit; margin-bottom: 2px;
}
.nav button:hover { background: var(--panel); color: var(--text); }
.nav button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav .ico { width: 20px; text-align: center; font-size: 15px; }
.nav .count { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--panel); padding: 1px 7px; border-radius: 20px; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); padding: 14px 10px 6px; }

.side-foot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.save-state { font-size: 11.5px; color: var(--muted); margin-left: auto; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: var(--bg-soft); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.burger { display: none; }
.view { padding: 20px 22px 60px; max-width: 1180px; }

/* ---------- елементи ---------- */

button, .btn {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); padding: 8px 14px;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--panel-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #14181d; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--panel); color: var(--text); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
button.sm { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -1px; }
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px;
}
.card.tight { padding: 12px 14px; }
.card-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .sp { margin-left: auto; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat .n { font-size: 12px; color: var(--muted); margin-top: 3px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  padding: 2px 9px; border-radius: 20px; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.tag.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.tag.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.tag.acc { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: Consolas, ui-monospace, monospace; }
.empty { color: var(--muted); padding: 26px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.sep { height: 1px; background: var(--line); margin: 14px 0; border: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

ul.plain { list-style: none; padding: 0; margin: 0; }
ul.dash { padding-left: 18px; margin: 0 0 .8em; }
ul.dash li { margin-bottom: 4px; }

/* список рядків із дією праворуч */
.list-row {
  display: flex; gap: 12px; align-items: center;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { font-weight: 600; }
.list-row .s { font-size: 12.5px; color: var(--muted); }

/* чеклісти */
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 2px; accent-color: var(--accent); }
.check.done > span { color: var(--muted); text-decoration: line-through; }

/* черга рекомендацій */
.advice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.advice:last-child { border-bottom: 0; }
.advice .w {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--panel-2); color: var(--muted);
}
.advice.p1 .w { background: color-mix(in srgb, var(--bad) 22%, transparent); color: var(--bad); }
.advice.p2 .w { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.advice.p3 .w { background: color-mix(in srgb, var(--accent-2) 20%, transparent); color: var(--accent-2); }
.advice .why { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* смуга прогресу */
.bar { height: 7px; background: var(--panel-2); border-radius: 20px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 20px; }
.bar.ok > i { background: var(--ok); }

/* кроки протоколу */
.step { border-left: 2px solid var(--line); padding: 0 0 0 14px; margin-left: 6px; }
.step > .s-head { display: flex; gap: 10px; align-items: center; padding: 9px 0; }
.step.done { border-color: var(--ok); }
.step .s-n { font-size: 11px; color: var(--muted); font-family: Consolas, monospace; }
.step .s-body { padding: 0 0 12px; }

/* вкладки */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; border-radius: 0; color: var(--muted);
  padding: 9px 13px; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

/* модалка */
.modal-root { position: fixed; inset: 0; background: rgba(4, 7, 11, .62); display: grid; place-items: center; padding: 18px; z-index: 40; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); width: min(720px, 100%); max-height: 88vh; display: flex; flex-direction: column;
}
.modal > header { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal > header h2 { margin: 0; }
.modal > .body { padding: 18px; overflow-y: auto; }
.modal > footer { padding: 13px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 10px 18px; border-radius: 10px; z-index: 60;
}

/* довідник */
.kv { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.gloss { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; font-size: 14px; }
.gloss b { font-weight: 600; }
.pin { display: grid; grid-template-columns: 44px 1fr; gap: 4px 10px; font-size: 13.5px; }
.pin .n { font-family: Consolas, monospace; color: var(--accent); text-align: right; }

/* друк протоколу */
@media print {
  .side, .topbar, .toast, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .view { padding: 0; max-width: none; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
}

@media (max-width: 880px) {
  .side {
    position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%);
    transition: transform .18s; box-shadow: var(--shadow);
  }
  .side.open { transform: none; }
  .burger { display: block; }
  .view { padding: 16px 14px 60px; }
  .topbar { padding: 12px 14px; }
  .gloss { grid-template-columns: 1fr; }
}
