* { box-sizing: border-box; margin: 0; padding: 0; }
:root[data-theme="dark"] {
  --bg: #0f1117; --bg2: #1a1d27; --accent: #6c5ce7; --text: #f1f1f5;
  --bubble-out: #6c5ce7; --bubble-in: #232634; --muted: #8a8d98;
}
:root[data-theme="light"] {
  --bg: #f5f6fa; --bg2: #ffffff; --accent: #6c5ce7; --text: #16181d;
  --bubble-out: #6c5ce7; --bubble-in: #eceef4; --muted: #6b6f7a;
}
:root[data-theme="amoled"] {
  --bg: #000000; --bg2: #0a0a0a; --accent: #00c2ff; --text: #ffffff;
  --bubble-out: #00c2ff; --bubble-in: #151515; --muted: #777;
}
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
body[data-font="rounded"] { font-family: 'Quicksand', sans-serif; }
body[data-font="mono"] { font-family: 'JetBrains Mono', monospace; }

.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* --- AUTH --- */
#screen-auth { align-items: center; justify-content: center; background: radial-gradient(circle at top, var(--bg2), var(--bg)); }
.auth-card { width: 380px; background: var(--bg2); border-radius: 20px; padding: 36px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.auth-card h1 { font-size: 28px; margin-bottom: 6px; color: var(--accent); }
.auth-card p.sub { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.input { width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid #3333; background: var(--bg); color: var(--text); margin-bottom: 12px; font-size: 15px; }
.btn { width: 100%; padding: 14px; border-radius: 12px; border: none; background: var(--accent); color: white; font-weight: 600; font-size: 15px; cursor: pointer; transition: transform .15s, opacity .15s; margin-bottom: 10px; }
.btn:hover { transform: scale(1.02); opacity: .92; }
.btn.secondary { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; display: block; margin-bottom: 12px; }
.link { color: var(--accent); font-size: 13px; cursor: pointer; text-align: center; display: block; margin-top: 8px; }

/* --- APP --- */
#screen-app { width: 100%; }
.sidebar { width: 340px; background: var(--bg2); display: flex; flex-direction: column; border-right: 1px solid #3333; }
.sidebar-header { padding: 18px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-header h2 { color: var(--accent); }
.tabs { display: flex; padding: 0 12px; gap: 8px; }
.tab { padding: 8px 14px; border-radius: 10px; cursor: pointer; color: var(--muted); font-size: 13px; }
.tab.active { background: var(--accent); color: white; }
.list { flex: 1; overflow-y: auto; padding: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; cursor: pointer; }
.list-item:hover { background: var(--bg); }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; color: white; flex-shrink: 0; }
.list-item-info { flex: 1; overflow: hidden; }
.list-item-info .name { font-weight: 600; font-size: 14px; }
.list-item-info .preview { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; display: flex; flex-direction: column; background: var(--wallpaper, var(--bg)); background-size: cover; }
.chat-header { padding: 16px 20px; background: var(--bg2); display: flex; align-items: center; justify-content: space-between; }
.chat-header .actions { display: flex; gap: 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--bg); color: var(--text); font-size: 16px; cursor: pointer; }
.icon-btn:hover { background: var(--accent); color: white; }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 60%; padding: 10px 14px; border-radius: 16px; font-size: 14px; position: relative; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); color: white; border-bottom-right-radius: 4px; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.bubble .meta { font-size: 11px; opacity: .7; margin-top: 4px; display: flex; gap: 4px; justify-content: flex-end; }

.composer { display: flex; gap: 10px; padding: 16px; background: var(--bg2); align-items: center; }
.composer .input { flex: 1; margin: 0; }

.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--bg2); border-radius: 20px; padding: 28px; width: 380px; max-height: 80vh; overflow-y: auto; }
.modal h3 { margin-bottom: 16px; color: var(--accent); }

.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid #3332; }
.switch { width: 44px; height: 24px; border-radius: 12px; background: #444; position: relative; cursor: pointer; }
.switch.on { background: var(--accent); }
.switch .dot { width: 18px; height: 18px; border-radius: 50%; background: white; position: absolute; top: 3px; left: 3px; transition: left .15s; }
.switch.on .dot { left: 23px; }

.call-overlay { position: fixed; inset: 0; background: #000c; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 200; color: white; }
.call-avatar { width: 120px; height: 120px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 40px; margin-bottom: 16px; }
.call-actions { display: flex; gap: 20px; margin-top: 30px; }
.call-btn { width: 60px; height: 60px; border-radius: 50%; border: none; font-size: 22px; cursor: pointer; }
.call-btn.end { background: #ff4757; color: white; }
.call-btn.accept { background: #2ed573; color: white; }
video { border-radius: 16px; max-width: 400px; margin: 8px; }

/* === МОБИЛЬНАЯ АДАПТАЦИЯ === */
#btn-back-mobile { display: none; }
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 10;
    transition: transform .25s ease;
  }
  .main { width: 100%; }
  #screen-app { position: relative; overflow: hidden; }
  #screen-app.chat-open .sidebar { transform: translateX(-100%); }
  #screen-app:not(.chat-open) .main { display: none; }
  #btn-back-mobile { display: inline-flex; }
  .bubble { max-width: 80%; }
  .auth-card { width: 92vw; padding: 24px; }
  video { max-width: 90vw; }
  .modal { width: 92vw; }
}
