/* Диспетчеризація котелень — власні стилі без бібліотек. Телефон від 360 px, ПК — широкий макет. */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1d2430;
  --muted: #5f6b7a;
  --line: #d9dee6;
  --primary: #1f5fae;
  --primary-dark: #174a88;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --ok: #2e7d32;
  --ok-bg: #e8f5e9;
  --warn: #9a6200;
  --warn-bg: #fff4e0;
  --info-bg: #e8f0fb;
  --radius: 8px;
  --gap: 16px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.2rem; margin: 20px 0 10px; }
h3 { font-size: 1.05rem; margin: 16px 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden, [hidden] { display: none !important; }
code, .pre { font-family: Consolas, "Courier New", monospace; font-size: .85rem; }
.pre { white-space: pre-wrap; word-break: break-word; background: #f6f8fa; border: 1px solid var(--line); padding: 10px; border-radius: 6px; max-height: 420px; overflow: auto; }

/* ---- верхня панель ---- */
.env-banner { background: #ffb300; color: #3d2b00; text-align: center; font-size: .8rem; font-weight: 600; padding: 2px 8px; letter-spacing: .02em; }
.topbar { display: flex; align-items: center; gap: 12px; background: #1d2b3e; color: #fff; padding: 8px 16px; flex-wrap: wrap; }
.topbar a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.sections { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.sections a { padding: 6px 10px; border-radius: 6px; opacity: .85; }
.sections a.active, .sections a:hover { background: rgba(255,255,255,.14); opacity: 1; }
.usermenu { position: relative; }
.usermenu summary { cursor: pointer; list-style: none; padding: 6px 10px; border-radius: 6px; background: rgba(255,255,255,.1); }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; color: var(--text); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.18); min-width: 180px; z-index: 50; padding: 6px 0; }
.usermenu .menu a, .usermenu .menu .linklike { display: block; width: 100%; text-align: left; padding: 8px 14px; color: var(--text); }
.usermenu .menu a:hover, .usermenu .menu .linklike:hover { background: var(--bg); }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; color: var(--primary); padding: 0; }
.subnav { display: flex; gap: 2px; background: #fff; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; white-space: nowrap; }
.subnav a { padding: 10px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.subnav a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.subnav a:hover { color: var(--text); }

/* ---- макет ---- */
.container { width: 100%; max-width: 960px; margin: 0 auto; padding: var(--gap); flex: 1; }
body.wide .container { max-width: 1500px; }
.container.narrow { max-width: 440px; padding-top: 32px; }
.footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; border-top: 1px solid var(--line); background: #fff; font-size: .85rem; }
.version { color: var(--muted); font-size: .8rem; }
.bare-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 1.15rem; margin-bottom: 20px; text-align: center; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.cols-2 { display: grid; gap: var(--gap); grid-template-columns: 1fr 1fr; }
@media (max-width: 760px) { .cols-2 { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text); }
.tile:hover { border-color: var(--primary); }
.tile strong { display: block; font-size: 1.05rem; margin-bottom: 4px; color: var(--primary); }

/* ---- кнопки ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: #aab4c3; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 30px; padding: 4px 10px; font-size: .85rem; }
.btn-big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
form.inline { display: inline; }

/* ---- форми ---- */
label { display: block; font-weight: 500; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .82rem; color: var(--muted); margin-top: 3px; }
.field .error { font-size: .85rem; color: var(--danger); margin-top: 3px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=tel], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid #b9c2cf; border-radius: 6px; font: inherit; background: #fff; color: var(--text); min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,95,174,.35); border-color: var(--primary); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
textarea { resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin-bottom: 8px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.form-grid { display: grid; gap: 0 var(--gap); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.form-grid .span-all { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 14px; }
legend { font-weight: 600; padding: 0 6px; }

/* ---- таблиці ---- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: var(--gap); }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: #f7f9fb; font-weight: 600; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tr.inactive td { color: var(--muted); }
.table td.num, .table th.num { text-align: right; white-space: nowrap; }
.table input[type=text], .table input[type=number], .table select { min-height: 34px; padding: 5px 7px; }
.table.compact td, .table.compact th { padding: 4px 6px; }

/* ---- повідомлення, позначки ---- */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); border-color: #b9dfbc; color: #1b5e20; }
.alert-error { background: var(--danger-bg); border-color: #f3b9b9; color: #8e1c1c; }
.alert-info { background: var(--info-bg); border-color: #c3d6f2; }
.alert-warn { background: var(--warn-bg); border-color: #f0d199; color: #6b4500; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e6eaf0; color: #3b4656; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--primary); }

/* ---- вікно ---- */
.dialog { border: 0; border-radius: 10px; padding: 20px; width: min(520px, calc(100vw - 24px)); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(20,30,45,.45); }
.dialog h2 { margin-top: 0; }

/* ---- телефон ---- */
@media (max-width: 600px) {
  :root { --gap: 12px; }
  .container { padding: 12px; }
  .topbar { padding: 8px 10px; }
  .brand span { display: none; }
  h1 { font-size: 1.3rem; }
  .table th, .table td { padding: 7px 8px; }
  .footer { justify-content: center; text-align: center; }
}

/* ---- друк ---- */
@media print {
  .topbar, .subnav, .footer, .env-banner, .toolbar, .btn, .dialog { display: none !important; }
  body { background: #fff; }
  .card, .table-wrap { border: 0; }
}

/* ===================== Етап 2: оператор, сповіщення ===================== */
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-info { background: var(--info-bg); color: var(--primary); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }

body.op .container { max-width: 560px; }
.op-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.op-head h1 { margin: 0; }
.op-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.op-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 96px; background: #fff; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); font-weight: 600; font-size: 1.05rem; }
.op-tile .ico { font-size: 1.8rem; }
.op-tile.alarm { grid-column: 1 / -1; background: var(--danger); border-color: var(--danger); color: #fff; font-size: 1.3rem; min-height: 80px; letter-spacing: .05em; }
.alarm-title { color: var(--danger); }

.task-card.pending { border: 2px solid var(--danger); }
.task-label { font-size: .85rem; color: var(--muted); }
.task-temps { display: flex; gap: 24px; font-size: 1.15rem; margin: 6px 0; }
.task-temps strong { font-size: 2rem; }
.task-temps.small-temps strong { font-size: 1.4rem; }
.task-status { margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.task-overlay { position: fixed; inset: 0; z-index: 1000; background: #b71c1c; color: #fff; display: flex; align-items: center; justify-content: center; padding: 16px; animation: pulse 1.2s infinite alternate; }
@keyframes pulse { from { background: #b71c1c; } to { background: #d32f2f; } }
body.overlay-open { overflow: hidden; }
.task-box { width: 100%; max-width: 440px; text-align: center; }
.task-head { font-size: 1.6rem; font-weight: 800; letter-spacing: .06em; margin-bottom: 4px; }
.task-temps.big { justify-content: center; gap: 28px; font-size: 1.4rem; margin: 16px 0 6px; }
.task-temps.big strong { font-size: 3.2rem; }
.task-box .actual { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 8px; text-align: left; }
.task-box .actual label { color: #fff; font-size: .9rem; }
.task-box .actual input { font-size: 1.4rem; text-align: center; margin-top: 4px; }
.btn-confirm { background: #fff; color: #b71c1c; border-color: #fff; font-weight: 800; font-size: 1.3rem; min-height: 64px; margin-top: 10px; }
.task-err { background: rgba(0,0,0,.25); border-radius: 6px; padding: 6px; margin-top: 6px; }
.sound-hint { margin-top: 10px; opacity: .9; }

.banners { position: sticky; top: 0; z-index: 900; }
.banner { display: flex; gap: 12px; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--info-bg); border-bottom: 1px solid #c3d6f2; }
.banner-high { background: var(--warn-bg); border-color: #f0d199; }
.banner-alarm { background: var(--danger); color: #fff; border-color: var(--danger); }
.banner-alarm .muted { color: #ffdede; }
.banner-actions { display: flex; gap: 6px; flex: none; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1100; max-width: calc(100vw - 24px); padding: 12px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); background: #263445; color: #fff; transition: opacity .6s; }
.toast-success { background: #1b5e20; }
.toast-error { background: #8e1c1c; }
.toast.gone { opacity: 0; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-item { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid #b9c2cf; border-radius: 999px; text-decoration: none; color: var(--text); background: #fff; font-weight: 500; cursor: pointer; }
.seg-item.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.choice-list { display: grid; gap: 8px; }
.choice { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid #b9c2cf; border-radius: 10px; background: #fff; font-weight: 500; cursor: pointer; margin: 0; }
.choice input { width: 22px; height: 22px; flex: none; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--info-bg); }
.big-check { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.big-check input { width: 24px; height: 24px; }
.meter-msg { font-size: .85rem; margin-top: 4px; color: var(--muted); }
.meter-msg.warn { color: var(--warn); font-weight: 600; }
.meter-msg.error { color: var(--danger); font-weight: 600; }
.meter-comment { margin-top: 6px; }
.summary h3 { margin-top: 14px; }
body.is-offline .topbar { background: #5a4a1e; }

/* ===================== Етап 3: диспетчер ===================== */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--ok); border-radius: var(--radius); text-decoration: none; color: var(--text); font-size: .9rem; }
.kpi .kpi-n { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.kpi small { color: var(--muted); }
.kpi-warn { border-left-color: #f0a500; background: #fffaf0; }
.kpi-danger { border-left-color: var(--danger); background: var(--danger-bg); }
.kpi-danger .kpi-n { color: var(--danger); }
.table tr.row-changed td { background: #f5f9ff; }
.table tr.row-wait td { background: #fffaf0; }
.table tr.row-danger td { background: var(--danger-bg); }
.text-danger { color: var(--danger); }
details > summary.btn { list-style: none; display: inline-flex; }
details > summary.btn::-webkit-details-marker { display: none; }

/* Вхід: список прізвищ */
.login-select { font-size: 1.05rem; min-height: 48px; }

/* Плашки сповіщень: текст переноситься, кнопки завжди в межах екрана */
.banner { flex-wrap: wrap; }
.banner > div:first-child { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.banner-actions { margin-left: auto; }

/* ===================== Етап 4: звіти й друк ===================== */
.print-only { display: none; }
.table.report th { text-align: center; vertical-align: middle; }
.table.report tr.total th { background: #eef2f7; }
.journal-shift { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; margin-bottom: 8px; background: #fff; }
.signature { margin-top: 8px; color: var(--muted); }
@media print {
  .no-print { display: none !important; }
  .print-only { display: block; }
  body.report-page .container { max-width: none; padding: 0; }
  body.report-page { font-size: 11px; }
  body.report-page .table th, body.report-page .table td { padding: 3px 5px; border: 1px solid #999; }
  body.report-page .table-wrap { overflow: visible; }
  body.report-page .badge { border: 1px solid #999; background: none; color: #000; }
  .banners, .task-overlay, .toast { display: none !important; }
}
@page { margin: 10mm; }
body.report-page { page: report; }
@page report { size: A4 landscape; margin: 8mm; }

/* Інструкції */
.help { max-width: 760px; }
.help h2 { margin-top: 22px; padding-top: 6px; border-top: 1px solid var(--line); }
.help li { margin-bottom: 4px; }
@media print { .help h2 { break-after: avoid; } .help ol, .help ul { break-inside: avoid; } }

/* ===================== Показ (відеоінструкції) ===================== */
body.tour-player { margin: 0; overflow: hidden; background: #111; display: block; }
#tour-frame { position: fixed; top: 0; left: 0; width: 100vw; height: calc(100vh - 128px); border: 0; background: #fff; }
.tour-hl { position: fixed; z-index: 50; border: 4px solid #ffb300; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(10, 20, 35, .45); pointer-events: none; transition: all .25s ease; }
.tour-panel { position: fixed; left: 0; right: 0; bottom: 0; height: 128px; z-index: 60; background: #1d2b3e; color: #fff; padding: 10px 16px; display: flex; flex-direction: column; gap: 4px; }
.tour-title { font-size: .8rem; opacity: .75; }
.tour-text { font-size: 1.15rem; line-height: 1.35; flex: 1; overflow: auto; }
.tour-bar { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.tour-bar button, .tour-bar a { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 6px; min-width: 40px; height: 32px; font-size: 1rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; padding: 0 8px; }
.tour-count { margin-right: auto; font-size: .85rem; opacity: .8; }
.tour-start { position: fixed; inset: 0; z-index: 70; background: rgba(10, 20, 35, .7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.tour-start .card { max-width: 520px; color: var(--text); }
body.in-tour .env-banner, body.in-tour .footer { display: none; }
@media (max-width: 600px) { .tour-text { font-size: 1rem; } }
