/* ═══════════════════════════════════════════════════════════════════════════
   CityChat — main.css
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Custom properties (light theme) ──────────────────────────────────────── */
:root {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --surface2:    #f7f8fa;
  --border:      #e0e0e0;
  --text:        #1a1a2e;
  --text-muted:  #6b7280;
  --accent:      #007cba;
  --accent-h:    #005f8e;
  --danger:      #d63638;
  --success:     #43a047;
  --msg-other:   #ffffff;
  --msg-mine:    #dcf1ff;
  --msg-private: #fff3e0;
  --msg-system:  transparent;
  --shadow:      0 2px 8px rgba(0,0,0,.08);
  --radius:      12px;
  --header-h:    60px;
  --input-h:     68px;
  --sidebar-w:   220px;
}

/* ── Dark theme ───────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface2:    #1c2128;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #58a6ff;
  --accent-h:    #79b8ff;
  --msg-other:   #1c2128;
  --msg-mine:    #0c2d48;
  --msg-private: #2d1f00;
  --msg-system:  transparent;
  --shadow:      0 2px 8px rgba(0,0,0,.3);
}

/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

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

/* ══════════════════════════════════════════════════════════════════════════
   BACKGROUND CHAT (blurred decoration)
═══════════════════════════════════════════════════════════════════════════ */
#bg-chat {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; gap: 18px;
  padding: 40px 60px;
  pointer-events: none;
  z-index: 0;
}

.bg-msg { display: flex; align-items: flex-start; gap: 10px; max-width: 480px; }
.bg-msg--b { align-self: flex-end; flex-direction: row-reverse; margin-left: auto; }

.bg-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.bg-bubble {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-muted);
  box-shadow: var(--shadow);
}

#bg-overlay {
  position: fixed; inset: 0;
  backdrop-filter: blur(12px) brightness(.95) saturate(.8);
  -webkit-backdrop-filter: blur(12px) brightness(.95) saturate(.8);
  background: rgba(240,242,245,.55);
  z-index: 1;
}

[data-theme="dark"] #bg-overlay {
  background: rgba(13,17,23,.72);
}

/* ══════════════════════════════════════════════════════════════════════════
   AUTH PANEL
═══════════════════════════════════════════════════════════════════════════ */
#auth-panel {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
  width: 100%; max-width: 420px;
  padding: 32px 36px;
  position: relative;
}

.auth-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 22px; font-weight: 700; color: var(--accent);
  margin-bottom: 24px;
  justify-content: center;
}

/* Tabs */
.auth-tabs {
  display: flex; gap: 4px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1; padding: 9px; border: none; background: none;
  border-radius: 6px; font-weight: 600; font-size: 14px;
  color: var(--text-muted); transition: .2s;
}
.auth-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* Fields */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
}
.field label small { font-weight: 400; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface2); color: var(--text);
  transition: border-color .2s;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}

/* City row */
.city-row { display: flex; gap: 8px; }
.city-row select { flex: 1; }
.city-row #btn-geo {
  width: 44px; height: 44px; flex-shrink: 0;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface2); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: .2s;
}
.city-row #btn-geo:hover { border-color: var(--accent); color: var(--accent); }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.hint-center { text-align: center; font-size: 14px; color: var(--text-muted); margin-bottom: 16px; }

/* Buttons */
.btn-primary {
  width: 100%; padding: 13px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  font-size: 15px; font-weight: 700;
  transition: background .2s;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:disabled { opacity: .6; pointer-events: none; }

.btn-ghost {
  width: 100%; padding: 10px;
  background: none; color: var(--text-muted);
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; margin-top: 8px; transition: .2s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.error-msg {
  background: #fef2f2; border: 1px solid #fca5a5;
  color: var(--danger); border-radius: 6px;
  padding: 10px 12px; font-size: 13px;
  margin-bottom: 12px;
}
[data-theme="dark"] .error-msg { background: #2d1212; border-color: #7f1d1d; }

/* Registration success */
.reg-success {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 16px 0; text-align: center;
}
.reg-success p { font-size: 16px; font-weight: 600; color: var(--success); }

/* ══════════════════════════════════════════════════════════════════════════
   CHAT APP LAYOUT
═══════════════════════════════════════════════════════════════════════════ */
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  z-index: 5;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#chat-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; gap: 12px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 10;
}

.header-logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 16px; color: var(--accent);
}
.header-left, .header-right { display: flex; align-items: center; gap: 10px; }
.header-center { flex: 1; display: flex; justify-content: center; }

.city-badge {
  background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700; border-radius: 20px;
  padding: 3px 10px;
}

#online-indicator {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
}
#online-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .4; }
}

/* User chip */
.user-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: 24px; padding: 5px 12px 5px 6px;
  font-size: 14px; font-weight: 600; color: var(--text);
  transition: .2s;
}
.user-chip:hover { border-color: var(--accent); }

.avatar-sm {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* Dropdown */
.user-menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  min-width: 160px; z-index: 100; overflow: hidden;
}
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 10px 14px;
  background: none; border: none; text-align: left;
  font-size: 14px; color: var(--text); transition: background .15s;
}
.dropdown-item:hover { background: var(--surface2); }
.dropdown-item.danger { color: var(--danger); }

.icon-btn {
  width: 36px; height: 36px; border: none; background: none;
  border-radius: 8px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface2); color: var(--accent); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
#chat-layout {
  flex: 1; display: flex; overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0; overflow-y: auto;
}
.sidebar-title {
  padding: 14px 16px 10px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted);
}
#online-list { list-style: none; padding: 0 8px 12px; }
#online-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 8px;
  font-size: 14px; cursor: pointer; transition: background .15s;
}
#online-list li:hover { background: var(--surface2); }
#online-list li .dot-sm {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); flex-shrink: 0;
}
#online-list li .pm-hint {
  margin-left: auto; font-size: 11px; color: var(--accent);
  opacity: 0; transition: opacity .15s;
}
#online-list li:hover .pm-hint { opacity: 1; }

/* ── Main chat ────────────────────────────────────────────────────────────── */
#chat-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; background: var(--bg);
  position: relative;
}

#messages-wrap {
  flex: 1; overflow-y: auto;
  padding: 20px 20px 8px;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}

#messages { display: flex; flex-direction: column; gap: 4px; }

/* ── Message bubbles ──────────────────────────────────────────────────────── */
.msg-group { margin-bottom: 12px; }

.msg-row {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 72%;
}
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.system-row {
  align-self: center; max-width: 90%;
  justify-content: center;
}

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0; align-self: flex-end;
}
.msg-row.mine .msg-avatar { display: none; }

.msg-content { display: flex; flex-direction: column; gap: 2px; }

.msg-meta {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 12px; margin-bottom: 3px;
}
.msg-row.mine .msg-meta { justify-content: flex-end; }
.msg-row.system-row .msg-meta { display: none; }

.msg-sender {
  font-weight: 700; color: var(--accent); cursor: pointer;
}
.msg-sender:hover { text-decoration: underline; }
.msg-time { color: var(--text-muted); font-size: 11px; }

.msg-bubble {
  display: inline-block;
  background: var(--msg-other);
  color: var(--text);
  padding: 9px 13px;
  border-radius: 16px 16px 16px 4px;
  box-shadow: var(--shadow);
  word-break: break-word; white-space: pre-wrap;
  font-size: 14px; line-height: 1.5;
  max-width: 100%;
  position: relative;
}
.msg-row.mine .msg-bubble {
  background: var(--msg-mine);
  border-radius: 16px 16px 4px 16px;
}

/* Private messages */
.msg-row.private .msg-bubble {
  background: var(--msg-private);
  border-left: 3px solid #f59e0b;
}
[data-theme="dark"] .msg-row.private .msg-bubble {
  border-left-color: #b45309;
}
.private-tag {
  font-size: 11px; font-weight: 700;
  color: #b45309; display: block; margin-bottom: 3px;
}
[data-theme="dark"] .private-tag { color: #fbbf24; }

/* System messages */
.msg-row.system-row .msg-bubble {
  background: none; box-shadow: none;
  font-size: 12px; color: var(--text-muted);
  font-style: italic; text-align: center;
  padding: 4px 8px;
}

/* Delete button on hover */
.msg-bubble-wrap { position: relative; }
.msg-delete-btn {
  position: absolute; top: -8px; right: -8px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff;
  border: none; font-size: 11px; line-height: 1;
  opacity: 0; transition: opacity .15s;
  display: flex; align-items: center; justify-content: center;
}
.msg-bubble-wrap:hover .msg-delete-btn { opacity: 1; }

/* File attachments */
.file-attachment {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--accent); text-decoration: none; font-size: 14px;
}
.file-attachment:hover { text-decoration: underline; }
.file-attachment svg { flex-shrink: 0; }

.msg-image { max-width: 280px; border-radius: 10px; display: block; }

/* ── PM bar ───────────────────────────────────────────────────────────────── */
#pm-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff8e1; border-top: 2px solid #f59e0b;
  padding: 8px 16px; font-size: 13px; color: #92400e;
  flex-shrink: 0;
}
[data-theme="dark"] #pm-bar { background: #2d1f00; color: #fbbf24; border-color: #b45309; }
#btn-pm-cancel {
  background: none; border: none; font-size: 16px;
  color: inherit; line-height: 1;
}

/* ── Input area ───────────────────────────────────────────────────────────── */
#input-area {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

#input-wrap { flex: 1; position: relative; }

#msg-input {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color .2s;
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}
#msg-input:focus { border-color: var(--accent); }

#file-preview {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; padding: 6px 10px;
  background: var(--surface2); border-radius: 8px;
  font-size: 13px; color: var(--text-muted);
}
#btn-file-clear { background: none; border: none; color: var(--danger); font-size: 16px; line-height: 1; }

/* Emoji picker */
.emoji-wrap { position: relative; }
#emoji-picker {
  position: absolute; bottom: calc(100% + 8px); left: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 10px; display: flex; flex-wrap: wrap;
  gap: 4px; width: 220px; z-index: 50;
}
.emoji-item {
  font-size: 20px; cursor: pointer; padding: 4px;
  border-radius: 6px; transition: background .15s;
  user-select: none;
}
.emoji-item:hover { background: var(--surface2); }

.btn-send {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s; flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-h); }
.btn-send:disabled { opacity: .5; pointer-events: none; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1a1a2e; color: #fff;
  padding: 10px 20px; border-radius: 24px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  z-index: 9999; transition: opacity .3s;
  white-space: nowrap;
}
#toast.success { background: var(--success); }
#toast.error   { background: var(--danger); }

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }

  #sidebar { display: none; }

  .auth-card { padding: 24px 20px; }

  .msg-row { max-width: 88%; }
  .msg-image { max-width: 200px; }

  #bg-chat { padding: 20px; }

  .header-logo span { display: none; }
}

@media (max-width: 400px) {
  .auth-card { padding: 20px 14px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   ADDITIONS: link-btn, new-msg-badge, history-spinner, forgot-form fixes
═══════════════════════════════════════════════════════════════════════════ */

.link-btn {
  background: none; border: none; color: var(--accent);
  font-size: 13px; cursor: pointer; padding: 0;
  text-decoration: underline;
}
.link-btn:hover { color: var(--accent-h); }

.new-msg-badge {
  position: absolute; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff;
  border: none; border-radius: 20px;
  padding: 6px 16px; font-size: 13px; font-weight: 600;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.2);
  z-index: 20; transition: opacity .2s;
}

.history-spinner {
  text-align: center; padding: 10px;
  font-size: 13px; color: var(--text-muted);
}

.emoji-wrap { position: relative; flex-shrink: 0; }

/* Online sidebar: italic "вы" */
#online-list li em { font-style: italic; color: var(--text-muted); font-size: 12px; }

/* Admin dropdown item: danger style */
.dropdown-item.danger { color: var(--danger); }
