:root {
  --bg: #0b1020;
  --panel: #121a33;
  --panel-2: #18213d;
  --text: #f5f7fb;
  --muted: #96a3bd;
  --line: #27c65a;
  --facebook: #1877f2;
  --accent: #f0c15a;
  --danger: #ff6b6b;
  --ok: #58d68d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: radial-gradient(circle at top, #17214a, var(--bg));
  color: var(--text);
}

.topbar {
  height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(8, 12, 26, 0.85);
}

.topbar h1 { margin: 0; font-size: 24px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }

.admin-key-box { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.admin-key-box input,
.conversation-tools input,
.conversation-tools select {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - 86px);
}

.sidebar {
  border-right: 1px solid rgba(255,255,255,0.08);
  background: rgba(10, 15, 31, 0.7);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px;
}

.sidebar-head h2 { margin: 0; }
button {
  background: var(--accent);
  color: #151515;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: bold;
  cursor: pointer;
}
button:hover { filter: brightness(1.06); }

.filters {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
  overflow-x: auto;
}
.filter-btn {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  white-space: nowrap;
  padding: 8px 10px;
  font-size: 12px;
}
.filter-btn.active {
  background: var(--accent);
  color: #151515;
}

.conversation-list {
  overflow-y: auto;
  height: calc(100vh - 205px);
  padding: 0 10px 12px;
}

.conversation-item {
  padding: 14px;
  border-radius: 14px;
  margin-bottom: 10px;
  background: var(--panel);
  cursor: pointer;
  border: 1px solid transparent;
}
.conversation-item.empty-item { color: var(--muted); cursor: default; }

.conversation-card-main {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: start;
}

.conversation-card-content { min-width: 0; }

.customer-avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: rgba(255,255,255,0.14);
  border: 2px solid rgba(255,255,255,0.12);
}
.customer-avatar.line { border-color: rgba(39,198,90,0.55); background: rgba(39,198,90,0.18); }
.customer-avatar.facebook { border-color: rgba(24,119,242,0.55); background: rgba(24,119,242,0.18); }
.customer-avatar.large { width: 56px; height: 56px; font-size: 16px; }

.chat-header-profile {
  display: flex;
  align-items: center;
  gap: 14px;
}

.conversation-item.active,
.conversation-item:hover {
  border-color: rgba(240, 193, 90, 0.55);
  background: var(--panel-2);
}

.conversation-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: bold;
}
.badge.line { background: rgba(39,198,90,0.18); color: var(--line); }
.badge.facebook { background: rgba(24,119,242,0.18); color: #71aaff; }
.status { font-size: 12px; margin-left: auto; }
.status-new { color: var(--ok); }
.status-open { color: var(--accent); }
.status-pending { color: #ffb86b; }
.status-closed { color: var(--muted); }

.customer-name { font-weight: bold; }
.last-message { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 5px; }
.conversation-meta { color: var(--muted); font-size: 11px; margin-top: 8px; }

.chat-panel {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  min-width: 0;
}

.chat-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(18, 26, 51, 0.7);
}
.chat-header h2 { margin: 0; }
.chat-header p { margin: 6px 0 0; color: var(--muted); }

.conversation-tools {
  display: grid;
  grid-template-columns: 150px 170px 1fr 100px;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(10, 15, 31, 0.7);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  align-items: end;
}
.conversation-tools label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}
.note-label input { width: 100%; }
.hidden { display: none !important; }

.messages {
  padding: 22px;
  overflow-y: auto;
}
.messages.empty { color: var(--muted); display: flex; align-items: center; justify-content: center; }

.message-row {
  display: flex;
  margin-bottom: 12px;
}
.message-row.admin { justify-content: flex-end; }
.message-bubble {
  max-width: min(680px, 72%);
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel-2);
  line-height: 1.5;
  white-space: pre-wrap;
}
.message-row.admin .message-bubble {
  background: rgba(240,193,90,0.18);
  border: 1px solid rgba(240,193,90,0.32);
}
.message-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.quick-replies {
  display: flex;
  gap: 8px;
  padding: 10px 16px 0;
  background: rgba(8, 12, 26, 0.85);
  border-top: 1px solid rgba(255,255,255,0.08);
  overflow-x: auto;
}
.quick-replies button {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  white-space: nowrap;
  padding: 8px 11px;
  font-size: 12px;
}
.quick-replies button:hover { background: rgba(240,193,90,0.22); }

.reply-form {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 12px;
  padding: 16px;
  background: rgba(8, 12, 26, 0.85);
}
.reply-form textarea {
  width: 100%;
  resize: none;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: var(--panel);
  color: var(--text);
  padding: 12px;
  font-size: 15px;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { height: 320px; border-right: 0; border-bottom: 1px solid rgba(255,255,255,0.08); }
  .conversation-list { height: 230px; }
  .chat-panel { height: calc(100vh - 86px - 320px); }
  .reply-form { grid-template-columns: 1fr; }
  .conversation-tools { grid-template-columns: 1fr; }
}
.admin-key-box button {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.12);
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.admin-key-box button:hover {
  background: rgba(255,255,255,.2);
}

.admin-role-label {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(240,193,90,.18);
  color: var(--accent);
  font-size: 11px;
  vertical-align: middle;
}
#currentAdminEmail small {
  color: var(--muted);
  font-weight: normal;
}

.quick-reply-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 0 18px 10px;
}

.quick-reply-toolbar button,
.secondary {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  color: #e5e7eb;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
}

.quick-reply-empty {
  color: #94a3b8;
  font-size: 13px;
  padding: 8px 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.58);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(920px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 18px;
  box-shadow: 0 30px 90px rgba(0,0,0,0.45);
  padding: 20px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  color: #fff;
}

.modal-head p {
  margin: 4px 0 0;
  color: #94a3b8;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.quick-reply-form {
  display: grid;
  grid-template-columns: 1.4fr 120px;
  gap: 12px;
  background: rgba(15,23,42,0.8);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 16px;
}

.quick-reply-form label {
  color: #cbd5e1;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quick-reply-form .wide {
  grid-column: 1 / -1;
}

.quick-reply-form input,
.quick-reply-form textarea {
  background: #020617;
  border: 1px solid rgba(255,255,255,0.12);
  color: #f8fafc;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

.quick-reply-active {
  flex-direction: row !important;
  align-items: center;
}

.quick-reply-active input {
  width: auto;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.form-actions button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.quick-reply-manager-list {
  display: grid;
  gap: 10px;
}

.quick-reply-manager-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  padding: 12px;
}

.quick-reply-manager-item.disabled {
  opacity: 0.58;
}

.manager-title {
  color: #fff;
  font-weight: 800;
  margin-bottom: 4px;
}

.manager-text {
  color: #cbd5e1;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.5;
}

.manager-status {
  color: #94a3b8;
  font-size: 12px;
  margin-top: 4px;
}

.manager-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.manager-actions button {
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  color: #e5e7eb;
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
}

.manager-actions .danger {
  color: #fecaca;
  border-color: rgba(248,113,113,0.35);
}

.manager-empty {
  color: #94a3b8;
  padding: 12px;
}

@media (max-width: 720px) {
  .quick-reply-form,
  .quick-reply-manager-item {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .manager-actions {
    justify-content: flex-start;
  }
}


.message-text {
  white-space: pre-wrap;
}

.message-attachments {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.message-image-link {
  display: block;
  line-height: 0;
}

.message-image {
  display: block;
  max-width: min(280px, 70vw);
  max-height: 360px;
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(15, 23, 42, 0.08);
}

.message-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.08);
  color: inherit;
  text-decoration: none;
  font-size: 13px;
}

.message-file.muted {
  opacity: 0.72;
}
