:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #eef7f4;
  --ink: #18212b;
  --muted: #657382;
  --line: #dce3ea;
  --accent: #128c7e;
  --accent-dark: #0b6f64;
  --blue: #2864b4;
  --danger: #b33636;
  --warning: #a86412;
  --shadow: 0 18px 44px rgba(22, 32, 44, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 24px;
}

.brand,
.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.brand h1,
.section-header h2 {
  margin: 2px 0 0;
  font-size: 24px;
  letter-spacing: 0;
}

.section-header h2 {
  font-size: 21px;
}

.section-header.compact h2 {
  font-size: 18px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-dot {
  display: inline-flex;
  min-width: 76px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-dot.ok {
  border-color: #b7dfd7;
  background: #e7f7f3;
  color: var(--accent-dark);
}

.status-dot.waiting {
  border-color: #f0d49d;
  background: #fff8e9;
  color: var(--warning);
}

.status-dot.error {
  border-color: #e7baba;
  background: #fff4f4;
  color: var(--danger);
}

.sidebar-actions {
  display: flex;
}

.primary-button,
.ghost-button,
.danger-button,
.send-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  font-weight: 800;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.primary-button,
.send-button {
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
}

.primary-button:hover,
.send-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
}

.ghost-button:hover {
  border-color: #b8c5d0;
}

.danger-button {
  border: 1px solid #e6b8b8;
  background: #fff4f4;
  color: var(--danger);
  padding: 0 14px;
}

.icon-button {
  width: 40px;
  background: #eef2f5;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.user-list {
  display: grid;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

.user-item {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  text-align: left;
}

.user-item:hover,
.user-item.active {
  border-color: #89cfc2;
  background: var(--panel-2);
}

.user-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 900;
}

.active-pill {
  flex: 0 0 auto;
  border-radius: 8px;
  background: #d9efe9;
  color: var(--accent-dark);
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 900;
}

.user-meta {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(460px, 1fr) minmax(360px, 440px);
  gap: 18px;
  padding: 18px;
}

.persona-panel,
.chat-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.persona-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
  overflow: auto;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  max-height: calc(100vh - 36px);
  padding: 18px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.persona-form {
  display: grid;
  gap: 16px;
}

.wa-connect-panel {
  display: grid;
  gap: 14px;
  border: 1px solid #d8e8e4;
  border-radius: 8px;
  background: #f7fbfa;
  padding: 16px;
}

.wa-connect-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.wa-connect-header h3 {
  margin: 2px 0 0;
  font-size: 17px;
  letter-spacing: 0;
}

.wa-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.qr-panel {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.qr-frame {
  display: grid;
  width: 176px;
  height: 176px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.qr-frame img {
  display: none;
  width: 160px;
  height: 160px;
}

.qr-frame img.ready {
  display: block;
}

.qr-hint,
.qr-meta {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 800;
}

.qr-meta {
  margin-top: 8px;
  color: var(--accent-dark);
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.14);
}

.chat-meta {
  margin-top: 12px;
  border: 1px solid #d8e8e4;
  border-radius: 8px;
  background: #f4fbf9;
  color: var(--accent-dark);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 800;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.quick-prompts button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
  padding: 12px;
}

.message {
  max-width: 86%;
  border-radius: 8px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.message.customer {
  align-self: flex-end;
  background: #dcf8c6;
}

.message.agent {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: #fff;
}

.message.pending {
  color: var(--muted);
}

.empty-state {
  margin: auto;
  max-width: 280px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
  margin-top: 12px;
}

.send-button {
  width: 100%;
}

.user-dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

.user-dialog::backdrop {
  background: rgba(16, 24, 32, 0.42);
}

.user-dialog form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  border: 1px solid #cfe2dc;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.toast.error {
  border-color: #e7baba;
  color: var(--danger);
}

/* ── Tablet (≤ 1080px): stack sidebar above workspace ── */
@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 16px;
    gap: 12px;
  }

  .user-list {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  .user-item {
    min-height: 72px;
    padding: 10px 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 14px;
  }

  .chat-panel {
    max-height: none;
  }

  .chat-messages {
    min-height: 220px;
    max-height: 400px;
  }
}

/* ── Mobile (≤ 720px): full single-column, touch-friendly ── */
@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  .sidebar {
    padding: 14px;
    gap: 10px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .brand .eyebrow {
    font-size: 10px;
  }

  .sidebar-actions {
    gap: 8px;
  }

  .sidebar-actions button {
    flex: 1;
    min-height: 38px;
    font-size: 13px;
  }

  .user-list {
    grid-template-columns: 1fr;
    max-height: 160px;
    overflow-y: auto;
    gap: 6px;
  }

  .user-item {
    min-height: auto;
    padding: 10px 12px;
    gap: 4px;
  }

  .user-title {
    font-size: 14px;
  }

  .user-meta {
    font-size: 12px;
  }

  .workspace {
    padding: 10px;
    gap: 10px;
  }

  .persona-panel,
  .chat-panel {
    padding: 14px;
    border-radius: 10px;
  }

  .section-header h2 {
    font-size: 18px;
  }

  .section-header.compact h2 {
    font-size: 16px;
  }

  .header-actions {
    justify-content: stretch;
    gap: 8px;
  }

  .header-actions button {
    width: 100%;
    min-height: 38px;
    font-size: 13px;
  }

  .persona-form {
    gap: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  label {
    font-size: 12px;
    gap: 5px;
  }

  input,
  textarea {
    padding: 10px;
    font-size: 14px;
    border-radius: 8px;
  }

  .wa-connect-panel {
    padding: 12px;
    gap: 10px;
  }

  .wa-connect-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .wa-connect-header h3 {
    font-size: 15px;
  }

  .wa-actions {
    width: 100%;
  }

  .wa-actions button {
    flex: 1;
    min-height: 38px;
    font-size: 13px;
  }

  .qr-panel {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .qr-frame {
    width: 100%;
    max-width: 200px;
    height: 200px;
  }

  .qr-frame img {
    width: 180px;
    height: 180px;
  }

  .chat-meta {
    font-size: 12px;
    padding: 8px 10px;
  }

  .quick-prompts {
    gap: 6px;
    margin: 10px 0;
  }

  .quick-prompts button {
    font-size: 12px;
    min-height: 30px;
    padding: 0 8px;
  }

  .chat-messages {
    min-height: 200px;
    max-height: 320px;
    padding: 10px;
    gap: 8px;
  }

  .message {
    max-width: 90%;
    font-size: 13px;
    padding: 8px 10px;
  }

  .chat-form {
    grid-template-columns: minmax(0, 1fr) 72px;
    gap: 8px;
    margin-top: 10px;
  }

  .send-button {
    font-size: 13px;
    min-height: 38px;
  }

  /* Dialog adjustments */
  .user-dialog {
    width: calc(100vw - 24px);
  }

  .user-dialog form {
    padding: 14px;
    gap: 12px;
  }

  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    flex-direction: column;
    gap: 8px;
  }

  .dialog-actions button {
    width: 100%;
  }

  .brand,
  .section-header {
    gap: 10px;
  }

  .toast {
    right: 10px;
    bottom: 10px;
    left: 10px;
    max-width: none;
    font-size: 13px;
  }
}

/* Onboarding Dialog Styles */
/* ── Onboarding Dialog ── */
.onboarding-dialog {
  border: none;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3), 0 0 0 1px rgba(0,0,0,0.05);
  padding: 0;
  max-width: 580px;
  width: 94vw;
  background: #ffffff;
  overflow: hidden;
  animation: dialogSlideUp 0.35s ease;
}

@keyframes dialogSlideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.onboarding-dialog::backdrop {
  background: rgba(10, 18, 26, 0.55);
  backdrop-filter: blur(4px);
}

/* ── Hero Header ── */
.onboarding-hero {
  background: linear-gradient(135deg, #0b6f64 0%, #128c7e 40%, #15a085 100%);
  color: #fff;
  padding: 44px 32px 36px;
  text-align: center;
  position: relative;
}

.onboarding-hero h2 {
  font-size: 24px;
  margin: 0 0 8px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.3;
}

.onboarding-hero > p {
  font-size: 14px;
  color: rgba(255,255,255,0.88);
  max-width: 420px;
  margin: 0 auto;
  line-height: 1.55;
}

.onboarding-badge {
  display: inline-block;
  background: rgba(255,255,255,0.22);
  color: #fff;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 14px;
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.18);
}

.onboarding-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.onboarding-close-btn:hover {
  background: rgba(255,255,255,0.35);
  transform: scale(1.1);
}

/* ── Steps Body ── */
.onboarding-body {
  padding: 28px 28px 12px;
  max-height: 52vh;
  overflow-y: auto;
  background: #ffffff;
}

.step-card {
  display: flex;
  gap: 14px;
  margin-bottom: 14px;
  background: #f8fafb;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid #e8edf2;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.step-card:hover {
  border-color: #c4d8d3;
  box-shadow: 0 2px 8px rgba(18,140,126,0.08);
}

.step-number {
  background: linear-gradient(135deg, #128c7e, #15a085);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(18,140,126,0.25);
}

.step-content h3 {
  margin: 0 0 4px;
  font-size: 15px;
  color: #18212b;
  font-weight: 700;
}

.step-content p {
  color: #657382;
  font-size: 13px;
  line-height: 1.55;
  margin: 0;
}

.info-note {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  color: #78590a;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  margin-top: 6px;
  border: 1px solid #fde68a;
}

/* ── Footer ── */
.onboarding-footer {
  padding: 18px 28px;
  border-top: 1px solid #e8edf2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fafbfc;
}

.onboarding-footer p {
  font-size: 14px;
  color: #657382;
  margin: 0;
  font-weight: 600;
}

/* ── Onboarding Dialog Mobile ── */
@media (max-width: 720px) {
  .onboarding-dialog {
    width: 96vw;
    border-radius: 14px;
  }

  .onboarding-hero {
    padding: 28px 18px 24px;
  }

  .onboarding-hero h2 {
    font-size: 19px;
  }

  .onboarding-hero > p {
    font-size: 13px;
  }

  .onboarding-close-btn {
    width: 30px;
    height: 30px;
    font-size: 18px;
    top: 10px;
    right: 10px;
  }

  .onboarding-body {
    padding: 18px 16px 8px;
    max-height: 42vh;
  }

  .step-card {
    padding: 12px;
    gap: 10px;
  }

  .step-number {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }

  .step-content h3 {
    font-size: 14px;
  }

  .step-content p {
    font-size: 12px;
  }

  .info-note {
    font-size: 12px;
    padding: 10px 12px;
  }

  .onboarding-footer {
    padding: 14px 16px;
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }
}

