/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--border-radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-danger { background: transparent; color: var(--color-danger); border-color: var(--color-danger); }
.btn-danger:hover:not(:disabled) { background: var(--color-danger); color: #fff; }

.btn-secondary { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover:not(:disabled) { background: var(--color-border); }

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

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

.btn .spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }

/* ── Form elements ── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  color: var(--color-text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  transition: border-color var(--transition);
  outline: none;
}

.form-control:focus { border-color: var(--color-accent); }
.form-control::placeholder { color: var(--color-muted); }
.form-control:disabled { opacity: 0.5; cursor: not-allowed; }

.form-control.mono { font-family: var(--font-mono); font-size: 13px; }

textarea.form-control { resize: vertical; min-height: 80px; }
textarea.form-control.large { min-height: 300px; }
textarea.form-control.xl { min-height: 500px; }

.form-hint { font-size: 11px; color: var(--color-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ── Toggle / switch ── */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--color-accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}

.toggle-row:last-child { border-bottom: none; }
.toggle-row-label { font-size: 13px; }
.toggle-row-desc { font-size: 11px; color: var(--color-muted); margin-top: 2px; }

/* ── Cards ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 20px;
}

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

.card-title {
  font-size: 14px;
  font-weight: 600;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-review-negative { background: rgba(239,68,68,0.15); color: #f87171; }
.badge-review-positive { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge-question { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-complaint { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-chat { background: rgba(148,163,184,0.15); color: #94a3b8; }
.badge-recommendation { background: rgba(139,92,246,0.15); color: #a78bfa; }
.badge-pending { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-published { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge-failed { background: rgba(239,68,68,0.15); color: #f87171; }
.badge-processing { background: rgba(59,130,246,0.15); color: #60a5fa; }

/* ── Stars ── */
.stars { color: #fbbf24; font-size: 13px; letter-spacing: -1px; }
.star-empty { color: var(--color-border); }

/* ── Table ── */
.table-wrapper { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--color-surface-2); }


/* ── Chips ── */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  cursor: pointer;
  color: var(--color-muted);
  background: transparent;
  transition: all var(--transition);
}
.chip:hover { border-color: var(--color-accent); color: var(--color-accent); }
.chip.active { background: rgba(59,130,246,0.15); border-color: var(--color-accent); color: var(--color-accent); }

/* ── Search box ── */
.search-box {
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted);
  font-size: 13px;
}

.search-box .form-control { padding-left: 30px; }

/* ── Stats tiles ── */
.stat-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.stat-tile:hover { background: var(--color-surface-2); }

.stat-tile-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.stat-tile-label {
  font-size: 11px;
  color: var(--color-muted);
  line-height: 1.2;
}

.stat-tile-sep { color: var(--color-border); padding: 0 4px; }

/* ── Conversation list ── */
.conv-list {
  flex: 1;
  overflow-y: auto;
}

.conv-row {
  display: flex;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  gap: 10px;
  position: relative;
  transition: background var(--transition);
}

.conv-row:hover { background: var(--color-surface-2); }
.conv-row.selected { background: rgba(59,130,246,0.08); }

.conv-row-stripe {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 0 2px 2px 0;
}

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

.conv-row-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.conv-row-platform {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.conv-row-preview {
  font-size: 12px;
  color: var(--color-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
}

.conv-row-product {
  font-size: 12px;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 2px;
}

.conv-row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--color-muted);
}

.conv-row-icons { display: flex; gap: 4px; }

/* ── Conversation detail ── */
.detail-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 10px;
  min-height: 56px;
}

.detail-header-main {
  flex: 1;
  min-width: 0;
}

.detail-header-top {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}

.detail-header-sub {
  font-size: 11px;
  color: var(--color-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.platform-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.detail-client-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.detail-header-meta {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 2px;
  font-size: 10px;
  color: var(--color-muted);
  opacity: 0.65;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-header-meta .meta-item {
  font-size: 10px;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  gap: 8px;
}

.detail-empty-icon { font-size: 48px; opacity: 0.3; }

/* ── Chat history ── */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: var(--border-radius);
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg.client { align-self: flex-start; background: var(--color-surface-2); }
.chat-msg.business { align-self: flex-end; background: rgba(59,130,246,0.15); }
.chat-msg.system {
  align-self: center;
  background: transparent;
  border: 1px dashed var(--color-border);
  color: var(--color-muted);
  font-size: 12px;
}

.chat-msg-author {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: 3px;
}

.chat-msg-time {
  font-size: 10px;
  color: var(--color-muted);
  margin-top: 3px;
  text-align: right;
}

/* ── Draft editor ── */
.draft-section {
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
  flex-shrink: 0;
  background: var(--color-surface);
}

.draft-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
}

.draft-title { font-weight: 600; }
.draft-meta { color: var(--color-muted); font-size: 11px; }

.char-counter {
  font-size: 11px;
  font-weight: 600;
  transition: color var(--transition);
}

.char-counter.ok { color: var(--color-success); }
.char-counter.warn { color: var(--color-warning); }
.char-counter.over { color: var(--color-danger); }

.draft-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--border-radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  pointer-events: all;
  cursor: pointer;
  animation: slideIn 0.2s ease;
  max-width: 360px;
}

.toast-success { background: #14532d; color: #4ade80; border: 1px solid #166534; }
.toast-error   { background: #450a0a; color: #f87171; border: 1px solid #7f1d1d; }
.toast-info    { background: #0c4a6e; color: #38bdf8; border: 1px solid #075985; }
.toast-warning { background: #451a03; color: #fbbf24; border: 1px solid #78350f; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  animation: fadeIn 0.15s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.modal-close:hover { color: var(--color-text); background: var(--color-surface-2); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ── Skeleton loading ── */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface) 25%, var(--color-surface-2) 50%, var(--color-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-row {
  padding: 14px 12px;
  border-bottom: 1px solid var(--color-border);
}

.skeleton-line {
  height: 10px;
  margin-bottom: 6px;
}

/* ── Orchestrator indicator ── */
.orch-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--color-muted);
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--color-surface-2);
}

.orch-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-success);
  flex-shrink: 0;
}

.orch-dot.unhealthy { background: var(--color-danger); animation: pulse 1s infinite; }

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: 16px 0;
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--color-muted);
  text-align: center;
  gap: 8px;
}

.empty-state-icon { font-size: 40px; opacity: 0.4; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--color-text); }
.empty-state-desc { font-size: 13px; }

/* ── Section title ── */
.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  margin-bottom: 12px;
  margin-top: 24px;
}

.section-title:first-child { margin-top: 0; }

/* ── Prompts editor ── */
.prompts-layout {
  display: flex;
  gap: 0;
  height: 100%;
  overflow: hidden;
}

.prompts-list {
  width: 200px;
  min-width: 200px;
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 8px 0;
}

.prompt-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-muted);
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.prompt-item:hover { background: var(--color-surface-2); color: var(--color-text); }
.prompt-item.active { background: rgba(59,130,246,0.08); color: var(--color-text); border-left-color: var(--color-accent); }
.prompt-item-size { font-size: 10px; color: var(--color-muted); margin-top: 1px; }

.prompt-editor { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 16px; }
.prompt-editor-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.prompt-editor-title { font-size: 14px; font-weight: 600; }
.prompt-editor textarea { flex: 1; resize: none; font-size: 13px; }

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Light theme overrides ── */
[data-theme="light"] .toast-success { background: #f0fdf4; color: #15803d; border-color: #86efac; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
[data-theme="light"] .toast-error   { background: #fef2f2; color: #dc2626; border-color: #fca5a5; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
[data-theme="light"] .toast-info    { background: #eff6ff; color: #2563eb; border-color: #93c5fd; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
[data-theme="light"] .toast-warning { background: #fffbeb; color: #d97706; border-color: #fcd34d; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }

[data-theme="light"] .badge-review-negative { background: rgba(220,38,38,0.08); color: #dc2626; }
[data-theme="light"] .badge-review-positive { background: rgba(22,163,74,0.08); color: #16a34a; }
[data-theme="light"] .badge-question        { background: rgba(37,99,235,0.08); color: #2563eb; }
[data-theme="light"] .badge-complaint       { background: rgba(217,119,6,0.08); color: #d97706; }
[data-theme="light"] .badge-chat            { background: rgba(100,116,139,0.08); color: #475569; }
[data-theme="light"] .badge-recommendation { background: rgba(124,58,237,0.08); color: #7c3aed; }
[data-theme="light"] .badge-pending         { background: rgba(217,119,6,0.08); color: #d97706; }
[data-theme="light"] .badge-published       { background: rgba(22,163,74,0.08); color: #16a34a; }
[data-theme="light"] .badge-failed          { background: rgba(220,38,38,0.08); color: #dc2626; }
[data-theme="light"] .badge-processing      { background: rgba(37,99,235,0.08); color: #2563eb; }

[data-theme="light"] .chat-msg.business { background: rgba(59,130,246,0.08); }
