:root {
  --bg: #0b1014;
  --panel: #111b21;
  --panel-strong: #202c33;
  --ink: #e9edef;
  --muted: #8696a0;
  --line: #2a3942;
  --green: #00a884;
  --green-dark: #047857;
  --blue: #34b7f1;
  --out: #005c4b;
  --in: #202c33;
  --danger: #dc2626;
  --shadow: 0 24px 70px rgba(0, 0, 0, .38);
  --admin-drawer-width: clamp(340px, 24vw, 430px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }
.hidden-field {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.svg-sprite { display: none; }
.ui-icon {
  width: 20px;
  height: 20px;
  display: block;
  fill: currentColor;
}

.app-shell {
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.brand-bar {
  position: fixed;
  top: 24px;
  left: 34px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--green);
  font-weight: 900;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-weight: 950;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.boot-screen,
.login-screen,
.connect-screen {
  display: none;
  min-height: 100dvh;
  place-items: center;
  padding: 96px 24px 56px;
}

.boot-screen,
.login-screen {
  background:
    radial-gradient(circle at 22% 18%, rgba(0, 168, 132, .16), transparent 34%),
    radial-gradient(circle at 78% 72%, rgba(52, 183, 241, .11), transparent 32%),
    linear-gradient(135deg, #071014 0%, #0b1014 52%, #0d1b18 100%);
}

.app-shell[data-mode="boot"] .boot-screen,
.app-shell[data-mode="login"] .login-screen,
.app-shell[data-mode="connect"] .connect-screen { display: grid; }

.boot-loader {
  position: relative;
  display: grid;
  width: 170px;
  height: 170px;
  place-items: center;
  color: var(--green);
}

.loading-ring {
  position: absolute;
  width: 92px;
  height: 92px;
  border: 5px solid rgba(0, 168, 132, .16);
  border-top-color: #00d39b;
  border-right-color: rgba(52, 183, 241, .8);
  border-radius: 50%;
  box-shadow: 0 0 34px rgba(0, 168, 132, .24);
  animation: spin 1s linear infinite;
}

.loading-ring::after {
  position: absolute;
  inset: 16px;
  border: 2px solid rgba(0, 211, 155, .22);
  border-bottom-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 1.8s linear infinite reverse;
}

.boot-loader p {
  position: relative;
  margin: 138px 0 0;
  color: #d7fff3;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

.particle-field {
  position: absolute;
  inset: 0;
  animation: spin 5.4s linear infinite;
}

.particle-field span {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #00d39b;
  box-shadow: 0 0 16px rgba(0, 211, 155, .85);
  opacity: .35;
}

.particle-field span:nth-child(1) { top: 5%; left: 48%; animation: pulse .9s ease-in-out infinite; }
.particle-field span:nth-child(2) { top: 13%; left: 75%; animation: pulse 1.2s ease-in-out infinite; }
.particle-field span:nth-child(3) { top: 32%; left: 91%; animation: pulse 1s ease-in-out infinite; }
.particle-field span:nth-child(4) { top: 62%; left: 88%; animation: pulse 1.35s ease-in-out infinite; }
.particle-field span:nth-child(5) { top: 84%; left: 68%; animation: pulse 1.1s ease-in-out infinite; }
.particle-field span:nth-child(6) { top: 92%; left: 43%; animation: pulse 1.4s ease-in-out infinite; }
.particle-field span:nth-child(7) { top: 77%; left: 18%; animation: pulse .95s ease-in-out infinite; }
.particle-field span:nth-child(8) { top: 51%; left: 5%; animation: pulse 1.25s ease-in-out infinite; }
.particle-field span:nth-child(9) { top: 24%; left: 12%; animation: pulse 1.05s ease-in-out infinite; }
.particle-field span:nth-child(10) { top: 38%; left: 66%; width: 5px; height: 5px; animation: pulse 1.5s ease-in-out infinite; }
.particle-field span:nth-child(11) { top: 58%; left: 31%; width: 5px; height: 5px; animation: pulse 1.18s ease-in-out infinite; }
.particle-field span:nth-child(12) { top: 70%; left: 55%; width: 4px; height: 4px; animation: pulse .8s ease-in-out infinite; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  50% { transform: scale(1.9); opacity: 1; }
}

.login-card,
.connect-card {
  border: 1px solid rgba(134, 150, 160, .28);
  border-radius: 8px;
  background: rgba(32, 44, 51, .94);
  box-shadow: var(--shadow);
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 38px;
  backdrop-filter: blur(12px);
}

.connect-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 38px;
  width: min(760px, 100%);
  padding: 42px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #00d39b;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 20px; font-size: clamp(30px, 4vw, 44px); line-height: 1.08; }
h2 { margin-bottom: 0; font-size: 20px; }

label {
  display: grid;
  gap: 7px;
  color: #d7e2de;
  font-size: 13px;
  font-weight: 800;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #162229;
  color: var(--ink);
  padding: 12px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(0, 168, 132, .78);
  box-shadow: 0 0 0 3px rgba(0, 168, 132, .14);
}

.login-card input {
  background: #0f191f;
  border-color: rgba(134, 150, 160, .25);
  min-height: 46px;
}

textarea { resize: vertical; }

.primary-button,
.send-button {
  border: 0;
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

.primary-button {
  min-height: 46px;
  padding: 0 24px;
  border-radius: 999px;
}

.text-button {
  width: fit-content;
  border: 0;
  background: transparent;
  color: var(--green-dark);
  font-weight: 900;
}

.danger-outline-button {
  min-height: 46px;
  padding: 0 24px;
  border: 1px solid rgba(220, 38, 38, .5);
  border-radius: 999px;
  background: rgba(220, 38, 38, .08);
  color: #ffb4b4;
  font-weight: 900;
}

.danger-outline-button:hover {
  background: rgba(220, 38, 38, .14);
  border-color: rgba(220, 38, 38, .75);
}

.status-detail,
.small-note,
.error-line { color: var(--muted); }
.error-line { min-height: 18px; margin: 0; color: var(--danger); font-size: 13px; }

.steps {
  display: grid;
  gap: 18px;
  margin: 0 0 28px;
  padding: 0;
  list-style: none;
  color: #3e4a46;
}

.steps li { position: relative; padding-left: 42px; min-height: 28px; }
.steps li::before {
  position: absolute;
  left: 0;
  top: -2px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid #8d9994;
  border-radius: 50%;
  color: #5f6d68;
  content: counter(list-item);
  font-size: 14px;
}

.qr-panel {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 16px;
}

.qr-code {
  position: relative;
  width: 220px;
  aspect-ratio: 1;
  border: 12px solid #fff;
  background:
    linear-gradient(90deg, #163b3b 10px, transparent 10px) 0 0 / 22px 22px,
    linear-gradient(#163b3b 10px, transparent 10px) 0 0 / 22px 22px,
    conic-gradient(from 90deg, #163b3b 25%, transparent 0 50%, #163b3b 0 75%, transparent 0) 0 0 / 44px 44px,
    #f7fffb;
  box-shadow: inset 0 0 0 1px #dbe7e2;
}

.qr-code img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #fff;
}

.qr-logo {
  position: absolute;
  inset: 50% auto auto 50%;
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 5px solid #f7fffb;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-weight: 950;
  transform: translate(-50%, -50%);
}

.chat-screen {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-columns: 390px minmax(0, 1fr);
  padding-right: var(--admin-drawer-width);
  overflow: hidden;
  background: var(--bg);
}

.app-shell[data-mode="chat"] .chat-screen { display: grid; }

.sidebar {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}

.sidebar-top,
.conversation-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

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

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.icon-button:hover,
.chat-item:hover { background: rgba(255, 255, 255, .04); }

.mobile-back-button { display: none; }

.search-wrap {
  position: relative;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.search-icon {
  position: absolute;
  left: 26px;
  top: 22px;
  color: var(--muted);
  font-size: 20px;
}

.search-wrap input {
  height: 44px;
  padding-left: 42px;
  border-color: transparent;
  background: var(--panel-strong);
  color: var(--ink);
}

.chat-list {
  min-height: 0;
  overflow: auto;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  font-size: 14px;
}

.empty-state.centered {
  align-self: center;
  margin: auto;
  border-radius: 8px;
  background: rgba(255, 255, 255, .65);
}

.chat-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.chat-item.active { background: rgba(255, 255, 255, .07); }

.avatar {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #00a884, #1d4ed8);
  color: #fff;
  font-weight: 950;
}

.chat-main { min-width: 0; }
.chat-main strong,
.chat-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-main span,
.chat-meta,
.contact-title p { color: var(--muted); font-size: 13px; }
.chat-meta { display: grid; gap: 7px; justify-items: end; }

.mini-badge {
  display: grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.conversation {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background:
    linear-gradient(rgba(11, 16, 20, .88), rgba(11, 16, 20, .88)),
    url("fondo_trans.png"),
    #0b1014;
  background-size: auto, 350px 350px, auto;
}

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

.contact-title p { margin: 3px 0 0; }

.chat-menu-wrap {
  position: relative;
  flex: 0 0 auto;
}

.chat-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  min-width: 230px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #233138;
  box-shadow: var(--shadow);
  z-index: 25;
}

.chat-menu button {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-size: 13px;
  font-weight: 800;
}

.chat-menu button:hover {
  background: rgba(255, 255, 255, .07);
}

.chat-menu button.danger { color: #ff9b9b; }

.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding: 18px min(5vw, 58px);
  align-items: flex-start;
}

.message {
  width: fit-content;
  min-width: 0;
  max-width: min(620px, 64%);
  padding: 7px 8px 5px 10px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .06);
  white-space: normal;
  font-size: 14.5px;
  color: var(--ink);
}

.message.in { background: var(--in); }
.message.out { align-self: flex-end; background: var(--out); }
.message p {
  margin: 0;
  line-height: 1.28;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message time { display: block; margin-top: 3px; color: var(--muted); font-size: 10.5px; text-align: right; }

.composer {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer input {
  height: 44px;
  padding: 0 16px;
  border-color: transparent;
  background: var(--panel-strong);
  color: var(--ink);
}

.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
}

.drawer-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  display: none;
  width: var(--admin-drawer-width);
  min-width: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 5;
  overflow: hidden;
}

.app-shell[data-mode="chat"] .drawer-backdrop,
.app-shell[data-mode="chat"] .drawer-backdrop.open { display: block; }

.drawer {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--panel);
  box-shadow: none;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.drawer-body { padding: 18px; }
.drawer-body { min-height: 0; overflow: auto; }
.drawer-head #closeDrawer { display: none; }
.form-grid { display: grid; gap: 13px; }
.questionnaire {
  display: grid;
  gap: 13px;
  padding-top: 4px;
}
.section-title {
  margin: 0;
  color: var(--ink);
  font-weight: 900;
}
.switch-row { grid-template-columns: 1fr auto; align-items: center; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--green); }

.section-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.mini-action {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.drawer-list {
  display: grid;
  gap: 8px;
  max-height: 32dvh;
  overflow: auto;
  padding-right: 4px;
}

.drawer-contact {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .035);
}

.drawer-contact .avatar {
  width: 42px;
  height: 42px;
}

.drawer-contact strong,
.drawer-contact span,
.drawer-contact small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-contact span,
.drawer-contact small { color: var(--muted); font-size: 12px; }

.drawer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-button.subtle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .045);
  color: var(--ink);
}

.icon-button.subtle:hover {
  border-color: rgba(0, 168, 132, .55);
  background: rgba(0, 168, 132, .12);
  color: #12d99f;
}

.icon-button.subtle.danger:hover {
  border-color: rgba(220, 38, 38, .55);
  background: rgba(220, 38, 38, .14);
  color: #ff8a8a;
}

.contact-editor {
  display: grid;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.contact-editor textarea[readonly] {
  min-height: 150px;
  color: #bfd0d5;
  background: rgba(255, 255, 255, .035);
}

.inline-status {
  display: inline-grid;
  width: fit-content;
  margin-left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(134, 150, 160, .16);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.inline-status.custom {
  background: rgba(0, 168, 132, .16);
  color: #12d99f;
}

.avatar-preview {
  display: grid;
  width: 88px;
  height: 88px;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 12px;
}

.avatar-preview img,
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.contact-actions {
  display: flex;
  gap: 7px;
  margin-top: 7px;
}

.contact-actions button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  min-width: min(420px, calc(100vw - 28px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #17201d;
  color: #fff;
  font-weight: 850;
  box-shadow: var(--shadow);
  transition: .18s ease;
  z-index: 30;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.user-login-shell {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  overflow: auto;
  padding: 28px;
  background:
    radial-gradient(circle at 20% 10%, rgba(0, 168, 132, .18), transparent 34%),
    radial-gradient(circle at 82% 78%, rgba(52, 183, 241, .12), transparent 32%),
    linear-gradient(135deg, #071014 0%, #0b1014 58%, #0d1b18 100%);
}

.user-login-card,
.user-editor-card {
  display: grid;
  gap: 18px;
  width: min(760px, 100%);
  padding: 32px;
  border: 1px solid rgba(134, 150, 160, .28);
  border-radius: 8px;
  background: rgba(17, 27, 33, .96);
  box-shadow: var(--shadow);
}

.user-login-card { width: min(440px, 100%); }

.user-editor-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.user-editor-card textarea {
  min-height: 170px;
  line-height: 1.35;
}

.behavior-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .025);
}

.behavior-master {
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(134, 150, 160, .2);
}

.behavior-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.behavior-options label {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid rgba(134, 150, 160, .2);
  border-radius: 8px;
  background: rgba(255, 255, 255, .025);
}

.behavior-options input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.behavior-options label:has(input:disabled) {
  opacity: .45;
}

@media (max-width: 820px) {
  .brand-bar { position: static; padding: 18px 18px 0; }
  .boot-screen,
  .login-screen,
  .connect-screen { display: none; padding: 28px 16px; }
  .connect-card { grid-template-columns: 1fr; gap: 28px; padding: 28px; }
  .chat-screen {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    padding-right: 0;
  }
  .sidebar { height: 100%; min-height: 0; border-right: 0; }
  .conversation { display: none; height: 100%; min-height: 0; }
  .drawer-backdrop {
    position: fixed;
    inset: 0;
    display: none;
    width: auto;
    justify-content: flex-end;
    background: rgba(23, 32, 29, .28);
    border-left: 0;
    z-index: 20;
  }
  .app-shell[data-mode="chat"] .drawer-backdrop { display: none; }
  .app-shell[data-mode="chat"] .drawer-backdrop.open { display: flex; }
  .drawer {
    width: min(460px, 100%);
    height: 100dvh;
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
  .drawer-head #closeDrawer { display: grid; }
  .app-shell.mobile-chat-open .sidebar { display: none; }
  .app-shell.mobile-chat-open .conversation { display: grid; }
  .mobile-back-button {
    display: grid;
    flex: 0 0 auto;
    font-size: 34px;
    line-height: 1;
  }
  .conversation-top {
    gap: 10px;
    min-height: 68px;
    padding: 10px 12px;
  }
  .contact-title { gap: 10px; }
  .contact-title .avatar {
    width: 42px;
    height: 42px;
  }
  .contact-title h2 {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .contact-title p {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .messages { padding: 18px 14px; }
  .message { max-width: 88%; }
  .composer { padding: 10px 12px; }
  .user-login-shell { padding: 16px; place-items: start center; }
  .user-login-card,
  .user-editor-card { padding: 22px; }
  .user-editor-head { align-items: center; }
  .behavior-options { grid-template-columns: 1fr; }
}
