@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f4f6f9;
  color: #222;
}

a {
  color: #0b5cff;
  text-decoration: none;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  background: #0b5cff;
  color: #fff;
  transition: background .15s;
}

button:hover {
  background: #0e6f63;
}

button.secondary {
  background: #6c757d;
}

button.secondary:hover {
  background: #565e64;
}

button.danger {
  background: #d9534f;
}

button.danger:hover {
  background: #b53b37;
}

button:disabled {
  background: #adb5bd;
  cursor: not-allowed;
}

input,
textarea,
select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #0b5cff;
  box-shadow: 0 0 0 2px rgba(18, 140, 126, .15);
}

label {
  display: block;
  margin: 10px 0 5px;
  font-size: 13px;
  color: #555;
  font-weight: 500;
}

/* LOGIN */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 30px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .08);
}

.login-card h1 {
  margin: 0 0 20px;
  font-size: 22px;
  text-align: center;
  color: #0b5cff;
}

.login-card .err {
  color: #d9534f;
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
}

/* APP LAYOUT */
.topbar {
  background: #0b5cff;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.topbar .user {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar button {
  background: rgba(255, 255, 255, .18);
  padding: 6px 12px;
  font-size: 13px;
}

.topbar button:hover {
  background: rgba(255, 255, 255, .3);
}

.tabs {
  background: #fff;
  border-bottom: 1px solid #e6e8eb;
  padding: 0 20px;
  display: flex;
  gap: 4px;
}

.tabs button {
  background: transparent;
  color: #555;
  border-radius: 0;
  padding: 14px 18px;
  border-bottom: 3px solid transparent;
  font-weight: 500;
}

.tabs button:hover {
  background: #f4f6f9;
}

.tabs button.active {
  color: #0b5cff;
  border-bottom-color: #0b5cff;
}

.container {
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}

.container.chat-view {
  max-width: 100%;
  height: calc(100dvh - 118px);
  min-height: calc(100dvh - 118px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.container.chat-view #tab-chats {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.container.chat-view #tab-chats > .section-header {
  flex: 0 0 auto;
}

.container.chat-view .chat-shell {
  flex: 1;
  min-height: 0;
  height: auto;
}

.container.chat-view .card {
  margin-bottom: 0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.section-header h2 {
  margin: 0;
  font-size: 19px;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
  margin-bottom: 16px;
}
.chat-sidebar-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(11, 92, 255, 0.10);
  border-radius: 18px;
  background:
    radial-gradient(circle at top left, rgba(11, 92, 255, 0.08), transparent 44%),
    linear-gradient(180deg, #ffffff, #f7fbff);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.chat-device-switcher {
  flex: 1;
  min-width: 0;
}

.chat-device-switcher label {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #5b6472;
}

.chat-device-switcher select {
  min-height: 44px;
  border-radius: 12px;
  border-color: #d7dfeb;
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.chat-device-switcher select:focus {
  border-color: #0b5cff;
  box-shadow: 0 0 0 3px rgba(11, 92, 255, 0.10);
}


.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-card .name {
  font-weight: 600;
  font-size: 16px;
}

.device-card .meta {
  font-size: 12px;
  color: #777;
  word-break: break-all;
}

.device-card .qr-box {
  background: #f4f6f9;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.device-card .qr-box img {
  width: 220px;
  max-width: 100%;
}

.device-card .actions {
  display: flex;
  gap: 8px;
}

.device-card .actions button {
  flex: 1;
}

.device-logs {
  margin-top: 4px;
  padding: 12px;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef3fb 100%);
  border: 1px solid #dfe7f4;
}

.device-logs-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: #344054;
  font-size: 12px;
}

.device-logs-state {
  color: #667085;
  text-align: right;
}

.device-logs-list {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
  padding-right: 2px;
}

.device-log-item {
  border-radius: 10px;
  padding: 10px 11px;
  background: #fff;
  border: 1px solid #e3e8ef;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03);
}

.device-log-item.warn {
  border-left: 4px solid #d98a00;
}

.device-log-item.error {
  border-left: 4px solid #d92d20;
}

.device-log-item.info {
  border-left: 4px solid #2563eb;
}

.device-log-item.debug {
  border-left: 4px solid #667085;
}

.device-log-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 11px;
  color: #667085;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.device-log-level {
  font-weight: 700;
}

.device-log-event {
  font-size: 13px;
  font-weight: 600;
  color: #101828;
  margin-bottom: 2px;
}

.device-log-message,
.device-log-details {
  font-size: 12px;
  line-height: 1.4;
  color: #475467;
  word-break: break-word;
}

.device-log-details {
  margin-top: 4px;
  color: #667085;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.device-log-empty {
  padding: 8px 2px;
  font-size: 12px;
  color: #667085;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.badge.connected {
  background: #d4edda;
  color: #155724;
}

.badge.superadmin {
  background: #e0cffc;
  color: #4b0082;
}

.badge.admin {
  background: #cce5ff;
  color: #004085;
}

.badge.user {
  background: #e2e3e5;
  color: #383d41;
}

.badge.qr {
  background: #fff3cd;
  color: #856404;
}

.badge.disconnected,
.badge.logged_out {
  background: #f8d7da;
  color: #721c24;
}

.badge.starting {
  background: #cfe2ff;
  color: #084298;
}

.empty {
  color: #888;
  text-align: center;
  padding: 30px;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #333;
  color: #fff;
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 1000;
  max-width: 320px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #d9534f;
}

.toast.success {
  background: #198754;
}

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1200;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.modal-header,
.modal-footer {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header {
  border-bottom: 1px solid #e6e8eb;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-header button {
  width: 36px;
  height: 36px;
  padding: 0;
  line-height: 1;
  border-radius: 999px;
  font-size: 22px;
}

.modal-body {
  padding: 18px;
}

.modal-help {
  margin: 10px 0 0;
  color: #666;
  font-size: 12px;
}

.modal-footer {
  border-top: 1px solid #e6e8eb;
  justify-content: flex-end;
}

.modal-footer button {
  min-width: 150px;
}

.modal-body hr {
  opacity: 1;
}

.doc-code {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* CHATS */
.chat-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  height: 100%;
  min-height: 0;
}

.chat-sidebar,
.chat-panel {
  margin-bottom: 0;
  min-height: 0;
  max-height: 100%;
  height: 100%;
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow: hidden;
}

.new-chat-quick {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #0b5cff, #0a53d8);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(11, 92, 255, 0.18);
  flex: 0 0 auto;
}

.new-chat-quick:hover {
  background: linear-gradient(135deg, #0a53d8, #084ac2);
}

.conversation-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  background: #f8fafb;
  color: #1f2937;
  border-radius: 14px;
  padding: 12px;
  border: 1px solid transparent;
  min-height: 84px;
  max-height: 84px;
  overflow: hidden;
}

.conversation-item:hover {
  background: #eefaf7;
}

.conversation-item.active {
  border-color: rgba(18, 140, 126, 0.28);
  background: #e8f7f4;
}

.conversation-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0b5cff, #075e54);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
}

.conversation-avatar.has-photo {
  background: #dbeafe;
}

.conversation-avatar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.conversation-content {
  min-width: 0;
  overflow: hidden;
}

.conversation-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.conversation-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-time {
  font-size: 11px;
  color: #667085;
  white-space: nowrap;
}

.conversation-preview {
  margin-top: 4px;
  color: #667085;
  font-size: 13px;
  overflow: hidden;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
  max-height: 3.25em;
  word-break: break-word;
}

.conversation-unread {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #0b5cff;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  min-height: 0;
}

.chat-panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid #e6e8eb;
  background: linear-gradient(180deg, #ffffff, #fbfcfc);
}

.chat-header-contact {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-header-copy {
  min-width: 0;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0b5cff, #075e54);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  flex: 0 0 auto;
}

.chat-header-avatar.has-photo {
  background: #dbeafe;
}

.chat-header-avatar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-title {
  font-size: 17px;
  font-weight: 700;
}

.chat-subtitle {
  margin-top: 3px;
  color: #667085;
  font-size: 12px;
}

.chat-messages {
  flex: 1;
  overflow: auto;
  min-height: 0;
  padding: 20px;
  background:
    radial-gradient(circle at top left, rgba(18, 140, 126, 0.05), transparent 32%),
    radial-gradient(circle at top right, rgba(7, 94, 84, 0.05), transparent 28%),
    #eef2f4;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  display: flex;
}

.chat-bubble.in {
  justify-content: flex-start;
}

.chat-bubble.out {
  justify-content: flex-end;
}

.chat-bubble-card {
  max-width: min(78%, 540px);
  border-radius: 16px;
  padding: 12px 14px 10px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
}

.chat-bubble.in .chat-bubble-card {
  background: #fff;
  border-top-left-radius: 6px;
}

.chat-bubble.out .chat-bubble-card {
  background: #d9fdd3;
  border-top-right-radius: 6px;
}

.chat-bubble-text {
  font-size: 14px;
  line-height: 1.45;
  color: #111827;
  word-break: break-word;
}

.chat-link {
  color: #0b5cff;
  text-decoration: underline;
  word-break: break-all;
}

.chat-link:hover {
  color: #0847c7;
}

.chat-media-image {
  display: block;
  max-width: 240px;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 12px;
}

.chat-media-sticker {
  max-width: 180px;
  max-height: 180px;
  object-fit: contain;
  background: transparent;
}

.chat-media-audio {
  width: 260px;
  max-width: 100%;
}

.chat-media-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(18, 140, 126, 0.1);
  color: #075e54;
  font-weight: 700;
  word-break: break-word;
}

.chat-media-caption {
  margin-top: 8px;
  font-size: 13px;
  color: #334155;
}

.chat-bubble-footer {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.reply-action-btn {
  border: 0;
  background: transparent;
  color: #667085;
  font-size: 12px;
  padding: 0;
  min-height: 0;
  cursor: pointer;
}

.reply-action-btn:hover {
  color: #0b5cff;
}

.reply-preview {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(11, 92, 255, 0.08), rgba(7, 94, 84, 0.08));
  border: 1px solid rgba(11, 92, 255, 0.16);
}

.reply-preview-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reply-preview-title {
  font-size: 12px;
  font-weight: 700;
  color: #0b5cff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.reply-preview-text {
  margin-top: 4px;
  color: #334155;
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.reply-cancel-btn {
  border: 0;
  background: rgba(255, 255, 255, 0.7);
  color: #475467;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  min-height: 26px;
  padding: 0;
}

.reply-cancel-btn:hover {
  background: #fff;
  color: #111827;
}

.chat-reply-quote {
  margin-bottom: 8px;
  padding: 8px 10px;
  border-left: 3px solid rgba(11, 92, 255, 0.55);
  background: rgba(255, 255, 255, 0.56);
  border-radius: 10px;
}

.chat-bubble.out .chat-reply-quote {
  background: rgba(255, 255, 255, 0.4);
}

.chat-reply-quote-label {
  font-size: 11px;
  font-weight: 700;
  color: #0b5cff;
  margin-bottom: 2px;
}

.chat-reply-quote-text {
  font-size: 12px;
  color: #475467;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-composer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid #e6e8eb;
  background: linear-gradient(180deg, #ffffff, #fafbfc);
}

.chat-composer .reply-preview,
.chat-composer textarea,
.chat-composer #chatSendBtn {
  width: 100%;
}

.chat-composer textarea {
  flex: 1;
  resize: none;
  min-height: 56px;
}

.chat-bubble-badge {
  margin-bottom: 6px;
  font-size: 10px;
  font-weight: 700;
  font-style: italic;
  text-transform: capitalize;
  letter-spacing: .4px;
  color: #020202;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-bubble-meta {
  margin-top: 6px;
  font-size: 11px;
  text-align: right;
  color: rgba(17, 24, 39, 0.58);
}

@media (max-width: 980px) {
  .container.chat-view {
    height: calc(100dvh - 106px);
    min-height: calc(100dvh - 106px);
  }

  .chat-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat-sidebar,
  .chat-panel {
    min-height: auto;
  }
}
