/* ============================================================
   endpoints.css — Endpoint Configurator Styles
   ============================================================
   Covers: card layout, model discovery, test connection,
   toast notifications, error/empty states, delete modal,
   status pills, error banners, skeletons, transitions.
   Design tokens from base.html (--bg-surface, --border-standard,
   --radius-xl, --shadow-elevated, --text-*, --danger, --accent,
   --info, --warn, --font-mono, etc.).
   ============================================================ */

/* ── Card Grid ─────────────────────────────────────────── */
.ep-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* ── Card ──────────────────────────────────────────────── */
.ep-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-standard);
  border-radius: var(--radius-xl);
  overflow: hidden;
  /* Fallback spacing when grid is not active */
  margin-bottom: 16px;
}

.ep-card-header,
.ep-card-heading.ep-card-heading-legacy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.ep-card-header strong,
.ep-card-heading .ep-card-title {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
}

/* Remove bottom margin on last card (block layout fallback) */
.ep-card:last-child {
  margin-bottom: 0;
}

/* When inside grid, let gap handle spacing */
.ep-grid > .ep-card {
  margin-bottom: 0;
}

.ep-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ep-card-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ── Fields ────────────────────────────────────────────── */
.ep-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 639px) {
  .ep-field-row {
    grid-template-columns: 1fr;
  }
}

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

.ep-field label {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ep-field input,
.ep-field select {
  background: var(--bg-root);
  border: 1px solid var(--border-standard);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 12px;
  width: 100%;
  box-sizing: border-box;
  transition: border-color var(--transition);
}

.ep-field input:focus,
.ep-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.ep-field input::placeholder {
  color: var(--text-quaternary);
}

.ep-field.full-row {
  grid-column: 1 / -1;
}

/* ── Badges ──────────────────────────────── */
.ep-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ep-badge--oauth {
  background: var(--info-dim);
  color: var(--info);
}

.ep-badge--enabled {
  background: var(--accent-dim, rgba(78, 232, 138, 0.15));
  color: var(--accent, #4ee88a);
}

.ep-badge--disabled {
  background: var(--warn-dim, rgba(255, 203, 102, 0.15));
  color: var(--warn, #ffcb66);
}

.ep-badge--failover {
  background: var(--danger-dim, rgba(255, 107, 122, 0.15));
  color: var(--danger, #ff6b7a);
}

/* ── Hidden fields ──────────────────────────────── */
.ep-field--hidden {
  display: none !important;
}

/* ── Field variants (used by JS card builder) ────────────── */
.ep-field--id {
  flex: 0 0 120px;
}

.ep-field--id span {
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 8px 0;
}

.ep-field--action {
  align-items: flex-end;
  justify-content: flex-end;
  padding-top: 18px; /* align with input baseline */
}

/* ── Toggle / Checkbox label ─────────────────────────────── */
.ep-toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 0;
}

.ep-toggle-label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

/* ── Notes field ─────────────────────────────────────────── */
.ep-field-notes textarea {
  background: var(--bg-root);
  border: 1px solid var(--border-standard);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 12px;
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 48px;
  transition: border-color var(--transition);
}

.ep-field-notes textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ── Health indicator ────────────────────────────────────── */
.ep-health {
  padding: 0 0 4px;
}

.health-indicator {
  display: inline-block;
  font-size: 12px;
}

.health-indicator--hidden {
  display: none;
}

.ep-field.invalid input {
  border-color: var(--danger);
  box-shadow: var(--shadow-error);
}

.ep-field .error {
  display: none;
  color: var(--danger);
  font-size: 11px;
  margin-top: 2px;
}

.ep-field.invalid .error {
  display: block;
}

/* ── API Key ───────────────────────────────────────────── */
.ep-api-key-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ep-api-key-wrap input {
  flex: 1;
}

.ep-api-key-toggle {
  background: var(--btn-ghost-bg);
  border: 1px solid var(--border-standard);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 14px;
  padding: 6px 10px;
  line-height: 1;
  flex-shrink: 0;
}

.ep-api-key-toggle:hover {
  background: var(--btn-ghost-hover-bg);
  color: var(--text-primary);
}

/* ── Model Discovery Status ────────────────────────────── */
.ep-model-status {
  display: inline-block;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
  transition: opacity 0.3s ease;
}

.ep-model-status.loading {
  color: var(--info);
}

.ep-model-status.success {
  color: var(--accent);
}

.ep-model-status.error {
  color: var(--danger);
}

.ep-model-status.warn {
  color: var(--warn);
}

.ep-model-status.fading {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ep-model-raw {
  margin-top: 4px;
}

.ep-model-raw summary {
  color: var(--text-tertiary);
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}

.ep-model-raw pre {
  background: var(--bg-root);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 4px;
  max-height: 160px;
  overflow: auto;
  padding: 8px 12px;
}

/* ── Test Connection Status ────────────────────────────── */
.ep-test-status {
  display: none;
  font-size: 12px;
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  white-space: nowrap;
  transition: opacity 0.3s ease;
}

.ep-test-status.testing {
  display: inline-block;
  background: var(--info-dim);
  color: var(--info);
}

.ep-test-status.success {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
}

.ep-test-status.error {
  display: inline-block;
  background: var(--danger-dim);
  color: var(--danger);
}

.ep-test-status.warn {
  display: inline-block;
  background: var(--warn-dim);
  color: var(--warn);
}

.ep-test-status.fading {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ep-test-raw {
  width: 100%;
}

.ep-test-raw summary {
  color: var(--text-tertiary);
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}

.ep-test-raw pre {
  background: var(--bg-root);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 4px;
  max-height: 200px;
  overflow: auto;
  padding: 8px 12px;
}

.ep-test-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ep-spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}

/* ── Error / Empty States ──────────────────────────────── */
.ep-error-state {
  grid-column: 1 / -1;
}

.ep-empty-state {
  grid-column: 1 / -1;
}

.ep-error-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ep-error-raw {
  width: 100%;
  overflow-x: auto;
  max-height: 200px;
}

/* ── Toast Notifications ───────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--z-toast, 4000);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-visible);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  color: var(--text-primary);
  font-size: 13px;
  padding: 12px 20px;
  pointer-events: auto;
  animation: toastIn 0.25s ease;
  max-width: 400px;
}

.toast.ok {
  border-color: var(--accent);
}

.toast.err {
  border-color: var(--danger);
  color: var(--danger);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Delete Modal ──────────────────────────────────────── */
.del-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal, 3100);
}

.del-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-standard);
  border-radius: var(--radius-xl);
  padding: 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-elevated);
}

.del-modal h3 {
  color: var(--text-primary);
  font-size: 16px;
  margin: 0 0 8px;
}

.del-modal p {
  color: var(--text-tertiary);
  font-size: 13px;
  margin: 0 0 20px;
}

.del-modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.del-modal .btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
}

.del-modal .btn-danger:hover {
  background: var(--danger-hover-bg);
}

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

.del-modal-buttons button {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
}

/* ── Status Pill ───────────────────────────────────────── */
.ep-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

.ep-status--untested {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.ep-status--testing {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  animation: ep-pulse 1.5s ease-in-out infinite;
}

.ep-status--pass {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.ep-status--fail {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.ep-status--unknown {
  background: rgba(107, 114, 128, 0.15);
  color: #6b7280;
}

.ep-status-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ep-spin 0.6s linear infinite;
}

@keyframes ep-spin {
  to { transform: rotate(360deg); }
}

@keyframes ep-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* ── Error Banner ──────────────────────────────────────── */
.ep-error-banner {
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}

.ep-error-banner h4 {
  color: var(--danger);
  margin: 0 0 6px;
  font-size: 14px;
}

.ep-error-banner p {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 12px;
}

.ep-error-banner button {
  margin-right: 8px;
}

.ep-error-raw {
  background: var(--bg-root);
  padding: 12px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 8px;
  max-height: 200px;
  overflow-y: auto;
}

/* ── Skeleton Card ─────────────────────────────────────── */
.ep-skeleton {
  background: var(--bg-surface);
  border: 1px solid var(--border-standard);
  border-radius: var(--radius-xl);
  height: 180px;
  overflow: hidden;
}

.ep-skeleton .shimmer {
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.03),
    transparent
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Card Transitions ──────────────────────────────────── */
.ep-card.removing {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 200ms ease, transform 200ms ease;
}

.ep-card-body.fade-in {
  animation: cardFadeIn 300ms ease forwards;
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Screen Reader Only ────────────────────────────────── */
.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;
}

/* ── Extras ────────────────────────────────────────────── */
.ep-card-footer .test-error-detail {
  width: 100%;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
  word-break: break-all;
}

/* Endpoint command center redesign */
.endpoint-command-center {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.ep-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: 22px;
  border: 1px solid var(--border, rgba(148, 163, 184, 0.22));
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(8, 13, 20, 0.96));
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.26);
}
.ep-eyebrow {
  color: var(--accent, #4ee88a);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.ep-page-subtitle {
  color: var(--text-muted, #94a3b8);
  max-width: 780px;
  margin: 10px 0 0;
  line-height: 1.5;
}
.ep-page-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.ep-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.ep-summary-card {
  border: 1px solid var(--border, rgba(148, 163, 184, 0.22));
  border-radius: 16px;
  padding: 14px 16px;
  background: rgba(15, 23, 42, 0.72);
}
.ep-summary-value {
  display: block;
  color: var(--text-primary, #e5eef7);
  font-size: 1.35rem;
  font-weight: 900;
}
.ep-summary-label {
  display: block;
  color: var(--text-muted, #94a3b8);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 4px;
}
.ep-filter-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) repeat(4, auto);
  gap: 10px;
  border: 1px solid var(--border, rgba(148, 163, 184, 0.22));
  border-radius: 18px;
  padding: 12px;
  background: rgba(8, 13, 20, 0.78);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 12px;
  z-index: 5;
}
.ep-filter-search {
  margin: 0;
}
.ep-filter-search input {
  width: 100%;
  box-sizing: border-box;
}
.ep-filter-select {
  min-width: 140px;
}
.ep-filter-hint {
  color: var(--text-muted, #94a3b8);
  font-size: 0.82rem;
}
.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;
}
@media (max-width: 1100px) {
  .ep-page-header,
  .ep-filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .ep-filter-bar {
    grid-template-columns: 1fr;
    position: static;
  }
  .ep-page-actions {
    justify-content: flex-start;
  }
  .ep-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 720px) {
  .ep-summary-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Hidden utility ───────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Card heading refinements ──────────────────────────── */
.ep-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 10px;
}

.ep-card-heading-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.ep-card-heading-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ep-card-title {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ep-card-slug {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  opacity: 0.75;
}

/* ── State badges ──────────────────────────────────────── */
.ep-badge--enabled {
  background: var(--accent-dim, rgba(78, 232, 138, 0.15));
  color: var(--accent, #4ee88a);
}

.ep-badge--disabled {
  background: var(--warn-dim, rgba(255, 203, 102, 0.15));
  color: var(--warn, #ffcb66);
}

.ep-badge--failover {
  background: var(--info-dim, rgba(98, 174, 255, 0.12));
  color: var(--info, #62aeff);
}

/* ── Reasoning preview ─────────────────────────────────── */
.ep-reasoning-preview {
  display: block;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 4px;
  word-break: break-all;
  line-height: 1.5;
}


/* ==========================================================================
   AUTO-TEST: Greyed-out unhealthy endpoints
   Applied by HealthIndicator when test probe fails (connection refused,
   timeout, HTTP 4xx/5xx, out of funds, etc.)
   ========================================================================== */
.ep-card--unhealthy {
    opacity: 0.5;
    filter: grayscale(40%);
    transition: opacity 0.3s ease, filter 0.3s ease;
}

.ep-card--unhealthy:hover {
    opacity: 0.75;
    filter: grayscale(20%);
}

.ep-card--unhealthy .ep-card-heading .ep-badge--enabled {
    background: var(--warn-dim, rgba(250, 204, 21, 0.12));
    color: var(--warn, #facc15);
}
