:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2129;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --self: #dbeafe;
  --other: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --border: #2a2f3a;
    --accent: #3b82f6;
    --self: #1e3a5f;
    --other: #232733;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* ── Auth ── */
#auth-screen { align-items: center; justify-content: center; padding: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.step { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
label { font-size: 13px; color: var(--muted); }
input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
#code { letter-spacing: 6px; font-size: 20px; text-align: center; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  background: var(--accent);
  color: var(--accent-text);
}
button:disabled { opacity: 0.5; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 11px;
}
button.link {
  background: transparent;
  color: var(--accent);
  padding: 4px;
  text-align: left;
}
.msg { min-height: 18px; font-size: 13px; margin: 12px 0 0; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ── App header ── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.header-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.header-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { font-size: 11px; color: var(--muted); }
.conn.online { color: var(--ok); }
.conn.offline { color: var(--danger); }
.header-actions { display: flex; gap: 6px; flex-shrink: 0; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px;
  background: var(--accent); color: var(--accent-text);
  border-radius: 9px; font-size: 12px; text-align: center;
}

/* ── Messages ── */
.messages {
  flex: 1; overflow-y: auto;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.bubble {
  position: relative;
  max-width: min(78%, 560px);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--other);
  align-self: flex-start;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
}
.bubble.self { background: var(--self); align-self: flex-end; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.bubble .text { line-height: 1.4; }
.bubble .actions { margin-top: 6px; display: flex; gap: 6px; }
.bubble .copy-btn, .bubble .del-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 3px 9px; font-size: 12px; border-radius: 8px;
}
.bubble .copy-btn { color: var(--accent); }
.bubble .copy-btn.copied { color: var(--ok); border-color: var(--ok); }
.bubble .del-btn { color: var(--muted); }
.bubble .del-btn.arm { color: var(--danger); border-color: var(--danger); }

/* ── Файл-карточка ── */
.bubble .file-card {
  margin-top: 4px; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: rgba(127,127,127,0.06);
}
.bubble .file-card::before { content: "📄"; font-size: 22px; }
.bubble .file-info { min-width: 0; flex: 1; }
.bubble .file-name { font-weight: 600; word-break: break-all; }
.bubble .file-meta { font-size: 12px; color: var(--muted); }
.bubble .dl-btn {
  flex-shrink: 0;
  background: var(--accent); color: var(--accent-text);
  border: none; padding: 6px 12px; font-size: 13px; border-radius: 8px;
}
.bubble .dl-btn:disabled { opacity: 0.6; }

/* ── Статус загрузки ── */
.upload-status {
  padding: 8px 14px; font-size: 13px; color: var(--muted);
  background: var(--card); border-top: 1px solid var(--border);
}
.upload-status.error { color: var(--danger); }

/* ── Composer ── */
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--card);
}
.composer textarea { flex: 1; resize: none; max-height: 140px; }
.composer button { flex-shrink: 0; }
.composer .attach {
  background: transparent; border: 1px solid var(--border);
  font-size: 18px; padding: 8px 10px; line-height: 1;
}

/* ── Devices panel ── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 9;
}
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 10;
  width: min(360px, 86vw);
  background: var(--card); border-left: 1px solid var(--border);
  padding: 14px; padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: -8px 0 24px rgba(0,0,0,0.12);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.devices-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.device {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--border);
}
.device .d-name { font-weight: 600; }
.device .d-sub { font-size: 12px; color: var(--muted); }
.device.current .d-name::after {
  content: " (это устройство)"; font-weight: 400; color: var(--muted); font-size: 12px;
}
.device .revoke {
  background: transparent; color: var(--danger);
  border: 1px solid var(--border); padding: 5px 10px; font-size: 13px;
}
