/* ── Automations Page ─────────────────────────────────── */
.automations-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.automations-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Page header ──────────────────────────────────────── */
.am-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.am-page-header-left h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}
.am-page-header-left p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}
.am-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Status pill ──────────────────────────────────────── */
.bot-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
}
.bot-status-pill.on  { background: var(--green-light); color: var(--green); }
.bot-status-pill.off { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.bot-status-pill .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.bot-status-pill.on .dot { animation: am-pulse 1.8s ease infinite; }
@keyframes am-pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .4; }
}

/* ── KPI stats grid ───────────────────────────────────── */
.am-stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.am-stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s;
}
.am-stat-card:hover { box-shadow: var(--shadow-md, 0 4px 12px rgba(0,0,0,.08)); }
.am-stat-icon {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.am-stat-icon.green  { background: var(--green-light);  color: var(--green); }
.am-stat-icon.blue   { background: var(--blue-light);   color: var(--blue); }
.am-stat-icon.amber  { background: #fef3c7;              color: #d97706; }
.am-stat-icon.purple { background: #f3e8ff;              color: #9333ea; }
.am-stat-icon.slate  { background: var(--bg);            color: var(--text-secondary); border: 1px solid var(--border); }
.am-stat-icon svg { width: 17px; height: 17px; }
.am-stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.am-stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.3;
}

/* ── Main two-column grid ─────────────────────────────── */
.am-main-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}

/* ── Config card ──────────────────────────────────────── */
.am-config-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.am-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.am-card-icon {
  width: 36px; height: 36px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.am-card-icon svg { width: 18px; height: 18px; }
.am-card-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.am-card-sub   { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Toggle section ───────────────────────────────────── */
.am-toggles {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.am-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  gap: 16px;
  transition: background .12s;
}
.am-toggle-row:hover { background: var(--bg); }
.am-toggle-row + .am-toggle-row {
  border-top: 1px solid var(--border-light, var(--border));
}
.am-toggle-info { flex: 1; min-width: 0; }
.am-toggle-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.am-toggle-desc  { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* Modern pill toggle */
.am-switch {
  position: relative;
  width: 42px; height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.am-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.am-track {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background .2s;
}
.am-thumb {
  position: absolute;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s cubic-bezier(.4,0,.2,1);
}
.am-switch input:checked ~ .am-track  { background: var(--accent); }
.am-switch input:checked ~ .am-thumb  { transform: translateX(18px); }
.am-switch input:focus-visible ~ .am-track { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── Config fields grid ───────────────────────────────── */
.am-fields {
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.am-field { display: flex; flex-direction: column; gap: 5px; }
.am-field.full { grid-column: 1 / -1; }
.am-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.am-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}
.am-hint a { color: var(--accent); text-decoration: none; }
.am-input-wrap { display: flex; gap: 8px; }
.am-input-wrap input { flex: 1; }

input[type="text"].am-input,
input[type="password"].am-input,
select.am-select,
textarea.am-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg);
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.4;
}
input[type="text"].am-input:focus,
input[type="password"].am-input:focus,
select.am-select:focus,
textarea.am-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  outline: none;
}
select.am-select { cursor: pointer; }

textarea.am-textarea {
  min-height: 200px;
  resize: vertical;
  font-family: 'Fira Code', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.65;
}

/* ── Config card footer ───────────────────────────────── */
.am-config-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ── Buttons ──────────────────────────────────────────── */
.am-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s, transform .1s;
  white-space: nowrap;
  line-height: 1;
}
.am-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.am-btn:active { transform: scale(.97); }
.am-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.am-btn-primary {
  background: var(--accent);
  color: #fff;
}
.am-btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.am-btn-secondary {
  background: var(--card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.am-btn-secondary:hover:not(:disabled) { background: var(--bg); }

.am-btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
  font-size: 11px;
}
.am-btn-ghost:hover { color: var(--text-primary); }

.am-btn-icon {
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.am-btn-icon svg { width: 16px; height: 16px; }
.am-btn-icon:hover { background: var(--bg); }

/* ── Test panel (right column) ────────────────────────── */
.am-test-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.am-test-chat {
  min-height: 140px;
  max-height: 320px;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}
.am-test-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
  min-height: 120px;
}
.am-test-empty svg { width: 28px; height: 28px; opacity: .4; }
.am-test-empty p { font-size: 12px; }

.am-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.am-msg-bubble {
  max-width: 90%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.am-msg.user { flex-direction: row-reverse; }
.am-msg.user .am-msg-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 12px 2px 12px 12px;
}
.am-msg.bot .am-msg-bubble {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 2px 12px 12px 12px;
}
.am-msg.bot.error .am-msg-bubble {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #dc2626;
}
.am-msg-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.am-msg.user .am-msg-avatar { background: var(--accent); color: #fff; }
.am-msg.bot  .am-msg-avatar { background: var(--bg); border: 1px solid var(--border); color: var(--text-secondary); }
.am-msg.bot  .am-msg-avatar svg { width: 13px; height: 13px; }

.am-msg-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  padding: 0 4px;
  text-align: right;
}

.am-test-typing { display: flex; gap: 3px; padding: 10px 14px; }
.am-test-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: am-bounce 1.1s ease infinite;
}
.am-test-typing span:nth-child(2) { animation-delay: .18s; }
.am-test-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes am-bounce {
  0%,60%,100% { transform: translateY(0); }
  30%          { transform: translateY(-5px); }
}

.am-test-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.am-test-footer input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg);
  color: var(--text-primary);
}
.am-test-footer input:focus { border-color: var(--accent); outline: none; }

.am-test-meta {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: none;
}

/* ── System prompt section (full-width below grid) ───── */
.am-prompt-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.am-prompt-body { padding: 16px 18px; }
.am-prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

/* ── Leads card ───────────────────────────────────────── */
.am-leads-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.am-leads-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.am-leads-title { font-size: 14px; font-weight: 700; }
.am-leads-tabs { display: flex; gap: 3px; margin-left: 4px; }
.am-leads-tab {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  transition: background .12s, color .12s;
}
.am-leads-tab.active   { background: var(--accent-light); color: var(--accent); }
.am-leads-tab:hover:not(.active) { background: var(--bg); }

.am-leads-actions { margin-left: auto; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 1024px) {
  .am-stats-grid { grid-template-columns: repeat(3, 1fr); }
  .am-main-grid  { grid-template-columns: 1fr; }
  .am-test-card  { position: static; }
}
@media (max-width: 640px) {
  .automations-body { padding: 16px; gap: 14px; }
  .am-stats-grid    { grid-template-columns: repeat(2, 1fr); }
  .am-fields        { grid-template-columns: 1fr; }
  .am-page-header   { flex-direction: column; }
}

/* ── Skeleton shimmer ─────────────────────────────────── */
.am-skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: am-shimmer 1.4s ease infinite;
  border-radius: 4px;
}
@keyframes am-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
