/* ======== MODALS ======== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h2 { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }

/* Preview modal */
.preview-modal-box {
  background: var(--card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 420px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.preview-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--bg);
  flex-shrink: 0;
}
.preview-toolbar-label { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.preview-theme-btns { display: flex; gap: 4px; }
.preview-theme-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.preview-theme-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.preview-color-wrap { display: flex; align-items: center; gap: 6px; }
.preview-color-wrap input[type=color] { width: 30px; height: 30px; border: 1.5px solid var(--border); border-radius: 6px; cursor: pointer; padding: 2px; background: #fff; }
.preview-save-btn {
  margin-left: auto;
  padding: 5px 14px;
  border-radius: 7px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}
.preview-save-btn:hover { background: var(--primary-dark); }
.preview-modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.preview-modal-header h2 { font-size: 1rem; font-weight: 700; margin: 0; }
.preview-pane { background: #f1f5f9; flex: 1; position: relative; overflow: hidden; min-height: 480px; }
.preview-pane-label {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .72rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
  z-index: 5;
  pointer-events: none;
}

/* ======== LOGIN VIEW ======== */
#loginView {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}
#loginView.show { display: flex; }
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  margin: 24px;
}
.login-card h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); font-size: .875rem; margin-bottom: 24px; }

/* ======== ONBOARDING VIEW ======== */
#onboardView {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 20px;
}
#onboardView.show { display: flex; }
.onboard-inner { width: 100%; max-width: 520px; }

/* ======== TOAST NOTIFICATIONS ======== */
#globalAlerts { position: fixed; top: 68px; right: 24px; z-index: 500; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }
.toast { padding: 12px 16px; border-radius: var(--radius); font-size: .875rem; box-shadow: 0 4px 16px rgba(0,0,0,.1); animation: slideIn .2s ease; }
@keyframes slideIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: translateX(0); } }
.toast-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.toast-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ======== CONVERSATIONS VIEW ======== */
.conv-card { border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--card); margin-bottom: 10px; overflow: hidden; transition: border-color 0.15s; }
.conv-card:hover { border-color: var(--primary); }
.conv-header { display: flex; align-items: center; gap: 14px; padding: 14px 18px; cursor: pointer; user-select: none; }
.conv-avatar { width: 36px; height: 36px; border-radius: 50%; background: #eff6ff; color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; font-weight: 700; }
.conv-info { flex: 1; min-width: 0; }
.conv-visitor { font-weight: 600; font-size: .875rem; color: var(--text); }
.conv-preview { font-size: .8rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.conv-time { font-size: .75rem; color: var(--muted); }
.conv-count { font-size: .72rem; font-weight: 600; background: #eff6ff; color: var(--primary); padding: 2px 8px; border-radius: 10px; }
.conv-chevron { color: var(--muted); font-size: .9rem; margin-left: 8px; transition: transform 0.2s; flex-shrink: 0; }
.conv-card.open .conv-chevron { transform: rotate(90deg); }
.conv-messages { display: none; border-top: 1px solid var(--border); background: #f8fafc; padding: 16px; max-height: 420px; overflow-y: auto; }
.conv-card.open .conv-messages { display: flex; flex-direction: column; gap: 10px; }
.msg-bubble { max-width: 75%; padding: 10px 14px; border-radius: 14px; font-size: .845rem; line-height: 1.55; word-break: break-word; }
.msg-bubble.visitor { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.msg-bubble.bot { align-self: flex-start; background: #fff; color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg-role-label { font-size: .7rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.msg-wrapper { display: flex; flex-direction: column; }
.msg-wrapper.visitor { align-items: flex-end; }
.msg-wrapper.bot { align-items: flex-start; }
.conv-loading { text-align: center; color: var(--muted); font-size: .875rem; padding: 16px 0; }
.skeleton { background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
