/* SPDX-License-Identifier: AGPL-3.0-or-later */
/* Copyright (C) 2024-2026 Philippe Naveau — contact@perfshop.io */
/* PerfShop — Test AI — https://perfshop.io */

/**
 * components.css — Atomic components shared across screens : buttons,
 * toast. Future B2.b/c/d additions go here too (modal-overlay,
 * pills, badges).
 *
 * Cascade : tokens → layout → THIS → inline-fix.
 */

/* ── Buttons ─────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none;
}

.btn:hover:not(:disabled) {
  background: var(--border);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent2);
  border-color: var(--accent2);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface2);
}

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

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #0d2c1a;
}

.btn-warning {
  background: var(--warning);
  border-color: var(--warning);
  color: #2e1c00;
}

.btn-sm  { padding: 6px 12px; font-size: 12px; }
.btn-xs  { padding: 4px  9px; font-size: 11px; }

/* Width-100% inside the login card so the submit button fills its
   column without an inline style attribute (CSP-friendly). */
.login-card .btn {
  width: 100%;
  margin-top: 4px;
}

/* ── Toast ───────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}

.toast.ta-toast-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.toast-ok    { border-color: var(--success); }
.toast-error { border-color: var(--danger);  color: #ffd1d4; }
.toast-warn  { border-color: var(--warning); }

/* ── Modal — LLM settings (B2.b) ────────────────────────────────── */

.ta-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .65);
  z-index: 90;
  padding: 24px;
}

.ta-modal-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(640px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .5);
  padding: 22px 24px 18px;
}

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

.ta-modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.ta-modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 6px;
}

.ta-modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.ta-modal-subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.ta-llm-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ta-llm-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ta-llm-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.ta-llm-field input,
.ta-llm-field select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.ta-llm-field input:focus,
.ta-llm-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.ta-llm-endpoint-control,
.ta-llm-api-key-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ta-llm-clear-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.ta-llm-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.ta-llm-disclaimer {
  margin: 0;
  padding: 10px 12px;
  background: rgba(255, 196, 0, .08);
  border: 1px solid rgba(255, 196, 0, .35);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
}

.ta-llm-status {
  min-height: 18px;
  font-size: 13px;
  padding: 4px 0;
}

.ta-llm-status.is-error   { color: #ffd1d4; }
.ta-llm-status.is-success { color: #b7f7d3; }

.ta-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ── Sidebar items + per-section actions (B2.c) ────────────────── */

.ta-sidebar-section-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.ta-sidebar-section-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  border-radius: 6px;
}

.ta-sidebar-section-toggle:hover { background: var(--surface2); }
.ta-sidebar-section-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.ta-sidebar-section.is-collapsed .ta-sidebar-chevron { transform: rotate(-90deg); }
.ta-sidebar-section.is-collapsed .ta-sidebar-body    { display: none; }

.ta-sidebar-section-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.ta-sidebar-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

.ta-sidebar-action-btn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

.ta-sidebar-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.ta-sidebar-body {
  list-style: none;
  margin: 0;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ta-sidebar-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 6px;
  background: var(--surface);
}

.ta-sidebar-item:hover { background: var(--surface2); }
.ta-sidebar-item.is-dragging { opacity: .35; }

.ta-sidebar-item-handle,
.ta-sidebar-item-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: grab;
  font-size: 14px;
  border-radius: 4px;
}

.ta-sidebar-item-handle { cursor: grab; }
.ta-sidebar-item-handle:active { cursor: grabbing; }

.ta-sidebar-item-handle:hover,
.ta-sidebar-item-delete:hover {
  background: var(--border);
  color: var(--text);
}

.ta-sidebar-item-handle:focus-visible,
.ta-sidebar-item-delete:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.ta-sidebar-item-body {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 6px 8px;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
  border-radius: 4px;
  overflow: hidden;
}

.ta-sidebar-item-body:hover { background: var(--surface2); }
.ta-sidebar-item-body:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.ta-sidebar-item-name {
  flex: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  font-size: 13px;
}

.ta-sidebar-item-sev {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ta-sidebar-item-sev.sev-low      { background: #6e7894; }
.ta-sidebar-item-sev.sev-medium   { background: var(--warning); }
.ta-sidebar-item-sev.sev-high     { background: #ff8838; }
.ta-sidebar-item-sev.sev-critical { background: var(--danger); }

.ta-sidebar-empty {
  list-style: none;
  padding: 12px 8px;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  text-align: center;
}

.ta-sidebar-empty.is-error { color: #ffd1d4; }

/* Screen-reader-only utility for the aria-live region. */
.ta-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Central-pane editor (B2.c) ────────────────────────────────── */

.ta-editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 20px;
  overflow-y: auto;
}

.ta-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.ta-editor-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.ta-editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.ta-editor-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ta-editor-field.ta-editor-field-content {
  flex: 1;
}

.ta-editor-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.ta-editor-field input,
.ta-editor-field select,
.ta-editor-field textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.ta-editor-field textarea {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  min-height: 220px;
}

.ta-editor-field input:focus,
.ta-editor-field select:focus,
.ta-editor-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.ta-editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* ── Confirm alert dialog (B2.c) ────────────────────────────────── */

.ta-confirm-card { max-width: 460px; }

.ta-confirm-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.ta-confirm-body {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

/* ── B2.d Run view (Logs / Vidéo / Script / Anomalie) ──────────── */

.ta-run-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
}

.ta-run-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.ta-run-tabs {
  display: flex;
  gap: 4px;
}

.ta-run-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .02em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

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

.ta-run-tab.is-active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.ta-run-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ta-run-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
}

.ta-run-status-running   { color: var(--accent);   border-color: var(--accent);   }
.ta-run-status-completed { color: #16a34a;         border-color: #16a34a;          }
.ta-run-status-failed    { color: #DC2626;         border-color: #DC2626;          }
.ta-run-status-cancelled { color: var(--muted);    }

.ta-run-pane {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
}

.ta-log-feed {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.ta-log-line {
  padding: 1px 0;
}

.ta-log-system { color: var(--muted); font-style: italic; }
.ta-log-error  { color: #DC2626; }

.ta-run-video {
  width: 100%;
  max-height: 65vh;
  background: #000;
  border-radius: 6px;
}

.ta-run-script {
  margin: 0;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
  background: var(--surface2);
  border-radius: 6px;
  padding: 12px;
  overflow: auto;
  color: var(--text);
}

.ta-run-anomaly {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 640px;
}

.ta-run-anomaly h3 { margin: 0; font-size: 16px; }
.ta-run-anomaly p  { margin: 0; color: var(--muted); line-height: 1.6; }

/* Iterate checkbox in the prompt bar */
.ta-prompt-iterate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
  cursor: pointer;
}

.ta-prompt-iterate input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}
