/* =========================================================
   GABBRO — article.css
   Layout articolo, tipografia, codice, callout, passi,
   tabelle, indice laterale. Richiede base.css.
   ========================================================= */
.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 48px;
  align-items: start;
  padding-top: 40px;
  padding-bottom: 96px;
}

.article-shell {
  min-width: 0;
  padding: 44px 52px 52px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(10, 11, 14, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 32px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
}
.breadcrumb a { color: var(--text-dim); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { color: #3a3d45; }

.article-header {
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}
.article-header .card-meta { margin-bottom: 18px; }
.article-header h1 {
  margin: 0 0 18px;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.12;
}
.article-header .lead {
  margin: 0 0 22px;
  font-family: var(--text-font);
  font-size: 17.5px;
  line-height: 1.7;
  color: var(--text-dim);
}

/* ── tipografia del corpo ── */
.article-body {
  font-family: var(--text-font);
  font-size: 16px;
  color: var(--text-dim);
}

.article-body h2 {
  position: relative;
  margin: 56px 0 16px;
  font-family: var(--font);
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.25;
  color: var(--text);
}
.article-body h2:first-child { margin-top: 0; }

.article-body h3 {
  margin: 34px 0 10px;
  font-family: var(--font);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

.article-body .anchor {
  position: absolute;
  left: -26px;
  top: 0;
  padding-right: 8px;
  color: var(--text-faint);
  text-decoration: none;
  border: 0;
  opacity: 0;
  font-weight: 400;
  transition: opacity 0.15s;
}
.article-body h2:hover .anchor,
.article-body .anchor:focus { opacity: 1; }

.article-body p { margin: 0 0 18px; line-height: 1.8; }
.article-body strong { color: var(--text); font-weight: 600; }
.article-body em { color: var(--text); }

.article-body a {
  color: var(--accent-3);
  text-decoration: none;
  border-bottom: 1px solid rgba(34, 211, 238, 0.3);
  transition: border-color 0.15s;
}
.article-body a:hover { border-color: var(--accent-3); }

.article-body ol,
.article-body ul {
  margin: 0 0 18px;
  padding-left: 22px;
  line-height: 1.8;
}
.article-body li { margin-bottom: 6px; }
.article-body li::marker { color: var(--text-faint); }

.article-body hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 40px 0;
}

/* ── codice ── */
.article-body code {
  font-family: var(--mono);
  font-size: 0.84em;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: #c8f2fa;
  overflow-wrap: anywhere;
}

.article-body pre {
  position: relative;
  margin: 0 0 20px;
  padding: 40px 18px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #090a0c;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  color: #bfe9f2;
}
.article-body pre::before {
  content: attr(data-label);
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 7px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 80px;
}
.article-body pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  color: inherit;
  overflow-wrap: normal;
}
.article-body pre.wrap > code {
  white-space: pre-wrap;
  word-break: break-word;
}

/* con JS (js/article.js) il blocco viene avvolto in .code, con intestazione propria */
.code {
  margin: 0 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #090a0c;
  overflow: hidden;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 6px 4px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.code-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code pre {
  margin: 0;
  padding: 14px 18px 16px;
  border: 0;
  border-radius: 0;
  background: none;
}
.code pre::before { display: none; }
.steps .code { margin-top: 10px; }

.copy-btn {
  flex-shrink: 0;
  height: 24px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.copy-btn:hover { color: var(--text); border-color: var(--border-2); }
.copy-btn.done { color: var(--accent-ok); }

/* ── callout ── */
.callout {
  position: relative;
  margin: 0 0 22px;
  padding: 16px 20px 16px 20px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--c, var(--text-faint));
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(var(--c-rgb, 255, 255, 255), 0.04);
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text-dim);
}
.callout::before {
  content: var(--label, "Nota");
  display: block;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--c, var(--text-faint));
}
.callout > strong:first-child {
  display: block;
  margin-bottom: 4px;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
}
.callout p { margin: 0 0 10px; line-height: 1.7; }
.callout p:last-child { margin-bottom: 0; }

.callout-info  { --c: var(--accent-3);  --c-rgb: 34, 211, 238;  --label: "Contesto"; }
.callout-def   { --c: var(--accent-4);  --c-rgb: 167, 139, 250; --label: "Definizione"; }
.callout-warn  { --c: var(--accent-2);  --c-rgb: 245, 165, 36;  --label: "Attenzione"; }
.callout-tip   { --c: var(--accent-ok); --c-rgb: 74, 222, 128;  --label: "Nota pratica"; }
.callout-risk  { --c: var(--accent);    --c-rgb: 230, 57, 70;   --label: "Ambito"; }
.callout-ok    { --c: var(--accent-ok); --c-rgb: 74, 222, 128;  --label: "Risultato"; }

/* termine definito dentro un callout */
.term {
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0 6px;
  border-radius: 4px;
  background: rgba(167, 139, 250, 0.1);
  border: 1px solid rgba(167, 139, 250, 0.25);
  color: #d4c8ff;
}

/* ── elenco a passi ── */
.steps {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  counter-reset: step;
}
.steps li {
  counter-increment: step;
  position: relative;
  margin: 0;
  padding: 0 0 20px 48px;
  line-height: 1.7;
}
.steps li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0; top: 1px;
  width: 30px; height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-2);
  border-radius: 5px;
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}
.steps li::after {
  content: "";
  position: absolute;
  left: 15px; top: 30px; bottom: 4px;
  width: 1px;
  background: var(--border);
}
.steps li:last-child { padding-bottom: 4px; }
.steps li:last-child::after { display: none; }
.steps li > strong:first-child {
  display: block;
  margin-bottom: 2px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
}
.steps pre { margin-top: 10px; }

/* ── tabelle ── */
.table-wrap {
  margin: 0 0 10px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.article-body table {
  width: 100%;
  min-width: 440px;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12.5px;
}
.article-body th,
.article-body td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
  color: var(--text-dim);
}
.article-body th {
  background: rgba(255, 255, 255, 0.025);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.article-body tr:last-child td { border-bottom: 0; }
.article-body th:first-child,
.article-body td:first-child { text-align: left; color: var(--text); }
.article-body td .unit { color: var(--text-faint); margin-left: 6px; }
.article-body td.hl { color: var(--accent-3); background: rgba(34, 211, 238, 0.07); }
.article-body table.left td,
.article-body table.left th { text-align: left; white-space: normal; }

.table-note {
  margin: 0 0 22px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-faint);
}

/* ── piè di articolo ── */
.article-end {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
}
.article-end a { color: var(--text-dim); text-decoration: none; }
.article-end a:hover { color: var(--text); }

/* ── indice laterale ── */
.toc {
  position: sticky;
  top: calc(var(--nav-h) + 40px);
  max-height: calc(100vh - var(--nav-h) - 80px);
  overflow-y: auto;
  padding: 18px 0 18px 18px;
  border-left: 1px solid var(--border);
  font-size: 13px;
}
.toc-title {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  position: relative;
  display: block;
  padding: 5px 0;
  line-height: 1.4;
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.15s;
}
.toc a:hover { color: var(--text-dim); }
.toc a.is-current { color: var(--text); }
.toc a.is-current::before {
  content: "";
  position: absolute;
  left: -19px; top: 6px; bottom: 6px;
  width: 1px;
  background: var(--accent);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
.article-header .ai-flag { margin-top: 18px; }

/* pulsante "Indice" con anello di avanzamento (schermi stretti) */
.toc-fab {
  display: none;
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 95;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 18px 0 14px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: rgba(19, 20, 24, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.toc-fab .ring {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: conic-gradient(rgba(var(--glow), 1) calc(var(--read, 0) * 360deg), rgba(255, 255, 255, 0.12) 0);
  -webkit-mask: radial-gradient(circle, transparent 6px, #000 6.5px);
          mask: radial-gradient(circle, transparent 6px, #000 6.5px);
}
.toc-fab .pct { color: var(--text-faint); font-variant-numeric: tabular-nums; }

@media (max-width: 1100px) {
  .article-layout { grid-template-columns: minmax(0, 1fr); max-width: 820px; }

  /* l'indice diventa un pannello che sale dal basso */
  .toc {
    position: fixed;
    top: auto;
    left: 12px; right: 12px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    z-index: 94;
    max-width: 420px;
    margin-left: auto;
    max-height: min(62vh, 520px);
    padding: 18px 22px 12px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-lg);
    background: rgba(13, 14, 17, 0.97);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.98);
    transform-origin: 100% 100%;
    transition: opacity 0.25s var(--ease), transform 0.3s var(--ease), visibility 0.3s;
  }
  .toc.is-open { opacity: 1; visibility: visible; transform: none; }
  .toc a { padding: 9px 0; font-size: 14.5px; border-bottom: 1px solid var(--border); }
  .toc li:last-child a { border-bottom: 0; }
  .toc a.is-current::before { left: -12px; top: 12px; bottom: 12px; }
  .toc-fab { display: inline-flex; }
}

@media (max-width: 640px) {
  .article-layout { padding-top: 0; padding-bottom: 72px; }
  /* articolo a tutta larghezza */
  .article-shell {
    margin: 0 calc(-1 * var(--gutter));
    padding: 26px var(--gutter) 40px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    background: rgba(10, 11, 14, 0.8);
  }
  .breadcrumb { margin-bottom: 22px; }
  .article-header { margin-bottom: 30px; padding-bottom: 26px; }
  .article-header h1 { font-size: clamp(27px, 8vw, 34px); }
  .article-header .lead { font-size: 16.5px; }
  .article-body { font-size: 16px; }
  .article-body h2 { font-size: 22px; margin-top: 46px; }
  .article-body h3 { font-size: 17px; }
  .article-body .anchor { display: none; }
  .article-body pre, .code { margin-left: calc(-1 * var(--gutter)); margin-right: calc(-1 * var(--gutter)); border-radius: 0; border-left: 0; border-right: 0; }
  .code pre { margin: 0; font-size: 12.5px; }
  .steps li { padding-left: 42px; }
  .callout { margin-left: calc(-1 * var(--gutter) + 6px); margin-right: calc(-1 * var(--gutter) + 6px); }
  .table-wrap { margin-left: calc(-1 * var(--gutter)); margin-right: calc(-1 * var(--gutter)); border-radius: 0; border-left: 0; border-right: 0; }
  .article-end { flex-direction: column; align-items: flex-start; }
}
.lab-head .ai-flag { margin-top: 16px; }
