:root {
  --accent: #5865F2;
  --bg: #1e1f22;
  --bg-elevated: #2b2d31;
  --bg-panel: #313338;
  --bg-hover: #35373c;
  --text: #f2f3f5;
  --text-muted: #949ba4;
  --border: #3f4147;
  --danger: #da373c;
  --success: #23a55a;
  --warning: #f0a020;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --radius-sm: 6px;
}
[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f2f3f5;
  --bg-panel: #ffffff;
  --bg-hover: #ebedef;
  --text: #1e1f22;
  --text-muted: #5c5e66;
  --border: #e3e5e8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; transition: background 0.15s ease, opacity 0.15s ease; }
input, textarea, select { font-family: inherit; }

/* --- Icon system --- */
.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  vertical-align: middle;
}
.icon-lg { width: 22px; height: 22px; }
.icon-sm { width: 14px; height: 14px; }

/* --- Auth --- */
.screen { height: 100vh; }
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(88,101,242,0.12), transparent 50%), var(--bg);
}
.auth-card {
  background: var(--bg-elevated); padding: 36px; border-radius: 16px; width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.auth-card h1 {
  text-align: center; color: var(--accent); margin: 0 0 24px; font-size: 28px; font-weight: 800;
  letter-spacing: -0.02em;
}
.auth-tabs { display: flex; margin-bottom: 20px; border-radius: 10px; overflow: hidden; background: var(--bg-panel); padding: 4px; }
.tab-btn {
  flex: 1; padding: 9px; border: none; background: transparent; color: var(--text-muted);
  border-radius: 8px; font-weight: 600; font-size: 14px;
}
.tab-btn.active { background: var(--accent); color: white; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 14px; outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-form button[type=submit] {
  padding: 12px; border-radius: var(--radius-sm); border: none; background: var(--accent); color: white;
  font-weight: 700; font-size: 14px; margin-top: 4px;
}
.auth-form button[type=submit]:hover { opacity: 0.92; }
.checkbox-row { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; }
.checkbox-row input { accent-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex;
  align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(2px);
}
.modal-content {
  background: var(--bg-elevated); padding: 28px; border-radius: 14px; max-width: 480px; width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.modal-content h2 { margin-top: 0; font-size: 19px; }
.modal-content label { font-size: 12px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; letter-spacing: 0.03em; }
.modal-content button {
  margin-top: 12px; padding: 10px 18px; border: none; border-radius: var(--radius-sm); background: var(--accent);
  color: white; font-weight: 600; font-size: 14px; margin-right: 8px;
}
.modal-content button:hover { opacity: 0.92; }
.modal-content input, .modal-content textarea, .modal-content select {
  width: 100%; padding: 9px 12px; margin-bottom: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px;
}
.modal-content input[type=color] { padding: 4px; height: 38px; cursor: pointer; }

/* --- App layout --- */
#app-screen { display: flex; flex-direction: column; height: 100vh; }
.app-layout { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.sidebar {
  width: 250px; background: var(--bg-elevated); display: flex; flex-direction: column;
  border-right: 1px solid var(--border); flex-shrink: 0; height: 100%; overflow-y: auto;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid var(--border);
}
.avatar-sm { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--border); flex-shrink: 0; }
#my-username { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.nav-section { padding: 10px 12px; overflow-y: auto; }
.nav-section.bottom { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; }
.nav-section-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; font-weight: 700;
  letter-spacing: 0.04em; padding: 0 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 10px; border: none;
  background: transparent; color: var(--text-muted); border-radius: var(--radius-sm); margin-bottom: 2px; font-size: 14px;
  font-weight: 500;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent); color: white; }
.friend-item, .group-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 14px; color: var(--text);
}
.friend-item:hover, .group-item:hover { background: var(--bg-hover); }
.friend-item.active, .group-item.active { background: var(--accent); color: white; }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.presence-dot.online { background: var(--success); box-shadow: 0 0 0 2px rgba(35,165,90,0.25); }

.icon-btn {
  background: transparent; border: none; color: var(--text-muted); position: relative;
  display: inline-flex; align-items: center; justify-content: center; padding: 6px; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.small { padding: 3px; }
.icon-btn.small .icon { width: 14px; height: 14px; }
.badge {
  position: absolute; top: -2px; right: -2px; background: var(--danger); color: white; border-radius: 10px;
  font-size: 10px; padding: 1px 5px; min-width: 14px; text-align: center; font-weight: 700; line-height: 1.4;
}

.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-panel); min-width: 0; height: 100%; min-height: 0; }
.chat-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.chat-header h2 { margin: 0; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.message-row { display: flex; gap: 12px; align-items: flex-start; }
.message-row .avatar-sm { margin-top: 2px; }
.message-body { max-width: 70%; }
.message-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.message-meta .name { color: var(--text); font-weight: 700; }
.message-bubble {
  background: var(--bg-elevated); padding: 10px 14px; border-radius: var(--radius); word-wrap: break-word;
  white-space: pre-wrap; font-size: 14.5px; line-height: 1.5;
}
.message-bubble.filtered-warn { border: 1px solid var(--warning); }
.report-link {
  font-size: 11px; color: var(--text-muted); cursor: pointer; opacity: 0; transition: opacity 0.15s ease;
  display: inline-flex; align-items: center;
}
.message-row:hover .report-link { opacity: 1; }
.report-link:hover { color: var(--danger); }
.delete-link { padding: 0 2px; }
.typing-indicator { padding: 0 20px; font-size: 12px; color: var(--text-muted); min-height: 20px; font-style: italic; }

.message-form {
  display: flex; gap: 10px; padding: 10px 20px 20px; align-items: center; flex-shrink: 0;
}
.message-form input {
  flex: 1; padding: 12px 16px; border-radius: 22px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 14px; outline: none;
}
.message-form input:focus { border-color: var(--accent); }
.message-form button {
  padding: 11px 20px; border-radius: 22px; border: none; background: var(--accent); color: white; font-weight: 700;
  font-size: 14px;
}
.message-form button:hover { opacity: 0.92; }

.online-panel {
  width: 210px; background: var(--bg-elevated); border-left: 1px solid var(--border); padding: 16px 14px; flex-shrink: 0;
  overflow-y: auto;
}
.online-panel h3 {
  font-size: 11px; text-transform: uppercase; color: var(--text-muted); margin: 0 0 12px; font-weight: 700;
  letter-spacing: 0.04em;
}

.announcement-banner {
  background: #3b4252; color: #ffffff; padding: 10px 16px; text-align: center; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .online-panel { display: none; }
  .sidebar { width: 210px; }
}
