:root {
  --bg: #0b141a;
  --bg-elevated: #111b21;
  --bg-panel: #202c33;
  --bg-hover: #2a3942;
  --border: #2f3b43;
  --text: #e9edef;
  --text-muted: #8696a0;
  --accent: #00a884;
  --accent-dark: #008f72;
  --danger: #ea4335;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --chat-bg: #0b141a;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --bubble-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.topbar-brand { display: flex; align-items: center; gap: 0.6rem; }
.topbar-nav { display: flex; gap: 0.75rem; flex: 1; }
.topbar-nav a {
  color: var(--text-muted);
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
}
.topbar-nav a.active,
.topbar-nav a:hover { color: var(--text); background: var(--bg-hover); }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; color: var(--text-muted); }

.logo-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--accent); display: inline-block;
}
.logo-dot.lg { width: 18px; height: 18px; }

.btn {
  border: 0; border-radius: 8px; padding: 0.55rem 1rem;
  font: inherit; cursor: pointer; transition: 0.15s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: rgba(234, 67, 53, 0.15); color: #ff8a80; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.9rem; }
.btn-block { width: 100%; }

.login-page {
  display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(circle at top, #1f2c34, var(--bg));
}
.login-card {
  width: min(420px, 92vw); background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 16px; padding: 2rem; box-shadow: var(--shadow);
}
.login-header { text-align: center; margin-bottom: 1.5rem; }
.login-header h1 { margin: 0.75rem 0 0.25rem; }
.login-header p { margin: 0; color: var(--text-muted); }
.login-form label { display: grid; gap: 0.35rem; margin-bottom: 1rem; color: var(--text-muted); font-size: 0.92rem; }
.login-form input,
.modal input,
.modal textarea,
.modal select,
.search-box input,
.chat-composer textarea {
  width: 100%; background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 0.9rem; font: inherit;
}
.form-error { color: #ff8a80; font-size: 0.9rem; }

.is-hidden { display: none !important; }

.wa-status { background: #182229; border-bottom: 1px solid var(--border); }
.wa-status-inner {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 1.25rem; flex-wrap: wrap;
}
.wa-status-inner #wa-account { flex: 1; min-width: 180px; }
.btn-link-wa-empty { margin-top: 1.25rem; padding: 0.7rem 1.5rem; }
.status-pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.25rem 0.65rem; border-radius: 999px; font-size: 0.85rem; background: var(--bg-hover);
}
.status-pill.online { color: #7dffb3; }
.status-pill.offline { color: #ffb4a9; }

.wa-nav-status {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.55rem; border-radius: 999px; font-size: 0.8rem;
  background: rgba(0, 168, 132, 0.15); color: #7dffb3;
}
.wa-nav-status::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}

.wa-qr-dialog { width: min(380px, 92vw); }
.wa-qr-dialog-body { padding: 1.25rem; display: grid; gap: 0.85rem; text-align: center; }
.wa-qr-dialog-body h3 { margin: 0; }
.wa-qr-hint { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.wa-qr-img {
  justify-self: center; background: #fff; padding: 0.75rem; border-radius: 12px;
  width: min(280px, 80vw); height: auto;
}

.chat-layout {
  display: grid; grid-template-columns: 360px 1fr; height: calc(100vh - 57px);
}
.chat-sidebar {
  border-right: 1px solid var(--border); background: var(--bg-elevated);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem; border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { margin: 0; font-size: 1.05rem; }
.search-box { padding: 0.5rem 0.85rem 0.75rem; }
.search-box input {
  background: var(--bg-panel); border: none; border-radius: 8px;
  padding: 0.55rem 0.85rem 0.55rem 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238696a0' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 0.65rem center;
}
.conversation-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.conversation-item {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.7rem 1rem; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.conversation-item:hover,
.conversation-item.active { background: var(--bg-hover); }
.conv-avatar {
  flex-shrink: 0; width: 49px; height: 49px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; font-size: 1.1rem; color: #fff;
}
.conv-body { flex: 1; min-width: 0; display: grid; gap: 0.15rem; }
.conversation-item strong {
  font-size: 1rem; font-weight: 400; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conversation-item small,
.conversation-preview { color: var(--text-muted); font-size: 0.8rem; }
.conversation-preview {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.conversation-meta {
  display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
}
.unread-badge {
  background: var(--accent); color: #111b21; border-radius: 999px;
  min-width: 1.25rem; height: 1.25rem; padding: 0 0.35rem;
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 600; flex-shrink: 0;
}

.chat-panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--chat-bg);
}
.chat-empty {
  margin: auto; text-align: center; color: var(--text-muted); max-width: 460px; padding: 2rem;
  border-bottom: 6px solid var(--accent);
}
.chat-empty-icon { color: var(--text-muted); opacity: 0.35; margin-bottom: 1.25rem; }
.chat-empty h3 { color: var(--text); font-weight: 300; font-size: 2rem; margin: 0 0 1rem; }
.chat-empty p { line-height: 1.6; margin: 0; font-size: 0.92rem; }

.chat-active { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.chat-header {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.65rem 1rem 0.65rem 1.25rem; background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  min-height: 60px;
}
.chat-header-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; color: #fff; flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info strong {
  display: block; font-size: 1rem; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-info small {
  display: block; color: var(--text-muted); margin-top: 0.1rem; font-size: 0.8rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-actions {
  display: flex; align-items: center; gap: 0.15rem; margin-left: auto;
}
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: grid; place-items: center; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn-sm { width: 32px; height: 32px; font-size: 1.25rem; }

.header-menu-wrap { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 50;
  min-width: 220px; background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); padding: 0.35rem 0;
}
.dropdown-item {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); padding: 0.65rem 1rem; font: inherit; cursor: pointer;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: #ff8a80; }
.dropdown-divider { border: 0; border-top: 1px solid var(--border); margin: 0.35rem 0; }

.chat-search-bar {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.5rem 1rem; background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.chat-search-bar input {
  flex: 1; border: none; background: transparent; color: var(--text); font: inherit;
  padding: 0.35rem 0;
}
.chat-search-bar input:focus { outline: none; }
.chat-search-empty {
  text-align: center; color: var(--text-muted); padding: 2rem; margin: 0;
}
mark.search-hit { background: rgba(255, 214, 102, 0.35); color: inherit; padding: 0 0.1rem; border-radius: 2px; }

.contact-info-dialog { width: min(360px, 92vw); }
.contact-info-body { padding: 1.5rem; text-align: center; position: relative; }
.contact-info-close { position: absolute; top: 0.75rem; right: 0.75rem; }
.contact-info-avatar {
  width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 1rem;
  display: grid; place-items: center; font-size: 2.2rem; font-weight: 600; color: #fff;
}
.contact-info-body h3 { margin: 0 0 0.25rem; font-weight: 400; font-size: 1.35rem; }
.contact-info-phone { margin: 0 0 1.25rem; color: var(--text-muted); }
.contact-info-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem;
  margin: 0; padding: 1rem 0 0; border-top: 1px solid var(--border); text-align: center;
}
.contact-info-stats dt { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.contact-info-stats dd { margin: 0; font-size: 1.1rem; font-weight: 500; }

.chat-messages-wrap {
  flex: 1; min-height: 0; overflow: hidden;
  background-color: var(--chat-bg);
  background-image: url('/img/wa-wallpaper.svg');
  background-size: 400px 400px;
  background-repeat: repeat;
}
.chat-messages {
  height: 100%; overflow: auto; padding: 1.25rem 5% 1rem;
  display: flex; flex-direction: column; gap: 0.12rem;
}

.message-row {
  display: flex; max-width: 65%; margin-bottom: 0.12rem;
}
.message-row.inbound { align-self: flex-start; }
.message-row.outbound { align-self: flex-end; margin-left: auto; }

.message-bubble {
  position: relative; padding: 0.38rem 0.55rem 0.28rem 0.65rem;
  line-height: 1.35; box-shadow: var(--bubble-shadow);
  max-width: 100%;
}
.message-row.inbound .message-bubble {
  background: var(--bubble-in);
  border-radius: 0 7.5px 7.5px 7.5px;
}
.message-row.inbound .message-bubble::before {
  content: '';
  position: absolute; top: 0; left: -8px;
  border-width: 0 8px 8px 0;
  border-style: solid;
  border-color: transparent var(--bubble-in) transparent transparent;
}
.message-row.outbound .message-bubble {
  background: var(--bubble-out);
  border-radius: 7.5px 0 7.5px 7.5px;
}
.message-row.outbound .message-bubble::before {
  content: '';
  position: absolute; top: 0; right: -8px;
  border-width: 8px 0 0 8px;
  border-style: solid;
  border-color: var(--bubble-out) transparent transparent transparent;
}

.message-sender {
  display: block; font-size: 0.72rem; font-weight: 600;
  color: rgba(255,255,255,0.75); margin-bottom: 0.15rem;
}
.message-text {
  display: inline; white-space: pre-wrap; word-break: break-word;
  font-size: 0.875rem; padding-right: 0.35rem;
}
.message-meta {
  float: right; margin-left: 0.5rem; margin-top: 0.35rem;
  display: inline-flex; align-items: center; gap: 0.2rem;
  position: relative; top: 0.25rem;
}
.message-meta time {
  font-size: 0.68rem; color: rgba(255,255,255,0.55); white-space: nowrap;
}

.chat-composer {
  display: flex; align-items: flex-end; gap: 0.5rem;
  padding: 0.55rem 1rem; background: var(--bg-elevated);
}
.composer-field {
  flex: 1; background: var(--bg-panel); border-radius: 8px;
  padding: 0.45rem 0.75rem;
}
.composer-field textarea {
  width: 100%; border: none; background: transparent; color: var(--text);
  resize: none; font: inherit; font-size: 0.95rem; line-height: 1.4;
  max-height: 120px; padding: 0.15rem 0;
}
.composer-field textarea:focus { outline: none; }
.btn-send {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center; flex-shrink: 0;
  transition: background 0.15s ease;
}
.btn-send:hover { background: var(--accent-dark); }

.page-content { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
.page-header {
  display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0 0 0.35rem; }
.page-header p { margin: 0; color: var(--text-muted); }
.table-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th,
.data-table td { padding: 0.9rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-muted); font-size: 0.85rem; font-weight: 600; }
.badge {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.8rem;
  background: var(--bg-hover);
}
.badge.admin { color: #9ad7ff; }
.badge.agent { color: #c6f6b0; }
.badge.inactive { color: #ffb4a9; }

.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--bg-elevated); color: var(--text);
  width: min(460px, 92vw);
}
.modal::backdrop { background: rgba(0,0,0,0.55); }
.modal form { padding: 1.25rem; display: grid; gap: 0.85rem; }
.modal h3 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 112px); }
  .chat-sidebar { max-height: 42vh; }
}
