/* «Связь»: мобильные экраны в первую очередь, светлая и тёмная темы по настройке системы. */

:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #14202b;
  --muted: #5c6b78;
  --line: #dde3e8;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --danger: #c62828;
  --ok: #1b8a3a;
  --warn: #b26a00;
  --missed: #c62828;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.08);
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --card: #172026;
    --text: #e8eef2;
    --muted: #93a4b0;
    --line: #26323b;
    --accent: #2bb3a6;
    --accent-text: #04201d;
    --danger: #ef5350;
    --ok: #4caf50;
    --warn: #ffb74d;
    --missed: #ff6b6b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; color: var(--muted); margin: 18px 4px 8px; text-transform: none; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

/* ---------- каркас ---------- */
.shell { min-height: 100%; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.25rem; flex: 1; }
.net { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.net.on { background: var(--ok); }
.net.off { background: var(--danger); }

.view { max-width: 640px; margin: 0 auto; padding: 12px 12px 24px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem;
}
.tabs a .ico { font-size: 1.35rem; line-height: 1; }
.tabs a.active { color: var(--accent); font-weight: 600; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--missed); color: #fff; font-size: 0.7rem; line-height: 18px; text-align: center;
}

/* ---------- экраны без входа ---------- */
.gate {
  max-width: 460px; margin: 0 auto; min-height: 100%;
  display: flex; flex-direction: column; justify-content: center; gap: 12px;
  padding: calc(24px + env(safe-area-inset-top)) 20px 24px;
}
.gate .logo { font-size: 3rem; text-align: center; }
.gate h1 { text-align: center; font-size: 1.6rem; }
.gate > p { text-align: center; }
.gate .big-number { font-size: 1.6rem; text-align: center; font-weight: 600; margin: 4px 0; }

/* ---------- карточки и списки ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 12px;
}
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  min-height: 60px;
}
.item:last-child { border-bottom: 0; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.item.missed .title, .item.missed .dir { color: var(--missed); }
.item .dir { width: 22px; text-align: center; font-size: 1.1rem; }
.item.tap { cursor: pointer; }
.item.tap:active { background: var(--line); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.verified { color: var(--ok); font-size: 0.85rem; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* ---------- кнопки и поля ---------- */
.btn {
  appearance: none; border: 0; border-radius: 10px;
  padding: 11px 16px; min-height: 44px;
  background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 0.9rem; }
.btn.wide { width: 100%; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.15rem; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn.phone { color: var(--ok); }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=url], input:not([type]) {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 1rem; }
.field + .field { margin-top: 10px; }

details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 10px; }

.qr { display: block; width: 240px; max-width: 100%; margin: 8px auto; background: #fff; border-radius: 8px; padding: 8px; }
.link-box { word-break: break-all; font-size: 0.85rem; background: var(--bg); padding: 8px 10px; border-radius: 8px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; background: var(--line); color: var(--text); }
.pill.warn { background: var(--warn); color: #1d1300; }
.pill.ok { background: var(--ok); color: #fff; }
.pill.bad { background: var(--danger); color: #fff; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-right: 4px; }
.dot.on { background: var(--ok); }

/* ---------- набор номера ---------- */
.dial-display { text-align: center; padding: 8px 0 4px; }
.dial-display input {
  border: 0; background: transparent; text-align: center;
  font-size: 1.9rem; font-weight: 500; min-height: 52px;
}
.dial-display input:focus { outline: none; }
.dial-hint { min-height: 1.4em; color: var(--muted); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 300px; margin: 12px auto; }
.keypad button {
  appearance: none; border: 0; border-radius: 50%; aspect-ratio: 1;
  background: var(--card); color: var(--text); box-shadow: var(--shadow);
  font: 500 1.6rem system-ui, sans-serif; cursor: pointer;
}
.keypad button:active { background: var(--line); }
.dial-actions { display: flex; justify-content: center; gap: 20px; margin-top: 8px; }

/* ---------- модальные окна и тосты ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 30;
  background: rgb(0 0 0 / 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) {
  .modal-wrap { align-items: center; }
  .modal { border-radius: 18px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: #22303a; color: #fff; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
/* Во время звонка тост сверху, чтобы не закрывал кнопки ответа */
body:has(#call:not([hidden])) .toast { bottom: auto; top: calc(16px + env(safe-area-inset-top)); }

/* ---------- экран звонка ---------- */
.call {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  background: #0b1216; color: #fff; overflow: hidden;
}
.remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.local-video {
  position: absolute; right: 12px; top: calc(12px + env(safe-area-inset-top)); z-index: 2;
  width: 28vw; max-width: 160px; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 12px; background: #222;
}
/* Фронтальную камеру показываем зеркально, как в зеркале; тыловую — как есть */
.local-video.mirror { transform: scaleX(-1); }
/* На широком экране видео с телефона не обрезаем */
@media (min-aspect-ratio: 1/1) { .remote-video { object-fit: contain; } }
.call-top, .call-sas, .call-actions, .call-alarm { position: relative; z-index: 3; }
.call-top { text-align: center; text-shadow: 0 1px 3px rgb(0 0 0 / 0.6); }
.call-name { font-size: 1.7rem; font-weight: 600; }
.call-number { opacity: 0.8; margin-top: 2px; }
.call-status { margin-top: 8px; font-size: 1.05rem; opacity: 0.9; }
.call-badges { margin-top: 8px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.call-alarm {
  margin: 12px auto; max-width: 480px; padding: 14px 16px; border-radius: 12px;
  background: #b71c1c; color: #fff; font-weight: 600; text-align: center;
}
.call-sas {
  margin: 12px auto; max-width: 480px; width: 100%; padding: 12px; border-radius: 14px;
  background: rgb(255 255 255 / 0.1); text-align: center;
}
.call-sas.big .sas-emoji { font-size: 2.7rem; }
.sas-title { font-size: 0.85rem; opacity: 0.85; }
.sas-emoji { font-size: 2.2rem; letter-spacing: 0.06em; white-space: nowrap; margin: 6px 0 2px; }
.sas-names { font-size: 0.85rem; opacity: 0.85; margin-bottom: 8px; }
.sas-verified { color: #8be28b; font-weight: 600; }
.call-actions { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.round {
  appearance: none; border: 0; cursor: pointer;
  width: 68px; height: 68px; border-radius: 50%;
  background: rgb(255 255 255 / 0.16); color: #fff; font-size: 1.6rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative;
}
.round span { position: absolute; top: 74px; font-size: 0.72rem; white-space: nowrap; opacity: 0.85; }
.round.green { background: #2e7d32; }
.round.red { background: #c62828; }
.round[aria-pressed=true] { background: #fff; color: #111; }
.call-actions { margin-bottom: 22px; }
