/* Обёртка над удалённым браузером.
   Тёмная «рамка» вокруг стрима, светлый экран входа; акцентный цвет задаётся
   в .env (BRAND_COLOR) и попадает в --brand через index.html. */

:root {
  --ink: #1b2130;
  --ink-2: #252e42;
  --ink-3: #303a51;
  --ink-line: #3b4660;
  --on-ink: #e8ecf4;
  --on-ink-muted: #9ca7bb;
  --fog: #eef1f6;
  --paper: #ffffff;
  --text: #1c2230;
  --text-muted: #5b6577;
  --line: #cfd6e2;
  --ok: #3fb68b;
  --warn: #e9a23b;
  --bad: #e5484d;
  --on-brand: #0f1426;

  --radius: 12px;
  --bar-h: 44px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans",
    "Helvetica Neue", Arial, sans-serif;

  /* высота и сдвиг видимой области (меняются при открытии клавиатуры на телефоне) */
  --app-h: 100dvh;
  --app-top: 0px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

button { font: inherit; }

/* ── Вход ─────────────────────────────────────────────────────────────── */

.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background: var(--fog);
  color: var(--text);
  overflow: auto;
}

.login-card {
  width: min(100%, 360px);
  display: grid;
  gap: 18px;
}

.login-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand);
  display: grid;
  place-items: center;
}

.login-mark span {
  width: 24px;
  height: 17px;
  border-radius: 4px;
  border: 2.5px solid var(--on-brand);
  border-top-width: 6px;
}

.login-brand {
  margin: 4px 0 0;
  font-size: clamp(34px, 10vw, 46px);
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-weight: 760;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.login-lead {
  margin: -10px 0 10px;
  font-size: 17px;
  color: var(--text-muted);
}

.field { display: grid; gap: 6px; }

.field-label {
  font-size: 14px;
  color: var(--text-muted);
}

.field input {
  height: 50px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 28%, transparent);
}

.login-error {
  margin: -4px 0 0;
  font-size: 15px;
  line-height: 1.4;
  color: #c4282d;
}

.login-help {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.btn {
  height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
}

.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary { background: var(--brand); color: var(--on-brand); }

.btn-secondary {
  height: 42px;
  background: var(--ink-3);
  color: var(--on-ink);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.send-btn:focus-visible,
.toast-action:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media (prefers-color-scheme: dark) {
  .login { background: var(--ink); color: var(--on-ink); }
  .login-brand { color: var(--on-ink); }
  .login-lead, .field-label, .login-help { color: var(--on-ink-muted); }
  .field input { background: var(--ink-2); border-color: var(--ink-line); color: var(--on-ink); }
  .login-error { color: #ff8a8d; }
}

/* ── Рабочая область ──────────────────────────────────────────────────── */

.shell {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-top);
  height: var(--app-h);
  display: flex;
  flex-direction: column;
  background: var(--ink);
  color: var(--on-ink);
}

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
}

.bar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.status-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.status-dot[data-state="online"] { background: var(--ok); }
.status-dot[data-state="offline"] { background: var(--bad); }

.bar-brand {
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-text {
  font-size: 13px;
  color: var(--on-ink-muted);
  white-space: nowrap;
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.bar-sep {
  width: 1px;
  height: 20px;
  margin: 0 6px;
  background: var(--ink-line);
}

.icon-btn {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--on-ink);
  cursor: pointer;
}

.icon-btn:hover { background: var(--ink-2); }
.icon-btn[aria-pressed="true"] { background: var(--ink-3); }

.icon-btn svg,
.send-btn svg,
.sheet-row svg,
.toast-action svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.badge {
  position: absolute;
  top: 4px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

.stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #000;
}

/* подсказка при перетаскивании файла на стрим */
.stage[data-drop="on"]::after {
  content: "Отпустите файл, чтобы прикрепить его к сообщению";
  position: absolute;
  inset: 12px;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 2px dashed var(--brand);
  border-radius: 16px;
  background: color-mix(in srgb, var(--ink) 72%, transparent);
  color: var(--on-ink);
  font-size: 18px;
  text-align: center;
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: var(--ink);
  transition: opacity 0.2s ease;
}

.overlay[data-state="hidden"] { opacity: 0; pointer-events: none; }
.overlay[data-state="reconnecting"] { background: color-mix(in srgb, var(--ink) 78%, transparent); }

.overlay-box {
  max-width: 320px;
  padding: 24px;
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
}

.overlay-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--on-ink);
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--ink-line);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}

.overlay[data-state="error"] .spinner { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Поле ввода ───────────────────────────────────────────────────────── */

.dock {
  flex: none;
  position: relative;
  padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: var(--ink);
}

.shell[data-dock="off"] .dock { padding: 0; }
.shell[data-dock="off"] .dock-row { display: none; }

.dock-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.dock-btn { color: var(--on-ink-muted); }

.dock-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 168px;
  padding: 9px 15px;
  resize: none;
  border-radius: 20px;
  border: 1px solid var(--ink-line);
  background: var(--ink-2);
  color: var(--on-ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
}

.dock-input::placeholder { color: var(--on-ink-muted); }

.dock-input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--brand) 65%, var(--ink-line));
}

.send-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  cursor: pointer;
}

.send-btn svg { stroke-width: 2.3; }

.send-btn:disabled {
  background: var(--ink-3);
  color: var(--on-ink-muted);
  cursor: default;
}

.toast {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 8px);
  z-index: 5;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: var(--radius);
  background: var(--ink-3);
  color: var(--on-ink);
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  /* уведомление висит над нижней частью стрима, где у Claude поле ввода:
     клики проходят сквозь него, кроме кнопки действия */
  pointer-events: none;
}

.toast-action { pointer-events: auto; }

.toast-text {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
}

.toast-action {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.toast-action svg { width: 16px; height: 16px; stroke-width: 2.2; }

/* ── Нижняя панель (меню, файлы, ссылка) ──────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(8, 10, 16, 0.5);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-height: 82dvh;
  overflow: auto;
  padding: 6px 8px calc(12px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--ink-2);
  color: var(--on-ink);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  margin: 4px auto 10px;
  border-radius: 2px;
  background: var(--ink-line);
}

.sheet-title {
  margin: 2px 12px 8px;
  font-size: 15px;
  font-weight: 650;
  color: var(--on-ink-muted);
}

.sheet-row {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--on-ink);
  font-size: 16px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.sheet-row svg { flex: none; color: var(--on-ink-muted); }
.sheet-row:hover, .sheet-row:focus-visible { outline: none; background: var(--ink-3); }
.sheet-row .row-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-row .row-meta { flex: none; font-size: 13px; color: var(--on-ink-muted); }
.sheet-row.danger { color: #ff9a9c; }
.sheet-row.danger svg { color: currentColor; }

.sheet-sep {
  height: 1px;
  margin: 6px 12px;
  background: var(--ink-line);
}

.sheet-empty {
  margin: 4px 12px 14px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--on-ink-muted);
}

.sheet-form {
  display: grid;
  gap: 12px;
  padding: 2px 12px 8px;
}

.sheet-form input {
  height: 48px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--ink-line);
  background: var(--ink);
  color: var(--on-ink);
  font: inherit;
  font-size: 16px;
}

.sheet-form input:focus { outline: none; border-color: var(--brand); }

.sheet-hint {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--on-ink-muted);
}

/* Компьютер с мышью: меню выпадает справа под панелью */
@media (min-width: 720px) and (pointer: fine) {
  .sheet {
    left: auto;
    right: 10px;
    top: calc(var(--bar-h) + 6px);
    bottom: auto;
    width: 340px;
    max-height: 72vh;
    padding-bottom: 8px;
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  }
  .sheet-handle { display: none; }
  .sheet-backdrop { background: transparent; }
}

@media (pointer: coarse), (max-width: 719px) {
  .desktop-only { display: none !important; }
}

@media (pointer: fine) {
  .touch-only { display: none !important; }
}

@media (max-width: 420px) {
  .status-text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .overlay { transition: none; }
}
