/* llm-proxy-poc — stili custom (Tailwind via CDN per il resto) */

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

.card {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%);
  opacity: 0.5;
  pointer-events: none;
}
.card:hover {
  border-color: #475569;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.card h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #e2e8f0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  font-size: 0.875rem;
}

.btn-primary {
  background: #3b82f6;
  color: white;
}
.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { background: #475569; cursor: not-allowed; }

.btn-danger {
  background: #dc2626;
  color: white;
}
.btn-danger:hover { background: #b91c1c; }

.btn-ghost {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #334155;
}
.btn-ghost:hover { background: #334155; color: white; }

.input, .textarea, .select {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: #e2e8f0;
  font-family: inherit;
  font-size: 0.875rem;
}

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.textarea {
  font-family: ui-monospace, "SF Mono", "Monaco", monospace;
  resize: vertical;
  min-height: 200px;
}

.badge {
  display: inline-flex;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-green { background: #064e3b; color: #6ee7b7; }
.badge-blue  { background: #1e3a8a; color: #93c5fd; }
.badge-red   { background: #7f1d1d; color: #fca5a5; }
.badge-gray  { background: #334155; color: #cbd5e1; }

.nav {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 0.75rem 1.5rem;
  display: flex;
  gap: 1rem;
  align-items: center;
}

.nav a {
  color: #94a3b8;
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
}
.nav a:hover { background: #334155; color: white; }
.nav a.active { background: #3b82f6; color: white; }
.nav .brand { font-weight: 700; color: white; margin-right: 1rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

.toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  background: #1e293b;
  border: 1px solid #334155;
  color: white;
  z-index: 1000;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}
.toast.success { border-color: #10b981; }
.toast.error { border-color: #ef4444; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.4rem 0.5rem; text-align: left; border-bottom: 1px solid #334155; }
th { color: #94a3b8; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
tr:hover { background: rgba(255,255,255,0.03); }

code {
  font-family: ui-monospace, "SF Mono", monospace;
  background: #0f172a;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.85em;
  color: #93c5fd;
}

pre {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.85em;
}

.spinner {
  display: inline-block;
  width: 1rem; height: 1rem;
  border: 2px solid #334155;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: #64748b;
}
.empty h3 { color: #94a3b8; margin-bottom: 0.5rem; }

.kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  padding: 0.125rem 0.375rem;
  background: #334155;
  border: 1px solid #475569;
  border-radius: 0.25rem;
  color: #cbd5e1;
}

/* Toggle switch per API key (abilita/disabilita tenant key).
   Pattern classico iOS-style: input hidden + slider visivo. */
.key-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}
.key-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.key-toggle-slider {
  position: absolute;
  inset: 0;
  background-color: #475569; /* off: grigio */
  border-radius: 20px;
  transition: background-color 0.2s;
}
.key-toggle-slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  top: 3px;
  background-color: #f1f5f9;
  border-radius: 50%;
  transition: transform 0.2s;
}
.key-toggle input:checked + .key-toggle-slider {
  background-color: #10b981; /* on: verde */
}
.key-toggle input:checked + .key-toggle-slider::before {
  transform: translateX(16px);
}
.key-toggle input:focus + .key-toggle-slider {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4);
}
.key-toggle input:disabled + .key-toggle-slider {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === System Config: pannello collassabile (master only) ===
   Pattern: header sticky, body collassa con animazione max-height,
   chevron ruota per feedback visivo, stato persistito in localStorage. */
.system-config-header {
  outline: none;
}
.system-config-header:hover {
  color: #e2e8f0;
}
.system-config-header:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-radius: 0.25rem;
}
.system-config-chevron {
  font-size: 0.65rem;
  color: #64748b;
  width: 14px;
  display: inline-block;
  text-align: center;
}
#systemConfigCard.collapsed .system-config-chevron,
#upstreamBackupsCard.collapsed .system-config-chevron,
#discoveredModelsCard.collapsed .system-config-chevron,
#authCard.collapsed .system-config-chevron,
#evalCard.collapsed .system-config-chevron,
#capabilityCard.collapsed .system-config-chevron,
#benchmarkCard.collapsed .system-config-chevron {
  transform: rotate(-90deg);
}
.system-config-body {
  max-height: 4000px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease, margin-top 0.2s ease;
}
#systemConfigCard.collapsed .system-config-body,
#upstreamBackupsCard.collapsed .system-config-body,
#discoveredModelsCard.collapsed .system-config-body,
#authCard.collapsed .system-config-body,
#evalCard.collapsed .system-config-body,
#capabilityCard.collapsed .system-config-body,
#benchmarkCard.collapsed .system-config-body {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

/* === Key Metrics Card compatto (Master + tenant) ===
   Design compatto e visivamente accattivante: hero metric grande a sx,
   sparkline a dx, sub-metriche inline, status pill con colore dinamico. */
.key-metric-card {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
  overflow: hidden;
}
.key-metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%);
  opacity: 0.5;
}
.key-metric-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border-color: #475569;
}
.key-metric-card.disabled {
  opacity: 0.5;
}
.key-metric-card .hero-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, #60a5fa 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.key-metric-card.idle .hero-value {
  background: linear-gradient(135deg, #475569 0%, #64748b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.key-metric-card .trend-up {
  color: #4ade80;
}
.key-metric-card .trend-down {
  color: #f87171;
}
.key-metric-card .trend-flat {
  color: #94a3b8;
}
.key-metric-card .sub-metric {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  background: #020617;
  border-radius: 0.375rem;
  font-size: 0.7rem;
  white-space: nowrap;
}
.key-metric-card .sub-metric .label {
  color: #64748b;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.key-metric-card .sub-metric .value {
  color: #e2e8f0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.key-metric-card .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.key-metric-card .status-pill.live {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.3);
}
.key-metric-card .status-pill.idle {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}
.key-metric-card .status-pill .pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.key-metric-card .sparkline-container {
  height: 50px;
  background: #020617;
  border-radius: 0.375rem;
  padding: 0.25rem;
  position: relative;
}
.key-metric-card .top-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.65rem;
  color: #94a3b8;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #1e293b;
}
.key-metric-card .top-info strong {
  color: #cbd5e1;
  font-weight: 500;
}

/* === Quota & Rate Limit Card compatto ===
   Stesso pattern delle key-metric-card ma con 2 mini-bars orizzontali
   (5h + weekly/7d), hero % usato in font grande, e refresh pill. */
.quota-metric-card {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 0.6rem 0.9rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
  overflow: hidden;
}
.quota-metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #8b5cf6 0%, #3b82f6 100%);
  opacity: 0.5;
}
.quota-metric-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border-color: #475569;
}
.quota-metric-card .quota-error {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 0.375rem;
  padding: 0.3rem 0.5rem;
  margin-top: 0.4rem;
  font-size: 0.7rem;
  color: #fed7aa;
}

/* Quota card grid: 2 colonne desktop, 1 colonna mobile */
.quota-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}
@media (max-width: 900px) {
  .quota-grid {
    grid-template-columns: 1fr;
  }
}

/* === Section card (Top-level panels) ===
   Stesso pattern visivo delle quota-metric-card ma per sezioni top-level
   che contengono form, tabelle, o contenuto strutturato. Padding leggermente
   maggiore (0.85rem 1rem) per dare respiro al contenuto interno.
   Le modali (.card) mantengono lo stile legacy "overlay" — sono visivamente
   diverse perché sono dialoghi centrati, non pannelli di pagina. */
.section-card {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 0.85rem 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}
.section-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%);
  opacity: 0.5;
  pointer-events: none;
}
.section-card:hover {
  border-color: #475569;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.section-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 0.75rem;
}
.section-card h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 0.5rem;
}
.section-card table {
  font-size: 0.8rem;
}
.section-card > p.section-footer,
.section-card p.section-footer {
  color: #64748b;
  font-size: 0.7rem;
  margin-top: 0.75rem;
  margin-bottom: 0;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(30, 41, 59, 0.5);
}
