:root {
  --wa-bg: #0b141a;
  --wa-sidebar: #111b21;
  --wa-rail: #202c33;
  --wa-panel: #202c33;
  --wa-hover: #2a3942;
  --wa-border: #222e35;
  --wa-text: #e9edef;
  --wa-muted: #8696a0;
  --wa-green: #00a884;
  --wa-green-hover: #06cf9c;
  --wa-bubble-out: #005c4b;
  --wa-bubble-in: #202c33;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background: var(--wa-bg);
  color: var(--wa-text);
  height: 100vh;
  overflow: hidden;
}

/* Login Screen */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, #00a884 0%, #00a884 22%, #0b141a 22%, #0b141a 100%);
}

.login-card {
  background: var(--wa-sidebar);
  border: 1px solid var(--wa-border);
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.login-logo h1 { font-size: 20px; font-weight: 700; }
.login-logo p { font-size: 13px; color: var(--wa-muted); margin-top: 2px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--wa-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  background: var(--wa-panel);
  border: 1px solid var(--wa-border);
  color: var(--wa-text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--wa-green);
}

.login-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid #ef4444;
  color: #fca5a5;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 12px;
}

.login-hint {
  margin-top: 16px;
  text-align: center;
  color: var(--wa-muted);
  line-height: 1.5;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #111b21;
}

.btn-wa { background: var(--wa-green); }
.btn-wa:hover { background: var(--wa-green-hover); }
.btn-full { width: 100%; }

/* WA Web Layout (3 Columns) */
.wa-app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Leftmost Icon Rail */
.nav-rail {
  width: 58px;
  background: var(--wa-rail);
  border-right: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  flex-shrink: 0;
}

.rail-top, .rail-bottom {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rail-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #aebac1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.rail-btn:hover { background: var(--wa-hover); }
.rail-btn.active { background: #2a3942; color: var(--wa-text); }

/* Sidebar */
.sidebar {
  width: 340px;
  background: var(--wa-sidebar);
  border-right: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.sidebar-title h2 { font-size: 20px; font-weight: 700; }

.wa-status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--wa-muted);
  margin-top: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
}
.status-dot.connected { background: var(--wa-green); }
.status-dot.disconnected { background: #ef4444; }
.status-dot.qr { background: #38bdf8; }

.operator-badge {
  font-size: 11px;
  background: var(--wa-panel);
  color: var(--wa-green);
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--wa-border);
  white-space: nowrap;
}

.search-wrap {
  padding: 6px 12px 10px 12px;
  border-bottom: 1px solid var(--wa-border);
}

.search-box {
  background: var(--wa-panel);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 8px 0 12px;
  gap: 8px;
}

.search-box input {
  border: none;
  background: transparent;
  padding: 8px 4px;
  font-size: 13px;
}

.btn-mini-add {
  background: var(--wa-green);
  color: #111b21;
  border: none;
  border-radius: 6px;
  width: 26px;
  height: 26px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(34, 46, 53, 0.7);
}

.chat-item:hover { background: var(--wa-panel); }
.chat-item.active { background: var(--wa-hover); }

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #3b4a54;
  color: #e9edef;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
}

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-item-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 11px;
  color: var(--wa-muted);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.chat-item-last {
  font-size: 13px;
  color: var(--wa-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--wa-green);
  color: #111b21;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Main Chat Panel */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--wa-bg);
  background-image: radial-gradient(rgba(134, 150, 160, 0.08) 1px, transparent 1px);
  background-size: 22px 22px;
}

.chat-header {
  height: 60px;
  background: var(--wa-panel);
  border-bottom: 1px solid var(--wa-border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-info strong { font-size: 15px; display: block; }
.chat-header-info small { font-size: 12px; color: var(--wa-muted); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 6%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble {
  max-width: 68%;
  padding: 7px 10px 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.38;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}

.bubble.in {
  align-self: flex-start;
  background: var(--wa-bubble-in);
  border-top-left-radius: 0;
}

.bubble.out {
  align-self: flex-end;
  background: var(--wa-bubble-out);
  border-top-right-radius: 0;
}

.bubble-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: rgba(233, 237, 239, 0.65);
  margin-top: 3px;
}

.bubble-ticks { color: #53bdeb; font-weight: 700; }

.composer {
  height: 62px;
  background: var(--wa-panel);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer input {
  flex: 1;
  background: #2a3942;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
}

.btn-send {
  background: transparent;
  border: none;
  color: var(--wa-muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
}
.btn-send:hover { color: var(--wa-green); }

.welcome-state, .empty-hint {
  margin: auto;
  text-align: center;
  color: var(--wa-muted);
  max-width: 420px;
  padding: 20px;
}
.welcome-state h3 { color: var(--wa-text); font-weight: 400; font-size: 24px; margin: 12px 0 8px; }
.welcome-state p { font-size: 13px; line-height: 1.5; }

/* QR Overlay */
.qr-panel {
  position: absolute;
  inset: 0;
  background: rgba(11, 20, 26, 0.95);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.qr-card {
  background: var(--wa-sidebar);
  border: 1px solid var(--wa-border);
  border-radius: 14px;
  padding: 26px;
  max-width: 390px;
  width: 100%;
  text-align: center;
}

.qr-card h2 { font-size: 18px; margin-bottom: 8px; }
.qr-card p { font-size: 13px; color: var(--wa-muted); line-height: 1.45; }
.qr-box { background: white; padding: 12px; border-radius: 10px; display: inline-block; margin: 16px 0; }
.qr-box img { width: 220px; height: 220px; display: block; }
.qr-hint { font-size: 11px; color: var(--wa-muted); display: block; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  background: var(--wa-sidebar);
  border: 1px solid var(--wa-border);
  border-radius: 12px;
  max-width: 520px;
  width: 100%;
  overflow: hidden;
}

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

.btn-close {
  background: transparent;
  border: none;
  color: var(--wa-muted);
  font-size: 22px;
  cursor: pointer;
}

.modal-body { padding: 16px 18px; font-size: 13px; color: var(--wa-muted); }

.modal-body pre {
  background: var(--wa-bg);
  border: 1px solid var(--wa-border);
  border-radius: 8px;
  padding: 10px 12px;
  color: #86efac;
  font-size: 12px;
  overflow-x: auto;
  margin-top: 10px;
}

.add-user-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.add-user-form button { grid-column: span 2; }

.users-list {
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid var(--wa-border);
  padding-top: 8px;
}

.user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--wa-border);
  color: var(--wa-text);
}

.user-row small { color: var(--wa-muted); }

.btn-del {
  background: transparent;
  border: 1px solid #ef4444;
  color: #ef4444;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

@media (max-width: 760px) {
  .wa-app { flex-direction: column; }
  .nav-rail { width: 100%; height: 48px; flex-direction: row; padding: 0 12px; border-right: none; border-bottom: 1px solid var(--wa-border); }
  .rail-top, .rail-bottom { flex-direction: row; }
  .sidebar { width: 100%; height: 38%; border-right: none; border-bottom: 1px solid var(--wa-border); }
  .chat-panel { height: calc(62% - 48px); }
}
