:root {
  --bg: #121316;
  --surface: #1b1d22;
  --surface-2: #24272e;
  --surface-hover: #2d313a;
  --border: #30343e;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #4c8df6;
  --accent-strong: #1a73e8;
  --accent-text: #ffffff;
  --bubble-in: #2b2f38;
  --bubble-out: #1a73e8;
  --danger: #f28b82;
  --success: #81c995;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Google Sans", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
}

.hidden {
  display: none !important;
}

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.auth-logo {
  width: 72px;
  height: 72px;
  margin-bottom: 12px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
}

.auth-subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.92rem;
}

.auth-card .field-label {
  text-align: left;
}

.auth-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.auth-actions .btn {
  flex: 1;
}

.auth-hint {
  margin: 18px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  height: 64px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

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

.brand-logo {
  width: 36px;
  height: 36px;
}

.brand-title {
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 999px;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  background: var(--accent-strong);
  color: var(--accent-text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  font-size: 0.8rem;
  color: var(--success);
  background: rgba(129, 201, 149, 0.12);
  padding: 5px 11px;
  border-radius: 999px;
}

.status-pill.error {
  color: var(--danger);
  background: rgba(242, 139, 130, 0.12);
}

/* Panels */
.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
}

.tab-panel.active {
  display: flex;
}

.messages-layout {
  flex-direction: row;
}

.sidebar {
  width: 340px;
  max-width: 100%;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.conv-item:hover {
  background: var(--surface-2);
}

.conv-item.active {
  background: rgba(76, 141, 246, 0.18);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  font-size: 0.95rem;
}

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

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.conv-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 0.74rem;
  color: var(--muted);
  flex-shrink: 0;
}

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

.conv-preview {
  font-size: 0.84rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--accent);
  color: #0b192e;
  font-weight: 700;
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Chat Pane */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.empty-logo {
  width: 68px;
  height: 68px;
  margin-bottom: 12px;
  opacity: 0.9;
}

.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-name {
  font-weight: 600;
  font-size: 1rem;
}

.chat-phone {
  font-size: 0.8rem;
  color: var(--muted);
}

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

.message-feed {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.msg-row.in {
  align-self: flex-start;
}

.msg-row.out {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-bubble {
  padding: 10px 15px;
  border-radius: 20px;
  line-height: 1.4;
  font-size: 0.95rem;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row.in .msg-bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 6px;
}

.msg-row.out .msg-bubble {
  background: var(--bubble-out);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg-img {
  max-width: 260px;
  border-radius: 12px;
  margin-top: 6px;
  display: block;
}

.msg-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
}

.smart-reply-bar {
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.smart-chip {
  border: 1px solid var(--accent);
  background: rgba(76, 141, 246, 0.12);
  color: #a8c7fa;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  white-space: nowrap;
  cursor: pointer;
  transition: 0.15s;
}

.smart-chip:hover {
  background: var(--accent-strong);
  color: #fff;
}

.composer {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

.composer input {
  flex: 1;
}

/* Single pane tabs */
.single-pane {
  overflow-y: auto;
  padding: 24px;
  justify-content: center;
  align-items: flex-start;
}

.card {
  width: 100%;
  max-width: 860px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
}

.setup-grid {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0 0 14px;
}

.inline-form {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.inline-form input {
  flex: 1;
}

.chips-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.reply-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
}

.reply-pill button {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 2px;
}

/* Inputs & Buttons */
.field-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 12px 0 6px;
}

input[type="text"], textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.94rem;
  font-family: inherit;
  outline: none;
}

input[type="text"]:focus, textarea:focus {
  border-color: var(--accent);
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--accent-strong);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: rgba(242, 139, 130, 0.14);
}

.full-width {
  width: 100%;
}

/* Setup helpers */
.copy-field {
  margin-bottom: 14px;
}

.copy-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 5px;
}

.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.copy-row code {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.84rem;
  overflow-x: auto;
  white-space: nowrap;
}

.steps-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-item {
  display: flex;
  gap: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-strong);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.step-item ol {
  margin: 8px 0 8px 18px;
  padding: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.code-block {
  background: #0b0c0e;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.82rem;
  overflow-x: auto;
  color: #a8c7fa;
  margin: 8px 0;
}

.card-footer-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.outbox-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.outbox-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.86rem;
}

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

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
}

.modal-card h3 {
  margin: 0 0 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #2b2f38;
  color: #fff;
  border: 1px solid var(--accent);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  z-index: 200;
}

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
  }
  .messages-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    max-height: 38vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
