/* ===== KinTalk — темы и интерфейс в стиле Telegram ===== */
:root, [data-theme="dark"] {
  --bg: #050506;
  --panel: #0c0c0e;
  --panel2: #17171a;
  --panel3: #121214;
  --accent: #7c5cff;
  --accent-2: #a78bfa;
  --accent-dark: #5f43d6;
  --out-bubble: #2b2342;
  --in-bubble: #1a1a1e;
  --text: #f4f4f5;
  --muted: #8e8e96;
  --border: #050506;
  --danger: #e05b5b;
  --online: #4caf50;
  --link: #b9a7ff;
  --shadow: rgba(0,0,0,.6);
  --chat-bg: #000000;
  --header: #08080a;
  --input-bg: #17171a;
  --hover: #1b1b1f;
  --bubble-meta: rgba(255,255,255,.55);
  --wallpaper: rgba(150,125,255,.055);
}

[data-theme="light"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel2: #f4f4f5;
  --panel3: #f7f7f8;
  --accent: #3390ec;
  --accent-2: #3390ec;
  --accent-dark: #2b7fd1;
  --out-bubble: #eeffde;
  --in-bubble: #ffffff;
  --text: #000000;
  --muted: #707579;
  --border: #e4e4e5;
  --danger: #e53935;
  --online: #4caf50;
  --link: #3390ec;
  --shadow: rgba(0,0,0,.12);
  --chat-bg: #e6ebee;
  --header: #ffffff;
  --input-bg: #f1f1f1;
  --hover: #f4f4f5;
  --bubble-meta: #6c7883;
  --wallpaper: rgba(51,144,236,.06);
}

[data-theme="blue"] {
  --bg: #0b1726;
  --panel: #122132;
  --panel2: #1b3148;
  --panel3: #16283c;
  --accent: #4ea1e8;
  --accent-2: #6cc0ff;
  --accent-dark: #3b7fb8;
  --out-bubble: #1f4f7a;
  --in-bubble: #13283e;
  --text: #eaf4ff;
  --muted: #86a3bf;
  --border: #08111c;
  --danger: #ff6b6b;
  --online: #4cd964;
  --link: #7cc4ff;
  --shadow: rgba(0,0,0,.5);
  --chat-bg: #0b1726;
  --header: #122132;
  --input-bg: #1b3148;
  --hover: #1a3048;
  --bubble-meta: rgba(255,255,255,.58);
  --wallpaper: rgba(78,161,232,.08);
}

[data-theme="pink"] {
  --bg: #1b1118;
  --panel: #261720;
  --panel2: #3a2230;
  --panel3: #2f1b26;
  --accent: #e05a8a;
  --accent-2: #ff7fae;
  --accent-dark: #b84670;
  --out-bubble: #6a2947;
  --in-bubble: #2a1822;
  --text: #fff0f6;
  --muted: #b08a9d;
  --border: #140c11;
  --danger: #ff6b6b;
  --online: #4cd964;
  --link: #ff9cc4;
  --shadow: rgba(0,0,0,.5);
  --chat-bg: #1b1118;
  --header: #261720;
  --input-bg: #3a2230;
  --hover: #33202c;
  --bubble-meta: rgba(255,255,255,.58);
  --wallpaper: rgba(224,90,138,.07);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow-x: hidden; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overflow: hidden;
  font-size: 15px;
}
.hidden { display: none !important; }
.screen { height: 100dvh; display: flex; flex-direction: column; position: relative; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; display: block; flex-shrink: 0;
}

input, select, textarea {
  background: var(--input-bg); border: 1px solid transparent; color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 15px; outline: none; width: 100%;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.btn {
  display: block; width: 100%; padding: 12px 16px; border-radius: 10px;
  font-size: 15px; font-weight: 600; margin-top: 10px;
  background: var(--panel2); color: var(--text); text-align: center;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
.btn.small { display: inline-block; width: auto; padding: 8px 14px; margin: 0; font-size: 13.5px; }
.link { background: none; color: var(--accent); margin-top: 14px; font-size: 14px; }
.icon-btn {
  background: none; color: var(--text); padding: 8px; border-radius: 50%;
  flex-shrink: 0; display: inline-grid; place-items: center; width: 40px; height: 40px;
  transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn .icon { width: 22px; height: 22px; }
.muted { color: var(--muted); font-size: 13px; }

/* ===== Авторизация ===== */
#auth-screen {
  align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 50% 0%, var(--panel2), transparent 55%),
    var(--bg);
}
.auth-box {
  width: min(390px, 92vw); background: var(--panel); padding: 32px 24px;
  border-radius: 22px; text-align: center; box-shadow: 0 12px 50px var(--shadow);
  border: 1px solid var(--border);
}
.logo img { border-radius: 22px; box-shadow: 0 8px 24px var(--shadow); }
.logo h1 { margin-top: 10px; font-size: 27px; letter-spacing: -.3px; }
.tagline { color: var(--muted); font-size: 13px; margin: 4px 0 22px; }
.auth-box input { margin-bottom: 10px; text-align: center; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.tariff-note { color: var(--accent); font-size: 13px; margin-bottom: 12px; }

/* ===== Верхняя панель ===== */
.topbar {
  display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px;
  background: var(--header); border-bottom: 1px solid var(--border);
  padding-top: calc(8px + env(safe-area-inset-top));
  min-height: 56px; flex-shrink: 0;
}
.topbar-title { flex: 1; font-size: 19px; font-weight: 600; letter-spacing: -.2px; }
#content { flex: 1; overflow: hidden; position: relative; }
.view { height: 100%; display: flex; flex-direction: column; gap: 0; overflow-y: auto; }
#view-chats, #view-chat { overflow: hidden; }

/* ===== Список чатов ===== */
.search-row {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: relative; flex-shrink: 0;
}
.search-row .search-icon {
  position: absolute; left: 20px; width: 18px; height: 18px;
  color: var(--muted); pointer-events: none;
}
#phone-search {
  padding-left: 36px; height: 38px; font-size: 14.5px;
  border-radius: 10px; background: var(--input-bg);
}
.search-row .btn { flex-shrink: 0; padding: 8px 12px; }
.search-error {
  color: var(--danger); font-size: 12.5px; padding: 0 14px;
  background: var(--panel); flex-shrink: 0;
}
.search-error:empty { display: none; }
.chat-list { flex: 1; overflow-y: auto; background: var(--bg); }
.secure-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; flex-shrink: 0;
  padding: 8px 12px; font-size: 12.5px; line-height: 1.35;
  background: rgba(240,177,62,.16); border-bottom: 1px solid var(--border);
}
.secure-banner a { color: var(--accent); font-weight: 600; text-decoration: none; }
.secure-banner a:hover { text-decoration: underline; }
.notify-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; flex-shrink: 0;
  padding: 8px 12px; font-size: 12.5px; line-height: 1.35;
  background: rgba(82,136,193,.18); border-bottom: 1px solid var(--border);
}
.notify-banner .btn { margin: 0; padding: 6px 10px; font-size: 12px; }
.notify-banner a { color: var(--accent); font-weight: 600; }
.notify-close {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  color: var(--muted); font-size: 19px; line-height: 1; background: none;
}
.notify-close:hover { background: var(--hover); color: var(--text); }
.side-head { display: none; }
.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 14px;
  background: transparent; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s;
}
.chat-item:hover { background: var(--hover); }
.chat-item:active { background: var(--panel2); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600; color: #fff; flex-shrink: 0;
  position: relative; user-select: none; overflow: hidden;
}
.avatar-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%;
}
.avatar-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: inherit; color: inherit;
}
.avatar-lg { width: 64px; height: 64px; font-size: 26px; }
.avatar-sm { width: 38px; height: 38px; font-size: 16px; }
.settings-profile .avatar.avatar-lg { width: 64px; height: 64px; }
.profile-row {
  display: flex; align-items: center; gap: 12px;
  padding: 2px 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.profile-row-info { min-width: 0; }
.profile-row-info .name { font-weight: 600; font-size: 16px; }
.avatar-buttons { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.avatar-buttons .btn { margin: 0; padding: 6px 10px; font-size: 12px; }
.chat-item .avatar { width: 52px; height: 52px; font-size: 21px; }
.avatar .dot {
  position: absolute; bottom: 0; right: 0; width: 13px; height: 13px;
  background: var(--online); border-radius: 50%; border: 2px solid var(--panel);
  z-index: 2;
}
.chat-item .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-item .name {
  font-weight: 600; font-size: 15px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.chat-item .last {
  color: var(--muted); font-size: 13.5px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.chat-item .last.typing { color: var(--accent-2); }
.chat-side {
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
  flex-shrink: 0; min-width: 46px;
}
.chat-item .time {
  color: var(--muted); font-size: 11.5px; margin: 0;
}
.unread {
  min-width: 20px; padding: 1px 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  text-align: center; line-height: 17px;
}
.unread.muted { background: var(--muted); }
.pin-mark { font-size: 10px; opacity: .9; }
.mute-mark { font-size: 10px; opacity: .75; }
.chat-item .channel-mark { color: var(--accent-2); font-size: 13px; margin-right: 4px; }

/* ===== Статусы сообщений ===== */
.checks {
  font-size: 11px; letter-spacing: -2px; color: var(--bubble-meta);
  margin-right: 1px;
}
.checks.read { color: var(--accent-2); }
.empty { text-align: center; color: var(--muted); padding: 34px 18px; font-size: 14px; line-height: 1.45; }

/* ===== Диалог ===== */
#view-chat { padding: 0; position: relative; }
.chat-header {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 2px;
  background: var(--header); border-bottom: 1px solid var(--border);
  padding-top: calc(6px + env(safe-area-inset-top));
  min-height: 56px; flex-shrink: 0;
}
.chat-back { margin-right: 0; }
.chat-header .avatar { width: 40px; height: 40px; font-size: 17px; }
.chat-head-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.chat-name {
  font-weight: 600; font-size: 16px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.chat-sub {
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.chat-sub.online { color: var(--online); }
.messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 10px 10px 6px;
  display: flex; flex-direction: column; gap: 3px;
  background: transparent;
}
#view-chat {
  background-color: var(--chat-bg);
  overflow: hidden;
}
#view-chat::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  pointer-events: none;
  background-image:
    url("/static/pattern-dark.svg?v=3"),
    radial-gradient(circle at 15% 15%, var(--wallpaper), transparent 32%),
    radial-gradient(circle at 85% 75%, var(--wallpaper), transparent 36%);
  background-size: 260px 260px, auto, auto;
}
[data-theme="light"] #view-chat::before {
  background-image:
    url("/static/pattern-light.svg?v=3"),
    radial-gradient(circle at 15% 15%, var(--wallpaper), transparent 32%),
    radial-gradient(circle at 85% 75%, var(--wallpaper), transparent 36%);
}
#view-chat .chat-header,
#view-chat .messages,
#view-chat .input-row,
#view-chat .reply-bar,
#view-chat .secret-bar,
#view-chat .channel-note,
#view-chat .bot-menu { position: relative; z-index: 1; }
#view-chat .input-row { z-index: 3; }
#view-chat .chat-header { z-index: 4; }
.msg { position: relative; z-index: 1; }
.msg {
  max-width: min(82%, 560px); padding: 7px 11px 6px; border-radius: 16px; font-size: 15px;
  line-height: 1.35; word-wrap: break-word; white-space: pre-wrap; position: relative;
  box-shadow: 0 1px 1px var(--shadow); align-self: flex-start;
}
.msg.out {
  align-self: flex-end; background: var(--out-bubble); color: var(--text);
}
.msg.in { background: var(--in-bubble); color: var(--text); }
.msg-text.jumbo {
  font-size: 64px; line-height: 1.08; display: inline-block;
  margin: 2px 0; vertical-align: middle;
}
.msg-text.medium {
  font-size: 42px; line-height: 1.14; display: inline-block;
  margin: 1px 0; vertical-align: middle;
}
.msg.out::after, .msg.in::after { display: none; }
.scroll-down {
  position: absolute; right: 22px; bottom: 86px; z-index: 6;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); display: grid; place-items: center;
  box-shadow: 0 4px 16px var(--shadow);
}
.scroll-down .icon { width: 22px; height: 22px; }
.msg.system {
  align-self: center; background: var(--panel2); color: var(--muted);
  font-size: 12.5px; text-align: center; max-width: 92%; border-radius: 12px;
  padding: 4px 10px; box-shadow: none; white-space: normal;
}
.msg.system::after { display: none; }
.msg .meta {
  display: flex; gap: 4px; justify-content: flex-end; align-items: center;
  font-size: 11px; color: var(--bubble-meta); margin-top: 3px;
  white-space: normal;
}
.msg .check { width: 14px; height: 14px; stroke-width: 2.6; }
.msg .reply-quote {
  border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px;
  font-size: 12.5px; color: var(--muted); border-radius: 4px;
  background: rgba(0,0,0,.14); white-space: normal;
}
.msg .silent-tag { font-size: 11px; }
.msg-actions {
  position: absolute; top: -15px; right: 8px; display: none; gap: 2px;
  background: var(--panel); border-radius: 9px; padding: 2px 6px; z-index: 2;
  box-shadow: 0 2px 8px var(--shadow);
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg-actions button { color: var(--muted); font-size: 12px; padding: 2px 4px; }
.msg .sender-name { font-size: 12px; font-weight: 600; color: var(--link); margin-bottom: 2px; }
.msg .sticker { width: 130px; display: block; border-radius: 10px; }
.msg .img-preview {
  max-width: 220px; max-height: 260px; border-radius: 10px;
  display: block; margin-bottom: 4px; cursor: pointer; object-fit: cover;
}
.file-link {
  color: var(--link); text-decoration: none; display: flex; gap: 6px;
  align-items: center; white-space: normal;
}
.date-sep {
  align-self: center; background: var(--panel2); color: var(--muted);
  font-size: 12px; padding: 4px 10px; border-radius: 12px; margin: 6px 0;
  box-shadow: 0 1px 1px var(--shadow);
}
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sticker-grid .sticker-pick {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px;
  cursor: pointer; background: var(--panel2);
}
.warn-btn { color: var(--danger) !important; }
.poll-box { min-width: 200px; }
.poll-box .q { font-weight: 600; margin-bottom: 6px; }
.poll-opt {
  display: flex; justify-content: space-between; gap: 8px; background: var(--panel2);
  border-radius: 8px; padding: 7px 10px; margin-top: 5px; font-size: 13.5px;
  cursor: pointer; position: relative; overflow: hidden;
}
.poll-opt.mine { outline: 2px solid var(--accent); }
.poll-opt .bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent); opacity: .35; z-index: 0;
}
.poll-opt span { position: relative; z-index: 1; }
.poll-total { font-size: 11px; color: var(--muted); margin-top: 4px; }
.voice { display: flex; align-items: center; gap: 8px; }
.voice .play { font-size: 18px; background: none; color: var(--text); }
.voice select { width: auto; font-size: 12px; padding: 3px 6px; border-radius: 6px; }

/* Панели над вводом */
.reply-bar, .secret-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: var(--panel2); font-size: 13px; color: var(--muted);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.reply-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar .icon { width: 18px; height: 18px; }
.secret-bar select { width: auto; padding: 6px; }
.channel-note {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; background: var(--panel2); color: var(--muted);
  font-size: 13px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.channel-note .btn { margin: 0; flex-shrink: 0; }
.input-row {
  display: flex; align-items: flex-end; gap: 1px; padding: 6px;
  background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.input-row .icon-btn { width: 38px; height: 38px; margin-bottom: 1px; }
.input-row .icon-btn .icon { width: 21px; height: 21px; }
#view-chat #btn-poll,
#view-chat #btn-silent { display: none; }
.input-row textarea {
  flex: 1; min-width: 0; resize: none; min-height: 38px; max-height: 120px;
  border-radius: 19px; padding: 9px 12px; background: var(--input-bg);
  border: 1px solid transparent; line-height: 1.3;
}
.input-row .send {
  background: var(--accent); color: #fff; width: 40px; height: 40px;
  box-shadow: 0 2px 7px rgba(0,0,0,.25);
}
.input-row .send .icon { stroke: #fff; }
.input-row .send:active { background: var(--accent-dark); }

/* ===== Панель смайликов ===== */
.emoji-panel {
  position: absolute; z-index: 40; left: 8px; right: 8px;
  bottom: calc(62px + env(safe-area-inset-bottom));
  max-width: 430px; max-height: 330px;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 10px 34px var(--shadow);
  overflow: hidden;
}
.emoji-tabs {
  display: flex; gap: 2px; padding: 6px 8px; flex-shrink: 0;
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.emoji-tab {
  font-size: 19px; line-height: 1; padding: 5px 7px; border-radius: 8px;
  opacity: .6; flex-shrink: 0; background: none;
}
.emoji-tab.active { opacity: 1; background: var(--panel2); }
.emoji-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 2px; padding: 8px; overflow-y: auto; flex: 1; align-content: start;
}
.emoji-btn {
  font-size: 24px; line-height: 1; padding: 6px 3px;
  border-radius: 8px; text-align: center; background: none;
}
.emoji-btn:hover { background: var(--hover); }
.input-row .icon-btn.active { color: var(--danger); }

/* ===== Каналы ===== */
#view-channels, #view-tariffs, #view-admin { padding: 12px; gap: 10px; }
.channels-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px; margin: 2px 2px 4px;
}
.channels-head h2 { font-size: 22px; letter-spacing: -.3px; }
.channels-head .muted { margin-top: 3px; max-width: 250px; }
.channels-head .btn { flex-shrink: 0; }
.channel-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.join-key {
  display: flex; gap: 8px; align-items: center; margin: 0 2px 4px;
}
.join-key input { flex: 1; min-width: 0; height: 40px; }
.join-key .btn { flex-shrink: 0; margin: 0; padding: 9px 14px; width: auto; }
.channel-card {
  display: flex; flex-direction: column; gap: 8px; padding: 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 1px 2px var(--shadow);
}
.channel-main { display: flex; align-items: center; gap: 12px; width: 100%; }
.channel-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark)) !important;
  font-size: 20px;
}
.channel-info { flex: 1; min-width: 0; }
.channel-name {
  font-weight: 600; font-size: 15px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.channel-desc {
  font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.channel-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.channel-card .btn { flex-shrink: 0; padding: 7px 12px; font-size: 12.5px; }
.channel-key, .channel-key-box {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel2); border-radius: 9px; padding: 7px 9px;
  font-size: 12.5px; color: var(--muted); word-break: break-all;
}
.channel-key code, .channel-key-box code {
  color: var(--text); font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px;
}
.channel-key .btn, .channel-key-box .btn {
  flex-shrink: 0; margin: 0; padding: 4px 9px; font-size: 11.5px;
}

/* ===== Тарифы ===== */
.page-head { margin: 2px 2px 4px; }
.page-head h2 { font-size: 22px; letter-spacing: -.3px; }
.table-wrap {
  overflow-x: auto; background: var(--panel); border-radius: 14px;
  border: 1px solid var(--border);
}
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td {
  padding: 10px 12px; text-align: center; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th { color: var(--accent); font-size: 13px; font-weight: 600; }
td:first-child, th:first-child {
  text-align: left; position: sticky; left: 0; background: var(--panel);
}
tr:last-child td { border-bottom: none; }
td.yes { color: #6fce85; }
td.no { color: var(--danger); }
tr.tariff-row td { font-weight: 700; color: var(--text); background: var(--panel2); }

/* ===== Админ ===== */
.admin-card {
  background: var(--panel); border-radius: 14px; padding: 14px;
  border: 1px solid var(--border);
}
.admin-card h3 { font-size: 15px; margin-bottom: 10px; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-row select, .form-row input { width: auto; flex: 1; min-width: 90px; }
.form-row .btn { width: auto; margin: 0; }
.key-line {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px;
  background: var(--panel2); border-radius: 8px; margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px; align-items: center; word-break: break-all;
}
.key-line .copy {
  background: var(--accent); color: #fff; border-radius: 6px;
  padding: 3px 10px; font-size: 12px; font-family: inherit; flex-shrink: 0;
}
.user-row {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 8px; background: var(--panel2); border-radius: 8px;
  margin-top: 6px; font-size: 13px;
}
.user-row b { min-width: 80px; }
.user-row button {
  background: var(--panel); color: var(--text); border-radius: 6px;
  padding: 4px 10px; font-size: 12px;
}
.user-row button.warn { color: var(--danger); }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.free { background: #33404f; color: var(--muted); }
.badge.lite { background: rgba(82,136,193,.35); color: #9ecbff; }
.badge.pro { background: rgba(240,177,62,.3); color: #f0b13e; }
.badge.admin { background: rgba(224,91,91,.3); color: #ff8a8a; }
#users-table td:last-child, #keys-table td:last-child { white-space: nowrap; }
#keys-table td:nth-child(4), #keys-table th:nth-child(4) { white-space: normal; }
#keys-table td:nth-child(4) { max-width: 300px; }
#users-table button, #keys-table button {
  background: var(--panel2); color: var(--text); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; margin: 0 2px;
}
#deleted-table button {
  background: var(--panel2); color: var(--text); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; margin: 0 2px;
}
#deleted-table button.restore { color: #9ecbff; }
#deleted-table td:last-child { white-space: nowrap; }
#users-table button.warn, #keys-table button.warn { color: var(--danger); }
#users-table .tariff-sel {
  display: inline-block; width: auto; min-width: 88px; margin: 0 2px;
  padding: 4px 6px; font-size: 12px; border-radius: 6px;
}

/* ===== Нижняя навигация ===== */
.bottom-nav {
  display: flex; background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); flex-shrink: 0;
}
.nav-btn {
  flex: 1; color: var(--muted); padding: 6px 0 8px; font-size: 10.5px;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
  transition: color .15s; position: relative;
}
.nav-btn .icon { width: 24px; height: 24px; stroke-width: 1.8; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
}

/* ===== Кнопка «создать» ===== */
.fab {
  position: absolute; right: 18px; bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 30; width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 16px var(--shadow); transition: transform .15s, background .15s;
}
.fab:hover { background: var(--accent-dark); }
.fab:active { transform: scale(.94); }
.fab .icon { width: 23px; height: 23px; stroke: #fff; }

/* ===== Модали ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--panel); width: 100%; max-width: 480px;
  max-height: 88dvh; overflow-y: auto; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0; box-shadow: 0 -8px 40px var(--shadow);
  animation: sheet-up .18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(30px); opacity: .6; } }
.modal-box h3 { margin-bottom: 12px; font-size: 18px; }
.modal-box input, .modal-box textarea, .modal-box select { margin-bottom: 8px; }
.modal-box .poll-opt-input { margin-bottom: 8px; }
.set-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 15px;
}
.switch {
  width: 46px; height: 26px; border-radius: 13px; background: #5a6b7d;
  position: relative; flex-shrink: 0; transition: background .15s;
}
.switch.on { background: var(--accent); }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: .15s;
}
.switch.on::after { left: 23px; }
.settings-profile {
  display: flex; align-items: center; gap: 12px; padding: 4px 0 14px;
  border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.settings-profile .avatar { width: 52px; height: 52px; }
.settings-profile .name { font-weight: 600; font-size: 16px; }
.settings-profile .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.settings-label {
  color: var(--muted); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .6px; margin: 14px 0 8px; font-weight: 600;
}
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.theme-card {
  display: flex; align-items: center; gap: 9px; padding: 10px;
  background: var(--panel2); color: var(--text); border: 2px solid transparent;
  border-radius: 12px; font-size: 13.5px; text-align: left;
}
.theme-card.active { border-color: var(--accent); }
.theme-preview {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.16);
}
.theme-preview.dark { background: linear-gradient(135deg, #050506 50%, #7c5cff 50%); }
.theme-preview.light { background: linear-gradient(135deg, #fff 50%, #e7ffdb 50%); border-color: #d5d5d5; }
.theme-preview.system { background: linear-gradient(135deg, #050506 0 50%, #ffffff 50% 100%); }
.theme-preview.blue { background: linear-gradient(135deg, #0b1726 50%, #1f4f7a 50%); }
.theme-preview.pink { background: linear-gradient(135deg, #1b1118 50%, #6a2947 50%); }
.menu-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px; margin-top: 8px; border-radius: 12px;
  background: var(--panel2); color: var(--text); font-size: 15px; text-align: left;
  transition: background .15s;
}
.menu-row:hover { background: var(--hover); }
.menu-row .icon { width: 22px; height: 22px; color: var(--accent); }
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.modal-actions .btn { margin-top: 0; }
.info-card {
  background: var(--panel2); border-radius: 12px; padding: 12px;
  margin-bottom: 8px;
}
.info-card .name { font-size: 17px; font-weight: 600; }
.info-card .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.info-card .desc { color: var(--text); font-size: 14px; margin-top: 8px; line-height: 1.4; }
.member-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.member-row:last-child { border-bottom: none; }
.member-row .btn { margin: 0; padding: 4px 10px; font-size: 12px; }

/* ===== Звонок ===== */
.call-screen {
  position: fixed; inset: 0; z-index: 150;
  background:
    radial-gradient(circle at 50% 44%, rgba(118, 82, 220, .34), transparent 38%),
    radial-gradient(circle at 50% 44%, rgba(46, 96, 190, .20), transparent 58%),
    linear-gradient(160deg, #0b1018, #05070b 72%);
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 20px 28px; color: #fff;
}
.call-top { width: 100%; display: flex; justify-content: flex-end; }
.call-top-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.10); color: #fff;
  display: grid; place-items: center; transition: background .15s;
}
.call-top-btn:hover { background: rgba(255,255,255,.2); }
.call-top-btn .icon { width: 21px; height: 21px; }
.call-info {
  margin: auto 0; display: flex; flex-direction: column; align-items: center;
}
.call-name {
  font-size: 28px; font-weight: 700; letter-spacing: -.3px;
  text-align: center; word-break: break-word;
}
.call-status { color: rgba(255,255,255,.62); margin-top: 8px; font-size: 15px; }
.call-avatar {
  width: 180px; height: 180px; font-size: 64px; font-weight: 700;
  display: grid; place-items: center; border-radius: 50%;
  margin-top: 30px; position: relative; overflow: hidden;
  background: linear-gradient(135deg, #241f38, #121214);
  border: 4px solid rgba(255,255,255,.92);
  box-shadow:
    0 0 60px 14px rgba(120, 88, 240, .38),
    0 0 140px 50px rgba(80, 50, 190, .20);
}
.call-avatar .avatar-img { border-radius: 50%; }
.call-avatar.ring { animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); opacity: .9; } }
.call-devices {
  display: flex; flex-direction: column; gap: 8px;
  width: min(420px, 100%); margin-bottom: 16px;
}
.call-devices label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: rgba(255,255,255,.55); text-transform: uppercase;
}
.call-devices select {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
  color: #fff; padding: 10px 12px; font-size: 14px; border-radius: 12px;
}
.call-devices select option { color: #111; background: #fff; }
.device-select { width: auto; max-width: 62%; padding: 8px 10px; font-size: 13px; }
.call-controls {
  display: flex; gap: 22px; justify-content: center;
  width: min(420px, 100%); margin-bottom: 8px;
}
.call-round {
  width: 64px; height: 64px; border-radius: 50%;
  background: rgba(255,255,255,.12); color: #fff;
  display: grid; place-items: center; transition: background .15s, transform .1s;
}
.call-round:hover { background: rgba(255,255,255,.22); }
.call-round:active { transform: scale(.95); }
.call-round .icon { width: 27px; height: 27px; stroke: #fff; }
.call-round.muted-on { background: rgba(255,255,255,.32); }
.call-round.end { background: #e5484d; }
.call-round.end .icon { transform: rotate(135deg); }
.call-round.accept { background: #31a24c; }
.call-mini {
  position: fixed; right: 18px; bottom: 18px; z-index: 160;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 12px; box-shadow: 0 10px 34px var(--shadow);
}
.call-mini-info { display: flex; flex-direction: column; min-width: 110px; font-size: 13px; }
.call-mini-info b { font-size: 14px; }
.call-mini-info span { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.call-mini-btn {
  padding: 8px 12px; border-radius: 10px;
  background: var(--panel2); color: var(--text); font-size: 12.5px;
}
.call-mini-btn.end { background: #e5484d; color: #fff; }

/* ===== Тост ===== */
.toast {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); color: var(--text); padding: 10px 18px;
  border-radius: 20px; font-size: 13.5px; z-index: 300; max-width: 85vw;
  text-align: center; box-shadow: 0 4px 18px var(--shadow);
  border: 1px solid var(--border);
}

/* ===== Скроллбары ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--panel2); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== Боты ===== */
.bot-menu {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px;
  background: var(--panel); border-top: 1px solid var(--border);
  flex-shrink: 0; max-height: 150px; overflow-y: auto;
}
.bot-btn {
  background: var(--input-bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 14px; font-size: 13.5px; font-weight: 500;
  transition: background .15s;
}
.bot-btn:hover { background: var(--hover); }
.bot-btn.ghost { opacity: .65; }
.bots-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.bot-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel2); border-radius: 10px; padding: 8px 10px;
}
.bot-item-info { min-width: 0; font-size: 13.5px; flex: 1; }
.bot-greeting {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 12px; margin-top: 2px;
}
.bot-item .btn { margin: 0; flex-shrink: 0; }
.bot-row {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 6px;
}
.bot-row input { margin: 0; padding: 9px; font-size: 13px; }
.bot-del {
  background: var(--panel2); color: var(--danger); border-radius: 8px;
  width: 34px; font-size: 14px;
}
#view-bot { padding: 12px; }
.bot-console-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin: 6px 2px 10px;
}
.bot-console-bar select { width: auto; flex: 0 0 auto; min-width: 150px; height: 40px; }
.bot-console-bar input { flex: 1; min-width: 180px; height: 40px; }
.bot-console-bar .btn { margin: 0; padding: 10px 14px; }
.bot-conv { cursor: pointer; transition: background .12s; }
.bot-conv:hover { background: var(--hover); }
.channel-name .unread { margin-left: 6px; vertical-align: middle; }
.empty-pane {
  margin: auto; text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 10px; padding: 20px;
}
#view-empty {
  background-color: var(--chat-bg);
  background-image: url("/static/pattern-dark.svg?v=3");
  background-size: 260px 260px;
}
[data-theme="light"] #view-empty {
  background-image: url("/static/pattern-light.svg?v=3");
}
.empty-pane h2 { font-size: 24px; color: var(--text); }
.empty-pane img { opacity: .85; border-radius: 18px; }

/* ===== Адаптив ===== */
@media (min-width: 700px) {
  .auth-box { box-shadow: 0 18px 60px var(--shadow); }
  .modal { align-items: center; padding: 16px; }
  .modal-box { border-radius: 18px; padding: 20px; }
  #view-channels, #view-tariffs, #view-admin, #view-bot { padding: 16px; }
  #view-admin, #view-tariffs { gap: 12px; }
  .channel-list, .table-wrap, .admin-card { max-width: 760px; width: 100%; margin-left: auto; margin-right: auto; }
  .empty-pane { padding: 40px; }
}
@media (min-width: 900px) {
  body { background: var(--bg); }
  #app-screen {
    max-width: none; width: 100%; margin: 0;
    border: 0; box-shadow: none;
  }
  #topbar, #bottom-nav { display: none !important; }
  #content {
    display: grid; grid-template-columns: 380px minmax(0, 1fr);
    grid-template-rows: 100%; min-height: 0;
  }
  #view-chats {
    display: flex !important; grid-column: 1; grid-row: 1;
    border-right: 1px solid var(--border); min-height: 0;
    background: var(--panel);
  }
  #view-chat, #view-channels, #view-tariffs, #view-admin, #view-bot, #view-empty {
    grid-column: 2; grid-row: 1; min-height: 0; overflow-y: auto;
  }
  #view-chat { overflow: hidden; }
  .side-head {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px 6px; flex-shrink: 0;
  }
  .side-menu-btn { width: 38px; height: 38px; }
  .side-search {
    flex: 1; display: flex; align-items: center; gap: 8px;
    height: 42px; background: var(--input-bg); border-radius: 21px;
    padding: 0 14px; min-width: 0;
  }
  .side-search .icon { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
  .side-search input {
    flex: 1; min-width: 0; background: transparent; border: none;
    padding: 0; height: auto; font-size: 14.5px;
  }
  #btn-side-profile { width: 38px; height: 38px; font-size: 16px; padding: 0; }
  #notify-banner, #secure-banner {
    margin: 8px 10px 4px; border: 1px solid var(--border);
    border-radius: 12px; border-bottom: 1px solid var(--border);
  }
  .notify-banner { justify-content: flex-start; }
  .notify-banner #notify-banner-text { flex: 1; }
  #chat-list { padding: 6px 0 12px; background: transparent; }
  .chat-item {
    margin: 1px 6px; padding: 8px; border-radius: 10px; border-bottom: none;
  }
  .chat-item .avatar { width: 54px; height: 54px; }
  .chat-item .name { font-size: 14.5px; }
  .chat-item .last { font-size: 13px; }
  .chat-item.active { background: var(--hover); }
  .fab {
    left: calc(380px - 72px); right: auto;
    bottom: calc(20px + env(safe-area-inset-bottom));
    width: 56px; height: 56px;
  }
  #view-chat { background-color: var(--chat-bg); overflow-x: hidden; }
  #view-chat .chat-header {
    width: auto; max-width: none; align-self: stretch;
    margin: 8px 12px 0; min-height: 58px;
    padding: 8px 12px; border: 1px solid var(--border);
    border-radius: 18px; background: var(--header);
    box-shadow: 0 6px 24px rgba(0,0,0,.28);
  }
  #view-chat .chat-back { display: none; }
  #view-chat .messages { padding: 10px 14px 8px; width: 100%; }
  #view-chat .input-row {
    width: calc(100% - 24px); max-width: 720px;
    align-self: center;
    margin: 4px 0 14px; padding: 7px 9px;
    border: 1px solid var(--border); border-radius: 26px;
    background: var(--panel); box-shadow: 0 8px 28px rgba(0,0,0,.28);
  }
  #view-chat .input-row #btn-mic {
    background: var(--accent); color: #fff;
    border-radius: 50%; width: 40px; height: 40px;
  }
  #view-chat .input-row #btn-mic .icon { stroke: #fff; }
  #view-chat .input-row #btn-poll,
  #view-chat .input-row #btn-silent { display: none; }
  #view-chat .emoji-panel {
    left: 50%; right: auto; transform: translateX(-50%);
    width: calc(100% - 24px); max-width: 720px; bottom: 82px;
  }
  #view-chat .bot-menu {
    width: calc(100% - 24px); max-width: 720px;
    align-self: center; margin: 0 0 4px;
    border: 1px solid var(--border); border-radius: 16px;
  }
  #view-chat .reply-bar,
  #view-chat .secret-bar {
    width: auto; max-width: 520px;
    align-self: center; margin: 0 0 6px;
    border-radius: 14px; padding: 8px 14px;
  }
  #chat-list .empty { padding: 40px 20px; }
  .admin-card, .table-wrap, .channel-list { max-width: 900px; }
}
@media (max-width: 380px) {
  .input-row .icon-btn { width: 34px; height: 34px; }
  .input-row .icon-btn .icon { width: 19px; height: 19px; }
  .input-row .send { width: 37px; height: 37px; }
  .input-row { gap: 0; }
  #msg-input { padding: 8px 10px; }
  .chat-item .avatar { width: 48px; height: 48px; font-size: 19px; }
  .msg-text.jumbo { font-size: 52px; }
  .msg-text.medium { font-size: 36px; }
}
