/* Темы платформы презентаций. Цвета задаются токенами, компоненты используют только их. */
@import url("fonts/fonts.css");
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --ink: #1d2433;
  --muted: #6b7486;
  --line: #d9e3f0;
  --accent: #2f7fd8;
  --accent-ink: #1f5fa8;
  --accent-soft: #e6f0fc;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --bad: #c0392b;
  --bad-bg: #fbe9e7;
  --warn: #a86400;
  --warn-bg: #fff3dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 36, 51, .06), 0 4px 16px rgba(29, 36, 51, .06);
  /* Свои шрифты с сервера: одинаковый вид на iPad, Windows и ТВ. Системные — только запасной вариант. */
  --font: "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", Consolas, Menlo, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-synthesis: none;
}
/* Иконки — SVG, а не эмодзи: эмодзи на каждой ОС выглядят по-своему. */
.ico { width: 1em; height: 1em; vertical-align: -0.14em; flex: none; }
button .ico { margin-right: .35em; }
button.icon-only .ico, .nav .ico, .tool .ico { margin-right: 0; }
h1 { font-size: 32px; line-height: 1.2; margin: 0 0 24px; }
h2 { font-size: 22px; line-height: 1.25; margin: 0 0 12px; }
h3 { font-size: 17px; margin: 0 0 8px; }
.kicker { margin: 0 0 4px; color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
code, pre, textarea, .mono { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
code { font-family: var(--mono); background: var(--surface-2); padding: .05em .35em; border-radius: 6px; font-size: .92em; }

button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button {
  padding: 10px 18px; border: 0; border-radius: var(--radius); cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .5; cursor: default; filter: none; }
button.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
button.ghost { background: transparent; color: var(--ink); }
button.danger { background: var(--bad); }
button.small { padding: 6px 12px; font-size: 14px; border-radius: 9px; }
a { color: var(--accent-ink); }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
label > input, label > select { color: var(--ink); font-size: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.error { color: var(--bad); font-size: 14px; min-height: 1.5em; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

/* Индикатор соединения. */
.conn { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.conn::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; }
.conn.online::before { background: var(--ok); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); }

/* ---------- Биты: 1 — заливка акцентом, 0 — контур ---------- */
.bits { display: inline-grid; grid-auto-flow: column; gap: 8px; }
.bitcell { display: grid; justify-items: center; gap: 4px; }
.bit {
  display: inline-grid; place-items: center; width: 52px; height: 60px;
  border: 2px solid var(--accent); border-radius: 10px; background: var(--surface);
  font: 600 26px var(--mono); color: var(--accent); user-select: none;
}
.bit.on { background: var(--accent); color: #fff; }
.bit.editable { cursor: pointer; }
.bit.editable:hover { box-shadow: 0 0 0 3px var(--accent-soft); }
.bit.readonly { border-color: var(--muted); color: var(--muted); }
.bit.readonly.on { background: var(--muted); color: #fff; }
.weight { font: 500 13px var(--mono); color: var(--muted); }
.bits-label { font: 600 18px var(--mono); color: var(--muted); width: 32px; align-self: start; padding-top: 16px; }

/* ---------- Права rwx ---------- */
.perm-grid { display: inline-grid; grid-template-columns: auto repeat(3, 56px); gap: 8px; align-items: center; }
.perm-grid .head { font: 600 14px var(--mono); color: var(--muted); text-align: center; }
.perm-grid .who { font-size: 14px; color: var(--muted); padding-right: 8px; }
.perm {
  height: 52px; border: 2px solid var(--accent); border-radius: 10px; background: var(--surface);
  font: 600 22px var(--mono); color: var(--accent); cursor: pointer; padding: 0;
}
.perm.on { background: var(--accent); color: #fff; }
.perm:disabled { cursor: default; opacity: 1; }
.bit, .perm {
  transition: background-color .2s ease, color .2s ease, border-color .2s ease, box-shadow .2s ease, transform .18s ease;
}
.bit.editable:focus-visible, .perm:focus-visible {
  outline: 3px solid var(--accent-ink); outline-offset: 4px;
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .bit.editable:hover, .perm:not(:disabled):hover { transform: translateY(-3px); }
  button:not(:disabled):active, .bit.editable:active { transform: scale(.96); }
}
.rwx-line { font: 600 26px var(--mono); letter-spacing: .08em; }

/* ---------- Сцена слайда 16:9 ---------- */
.stage-wrap { position: relative; overflow: hidden; background: var(--bg); }
.stage {
  position: absolute; left: 0; top: 0; width: 1600px; height: 900px; transform-origin: 0 0;
  background: var(--surface); box-shadow: var(--shadow); border-radius: 6px; overflow: hidden;
}
.stage > canvas.ink { position: absolute; inset: 0; width: 1600px; height: 900px; pointer-events: none; }

/* ---------- Уведомления ---------- */
.toasts { position: absolute; left: 16px; top: 16px; display: grid; gap: 8px; z-index: 50; pointer-events: none; max-width: min(420px, calc(100% - 32px)); }
.toast {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: 10px;
  padding: 10px 14px; box-shadow: var(--shadow); font-size: 15px; animation: toast-in .2s ease-out;
}
.toast small { display: block; color: var(--muted); font-size: 12px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Диалог ---------- */
dialog { border: 0; border-radius: 16px; padding: 24px; box-shadow: 0 10px 40px rgba(0,0,0,.2); max-width: min(480px, calc(100vw - 32px)); width: 100%; color: var(--ink); }
dialog::backdrop { background: rgba(29, 36, 51, .35); }

/* Чёрные поверхности, цветовые акценты и контрастные границы. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000;
  --surface: #000;
  --surface-2: #000;
  --ink: #f2f4f8;
  --muted: #a8b0be;
  --line: #39414e;
  --accent: #65a9ff;
  --accent-ink: #91c2ff;
  --accent-soft: #000;
  --ok: #63d994;
  --ok-bg: #000;
  --bad: #ff877c;
  --bad-bg: #000;
  --warn: #ffd078;
  --warn-bg: #000;
  --shadow: none;
}
:root[data-theme="dark"] .slide.title-slide { background: #000; }
:root[data-theme="dark"] .section-num { color: var(--line); }
:root[data-theme="dark"] dialog { background: #000; border: 1px solid var(--line); }
/* Меняем только отображение пометок: исходные цвета для ТВ и участников сохраняются. */
:root[data-theme="dark"] canvas.ink { filter: invert(1) hue-rotate(180deg); }
:root[data-theme="dark"] .tool .swatch { filter: invert(1) hue-rotate(180deg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ================= Платформа: общие компоненты ================= */

/* Тёмная тема по настройке системы, если страница явно не выбрала тему. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg: #12161f; --surface: #1b212d; --surface-2: #252d3c; --ink: #eef1f7; --muted: #9aa4b8;
    --line: #333d50; --accent: #5aa2f2; --accent-ink: #8dbdf7; --accent-soft: #22344f;
    --ok: #5fd38e; --ok-bg: #1d3a2b; --bad: #ff8a7d; --bad-bg: #402420; --warn: #f2c26b; --warn-bg: #3d3018;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root:not([data-theme="light"]):not([data-theme="dark"]) dialog { background: var(--surface); }

button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; box-shadow: 0 0 0 2px var(--accent); }
button.icon-only { padding: 8px 10px; }
textarea { resize: vertical; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%238a93a6' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }

/* Тосты (ui.js) */
.ui-toasts { position: fixed; z-index: 1000; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.ui-toast { pointer-events: auto; cursor: pointer; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); font-size: 15px; animation: toast-in .2s ease-out; }
.ui-toast.ok { border-left-color: var(--ok); }
.ui-toast.error { border-left-color: var(--bad); }
.ui-toast.warn { border-left-color: var(--warn); }
.ui-toast.out { opacity: 0; transition: opacity .2s; }

/* Модальные окна (ui.js) */
dialog.ui-dialog { padding: 0; max-width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); overflow: hidden; }
dialog.ui-dialog[open] { display: flex; flex-direction: column; }
dialog.ui-dialog.wide { max-width: min(760px, calc(100vw - 24px)); }
.ui-dialog-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 0 22px; }
.ui-dialog-head h2 { margin: 0; flex: 1; font-size: 20px; }
.ui-dialog-x { margin-left: auto; font-size: 26px; line-height: 1; padding: 2px 10px; color: var(--muted); }
.ui-dialog-body { padding: 14px 22px 22px; overflow: auto; }
.ui-confirm-text { margin: 0 0 18px; white-space: pre-line; }
.ui-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.ui-confirm .ui-actions { margin-top: 0; }
.ui-prompt { display: grid; gap: 8px; }

/* Шапка приложения */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: inline-grid; place-items: center; color: #fff; font-size: 15px; }
.page { max-width: 1280px; margin: 0 auto; padding: 24px; }
@media (max-width: 640px) { .topbar { padding: 8px 12px; } .page { padding: 16px 12px; } h1 { font-size: 26px; } }

/* Выпадающее меню */
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 6px; display: grid; }
.menu-list[hidden] { display: none; }
.menu-list button, .menu-list a { text-align: left; background: transparent; color: var(--ink); padding: 9px 12px; border-radius: 8px; font-weight: 500; text-decoration: none; display: block; font-size: 15px; }
.menu-list button:hover, .menu-list a:hover { background: var(--surface-2); filter: none; }
.menu-list button.danger-text { color: var(--bad); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 2px; }

/* Вкладки */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs button { background: transparent; color: var(--muted); border-radius: 10px 10px 0 0; border-bottom: 2px solid transparent; padding: 10px 16px; }
.tabs button[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* Таблицы */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
table.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-off td { opacity: .55; }
.table td.actions { text-align: right; white-space: nowrap; }

/* Страницы входа */
.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(420px, 100%); display: grid; gap: 14px; }
.auth-card h1 { margin: 0; font-size: 26px; }
