* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #e9edef;
  color: #111b21;
  height: 100vh;
  overflow: hidden;
}

/* ============ LOGIN ============ */
body.login-body {
  height: 100vh;
  overflow: auto;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #128C7E 0%, #25D366 100%);
  padding: 1rem;
}

.login-card {
  background: white;
  border-radius: 14px;
  padding: 2.25rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.login-logo {
  width: 64px; height: 64px;
  background: #008069;
  color: white;
  border-radius: 50%;
  display: grid; place-items: center;
  margin: 0 auto 1rem;
  font-size: 1.7rem;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(0, 128, 105, 0.3);
}

.login-card h1 { font-size: 1.6rem; margin-bottom: 0.2rem; color: #111b21; }
.login-subtitle { color: #667781; font-size: 0.9rem; margin-bottom: 1.5rem; }

.login-card form { display: flex; flex-direction: column; gap: 0.9rem; text-align: left; }

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: #54656f;
  font-weight: 500;
}

.login-card input {
  padding: 0.75rem 0.9rem;
  border: 1px solid #d1d7db;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input:focus {
  outline: none;
  border-color: #25D366;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.login-card button {
  background: #008069;
  color: white;
  border: none;
  padding: 0.85rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
  font-family: inherit;
  transition: background 0.15s;
}

.login-card button:hover { background: #006d59; }
.login-card button:active { background: #005c4b; }

.login-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: left;
}

/* ============ APP LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: minmax(320px, 30%) 1fr;
  height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: white;
  border-right: 1px solid #d1d7db;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  background: #008069;
  color: white;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.logo {
  width: 40px; height: 40px;
  background: white;
  color: #008069;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.2rem;
}

.brand h1 { font-size: 1.1rem; }
.brand p { font-size: 0.75rem; opacity: 0.85; }

.header-actions { display: flex; align-items: center; gap: 0.75rem; }

.conn-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #25D366;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
  transition: background 0.2s;
}
.conn-dot.disconnected { background: #ef4444; }

.logout-form { margin: 0; }

.logout-btn {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.15s;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.25); }

.user-bar {
  background: #f0f2f5;
  padding: 0.5rem 1.25rem;
  font-size: 0.8rem;
  color: #54656f;
  border-bottom: 1px solid #e9edef;
}

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

.empty-state {
  padding: 2rem 1rem;
  color: #667781;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.5;
}

.chat-item {
  display: grid;
  grid-template-columns: 49px 1fr;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-item:hover { background: #f5f6f6; }
.chat-item.active { background: #f0f2f5; }

.avatar {
  width: 49px; height: 49px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
  color: white;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.chat-meta { min-width: 0; }

.chat-row-1, .chat-row-2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.chat-row-1 { margin-bottom: 0.2rem; }

.chat-name {
  font-weight: 500;
  color: #111b21;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-time {
  font-size: 0.72rem;
  color: #667781;
  white-space: nowrap;
}

.chat-preview {
  color: #667781;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.chat-unread {
  background: #25D366;
  color: white;
  border-radius: 999px;
  padding: 0 0.5rem;
  min-width: 20px;
  height: 20px;
  font-size: 0.72rem;
  display: grid; place-items: center;
  font-weight: 600;
}
.chat-unread:empty { display: none; }

/* ============ CHAT PANEL ============ */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: #efeae2;
  overflow: hidden;
}

.no-chat-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  background: #f0f2f5;
}

.qr-container {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  min-width: 280px;
  min-height: 280px;
  display: grid; place-items: center;
}

.qr-loading, .qr-message {
  color: #667781;
  font-size: 0.95rem;
  padding: 1.5rem;
  text-align: center;
  line-height: 1.6;
}

.qr-message small { font-size: 0.8rem; opacity: 0.85; }

.qr-container img { width: 240px; height: 240px; display: block; }

.hint {
  color: #54656f;
  font-size: 0.9rem;
  max-width: 400px;
  line-height: 1.5;
}

/* ============ CHAT HEADER ============ */
.chat-header {
  background: #f0f2f5;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  border-bottom: 1px solid #d1d7db;
  flex-shrink: 0;
}

.chat-header .avatar { width: 40px; height: 40px; font-size: 0.95rem; }

.chat-header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header-name { font-weight: 500; color: #111b21; }
.chat-header-phone { font-size: 0.8rem; color: #667781; }

.state-toggle { display: flex; align-items: center; gap: 0.6rem; }

.toggle-label { font-size: 0.8rem; color: #54656f; font-weight: 500; }

.toggle {
  display: inline-flex;
  background: white;
  border: 1px solid #d1d7db;
  border-radius: 999px;
  padding: 0.2rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}

.toggle-option {
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  color: #54656f;
  transition: all 0.2s;
  font-weight: 500;
}

.toggle[data-state="bot"] .toggle-option.bot { background: #25D366; color: white; }
.toggle[data-state="human"] .toggle-option.human { background: #2196F3; color: white; }

/* ============ MESSAGES ============ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.message {
  max-width: 65%;
  padding: 0.5rem 0.75rem 0.55rem;
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.4;
  word-wrap: break-word;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
  position: relative;
}

.message.in { align-self: flex-start; background: white; border-top-left-radius: 0; }
.message.out { align-self: flex-end; background: #d9fdd3; border-top-right-radius: 0; }

.message-content { display: block; white-space: pre-wrap; }

.message-time {
  font-size: 0.68rem;
  color: #667781;
  display: block;
  text-align: right;
  margin-top: 0.2rem;
}

/* ============ FOOTER ============ */
.chat-footer {
  background: #f0f2f5;
  padding: 0.65rem 1rem;
  border-top: 1px solid #d1d7db;
  flex-shrink: 0;
}

.chat-footer input {
  width: 100%;
  border: none;
  background: white;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #667781;
  font-family: inherit;
}

.chat-footer input:disabled { cursor: not-allowed; opacity: 0.85; }

/* ============ SCROLLBARS ============ */
.chat-list::-webkit-scrollbar,
.messages::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}
