/* Спільні стилі. Без зовнішніх шрифтів і бібліотек: сторінки мають відкриватися й на слабкому зв'язку. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #d6d9de;
  --text: #15181d;
  --muted: #5d6573;
  --accent: #2b5fd9;
  --s-BG: #15803d;
  --s-NBG: #c62828;
  --s-AIR: #1d4ed8;
  --s-GROUND: #b45309;
  --s-NONE: #6b7280;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #c62828;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2d333d;
    --text: #e7eaee;
    --muted: #9aa3b1;
    --accent: #6b93ff;
    --s-BG: #22a352;
    --s-NBG: #e5484d;
    --s-AIR: #3b82f6;
    --s-GROUND: #d9822b;
    --s-NONE: #6b7280;
    --ok: #30a46c;
    --warn: #d9822b;
    --bad: #e5484d;
    --shadow: none;
    color-scheme: dark;
  }
}
body.tv {
  --bg: #0b0d10;
  --surface: #14181e;
  --surface-2: #1c2129;
  --border: #2a3039;
  --text: #f0f2f5;
  --muted: #9aa3b1;
  --s-BG: #22a352;
  --s-NBG: #e5484d;
  --s-AIR: #3b82f6;
  --s-GROUND: #d9822b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .title { font-weight: 650; font-size: 1.05rem; }
.topbar .sub { color: var(--muted); font-size: 0.85rem; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.conn::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.conn.off::before { background: var(--bad); }
.conn.off { color: var(--bad); }

/* ---------- кнопки й поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 0.9rem; }
.btn.big { min-height: 52px; font-size: 1.05rem; font-weight: 600; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }

label.field { display: block; }
label.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

/* Групи з вибором однієї кнопки */
.choice { display: flex; gap: 6px; flex-wrap: wrap; }
.choice button {
  flex: 1 1 auto; min-height: 42px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer;
}
.choice button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.choice button.on.good { background: var(--ok); border-color: var(--ok); }
.choice button.on.bad { background: var(--bad); border-color: var(--bad); }
.choice button.on.warn { background: var(--warn); border-color: var(--warn); }

/* ---------- картки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.info { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

.banner {
  padding: 10px 14px; border-radius: 8px; font-size: 0.95rem;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border));
}
.banner.info { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }

/* Кольори статусів */
.s-BG { --s: var(--s-BG); }
.s-NBG { --s: var(--s-NBG); }
.s-AIR { --s: var(--s-AIR); }
.s-GROUND { --s: var(--s-GROUND); }
.s-NONE { --s: var(--s-NONE); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--s); flex: none; }

/* ---------- списки ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { font-weight: 600; color: var(--muted); font-size: 0.82rem; background: var(--surface-2); position: sticky; top: 0; }
table.data tr.off td { color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

/* ---------- модальні вікна ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .modal-back { align-items: center; } }
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: 14px 14px 0 0; padding: 18px;
}
@media (min-width: 640px) { .modal { border-radius: 14px; } }
.modal h2 { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* ---------- сповіщення ---------- */
#toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(92vw, 460px); }
.toast { padding: 12px 14px; border-radius: 10px; background: #1f2937; color: #fff; box-shadow: 0 4px 16px rgb(0 0 0 / 0.25); font-size: 0.95rem; }
.toast.err { background: #9b1c1c; }
.toast.ok { background: #166534; }

/* ---------- вхід ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(100%, 360px); }
.login-box h1 { font-size: 1.3rem; margin-bottom: 4px; }

/* ---------- сторінка екіпажу ---------- */
.crew-main { max-width: 640px; margin: 0 auto; padding: 14px 14px 96px; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  min-height: 60px; border: 0; background: none; cursor: pointer; font-size: 0.85rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
}
.tabs button .ico { font-size: 1.25rem; line-height: 1; }
.tabs button.on { color: var(--accent); font-weight: 650; }
.tabs button.on::before { content: ""; position: absolute; top: 0; left: 20%; right: 20%; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }
.tabs .count { position: absolute; top: 6px; right: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 0.72rem; font-weight: 700; display: grid; place-items: center; }

.plate {
  border-radius: 14px; padding: 18px; color: #fff; background: var(--s);
  display: grid; gap: 4px; text-align: center;
}
.plate .label { font-size: 2.6rem; font-weight: 800; letter-spacing: 0.02em; }
.plate .since { font-size: 1rem; opacity: 0.92; }
.plate .reason { font-size: 1rem; font-weight: 600; }
.status-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.sbtn {
  min-height: 84px; border-radius: 12px; border: 2px solid var(--s); background: var(--surface);
  color: var(--s); font-size: 1.35rem; font-weight: 800; cursor: pointer;
}
.sbtn:not(:disabled):active { transform: scale(0.98); }
.sbtn:disabled { opacity: 0.28; cursor: not-allowed; }
.sbtn.current { background: var(--s); color: #fff; opacity: 1; }

.asset-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: start; }
.asset-row .serial { font-weight: 700; font-size: 1.05rem; }
.asset-row .actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.kind-title { margin: 18px 0 6px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1rem; padding: 0 4px; }

.check-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.check-item:first-child { border-top: 0; }
.check-item .choice button { min-width: 64px; }

/* ---------- табло ---------- */
.board-wrap { display: grid; grid-template-columns: 1fr 340px; gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 1100px) { .board-wrap { grid-template-columns: 1fr; } }
body.tv .board-wrap { grid-template-columns: 1fr 380px; padding: 14px; }
.counters { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.counter { border-radius: var(--radius); padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--s); }
.counter .n { font-size: 2rem; font-weight: 800; line-height: 1; }
.counter .l { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.counter.stale { --s: var(--warn); }
@media (max-width: 640px) { .counters { grid-template-columns: repeat(3, 1fr); } }

.site-title { margin: 14px 0 8px; font-size: 0.9rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.site-title:first-child { margin-top: 0; }
.crew-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
body.tv .crew-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.ccard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; text-align: left; padding: 0; display: block; width: 100%;
}
.ccard:hover { border-color: var(--muted); }
.ccard .head { background: var(--s); color: #fff; padding: 10px 12px; display: flex; align-items: baseline; gap: 8px; }
.ccard .head .st { font-size: 1.5rem; font-weight: 800; }
.ccard .head .dur { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.ccard .body { padding: 10px 12px; display: grid; gap: 6px; }
.ccard .name { font-weight: 700; font-size: 1.05rem; }
.ccard .reason { font-weight: 600; color: var(--s-NBG); }
.ccard .people { font-size: 0.88rem; color: var(--muted); }
.ccard .people b { color: var(--text); font-weight: 600; }
.ccard .badges { display: flex; flex-wrap: wrap; gap: 4px; }
.ccard.stale .head { background-image: repeating-linear-gradient(135deg, rgb(255 255 255 / 0.16) 0 10px, transparent 10px 20px); }
.ccard.flash { animation: flash 1s ease-in-out 4; }
@keyframes flash { 50% { box-shadow: 0 0 0 4px var(--s); } }
body.tv .ccard .head .st { font-size: 1.8rem; }
body.tv .ccard .name { font-size: 1.2rem; }

.feed { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
body.tv .feed { top: 14px; max-height: calc(100vh - 28px); }
.feed li { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 8px 0; }
.feed .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; padding-top: 1px; }
.feed .c { font-weight: 650; }
.feed .x { grid-column: 2; font-size: 0.92rem; }

.drawer-back { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 0.35); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41; width: min(100vw, 560px); overflow: auto;
  background: var(--bg); border-left: 1px solid var(--border); padding: 16px;
}
.drawer .plate { padding: 12px; }
.drawer .plate .label { font-size: 1.8rem; }

/* ---------- адмінка ---------- */
.admin-main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.subtabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.subtabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.subtabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.report { white-space: pre-wrap; font-size: 0.9rem; }

[data-mt] { margin-top: 12px; }

/* Виправлення верстки після перевірки в браузері */
.check-item.wide { grid-template-columns: 1fr; gap: 6px; }
.check-item.wide .choice button { flex: 1 1 0; }
.topbar select { width: auto; min-height: 32px; max-width: 220px; }
.topbar .title { white-space: nowrap; }
.ccard { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; }
.ccard .body { flex: 1; align-content: start; }
