:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3345;
  --text: #e8eaef;
  --text-muted: #8b92a8;
  --primary: #4f7cff;
  --primary-hover: #3d6aef;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --user-bubble: #2a3f6e;
  --admin-bubble: #2d3142;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Status icons */
.msg-status {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 4px;
}
.msg-status.sending { color: var(--warning); }
.msg-status.sent { color: var(--text-muted); }
.msg-status.read { color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Form */
.input {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--primary); }

.card.no-link { opacity: 0.65; cursor: not-allowed; }
.card.no-link:hover { transform: none; }
.input::placeholder { color: var(--text-muted); }

/* Chat bubbles */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}
.msg-row.user { align-self: flex-end; }
.msg-row.admin { align-self: flex-start; }
.msg-body {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
}
.msg-row.user .msg-body { flex-direction: row-reverse; }
.msg-delete-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
  margin-top: 6px;
}
.msg-row:hover .msg-delete-btn { opacity: 1; }
.msg-delete-btn:hover {
  background: var(--danger);
  color: #fff;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.msg-row.admin .msg-bubble {
  background: var(--admin-bubble);
  border-bottom-left-radius: 4px;
}
.msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg-row.user .msg-meta { justify-content: flex-end; }

/* Chat input */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-input-bar textarea {
  flex: 1;
  resize: none;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  max-height: 120px;
  min-height: 42px;
  line-height: 1.4;
}
.chat-input-bar textarea:focus { border-color: var(--primary); }
.chat-input-bar .btn-send {
  align-self: flex-end;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
}
.chat-input-bar .btn-attach {
  align-self: flex-end;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
  flex-shrink: 0;
}

.msg-media {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}
.msg-image { max-height: 280px; object-fit: contain; }
.msg-video { max-height: 280px; width: 100%; background: #000; }
.msg-file-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  word-break: break-all;
}
.msg-file-link:hover { text-decoration: underline; }
.msg-caption {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

/* Contact buttons */
.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.contact-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-decoration: none;
}
.contact-btn:hover {
  border-color: var(--primary);
  background: var(--surface);
  text-decoration: none;
}
.contact-btn .icon { font-size: 28px; }
.contact-btn .label { font-size: 12px; font-weight: 700; letter-spacing: .5px; }
.contact-btn.no-link { opacity: 0.65; cursor: not-allowed; }
.contact-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 8px;
  grid-column: 1 / -1;
}

/* Chat contact bar */
.chat-contact-section {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.chat-contact-section .section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.chat-contact-section .contact-grid {
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 0;
}
.chat-contact-section .contact-btn {
  padding: 8px 4px;
}
.chat-contact-section .contact-btn .icon { font-size: 20px; }
.chat-contact-section .contact-btn .label { font-size: 10px; }

@media (max-width: 640px) {
  .chat-contact-section .contact-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 640px) {
  .msg-row { max-width: 92%; }
  .chat-input-bar { padding: 10px 12px; }
  .msg-delete-btn { opacity: 1; }
  .conv-delete-btn { opacity: 1; }
}
