/* =========================================================
   Capi Messenger — dark Telegram-inspired design system
   ========================================================= */

:root {
  --bg-app: #0e1621;
  --bg-panel: #17212b;
  --bg-elevated: #1f2b38;
  --bg-hover: #202b36;
  --bg-active: #2b5278;
  --bg-input: #242f3d;
  --bg-msg-in: #242f3d;
  --bg-msg-out: #2b5278;
  --text-primary: #f4f7fa;
  --text-secondary: #8a9aa9;
  --text-muted: #6c7883;
  --accent: #5288c1;
  --accent-hover: #6aa5e0;
  --accent-light: rgba(82, 136, 193, 0.16);
  --danger: #e56555;
  --online: #4ecc5e;
  --warning: #f0a500;
  --border: rgba(255, 255, 255, 0.07);
  --divider: rgba(255, 255, 255, 0.06);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  --sidebar-width: 380px;
  --drawer-width: 360px;
  --msg-font-size: 14.5px;
  --ui-scale: 1;
  --wallpaper-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='0.028' stroke-width='1.2'%3E%3Ccircle cx='34' cy='34' r='18'/%3E%3Ccircle cx='126' cy='58' r='10'/%3E%3Cpath d='M18 118c14-14 30-14 44 0'/%3E%3Cpath d='M104 112l12 12-12 12-12-12z'/%3E%3Cpath d='M72 22l8 8-8 8-8-8z'/%3E%3Crect x='116' y='124' width='24' height='16' rx='4'/%3E%3C/g%3E%3C/svg%3E");
  --wallpaper-size: 320px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button, input, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(138, 154, 169, 0.28); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(138, 154, 169, 0.45); }

/* ============================ AUTH ============================ */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  padding: 20px;
  background:
    radial-gradient(circle at 18% 18%, rgba(82, 136, 193, 0.16), transparent 42%),
    radial-gradient(circle at 82% 78%, rgba(123, 81, 157, 0.14), transparent 44%),
    var(--bg-app);
}

.auth-top-bar { position: absolute; top: 18px; right: 20px; }

.auth-theme-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--text-primary); font-size: 13px; font-weight: 500;
}

.auth-card {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  opacity: 1;
  visibility: visible;
  width: 100%; max-width: 410px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 34px 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.capi-logo {
  width: 92px; height: 92px; margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
}

.auth-title { font-size: 23px; font-weight: 700; margin-bottom: 8px; }
.auth-subtitle { font-size: 14px; line-height: 1.5; color: var(--text-secondary); margin-bottom: 24px; }

.field { text-align: left; margin-bottom: 16px; }
.field label, .field-label {
  display: block; font-size: 12px; font-weight: 600; color: var(--accent);
  margin-bottom: 6px; padding-left: 2px;
}

.input, .select, textarea.input {
  width: 100%; min-height: 46px; padding: 0 14px;
  border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--bg-input); color: var(--text-primary);
  font-size: 15px; outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}
textarea.input { padding: 12px 14px; min-height: 96px; resize: vertical; }
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light);
}
.code-input { text-align: center; font-size: 24px; font-weight: 700; letter-spacing: 9px; }

.primary-btn {
  width: 100%; min-height: 46px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 700;
  letter-spacing: .5px; text-transform: uppercase; margin-top: 4px;
  transition: background .18s ease;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: .55; cursor: default; }

.btn-secondary {
  min-height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: transparent;
  color: var(--accent); font-weight: 600; font-size: 14px;
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-solid {
  min-height: 40px; padding: 0 18px; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
}
.btn-solid:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; border: 1px solid rgba(229, 101, 85, .45); color: var(--danger); }

.auth-error {
  margin-top: 12px; padding: 9px 12px; border-radius: 9px;
  background: rgba(229, 101, 85, .14); color: var(--danger);
  font-size: 13px; font-weight: 500; text-align: center;
}
.auth-hint {
  margin-top: 16px; padding: 10px 12px; border-radius: 9px;
  background: var(--accent-light); font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.auth-code-pill {
  border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--accent); font-weight: 700; padding: 4px 10px; border-radius: 7px;
}

.avatar-circle {
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; flex-shrink: 0; overflow: hidden;
  text-transform: uppercase; background: #5288c1; user-select: none;
}
.avatar-circle img { width: 100%; height: 100%; object-fit: cover; }

/* ============================ APP SHELL ============================ */
.app-shell {
  display: flex; width: 100vw; height: 100dvh; overflow: hidden;
  background: var(--bg-app); zoom: var(--ui-scale);
}

.sidebar {
  width: var(--sidebar-width); min-width: 300px; max-width: 420px;
  height: 100%; display: flex; flex-direction: column;
  background: var(--bg-panel); border-right: 1px solid var(--border);
  position: relative; z-index: 10;
}

.sidebar-top {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--divider);
}
.sidebar-search { position: relative; flex: 1; display: flex; align-items: center; }
.sidebar-search svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.search-input {
  width: 100%; height: 38px; padding: 0 34px 0 36px; border-radius: 19px;
  border: 1px solid transparent; background: var(--bg-input);
  color: var(--text-primary); font-size: 14px; outline: none;
}
.search-input:focus { border-color: var(--accent); background: var(--bg-panel); }
.search-clear {
  position: absolute; right: 7px; width: 24px; height: 24px; border: none;
  border-radius: 50%; background: transparent; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.search-clear:hover { background: var(--bg-hover); color: var(--text-primary); }

.icon-btn {
  width: 40px; height: 40px; min-width: 40px; border: none; border-radius: 50%;
  background: transparent; color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .16s ease, color .16s ease;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.active { color: var(--accent); background: var(--accent-light); }
.icon-btn svg { width: 21px; height: 21px; }

.folder-chips {
  display: flex; gap: 7px; padding: 8px 12px; overflow-x: auto;
  border-bottom: 1px solid var(--divider); scrollbar-width: none;
}
.folder-chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text-secondary);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.chip:hover { color: var(--text-primary); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.chats-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.chat-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 12px; border: none; background: transparent;
  text-align: left; color: var(--text-primary);
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item .avatar-circle { width: 48px; height: 48px; font-size: 16px; position: relative; }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 3px; }
.chat-item-title { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 11.5px; color: var(--text-muted); flex-shrink: 0; }
.chat-item-preview { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.active .chat-item-title,
.chat-item.active .chat-item-time,
.chat-item.active .chat-item-preview { color: #fff; }
.online-dot {
  position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--online); border: 2px solid var(--bg-panel);
}
.chat-item.active .online-dot { border-color: var(--bg-active); }

.empty-state { padding: 26px 18px; color: var(--text-secondary); font-size: 13px; text-align: center; line-height: 1.5; }

/* Global user search */
.global-search {
  position: absolute; inset: 0; top: 59px; z-index: 15;
  background: var(--bg-panel); overflow-y: auto; padding: 8px;
}
.global-search-title {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); padding: 7px 8px;
}
.global-user-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 8px; border: none; border-radius: 10px;
  background: transparent; color: var(--text-primary); text-align: left;
}
.global-user-item:hover { background: var(--bg-hover); }
.global-user-item .avatar-circle { width: 40px; height: 40px; font-size: 14px; }
.global-user-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.global-user-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.global-user-meta { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================ CHAT ============================ */
.chat-pane {
  flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column;
  position: relative; background-color: var(--bg-app);
  background-image: var(--wallpaper-image);
  background-size: var(--wallpaper-size); background-repeat: repeat;
}
.chat-pane::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(14, 22, 33, .55), rgba(14, 22, 33, .82));
}
.chat-pane > * { position: relative; z-index: 1; }

.chat-header {
  height: 62px; min-height: 62px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
.chat-header-left { display: flex; align-items: center; gap: 11px; min-width: 0; cursor: pointer; }
.chat-header-left .avatar-circle { width: 42px; height: 42px; font-size: 15px; }
.chat-header-title { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-status { font-size: 12.5px; color: var(--text-secondary); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-status.online { color: var(--online); }
.chat-header-status.typing { color: var(--accent); }
.chat-header-actions { display: flex; align-items: center; gap: 2px; }
.mobile-back-btn { display: none; }

.in-chat-search {
  display: flex; gap: 8px; padding: 8px 14px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
}

.messages-viewport { flex: 1; overflow-y: auto; padding: 18px 20px 10px; }
.messages-container {
  width: 100%; max-width: 920px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 6px;
}
.date-divider {
  align-self: center; margin: 8px 0; padding: 4px 12px; border-radius: 14px;
  background: rgba(23, 33, 43, .88); color: #d7e0e8; font-size: 12px; font-weight: 600;
}

.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: min(80%, 640px); }
.msg-row.in { align-self: flex-start; }
.msg-row.out { align-self: flex-end; flex-direction: row-reverse; }
.msg-row .avatar-circle { width: 34px; height: 34px; font-size: 12px; margin-bottom: 2px; }

.bubble {
  position: relative; min-width: 64px; max-width: 100%;
  padding: 8px 12px 6px; border-radius: var(--radius);
  font-size: var(--msg-font-size); line-height: 1.45;
  word-break: break-word; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.msg-row.out .bubble {
  background: var(--bg-msg-out); color: #fff;
  border-bottom-right-radius: 6px;
}
.msg-row.in .bubble {
  background: var(--bg-msg-in); color: #eef2f6;
  border-bottom-left-radius: 6px;
}
.msg-sender { font-size: 12.5px; font-weight: 700; color: #7fb5e8; margin-bottom: 3px; }
.msg-text { white-space: pre-wrap; }
.msg-text a { text-decoration: underline; }
.msg-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  margin-top: 3px; font-size: 10.5px; line-height: 1;
  color: rgba(255, 255, 255, .62);
}
.msg-row.in .msg-meta { color: rgba(200, 214, 226, .58); }
.msg-meta .lock { font-size: 9.5px; }

.msg-image {
  display: block; max-width: min(320px, 70vw); max-height: 360px;
  width: auto; border-radius: 12px; cursor: zoom-in; margin-bottom: 2px;
}
.msg-audio { width: min(280px, 68vw); margin: 2px 0 3px; }
.msg-video-note {
  width: min(250px, 64vw); height: min(250px, 64vw);
  border-radius: 28% / 24%; object-fit: cover; background: #000;
  clip-path: inset(0 round 28% / 24%);
  display: block; margin-bottom: 3px;
}
.sticker-bubble { background: transparent !important; box-shadow: none !important; padding: 2px !important; }
.sticker-emoji {
  display: inline-block; font-size: 66px; line-height: 1;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .35));
  animation: sticker-pop .42s cubic-bezier(.2, 1.4, .4, 1), sticker-float 2.4s ease-in-out .42s infinite;
}
@keyframes sticker-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes sticker-float { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-4px) rotate(2deg); } }

.msg-appear { animation: msg-in .16s cubic-bezier(.16, 1, .3, 1); }
@keyframes msg-in { from { opacity: 0; transform: translateY(5px) scale(.985); } to { opacity: 1; transform: none; } }

/* Composer */
.composer-wrap { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer {
  max-width: 920px; margin: 0 auto; display: flex; align-items: center; gap: 5px;
  padding: 6px 8px; border-radius: 16px;
  background: var(--bg-panel); border: 1px solid var(--border);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.composer-input {
  flex: 1; min-width: 0; height: 40px; border: none; outline: none;
  background: transparent; color: var(--text-primary); font-size: 14.5px;
}
.send-btn {
  width: 42px; height: 42px; min-width: 42px; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn svg { width: 19px; height: 19px; }

.recording-bar {
  max-width: 920px; margin: 0 auto 8px; padding: 10px 14px;
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-panel); border: 1px solid rgba(229, 101, 85, .45); border-radius: 12px;
}
.recording-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.recording-time { font-variant-numeric: tabular-nums; font-weight: 700; }
.record-preview { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; background: #000; }

/* Popovers */
.popover {
  position: absolute; right: 16px; bottom: 78px; z-index: 40;
  width: min(340px, calc(100vw - 32px)); max-height: 380px; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}
.popover-head { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--divider); overflow-x: auto; }
.emoji-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 10px; overflow-y: auto; }
.emoji-btn { height: 38px; border: none; border-radius: 9px; background: transparent; font-size: 21px; }
.emoji-btn:hover { background: var(--bg-hover); }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px; overflow-y: auto; }
.sticker-btn {
  aspect-ratio: 1; border: none; border-radius: 12px; background: transparent;
  font-size: 34px; display: flex; align-items: center; justify-content: center;
  transition: transform .14s ease, background .14s ease;
}
.sticker-btn:hover { background: var(--bg-hover); transform: scale(1.08); }
.sticker-lock {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 26px 18px; text-align: center; color: var(--text-secondary); font-size: 13px;
}
.sticker-lock .lock-big { font-size: 36px; }
.pack-tab {
  flex-shrink: 0; padding: 6px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: transparent; font-size: 17px; color: var(--text-secondary);
}
.pack-tab.active { background: var(--accent-light); border-color: var(--accent); }

/* ============================ DRAWER ============================ */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, .58); backdrop-filter: blur(2px);
}
.nav-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  width: min(var(--drawer-width), 88vw);
  display: flex; flex-direction: column;
  background: var(--bg-panel); border-right: 1px solid var(--border);
  transform: translateX(-104%);
  transition: transform .28s cubic-bezier(.16, 1, .3, 1);
  box-shadow: 16px 0 40px rgba(0, 0, 0, .35);
}
.nav-drawer.open { transform: translateX(0); }

.drawer-scroll { flex: 1; overflow-y: auto; }
.drawer-profile {
  display: flex; align-items: center; gap: 12px; padding: 18px 16px 14px;
  border-bottom: 1px solid var(--divider); cursor: pointer;
}
.drawer-profile:hover { background: var(--bg-hover); }
.drawer-profile .avatar-circle { width: 54px; height: 54px; font-size: 19px; }
.drawer-user-info { min-width: 0; flex: 1; }
.drawer-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.drawer-name { font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-handle { font-size: 12px; color: var(--accent); margin-top: 1px; font-weight: 600; }
.drawer-balance { display: inline-flex; align-items: center; gap: 5px; margin-top: 5px; font-size: 12.5px; font-weight: 700; color: #f0b429; }
.drawer-section-title {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); padding: 14px 18px 6px;
}
.account-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  border-radius: 10px; margin: 2px 8px; cursor: pointer;
}
.account-row:hover { background: var(--bg-hover); }
.account-row.active { background: var(--accent-light); }
.account-row .avatar-circle { width: 34px; height: 34px; font-size: 12px; }
.account-row-info { flex: 1; min-width: 0; }
.account-row-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-row-meta { font-size: 11.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-check { color: var(--accent); font-weight: 700; }
.account-add {
  display: flex; align-items: center; gap: 10px; width: calc(100% - 16px);
  margin: 4px 8px 8px; padding: 9px 12px; border: 1px dashed var(--border);
  border-radius: 10px; background: transparent; color: var(--accent); font-size: 13.5px; font-weight: 600;
}
.account-add:hover { background: var(--accent-light); }

.drawer-menu { padding: 6px 8px 16px; }
.drawer-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 11px 12px; border: none; border-radius: 10px;
  background: transparent; color: var(--text-primary); font-size: 14px; font-weight: 500; text-align: left;
}
.drawer-item:hover { background: var(--bg-hover); }
.drawer-item svg { width: 21px; height: 21px; color: var(--text-secondary); flex-shrink: 0; }
.drawer-item .item-badge {
  margin-left: auto; font-size: 11px; font-weight: 700; padding: 3px 8px;
  border-radius: 999px; background: var(--bg-elevated); color: var(--text-secondary); white-space: nowrap;
}
.drawer-item .item-badge.premium { background: linear-gradient(135deg, #ffd66b, #f0a500); color: #1b1300; }
.drawer-item .item-badge.admin { background: rgba(82, 136, 193, .18); color: #7fb5e8; }
.drawer-item.danger, .drawer-item.danger svg { color: var(--danger); }
.drawer-divider { height: 1px; background: var(--divider); margin: 6px 10px; }
.drawer-switch { margin-left: auto; }

/* ============================ MODALS ============================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 120;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(0, 0, 0, .64); backdrop-filter: blur(3px);
}
.modal {
  width: 100%; max-width: 470px; max-height: 90dvh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
}
.modal.wide { max-width: 680px; }
.settings-modal { max-width: 560px; height: min(88dvh, 780px); }
.modal-header {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 16px; border-bottom: 1px solid var(--divider); flex-shrink: 0;
}
.modal-title { flex: 1; font-size: 16.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--divider); display: flex; gap: 8px; justify-content: flex-end; flex-shrink: 0; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* Profile */
.profile-hero { text-align: center; padding: 22px 18px 14px; }
.profile-hero .avatar-circle { width: 96px; height: 96px; font-size: 34px; margin: 0 auto 12px; }
.profile-name { display: flex; align-items: center; justify-content: center; gap: 7px; font-size: 21px; font-weight: 700; }
.profile-status { font-size: 13px; color: var(--online); margin-top: 4px; }
.profile-status.offline { color: var(--text-secondary); }
.profile-bio { margin: 10px 16px 0; font-size: 13.5px; color: var(--text-secondary); line-height: 1.45; }
.profile-rows { padding: 8px 0 4px; }
.profile-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 18px; cursor: pointer;
}
.profile-row:hover { background: var(--bg-hover); }
.profile-row-value { font-size: 14.5px; font-weight: 600; }
.profile-row-label { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }
.pill {
  border: none; border-radius: 999px; padding: 5px 11px;
  background: var(--accent-light); color: var(--accent); font-size: 12px; font-weight: 600;
}
.nft-title { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); margin: 18px 18px 8px; }
.nft-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 9px; padding: 0 18px 18px; }
.nft-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px; padding: 12px 8px; text-align: center; }
.nft-card .nft-emoji { font-size: 32px; line-height: 1; }
.nft-card .nft-name { font-size: 11.5px; font-weight: 700; margin-top: 7px; }
.nft-card .nft-rarity { font-size: 10px; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .05em; }
.nft-card.legendary { border-color: rgba(240, 165, 0, .42); box-shadow: inset 0 0 22px rgba(240, 165, 0, .08); }
.nft-card.epic { border-color: rgba(168, 85, 247, .35); }

/* Settings */
.settings-list { display: flex; flex-direction: column; gap: 2px; }
.settings-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 12px; border: none; border-radius: 11px;
  background: transparent; color: var(--text-primary); text-align: left;
}
.settings-item:hover { background: var(--bg-hover); }
.settings-item svg { width: 22px; height: 22px; color: var(--text-secondary); flex-shrink: 0; }
.settings-item-body { flex: 1; min-width: 0; display: block; }
.settings-item-title { display: block; font-size: 14px; font-weight: 600; }
.settings-item-sub { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 2px; line-height: 1.4; }
.settings-item .chevron { color: var(--text-muted); font-size: 18px; }
.settings-section-title {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); margin: 16px 4px 8px;
}
.settings-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-bottom: 12px;
}
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 11px 2px; border-bottom: 1px solid var(--divider);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: 14px; font-weight: 500; }
.toggle-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.switch {
  position: relative; width: 44px; height: 25px; min-width: 44px;
  border: none; border-radius: 999px; background: #3b4b5b; transition: background .2s ease;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px;
  border-radius: 50%; background: #fff; transition: transform .2s ease;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(19px); }

.range { width: 100%; accent-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.wallpaper-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.wallpaper-tile {
  height: 78px; border-radius: 11px; border: 2px solid transparent;
  background-color: #0e1621; background-size: cover; background-position: center;
  display: flex; align-items: flex-end; justify-content: center; padding: 6px;
  color: #fff; font-size: 10.5px; font-weight: 700; text-shadow: 0 1px 4px #000;
}
.wallpaper-tile.active { border-color: var(--accent); }
.wallpaper-tile[data-preset="capi"] { background-image: var(--wallpaper-image); background-size: 120px; }
.wallpaper-tile[data-preset="midnight"] { background-image: radial-gradient(circle at 30% 30%, rgba(82,136,193,.35), transparent 55%), linear-gradient(160deg, #090e14, #17212b); }
.wallpaper-tile[data-preset="tangerine"] { background-image: radial-gradient(circle at 70% 30%, rgba(240,165,0,.35), transparent 55%), linear-gradient(160deg, #1a1206, #0e1621); }
.wallpaper-tile[data-preset="plain"] { background-image: none; }
.mini-status-img { width: 19px; height: 19px; border-radius: 50%; object-fit: cover; vertical-align: middle; }
.status-emoji { font-size: 16px; line-height: 1; }

.premium-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 6px; border-radius: 6px;
  background: linear-gradient(135deg, #ffd66b, #f0a500);
  color: #1b1300; font-size: 10px; font-weight: 800; letter-spacing: .03em;
}
.admin-badge {
  display: inline-flex; padding: 2px 6px; border-radius: 6px;
  background: rgba(82, 136, 193, .2); color: #7fb5e8;
  font-size: 10px; font-weight: 800; letter-spacing: .04em;
}

/* ============================ ADMIN ============================ */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 14px; }
.admin-stat { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 11px; }
.admin-stat b { display: block; font-size: 19px; }
.admin-stat span { font-size: 11.5px; color: var(--text-secondary); }
.admin-tabs { display: flex; gap: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--divider); padding-bottom: 8px; flex-wrap: wrap; }
.admin-tab {
  border: none; border-radius: 9px; padding: 7px 12px; background: transparent;
  color: var(--text-secondary); font-size: 13px; font-weight: 600;
}
.admin-tab.active { background: var(--accent-light); color: var(--accent); }
.admin-search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.admin-search-row .input { flex: 1; }
.admin-user-row, .admin-order-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; gap: 12px; padding: 12px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 8px;
}
.admin-user-info { min-width: 0; }
.admin-user-name { font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.admin-user-meta { font-size: 11.5px; color: var(--text-secondary); margin-top: 3px; word-break: break-word; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.admin-action-btn {
  min-height: 30px; padding: 0 9px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-primary); font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.admin-action-btn:hover { border-color: var(--accent); color: var(--accent); }
.admin-action-btn.danger { color: var(--danger); border-color: rgba(229, 101, 85, .35); }
.admin-action-btn.success { color: var(--online); border-color: rgba(78, 204, 94, .35); }
.admin-empty { font-size: 13px; color: var(--text-secondary); padding: 14px; text-align: center; line-height: 1.5; }
.admin-edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 600px) {
  .admin-user-row, .admin-order-row { grid-template-columns: 1fr; }
  .admin-actions { justify-content: flex-start; }
  .admin-edit-grid { grid-template-columns: 1fr; }
}

/* Wallet / premium */
.wallet-hero {
  background: linear-gradient(135deg, rgba(240, 165, 0, .2), rgba(255, 214, 107, .06));
  border: 1px solid rgba(240, 165, 0, .3); border-radius: 16px;
  padding: 16px; margin-bottom: 14px;
}
.wallet-balance { font-size: 34px; font-weight: 800; line-height: 1.1; }
.wallet-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 4px; }
.wallet-premium { margin-top: 9px; font-size: 13px; font-weight: 700; color: #f0b429; }
.wallet-tx-title { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); margin: 16px 0 8px; }
.wallet-tx-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.wallet-tx-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--bg-elevated); }
.wallet-tx-meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wallet-tx-desc { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-tx-date { font-size: 11px; color: var(--text-secondary); }
.wallet-tx-amount { font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.wallet-tx-amount.plus { color: var(--online); }
.wallet-tx-amount.minus { color: var(--danger); }

.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.plan-card {
  text-align: left; padding: 13px; border-radius: 13px;
  border: 1.5px solid var(--border); background: var(--bg-elevated);
  color: var(--text-primary);
}
.plan-card:hover { border-color: var(--accent); }
.plan-card.active { border-color: var(--accent); background: var(--accent-light); }
.plan-name { font-size: 13.5px; font-weight: 700; }
.plan-price { font-size: 19px; font-weight: 800; margin-top: 4px; }
.plan-price span { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
@media (max-width: 440px) { .plan-grid { grid-template-columns: 1fr; } }

.hint-box { background: var(--bg-elevated); border-radius: 11px; padding: 11px 12px; font-size: 12px; color: var(--text-secondary); line-height: 1.5; margin: 10px 0; }
.hint-box b { color: var(--text-primary); }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.preset-btn {
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-primary);
  border-radius: 9px; padding: 8px 13px; font-size: 13px; font-weight: 600;
}
.preset-btn:hover, .preset-btn.active { border-color: var(--accent); color: var(--accent); }

/* QR / lightbox / toast */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px; }
.qr-box img { width: 230px; height: 230px; border-radius: 12px; background: #fff; padding: 8px; }
.qr-link { font-size: 12px; color: var(--text-secondary); word-break: break-all; text-align: center; }

.lightbox {
  position: fixed; inset: 0; z-index: 160; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(0, 0, 0, .88); cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 200; max-width: min(420px, calc(100vw - 32px));
  padding: 10px 18px; border-radius: 20px;
  background: rgba(18, 28, 38, .96); border: 1px solid var(--border);
  color: #fff; font-size: 13.5px; font-weight: 500;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .4); text-align: center;
}

.lock-screen {
  position: fixed; inset: 0; z-index: 180; display: flex; align-items: center; justify-content: center;
  background: var(--bg-app); padding: 20px;
}
.lock-card { width: 100%; max-width: 340px; text-align: center; }
.lock-card .lock-icon { font-size: 44px; margin-bottom: 12px; }
.lock-card h2 { font-size: 20px; margin-bottom: 6px; }
.lock-card p { font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 1080px) {
  :root { --sidebar-width: 340px; }
}

@media (max-width: 820px) {
  :root { --sidebar-width: 100%; }
  .app-shell { display: block; }
  .sidebar {
    width: 100%; max-width: none; min-width: 0; height: 100dvh;
    border-right: none;
  }
  .chat-pane {
    position: fixed; inset: 0; z-index: 60; display: none;
    width: 100%; height: 100dvh;
  }
  .app-shell.chat-open .chat-pane { display: flex; }
  .app-shell.chat-open .sidebar { display: none; }
  .mobile-back-btn { display: inline-flex; }
  .chat-header { height: 58px; min-height: 58px; padding: 0 8px; gap: 6px; }
  .chat-header-left { gap: 7px; }
  .chat-header-actions .icon-btn { width: 38px; height: 38px; min-width: 38px; }
  .messages-viewport { padding: 12px 10px 8px; }
  .msg-row { max-width: 88%; }
  .bubble { font-size: 15px; }
  .composer-wrap { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer { gap: 2px; padding: 5px 6px; border-radius: 14px; }
  .composer .icon-btn { width: 38px; height: 38px; min-width: 38px; }
  .composer-input { font-size: 16px; }
  .chat-item { padding: 10px 12px; }
  .popover { right: 8px; left: 8px; width: auto; bottom: 74px; }
  .auth-card { padding: 28px 20px 24px; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 94dvh; border-radius: 18px 18px 0 0; }
  .settings-modal { height: 94dvh; max-width: none; }
  .drawer-profile { padding-top: calc(18px + env(safe-area-inset-top)); }
}

@media (max-width: 520px) {
  .chat-item .avatar-circle { width: 46px; height: 46px; }
  .msg-row .avatar-circle { display: none; }
  .msg-image { max-width: 78vw; }
  .nft-grid { grid-template-columns: repeat(3, 1fr); }
  .plan-grid { grid-template-columns: 1fr; }
  .wallpaper-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 821px) {
  .app-shell.chat-open .chat-pane { display: flex; }
}
