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

:root {
  --vk: #4a76a8;
  --vk-dark: #3d6a99;
  --vk-light: #e8f0f9;
  --orange: #ff9500;
  --orange-light: #fff3e0;
  --orange-border: #ffb347;
  --red: #ff3b30;
  --bg: #f0f2f5;
  --white: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: rgba(0,0,0,0.1);
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ── */
#app { height: 100dvh; display: flex; flex-direction: column; }

/* ── SCREENS ── */
.screen { display: none; flex-direction: column; height: 100%; }
.screen.active { display: flex; }

/* ── HEADER ── */
.header {
  background: var(--vk);
  color: #fff;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.header h1 { font-size: 15px; font-weight: 500; flex: 1; }
.header-btn {
  background: none; border: none; color: #fff;
  font-size: 22px; cursor: pointer; padding: 4px;
  position: relative; line-height: 1;
}
.header-dot {
  position: absolute; top: 2px; right: 2px;
  width: 8px; height: 8px;
  background: var(--red); border-radius: 50%;
  border: 1.5px solid var(--vk);
}

/* ── TABS ── */
.tabs {
  background: var(--vk-dark);
  display: flex;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 14px;
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
  user-select: none;
}
.tab.active { color: #fff; border-bottom-color: #fff; }
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--red); color: #fff;
  border-radius: 10px; font-size: 10px;
  padding: 1px 5px; margin-left: 4px;
  font-weight: 600; line-height: 1.4;
}
.tab-dot {
  position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px;
  background: var(--red); border-radius: 50%;
}

/* ── SEARCH ── */
.search-wrap { padding: 8px; background: var(--bg); flex-shrink: 0; }
.search-wrap input {
  width: 100%; background: #fff;
  border: none; border-radius: 20px;
  padding: 8px 14px 8px 36px;
  font-size: 14px; color: var(--text);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236b7280' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  outline: none;
}

/* ── SECTION LABEL ── */
.section-label {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  padding: 8px 12px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── DIALOG LIST ── */
.dialogs { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }

.dialog {
  background: var(--white);
  border-radius: var(--radius);
  margin-bottom: 6px;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  border: 0.5px solid transparent;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.dialog:active { background: #f5f7fa; }

.dialog.unanswered {
  background: var(--orange-light);
  border-color: var(--orange-border);
  animation: glow 2.5s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,179,71,0); }
  50% { box-shadow: 0 0 0 3px rgba(255,179,71,0.25); }
}

.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--vk);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 500;
  flex-shrink: 0; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.dialog-body { flex: 1; min-width: 0; }
.dialog-name {
  font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 5px;
  flex-wrap: wrap;
}
.tag-unanswered {
  font-size: 10px; font-weight: 600;
  background: #fff0dd; color: #b36200;
  border: 0.5px solid var(--orange-border);
  border-radius: 5px; padding: 1px 5px;
}
.dialog-community { font-size: 11px; color: var(--vk); margin-top: 1px; }
.dialog-preview {
  font-size: 12px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}

.dialog-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.dialog-time { font-size: 11px; color: var(--text-muted); }
.badge {
  border-radius: 10px; font-size: 11px; padding: 2px 7px;
  font-weight: 600; line-height: 1.4;
}
.badge-blue { background: var(--vk); color: #fff; }
.badge-orange { background: var(--orange); color: #fff; }

/* ── BOTTOM NAV ── */
.bottom-nav {
  background: var(--white);
  border-top: 0.5px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: calc(8px + var(--safe-bottom));
  flex-shrink: 0;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 10px;
  padding: 4px 12px; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--vk); }
.nav-btn svg { width: 24px; height: 24px; }
.nav-badge {
  position: absolute; top: 0; right: 4px;
  background: var(--red); color: #fff;
  border-radius: 10px; font-size: 9px; padding: 1px 4px;
  font-weight: 600; line-height: 1.4;
}

/* ── CHAT SCREEN ── */
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.msg {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14px; line-height: 1.5;
}
.msg-in {
  background: var(--white);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.msg-out {
  background: var(--vk); color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.msg-time {
  font-size: 10px; opacity: 0.65;
  margin-top: 2px; text-align: right;
}

.chat-input-area {
  background: var(--white);
  border-top: 0.5px solid var(--border);
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  display: flex; gap: 8px; align-items: flex-end;
  position: sticky;
  bottom: 0;
  z-index: 10;
}
.chat-input-area textarea {
  flex: 1; border: 0.5px solid var(--border);
  border-radius: 20px; padding: 8px 14px;
  font-size: 14px; resize: none; outline: none;
  font-family: inherit; max-height: 120px;
  background: var(--bg);
}
.send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--vk); border: none; cursor: pointer;
  color: #fff; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.send-btn:active { opacity: 0.8; }
.send-btn svg { width: 20px; height: 20px; }

/* ── LOGIN SCREEN ── */
.login-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100vh; gap: 24px; padding: 32px;
  background: var(--vk);
}
.login-logo {
  width: 80px; height: 80px; background: rgba(255,255,255,0.15);
  border-radius: 22px;
  display: flex; align-items: center; justify-content: center;
}
.login-logo svg { width: 48px; height: 48px; fill: #fff; }
.login-screen h1 { color: #fff; font-size: 24px; font-weight: 600; text-align: center; }
.login-screen p { color: rgba(255,255,255,0.75); text-align: center; font-size: 15px; }
.login-btn {
  background: #fff; color: var(--vk);
  border: none; border-radius: 24px;
  padding: 14px 40px; font-size: 16px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  display: inline-block;
}

/* ── TOKEN MODAL ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white); border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  width: 100%; max-width: 480px;
}
.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.modal p { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.5; }
.modal input {
  width: 100%; border: 0.5px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
  font-size: 14px; outline: none; margin-bottom: 12px;
}
.modal-btns { display: flex; gap: 8px; }
.btn-primary {
  flex: 1; background: var(--vk); color: #fff;
  border: none; border-radius: 10px;
  padding: 12px; font-size: 15px; font-weight: 500; cursor: pointer;
}
.btn-secondary {
  flex: 1; background: var(--bg); color: var(--text);
  border: none; border-radius: 10px;
  padding: 12px; font-size: 15px; cursor: pointer;
}

/* ── EMPTY / LOADING ── */
.empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; gap: 12px; color: var(--text-muted);
  padding: 32px;
}
.empty svg { width: 48px; height: 48px; opacity: 0.3; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--vk);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
