/* docs.crankpal.com — foglio di stile unico.
   I token cromatici sono gli stessi del CRM e del sito marketing
   (CrankPalWebsite/assets/css/style.css): il docs deve sembrare la stessa casa. */

:root {
  color-scheme: light dark;

  --green-950: #062b21;
  --green-900: #0a3329;
  --green-800: #0f4035;
  --green-700: #155d4b;
  --teal-500: #2dc8a6;
  --teal-600: #1ea48a;
  --teal-700: #15806c;
  --teal-50: #ecfdf5;
  --teal-100: #d1fae5;

  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #f0f4f2;
  --text: #16201c;
  --text-secondary: #44514b;
  --text-muted: #6d7a74;
  --border: #e2e9e6;
  --border-strong: #cbd5d0;
  --warning: #f59e0b;
  --danger: #e5484d;
  --success: #18a06a;
  --info: #3a7bd5;

  --shadow-sm: 0 1px 2px rgba(22, 32, 28, .05), 0 2px 8px rgba(22, 32, 28, .04);
  --shadow-md: 0 2px 4px rgba(22, 32, 28, .05), 0 8px 24px rgba(22, 32, 28, .08);
  --shadow-lg: 0 4px 8px rgba(10, 51, 41, .06), 0 20px 48px rgba(10, 51, 41, .14);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 100px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --topbar-h: 60px;
  --side-w: 282px;
  --rail-w: 232px;
  --measure: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1512;
    --surface: #111d19;
    --surface-2: #16241f;
    --text: #e8f2ee;
    --text-secondary: #b3c5bd;
    --text-muted: #839790;
    --border: #22332d;
    --border-strong: #2e433b;
    --teal-50: #10261f;
    --teal-100: #14332a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, .35), 0 20px 48px rgba(0, 0, 0, .45);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

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

a { color: var(--teal-700); text-decoration-color: color-mix(in srgb, var(--teal-700) 35%, transparent); text-underline-offset: 2px; }
a:hover { color: var(--teal-600); }
@media (prefers-color-scheme: dark) { a { color: var(--teal-500); } a:hover { color: var(--teal-100); } }

.skip {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--surface); color: var(--text); padding: 10px 16px; border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
}
.skip:focus { left: 8px; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__burger {
  display: none; flex-direction: column; gap: 4px; justify-content: center;
  width: 38px; height: 38px; padding: 0 9px;
  background: none; border: 1px solid var(--border); border-radius: var(--r-sm);
  cursor: pointer; color: var(--text);
}
.topbar__burger span { display: block; height: 2px; background: currentColor; border-radius: 2px; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); flex: none; }
.brand__mark {
  display: grid; place-items: center; width: 32px; height: 32px;
  border-radius: 9px; background: var(--green-900); color: var(--teal-500);
}
.brand__text { font-weight: 700; font-size: 15px; letter-spacing: -.2px; white-space: nowrap; }

.topbar__search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.topbar__search input {
  width: 100%; height: 38px; padding: 0 38px 0 14px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-full);
}
.topbar__search input:focus {
  outline: none; border-color: var(--teal-500); background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal-500) 20%, transparent);
}
.topbar__kbd {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
  border: 1px solid var(--border-strong); border-radius: 5px; padding: 1px 6px; pointer-events: none;
}
.topbar__search input:focus + .topbar__kbd { display: none; }

.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  max-height: min(64vh, 480px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); padding: 6px;
}
.search-results[hidden] { display: none; }
.search-hit { display: block; padding: 9px 12px; border-radius: var(--r-sm); text-decoration: none; color: inherit; }
.search-hit:hover, .search-hit.is-active { background: var(--teal-50); }
.search-hit__sec { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--teal-700); font-weight: 700; }
.search-hit__title { display: block; font-weight: 600; font-size: 14.5px; color: var(--text); }
.search-hit__snip { display: block; font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-hit mark { background: color-mix(in srgb, var(--teal-500) 30%, transparent); color: inherit; border-radius: 3px; }
.search-empty { padding: 14px; color: var(--text-muted); font-size: 14px; text-align: center; }

.topbar__right { display: flex; align-items: center; gap: 12px; flex: none; }
.lang { display: flex; border: 1px solid var(--border); border-radius: var(--r-full); overflow: hidden; }
.lang-opt {
  padding: 5px 11px; font-size: 12px; font-weight: 700; letter-spacing: .4px;
  text-decoration: none; color: var(--text-muted); background: var(--surface-2);
}
.lang-opt.is-current { background: var(--green-900); color: #fff; }

.btn-app {
  display: inline-flex; align-items: center; padding: 8px 18px;
  background: var(--teal-500); color: #04241c; font-weight: 700; font-size: 14px;
  border-radius: var(--r-full); text-decoration: none; white-space: nowrap;
}
.btn-app:hover { background: var(--teal-600); color: #04241c; }

/* ── Impianto a tre colonne ──────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--rail-w);
  gap: 40px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  align-items: start;
}

.sidebar {
  position: sticky; top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 28px 8px 48px 0;
}

.side-group { margin-bottom: 4px; }
.side-group__title {
  list-style: none; cursor: pointer;
  font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); padding: 10px 12px; border-radius: var(--r-sm);
  display: flex; align-items: center; gap: 8px;
}
.side-group__title::-webkit-details-marker { display: none; }
.side-group__title::before {
  content: "›"; font-size: 15px; line-height: 1; transition: transform .15s ease; color: var(--border-strong);
}
details[open] > .side-group__title::before { transform: rotate(90deg); }
.side-group__title:hover { color: var(--text); }

.side-list { list-style: none; margin: 0 0 8px; padding: 0 0 0 10px; border-left: 1px solid var(--border); }
.side-link {
  display: block; padding: 6px 12px; margin-left: -1px;
  font-size: 14px; color: var(--text-secondary); text-decoration: none;
  border-left: 2px solid transparent; border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.side-link:hover { color: var(--text); background: var(--surface-2); }
.side-link.is-current {
  color: var(--teal-700); font-weight: 600;
  border-left-color: var(--teal-500); background: var(--teal-50);
}
@media (prefers-color-scheme: dark) { .side-link.is-current { color: var(--teal-500); } }
.side-link--top {
  margin: 12px 0 8px; padding: 8px 12px; font-weight: 700; font-size: 14.5px;
  border: 1px solid transparent; border-radius: var(--r-sm); color: var(--text);
}
.side-link--top.is-current { border-color: var(--border); background: var(--surface); }

.main { min-width: 0; padding: 34px 0 72px; }
.rail { position: sticky; top: var(--topbar-h); padding: 34px 0 48px; max-height: calc(100vh - var(--topbar-h)); overflow-y: auto; }

.toc__title { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin: 0 0 10px; }
.toc__list { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 1px solid var(--border); }
.toc-item a { display: block; padding: 4px 0 4px 8px; margin-left: -13px; border-left: 2px solid transparent; font-size: 13.5px; color: var(--text-muted); text-decoration: none; }
.toc-item a:hover { color: var(--text); }
.toc-item a.is-active { color: var(--teal-700); border-left-color: var(--teal-500); font-weight: 600; }
@media (prefers-color-scheme: dark) { .toc-item a.is-active { color: var(--teal-500); } }
.toc-item--h3 a { padding-left: 20px; font-size: 13px; }

/* ── Contenuto ───────────────────────────────────────────────────────────── */

.doc { max-width: var(--measure); }
.doc-eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--teal-700); }
@media (prefers-color-scheme: dark) { .doc-eyebrow { color: var(--teal-500); } }
.doc-title { margin: 0 0 12px; font-size: clamp(28px, 4vw, 38px); line-height: 1.15; letter-spacing: -.6px; font-weight: 800; }
.doc-lead { margin: 0 0 28px; font-size: 18px; line-height: 1.6; color: var(--text-secondary); }

.doc h2.doc-h { margin: 46px 0 14px; font-size: 24px; letter-spacing: -.3px; font-weight: 700; padding-top: 8px; border-top: 1px solid var(--border); }
.doc h3.doc-h { margin: 32px 0 10px; font-size: 18.5px; font-weight: 700; }
.doc h4.doc-h { margin: 24px 0 8px; font-size: 16px; font-weight: 700; color: var(--text-secondary); }
.doc-anchor { margin-left: 8px; color: var(--border-strong); text-decoration: none; opacity: 0; font-weight: 400; }
.doc-h:hover .doc-anchor { opacity: 1; }
.doc-anchor:focus { opacity: 1; }

.doc p { margin: 0 0 16px; }
.doc ul, .doc ol { margin: 0 0 16px; padding-left: 24px; }
.doc li { margin-bottom: 6px; }
.doc li > ul, .doc li > ol { margin-top: 6px; }
.doc strong { font-weight: 650; color: var(--text); }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 40px 0; }

.doc blockquote {
  margin: 0 0 16px; padding: 2px 0 2px 18px;
  border-left: 3px solid var(--border-strong); color: var(--text-secondary); font-style: italic;
}

.doc code {
  font-family: var(--font-mono); font-size: .875em;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 5px; padding: .12em .38em; word-break: break-word;
}
.doc-code {
  position: relative; margin: 0 0 20px;
  background: var(--green-950); border-radius: var(--r-md); overflow: hidden;
}
.doc-code::before {
  content: attr(data-lang); position: absolute; top: 8px; right: 12px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .8px;
  text-transform: uppercase; color: rgba(255, 255, 255, .38);
}
.doc-code pre { margin: 0; padding: 18px 18px; overflow-x: auto; }
.doc-code code {
  background: none; border: none; padding: 0;
  color: #d7ece4; font-size: 13.5px; line-height: 1.65; white-space: pre;
}

.doc-table-wrap { overflow-x: auto; margin: 0 0 22px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.doc-table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.doc-table th, .doc-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-table th { background: var(--surface-2); font-weight: 700; font-size: 13px; letter-spacing: .2px; white-space: nowrap; }
.doc-table tr:last-child td { border-bottom: none; }
.doc-table code { white-space: nowrap; }

.doc img { max-width: 100%; height: auto; border-radius: var(--r-md); border: 1px solid var(--border); }

/* ── Componenti Markdoc ──────────────────────────────────────────────────── */

.doc-callout {
  margin: 0 0 22px; padding: 14px 18px;
  border: 1px solid var(--border); border-left-width: 3px;
  border-radius: var(--r-md); background: var(--surface);
}
.doc-callout__title { margin: 0 0 4px; font-weight: 700; font-size: 14px; letter-spacing: .1px; }
.doc-callout__body > :last-child { margin-bottom: 0; }
.doc-callout__body { font-size: 15px; color: var(--text-secondary); }
.doc-callout--note { border-left-color: var(--info); }
.doc-callout--note .doc-callout__title { color: var(--info); }
.doc-callout--tip { border-left-color: var(--success); background: var(--teal-50); }
.doc-callout--tip .doc-callout__title { color: var(--success); }
.doc-callout--warning { border-left-color: var(--warning); }
.doc-callout--warning .doc-callout__title { color: #b45309; }
.doc-callout--danger { border-left-color: var(--danger); }
.doc-callout--danger .doc-callout__title { color: var(--danger); }
@media (prefers-color-scheme: dark) { .doc-callout--warning .doc-callout__title { color: var(--warning); } }

.doc-steps { list-style: none; margin: 0 0 24px; padding: 0; counter-reset: step; }
.doc-step { position: relative; margin: 0; padding: 0 0 22px 44px; border-left: 1px solid var(--border); counter-increment: step; }
.doc-step:last-child { border-left-color: transparent; padding-bottom: 0; }
.doc-step::before {
  content: counter(step);
  position: absolute; left: -14px; top: -2px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--green-900); color: var(--teal-500);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.doc-step__title { margin: 2px 0 8px; font-weight: 700; font-size: 16px; }
.doc-step__body > :last-child { margin-bottom: 0; }
.doc-step__body { color: var(--text-secondary); }

.doc-badge {
  display: inline-block; vertical-align: baseline;
  padding: 1px 8px; border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap; border: 1px solid transparent;
}
.doc-badge--free { background: var(--surface-2); color: var(--text-secondary); border-color: var(--border-strong); }
.doc-badge--premium { background: var(--teal-100); color: var(--teal-700); border-color: color-mix(in srgb, var(--teal-700) 25%, transparent); }
.doc-badge--pro { background: var(--green-900); color: var(--teal-500); }
.doc-badge--enterprise { background: var(--green-950); color: #fff; }
.doc-badge--perm { font-family: var(--font-mono); font-weight: 600; font-size: 11px; background: var(--surface-2); color: var(--text-secondary); border-color: var(--border); }
@media (prefers-color-scheme: dark) { .doc-badge--premium { color: var(--teal-100); } }

.doc-ui {
  display: inline-flex; align-items: center; gap: 5px; flex-wrap: wrap;
  padding: 1px 9px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13.5px; font-weight: 600; color: var(--text-secondary);
}
.doc-ui__sep { color: var(--border-strong); font-weight: 400; }

.doc-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin: 0 0 26px; }
.doc-card {
  display: block; padding: 18px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm); transition: border-color .15s ease, transform .15s ease;
}
.doc-card:hover { border-color: var(--teal-500); transform: translateY(-1px); color: inherit; }
.doc-card__head { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; }
.doc-card__icon { font-size: 18px; line-height: 1; }
.doc-card__title { font-weight: 700; font-size: 15.5px; color: var(--text); }
.doc-card__body { display: block; font-size: 14px; color: var(--text-muted); line-height: 1.5; }

.doc-faq { margin: 0 0 10px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.doc-faq__q { cursor: pointer; list-style: none; padding: 14px 18px; font-weight: 650; font-size: 15.5px; display: flex; align-items: center; gap: 10px; }
.doc-faq__q::-webkit-details-marker { display: none; }
.doc-faq__q::before { content: "+"; color: var(--teal-700); font-weight: 800; font-size: 17px; line-height: 1; }
.doc-faq[open] .doc-faq__q::before { content: "−"; }
.doc-faq__a { padding: 0 18px 4px 42px; color: var(--text-secondary); font-size: 15px; }

/* ── Pager e footer ──────────────────────────────────────────────────────── */

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 56px; max-width: var(--measure); }
.pager__link {
  display: flex; flex-direction: column; gap: 3px; padding: 14px 18px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
  text-decoration: none; color: inherit;
}
.pager__link:hover { border-color: var(--teal-500); color: inherit; }
.pager__link--next { text-align: right; }
.pager__dir { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.pager__title { font-weight: 700; font-size: 15px; color: var(--text); }

.footer { border-top: 1px solid var(--border); padding: 22px 24px; text-align: center; color: var(--text-muted); font-size: 13.5px; }
.footer p { margin: 0; }

/* ── 404 ─────────────────────────────────────────────────────────────────── */

.page-plain { display: grid; place-items: center; min-height: 100vh; }
.plain { text-align: center; padding: 40px 24px; }
.plain__code { font-size: 56px; font-weight: 800; color: var(--teal-500); margin: 0; line-height: 1; }
.plain h1 { font-size: 24px; margin: 12px 0 6px; }
.plain p { color: var(--text-muted); margin: 0 0 20px; }

/* ── Adattamento ─────────────────────────────────────────────────────────── */

@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .rail { display: none; }
}

@media (max-width: 880px) {
  .topbar { gap: 10px; padding: 0 14px; }
  .topbar__burger { display: flex; }
  .brand__text { display: none; }
  .topbar__right .btn-app { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); padding: 0 18px; }
  .sidebar {
    position: fixed; inset: var(--topbar-h) auto 0 0; z-index: 30;
    width: min(86vw, 320px); padding: 18px 18px 40px;
    background: var(--surface); border-right: 1px solid var(--border);
    transform: translateX(-102%); transition: transform .2s ease;
    max-height: none; height: calc(100vh - var(--topbar-h));
  }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow-lg); }
  body.nav-open { overflow: hidden; }
  .nav-scrim { position: fixed; inset: var(--topbar-h) 0 0; z-index: 29; background: rgba(6, 43, 33, .45); border: 0; }
  .main { padding: 24px 0 56px; }
  .pager { grid-template-columns: 1fr; }
}

@media print {
  .topbar, .sidebar, .rail, .pager, .footer, .skip { display: none !important; }
  .shell { display: block; padding: 0; }
  .doc { max-width: none; }
  a { text-decoration: none; color: inherit; }
}
