* { box-sizing: border-box; }
:root {
  --bg: #0b1220;
  --surface: #121a2d;
  --surface-2: #1a253e;
  --text: #e6ecf5;
  --muted: #8796ae;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #10b981;
  --ko: #ef4444;
  --warn: #f59e0b;
  --border: #273350;
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }

.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.topbar .brand a { font-weight: 700; font-size: 16px; color: var(--text); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.topbar .logout { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.topbar .logout span { color: var(--muted); font-size: 13px; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

h1 { margin-top: 0; font-size: 24px; }
h2 { margin-top: 32px; font-size: 18px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }

.row-spread { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 24px 0; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 24px; font-weight: 600; margin: 6px 0; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.kpi.ok .kpi-value { color: var(--ok); }
.kpi.ko .kpi-value { color: var(--ko); }

/* Tabelle */
table { width: 100%; border-collapse: collapse; margin: 12px 0; background: var(--surface); border-radius: 8px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-off { opacity: 0.5; }
.row-err { background: rgba(239, 68, 68, 0.05); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Form */
form label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
form label input, form label textarea, form label select {
  display: block; width: 100%; margin-top: 4px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-size: 14px;
}
.form-narrow { max-width: 520px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.range-form { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.range-form label { margin-bottom: 0; }

button, .btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
  font-family: inherit;
}
button:hover, .btn:hover { background: var(--border); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); }
button.btn-warn, .btn-warn { background: var(--warn); color: #1a1a1a; border-color: var(--warn); }

/* Login */
.login-card {
  max-width: 360px; margin: 80px auto; background: var(--surface);
  padding: 32px; border-radius: 12px; border: 1px solid var(--border);
}
.login-card h1 { margin: 0 0 8px; }

/* Alert */
.alert { padding: 10px 14px; border-radius: 6px; margin: 12px 0; }
.alert-error { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--ko); color: #fca5a5; }
.alert-warn { background: rgba(245, 158, 11, 0.15); border: 1px solid var(--warn); color: #fde68a; }

.key-box {
  background: #000; color: #7dd3fc; padding: 16px; border-radius: 6px;
  font-family: "SF Mono", Consolas, monospace; word-break: break-all;
  user-select: all;
}

/* dl */
dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 16px 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* progress bar */
.progress {
  height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 4px;
}
.progress span { display: block; height: 100%; background: var(--accent); }

/* ========== Componenti per schemas / test panel / releases ========== */
.lead { color: var(--muted); font-size: 14px; max-width: 880px; }
.meta { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.muted { color: var(--muted); }
.mono { font-family: "SF Mono", Consolas, monospace; font-size: 12px; }

.banner {
  padding: 12px 16px; border-radius: 6px; margin: 12px 0;
  border: 1px solid transparent;
}
.banner-ok { background: rgba(16, 185, 129, 0.1); border-color: var(--ok); color: #a7f3d0; }
.banner-err { background: rgba(239, 68, 68, 0.12); border-color: var(--ko); color: #fecaca; }

.codearea {
  width: 100%;
  background: #0a0f1c;
  color: #d4dae6;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  tab-size: 2;
  resize: vertical;
}
.codearea:focus { outline: none; border-color: var(--accent); }

.actions { margin-top: 12px; display: flex; gap: 8px; }

.form-inline { display: grid; gap: 12px; max-width: 720px; margin-bottom: 28px; }
.form-inline label { font-weight: 600; font-size: 13px; }
.form-inline select,
.form-inline textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}
.form-inline textarea { resize: vertical; }

.truncate { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-x { overflow-x: auto; max-width: 100%; }
.table-data { font-size: 12px; }
.table-data td { white-space: nowrap; }

.quote {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  padding: 12px 14px;
  border-radius: 4px;
  font-family: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}
.code {
  background: #0a0f1c;
  color: #d4dae6;
  padding: 12px 14px;
  border-radius: 6px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ========== MODALI CUSTOM (showConfirm / showAlert / showPromptForm) ========== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(5, 8, 14, 0.65);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease;
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(460px, calc(100vw - 32px));
  padding: 22px 24px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}
.modal-overlay.show .modal-card { transform: translateY(0) scale(1); }
.modal-title { font-size: 15px; font-weight: 600; margin: 0 0 8px; color: var(--text); }
.modal-message { color: var(--muted); font-size: 13.5px; line-height: 1.55; margin: 0 0 16px; }
.modal-fields { display: flex; flex-direction: column; gap: 10px; margin: 0 0 18px; }
.modal-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.modal-fields input, .modal-fields textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
}
.modal-fields input:focus, .modal-fields textarea:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button { padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; border: 1px solid var(--border); }
.modal-actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal-actions button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.modal-actions button.danger  { background: var(--ko); color: #fff; border-color: var(--ko); }
.modal-actions button.ghost   { background: transparent; color: var(--text); }
.modal-actions button.ghost:hover { background: var(--surface-2); }
.modal-card.variant-info    { border-top: 3px solid var(--accent); }
.modal-card.variant-success { border-top: 3px solid var(--ok); }
.modal-card.variant-warning { border-top: 3px solid var(--warn); }
.modal-card.variant-danger  { border-top: 3px solid var(--ko); }
.modal-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  margin-bottom: 10px; font-size: 18px; line-height: 1;
}
.modal-icon.variant-info    { background: rgba(59, 130, 246, 0.15); color: #6ea8ff; }
.modal-icon.variant-success { background: rgba(16, 185, 129, 0.15); color: var(--ok); }
.modal-icon.variant-warning { background: rgba(245, 158, 11, 0.15); color: var(--warn); }
.modal-icon.variant-danger  { background: rgba(239, 68, 68, 0.15);  color: var(--ko); }

/* Riquadro per mostrare un valore (chiave plain decifrata) con bottone copia. */
.modal-value-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0 0 14px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  color: var(--text);
  word-break: break-all;
  white-space: pre-wrap;
}

/* ========== TOAST ========== */
.toast-container {
  position: fixed; bottom: 16px; right: 16px;
  z-index: 1100;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 280px; max-width: 420px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-start; gap: 10px;
  pointer-events: auto;
  transform: translateX(420px); opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.variant-success { border-left: 3px solid var(--ok); }
.toast.variant-info    { border-left: 3px solid var(--accent); }
.toast.variant-warning { border-left: 3px solid var(--warn); }
.toast.variant-danger  { border-left: 3px solid var(--ko); }
.toast-icon {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0; margin-top: 1px;
}
.toast-icon.variant-success { background: rgba(16, 185, 129, 0.15); color: var(--ok); }
.toast-icon.variant-info    { background: rgba(59, 130, 246, 0.15); color: #6ea8ff; }
.toast-icon.variant-warning { background: rgba(245, 158, 11, 0.15); color: var(--warn); }
.toast-icon.variant-danger  { background: rgba(239, 68, 68, 0.15);  color: var(--ko); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 13.5px; font-weight: 600; color: var(--text); margin: 0 0 2px; }
.toast-message { font-size: 12.5px; color: var(--muted); line-height: 1.45; word-break: break-word; }
.toast-close {
  background: transparent; border: 0; color: var(--muted);
  cursor: pointer; padding: 0 2px; font-size: 16px; line-height: 1;
  flex-shrink: 0; margin-top: -2px;
}
.toast-close:hover { color: var(--text); }
