/* =========================================================================
   Console della piattaforma — foglio di stile unico, senza dipendenze.
   Il tema segue quello del sito dei report: stessa famiglia di colori, stessa
   temperatura, cosi' che passare dalla console ai report non sia un salto.
   ========================================================================= */

:root {
  color-scheme: light dark;

  --blue-900: #123a63;
  --blue-700: #1d4e89;
  --blue-500: #3b7bc0;
  --blue-300: #8fb9e2;
  --teal-600: #0f9b9b;
  --amber-500: #e0913a;
  --rose-500: #d1435b;
  --green-600: #0f9d58;
  --violet-500: #7b61ff;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --surface-3: #eef2f8;
  --border: #dde4ee;
  --border-strong: #c4d0e0;
  --text: #16233a;
  --text-muted: #5b6b85;
  --text-faint: #8b99ad;
  --accent: var(--blue-700);
  --accent-contrast: #ffffff;
  --positive: var(--green-600);
  --negative: var(--rose-500);
  --warning: var(--amber-500);

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(18, 35, 58, .06), 0 1px 3px rgba(18, 35, 58, .04);
  --shadow: 0 2px 4px rgba(18, 35, 58, .05), 0 8px 24px rgba(18, 35, 58, .07);
  --shadow-lg: 0 12px 48px rgba(18, 35, 58, .16);
  --sidebar-width: 244px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070d17;
    --surface: #101a2c;
    --surface-2: #16223a;
    --surface-3: #1c2a45;
    --border: #24334f;
    --border-strong: #33456a;
    --text: #e6edf7;
    --text-muted: #a0b0c8;
    --text-faint: #7183a0;
    --accent: #63a4de;
    --accent-contrast: #08121f;
    --positive: #3ecf8e;
    --negative: #ff7b93;
    --warning: #f0b968;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--mono); font-size: .875em; }

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 640; letter-spacing: -.012em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .9em; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); font-size: .875rem; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------- impalcatura */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--blue-700), var(--teal-600));
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  flex: 0 0 auto;
}
.brand-text { min-width: 0; }
.brand-name { font-weight: 650; font-size: .95rem; letter-spacing: -.01em; }
.brand-sub { color: var(--text-faint); font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; }

.nav { padding: 12px 10px; flex: 1; }
.nav-group { margin-bottom: 16px; }
.nav-label {
  padding: 0 10px 6px;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-faint);
  font-weight: 620;
}
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .895rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .12s ease, color .12s ease;
}
.nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent); color: var(--accent-contrast); font-weight: 560; }
.nav a.active .ico { opacity: 1; }
.nav .ico { width: 16px; height: 16px; flex: 0 0 16px; opacity: .72; }
.nav-badge {
  margin-left: auto;
  font-size: .68rem;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--warning);
  color: #1b1200;
  font-weight: 700;
}

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 8px; border-radius: var(--radius-sm);
  background: var(--surface-3);
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--blue-700); color: #fff;
  display: grid; place-items: center;
  font-size: .74rem; font-weight: 700; flex: 0 0 auto;
}
.user-meta { min-width: 0; flex: 1; }
.user-mail { font-size: .8rem; font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: .7rem; color: var(--text-faint); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.12rem; }
.topbar .subtitle { color: var(--text-muted); font-size: .84rem; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.content { padding: 24px 26px 64px; max-width: 1440px; width: 100%; }

/* ------------------------------------------------------------- componenti */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 18px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  margin: -18px -18px 16px; padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { margin-left: auto; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { margin: 0; border-radius: var(--radius) var(--radius) 0 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .76rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat-value { font-size: 1.72rem; font-weight: 660; letter-spacing: -.025em; margin-top: 3px; line-height: 1.15; }
.stat-value.sm { font-size: 1.15rem; }
.stat-note { font-size: .78rem; color: var(--text-faint); margin-top: 3px; }
.stat-accent-ok .stat-value { color: var(--positive); }
.stat-accent-warn .stat-value { color: var(--warning); }
.stat-accent-bad .stat-value { color: var(--negative); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px;
  font-size: .74rem; font-weight: 620; line-height: 1.6;
  background: var(--surface-3); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-ok { background: color-mix(in srgb, var(--positive) 14%, transparent); color: var(--positive); border-color: color-mix(in srgb, var(--positive) 32%, transparent); }
.badge-warn { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 34%, transparent); }
.badge-bad { background: color-mix(in srgb, var(--negative) 14%, transparent); color: var(--negative); border-color: color-mix(in srgb, var(--negative) 32%, transparent); }
.badge-info { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit; font-size: .88rem; font-weight: 570;
  cursor: pointer;
  text-decoration: none;
  transition: filter .12s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--negative); border-color: var(--negative); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-size: .82rem; font-weight: 580; color: var(--text-muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%;
  padding: 8px 11px;
  font: inherit; font-size: .9rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
textarea { resize: vertical; min-height: 90px; }
textarea.code { font-family: var(--mono); font-size: .84rem; line-height: 1.6; tab-size: 2; }
.field { margin-bottom: 13px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 190px; margin-bottom: 13px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--text); font-weight: 500; }
.check input { width: auto; }

table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  text-align: left; font-weight: 620; font-size: .74rem;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
  white-space: nowrap;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; max-height: 62vh; overflow-y: auto; }

.flash {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; margin-bottom: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid; font-size: .89rem;
}
.flash-ok { background: color-mix(in srgb, var(--positive) 10%, var(--surface)); border-color: color-mix(in srgb, var(--positive) 34%, transparent); color: var(--text); }
.flash-bad { background: color-mix(in srgb, var(--negative) 10%, var(--surface)); border-color: color-mix(in srgb, var(--negative) 34%, transparent); color: var(--text); }
.flash-info { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--text); }

pre.log, pre.out {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 340px;
  font-size: .8rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty { padding: 34px 18px; text-align: center; color: var(--text-faint); }
.empty strong { display: block; color: var(--text-muted); margin-bottom: 4px; font-size: .95rem; }

.split { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }

.filelist { list-style: none; margin: 0; padding: 6px; max-height: 70vh; overflow-y: auto; }
.filelist li { margin: 0; }
.filelist a {
  display: block; padding: 6px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .84rem; font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.filelist a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.filelist a.active { background: var(--accent); color: var(--accent-contrast); }
.filelist .group { padding: 10px 10px 4px; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); font-weight: 640; }

.steps { list-style: none; margin: 0; padding: 0; }
.steps li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.steps li:last-child { border-bottom: none; }
.step-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: 0 0 9px; background: var(--text-faint); }
.step-ok { background: var(--positive); }
.step-bad { background: var(--negative); }
.step-warn { background: var(--warning); }
.step-run { background: var(--accent); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.step-body { flex: 1; min-width: 0; }
.step-name { font-family: var(--mono); font-size: .84rem; font-weight: 600; }
.step-meta { font-size: .78rem; color: var(--text-faint); }

details.detail { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0; margin-top: 8px; background: var(--surface-2); }
details.detail > summary { cursor: pointer; padding: 8px 12px; font-size: .83rem; font-weight: 560; color: var(--text-muted); list-style: none; }
details.detail > summary::-webkit-details-marker { display: none; }
details.detail > summary::before { content: "▸ "; color: var(--text-faint); }
details.detail[open] > summary::before { content: "▾ "; }
details.detail > div { padding: 0 12px 12px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 16px; font-size: .865rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 540; }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a, .tabs button {
  padding: 8px 14px; border: none; background: none; cursor: pointer;
  font: inherit; font-size: .88rem; font-weight: 560; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; }
.tabs a.active, .tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }

.bar-track { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* ------------------------------------------------------------ accesso/403 */

body.standalone {
  display: grid; place-items: center; min-height: 100vh; padding: 24px;
  background:
    radial-gradient(900px 500px at 12% -10%, color-mix(in srgb, var(--blue-500) 18%, transparent), transparent 60%),
    radial-gradient(760px 420px at 92% 108%, color-mix(in srgb, var(--teal-600) 16%, transparent), transparent 62%),
    var(--bg);
}
.auth-card, .gate-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 30px 26px;
}
.gate-card { max-width: 520px; text-align: center; }
.gate-badge {
  display: inline-block; padding: 3px 12px; border-radius: 99px;
  background: color-mix(in srgb, var(--negative) 14%, transparent);
  color: var(--negative); font-weight: 700; font-size: .8rem; margin-bottom: 12px;
}
.gate-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .brand-mark { width: 42px; height: 42px; font-size: 18px; margin: 0 auto 12px; border-radius: 11px; }
.auth-head h1 { font-size: 1.28rem; margin-bottom: 3px; }
.auth-foot { margin-top: 18px; text-align: center; font-size: .8rem; color: var(--text-faint); }

/* --------------------------------------------------------------- editor */

.editor-shell { display: grid; grid-template-rows: auto 1fr; gap: 12px; }
.editor-area { position: relative; }
.editor-area textarea {
  min-height: 58vh;
  font-family: var(--mono);
  font-size: .845rem;
  line-height: 1.62;
  background: var(--surface-2);
}
.diagnostics { margin-top: 12px; }
.diag { display: flex; gap: 9px; align-items: flex-start; padding: 7px 0; font-size: .85rem; border-bottom: 1px solid var(--border); }
.diag:last-child { border-bottom: none; }
.diag-bad { color: var(--negative); }
.diag-warn { color: var(--warning); }
.diag-ok { color: var(--positive); }

.sql-runner textarea { min-height: 150px; }
.result-meta { display: flex; gap: 14px; align-items: center; font-size: .8rem; color: var(--text-muted); margin: 10px 0; flex-wrap: wrap; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 26%, transparent);
  border-top-color: currentColor;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-stack { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 9px; z-index: 90; }
.toast {
  padding: 11px 15px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: .87rem; max-width: 380px;
  animation: rise .18s ease;
}
.toast-ok { border-left: 3px solid var(--positive); }
.toast-bad { border-left: 3px solid var(--negative); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group { margin: 0; display: contents; }
  .nav-label { display: none; }
  .content { padding: 18px 14px 48px; }
  .topbar { padding: 12px 14px; }
}
