/* ============================================================
   Guida C/C++ - Stylesheet Condiviso
   ============================================================ */

:root {
  --bg:           #0f172a;
  --bg-card:      #1e293b;
  --bg-card-2:    #162032;
  --sidebar-bg:   #0d1526;
  --text:         #e2e8f0;
  --text-muted:   #94a3b8;
  --green:        #22c55e;
  --green-dark:   #16a34a;
  --blue:         #38bdf8;
  --yellow:       #fbbf24;
  --red:          #f87171;
  --orange:       #fb923c;
  --border:       #1e293b;
  --border-light: #334155;
  --radius:       10px;
  --sidebar-w:    250px;
}

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

/* html e body coprono l'intero viewport — nessun bianco del browser */
html {
  scroll-behavior: smooth;
  background: #0f172a;   /* stesso valore di --bg, non var() per sicurezza */
  height: 100%;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: #0f172a;
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.7;
  /* Niente display:flex sul body: la sidebar è fixed, il main usa margin-left.
     Il layout flex/fixed causava la striscia bianca sul lato destro. */
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-light);
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.sidebar-logo {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.sidebar-logo a {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo .logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: #0f172a;
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-weight: 700; font-size: 15px; color: var(--text); line-height: 1.2;
}

.sidebar-logo .logo-sub {
  font-size: 11px; color: var(--text-muted); margin-top: 1px;
}

.sidebar-section {
  padding: 14px 10px 4px;
  flex-shrink: 0;
}

.sidebar-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 0 8px 6px;
  border-bottom: 1px solid rgba(148,163,184,0.1);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: #8898aa;
  font-size: 12.5px;
  transition: all 0.15s;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
}

.sidebar-nav a.active {
  background: rgba(34,197,94,0.12);
  color: var(--green);
  font-weight: 600;
}

.sidebar-nav a.active:hover {
  background: rgba(34,197,94,0.18);
}

.sidebar-nav .num {
  font-size: 10px;
  font-weight: 600;
  font-family: 'Fira Code', monospace;
  background: rgba(255,255,255,0.06);
  color: #64748b;
  border-radius: 3px;
  padding: 1px 5px;
  min-width: 24px;
  text-align: center;
  flex-shrink: 0;
  letter-spacing: 0;
}

.sidebar-nav a.active .num {
  background: rgba(34,197,94,0.18);
  color: var(--green);
}

/* ── Main content ─────────────────────────────────────────── */
.main {
  /* Layout classico: sidebar fixed + margin-left uguale alla sua larghezza.
     Nessun flex, nessun width esplicito: il block element si espande
     automaticamente a tutta la larghezza rimanente senza lasciare spazi bianchi. */
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 48px 52px 80px;
  background: var(--bg);
}

/* Larghezza massima del contenuto per leggibilità ottimale */
.page-header,
.section,
.exercises,
.nav-footer {
  max-width: 860px;
}

/* ── Header ──────────────────────────────────────────────── */
.page-header {
  margin-bottom: 40px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border-light);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.breadcrumb a { color: var(--green); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.page-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--green);
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.2);
  border-radius: 4px;
  padding: 3px 10px;
  margin-bottom: 12px;
}

.page-title {
  font-size: 36px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 10px;
}

.page-title span { color: var(--green); }

.page-subtitle {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 600px;
}

/* ── Section ─────────────────────────────────────────────── */
.section {
  margin-bottom: 48px;
}

.section-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title::before {
  content: '';
  display: block;
  width: 4px;
  height: 22px;
  background: var(--green);
  border-radius: 2px;
}

.section-sub {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 24px 0 12px;
}

p { margin-bottom: 14px; color: var(--text-muted); }
p strong { color: var(--text); }

/* ── Info boxes ──────────────────────────────────────────── */
.info-box {
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 20px 0;
  border-left: 4px solid;
  font-size: 14px;
}

.info-box.note  { background: rgba(56,189,248,0.06);  border-color: var(--blue);   color: #7dd3fc; }
.info-box.warn  { background: rgba(251,191,36,0.06);  border-color: var(--yellow); color: #fde68a; }
.info-box.tip   { background: rgba(34,197,94,0.06);   border-color: var(--green);  color: #86efac; }
.info-box.danger{ background: rgba(248,113,113,0.06); border-color: var(--red);    color: #fca5a5; }

.info-box strong { display: block; margin-bottom: 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Code blocks ─────────────────────────────────────────── */
.code-block {
  background: #0d1117;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin: 20px 0;
  overflow: hidden;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #161b22;
  border-bottom: 1px solid var(--border-light);
}

.code-block-lang {
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 6px;
}

.code-block-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.code-block pre {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.65;
}

.code-block pre code {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

/* Output block */
.output-block {
  background: #020809;
  border: 1px solid #0d2a2f;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-top: -8px;
  margin-bottom: 20px;
}

.output-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.output-block pre {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  color: #67e8f9;
  margin: 0;
}

/* ── Exercise cards ──────────────────────────────────────── */
.exercises {
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid var(--border-light);
}

.exercises-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.exercises-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.exercise-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}

.exercise-card:hover { border-color: var(--green); }

.exercise-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.exercise-num {
  width: 36px; height: 36px;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: var(--green);
  flex-shrink: 0;
}

.exercise-meta { flex: 1; }

.exercise-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

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

.badge {
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  padding: 2px 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge.easy   { background: rgba(34,197,94,0.15);  color: #86efac; border: 1px solid rgba(34,197,94,0.3); }
.badge.medium { background: rgba(251,191,36,0.15); color: #fde68a; border: 1px solid rgba(251,191,36,0.3); }
.badge.hard   { background: rgba(248,113,113,0.15);color: #fca5a5; border: 1px solid rgba(248,113,113,0.3); }
.badge.expert { background: rgba(167,139,250,0.15);color: #c4b5fd; border: 1px solid rgba(167,139,250,0.3); }
.badge.topic  { background: rgba(56,189,248,0.1);  color: #7dd3fc; border: 1px solid rgba(56,189,248,0.2); }

.exercise-text { font-size: 14px; color: var(--text-muted); line-height: 1.6; margin-bottom: 0; }

.exercise-hint {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(56,189,248,0.05);
  border: 1px solid rgba(56,189,248,0.15);
  border-radius: 6px;
  font-size: 13px;
  color: #7dd3fc;
}

.exercise-hint::before { content: '💡 Suggerimento: '; font-weight: 600; }

.solution-toggle {
  margin-top: 14px;
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.solution-toggle:hover { border-color: var(--green); color: var(--green); }

.solution-block {
  display: none;
  margin-top: 12px;
}

.solution-block.open { display: block; }

/* ── Concept grid ─────────────────────────────────────────── */
.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.concept-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 18px;
}

.concept-card h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 6px;
}

.concept-card p { font-size: 13px; color: var(--text-muted); margin: 0; }

/* ── Table ───────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-light);
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  vertical-align: top;
}

td:first-child { color: var(--blue); font-family: 'Fira Code', monospace; font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Inline code ─────────────────────────────────────────── */
code {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  background: rgba(56,189,248,0.08);
  color: var(--blue);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(56,189,248,0.15);
}

pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }

/* ── Navigation footer ───────────────────────────────────── */
.nav-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--border-light);
  gap: 16px;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  padding: 14px 20px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  transition: all 0.2s;
  max-width: 240px;
  flex: 1;
}

.nav-btn:hover { border-color: var(--green); background: rgba(34,197,94,0.04); }

.nav-btn.prev { align-items: flex-start; }
.nav-btn.next { align-items: flex-end; text-align: right; }

.nav-btn-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.nav-btn-title { font-size: 14px; font-weight: 600; color: var(--text); }

/* ── Progress bar ─────────────────────────────────────────── */
.progress-bar {
  position: fixed;
  top: 0; left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--green), var(--blue));
  z-index: 999;
  transition: width 0.1s;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 230px; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }
  .sidebar.open { transform: translateX(0); }
  .main {
    margin-left: 0;
    padding: 24px 20px 60px;
  }
  .page-title { font-size: 26px; }
  .hamburger { display: flex; }
}

@media (max-width: 480px) {
  .main { padding: 20px 16px 60px; }
  .concept-grid { grid-template-columns: 1fr; }
}

.hamburger {
  display: none;
  position: fixed;
  top: 16px; left: 16px;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
}

.hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: var(--text);
  border-radius: 2px;
}
