:root {
  --bg: #0f1416;
  --bg2: #131618;
  --panel: #1a1e21;
  --panel2: #20262a;
  --border: #2a3034;
  --text: #e9ece9;
  --muted: #9aa39c;
  --accent: #63e2b7;
  --accent-ink: #08231d;
  --danger: #e88080;
  --header-h: 60px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2f0;
    --bg2: #f6f8f7;
    --panel: #ffffff;
    --panel2: #f0f3f1;
    --border: #d9e0db;
    --text: #14201b;
    --muted: #5d6b63;
    --accent: #12a37a;
    --accent-ink: #ffffff;
    --danger: #c0392b;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.screen { height: 100%; min-height: 100dvh; }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
}
button:disabled { opacity: 0.55; cursor: default; }

/* ============ ВХОД ============ */

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px calc(20px + env(safe-area-inset-right)) calc(24px + var(--safe-bottom)) calc(20px + env(safe-area-inset-left));
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(99, 226, 183, 0.10), transparent 60%),
    var(--bg2);
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

.brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 6px; }
.brand-logo { border-radius: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); }
.card h1 { margin: 6px 0 0; font-size: 21px; }
.sub { margin: 0; color: var(--muted); font-size: 13.5px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

input, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  padding: 12px 13px;
  font: inherit;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); }

.card button {
  background: var(--accent);
  color: var(--accent-ink);
  padding: 13px 16px;
  font-weight: 700;
  border-radius: 12px;
}

.error { margin: 0; color: var(--danger); font-size: 13px; }
.muted { color: var(--muted); }

/* ============ ЧАТ ============ */

.chat {
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg2);
  animation: fade-in 0.25s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.ch-id { display: flex; align-items: center; gap: 11px; min-width: 0; }
.ch-avatar { border-radius: 50%; flex: none; }
.ch-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.ch-meta strong { font-size: 15.5px; }
.ch-status { font-size: 12px; color: var(--accent); }
.ch-status.off { color: var(--danger); }

.ch-actions { display: flex; align-items: center; gap: 4px; flex: none; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border-radius: 11px;
  font-size: 17px;
}
.icon-btn:hover { background: var(--panel2); }
.icon-btn.on { color: var(--accent); }
.icon-btn .ic { line-height: 1; }

/* баннер-подсказка */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(99, 226, 183, 0.12), rgba(99, 226, 183, 0.05));
  border-bottom: 1px solid var(--border);
}
.banner-text { flex: 1; font-size: 13px; color: var(--text); }
.banner-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.banner-btn {
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
}
.banner-x {
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  font-size: 14px;
}

/* лента сообщений */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: none;
}
.messages::-webkit-scrollbar { display: none; }

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty-emoji { font-size: 40px; margin-bottom: 8px; }
.empty p { margin: 0; font-size: 14px; }

.day { text-align: center; margin: 12px 0 8px; }
.day span {
  display: inline-block;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.msg {
  position: relative;
  max-width: 82%;
  border-radius: 16px;
  padding: 9px 13px 7px;
  font-size: 14.5px;
  margin-top: 4px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}
.msg-text { white-space: pre-wrap; word-break: break-word; }

.msg.client {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 5px;
}
.msg.admin, .msg.system {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.msg.system {
  align-self: center;
  text-align: center;
  background: var(--panel2);
  font-size: 13px;
  color: var(--muted);
}

.msg .time {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  opacity: 0.7;
  text-align: right;
}
.msg.client .time { color: var(--accent-ink); }
.msg.admin .time, .msg.system .time { color: var(--muted); }

/* кнопка «вниз» */
.scroll-down {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(86px + var(--safe-bottom));
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  z-index: 4;
}

/* поле ввода */
.compose {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}
.compose textarea {
  flex: 1;
  resize: none;
  max-height: 130px;
  border-radius: 20px;
  padding: 11px 15px;
}
.compose .send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex: none;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ============ ВЛОЖЕНИЕ-КЛЮЧ ============ */

.att {
  margin-top: 8px;
  padding: 10px 11px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  font-size: 13.5px;
  background: rgba(0, 0, 0, 0.08);
}
.msg.admin .att { border-color: var(--border); background: var(--panel2); }
.att.expired { color: var(--muted); }
.att-title { margin-bottom: 8px; font-weight: 600; }
.att-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.att-btn {
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 9px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
}
.att-btn.primary { background: var(--accent); color: var(--accent-ink); }

/* ============ OVERLAY (QR / текст / iOS) ============ */

.qr-overlay, .overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  animation: fade-in 0.18s ease;
}

.qr-card, .overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 92vw;
}
.overlay-card { align-items: stretch; max-width: min(420px, 92vw); }
.overlay-card strong { font-size: 16px; }

.qr-card img {
  width: min(320px, 78vw);
  height: auto;
  border-radius: 8px;
  background: #fff;
  padding: 6px;
}
.qr-tabs { justify-content: center; }
.qr-hint { font-size: 12.5px; color: var(--muted); text-align: center; }

.text-card { max-width: min(560px, 92vw); align-items: stretch; }
.conf-text {
  margin: 0;
  max-height: 50vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  -webkit-user-select: all;
  user-select: all;
}
.text-card .att-actions { justify-content: flex-end; }

.ios-steps { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.7; }
.ios-steps b { color: var(--text); }
.ios-share { display: inline-block; transform: translateY(2px); }
