/* Corso AI — stile del portale. Palette: indaco/viola su fondo chiaro caldo. */
:root {
  --brand: #4f46e5;
  --brand-dark: #3730a3;
  --brand-soft: #eef2ff;
  --accent: #7c3aed;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --ink: #1f2937;
  --muted: #6b7280;
  --bg: #f8fafc;
  --card: #ffffff;
  --line: #e5e7eb;
  --radius: 12px;
}

/* Tema scuro: variabili ridefinite + ritocchi mirati (in fondo al file). */
html[data-theme="dark"] {
  color-scheme: dark;
  --brand: #6366f1;
  --brand-dark: #4338ca;
  --brand-soft: #2b2b55;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --bg: #0f172a;
  --card: #1e293b;
  --line: #334155;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Header ---------------------------------------------------------- */
.site-header {
  background: linear-gradient(135deg, var(--brand-dark), var(--accent));
  color: #fff;
  padding: 0 20px;
}
.site-header .inner {
  max-width: 1040px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 60px; gap: 16px; flex-wrap: wrap;
}
.site-header .logo {
  font-size: 19px; font-weight: 700; color: #fff; display: flex;
  align-items: center; gap: 8px;
}
.site-header .logo small { font-weight: 400; opacity: .75; font-size: 12px; }
.site-header nav { display: flex; align-items: center; gap: 14px; }
.site-header nav a { color: rgba(255,255,255,.9); font-size: 14px; }
.site-header nav a:hover { color: #fff; text-decoration: none; }
.site-header .userbox { font-size: 13px; opacity: .85; }
.btn-logout {
  background: rgba(255,255,255,.14); color: #fff; border: none;
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

/* --- Layout ---------------------------------------------------------- */
.container { max-width: 1040px; margin: 0 auto; padding: 26px 20px 80px; }
.container--narrow { max-width: 760px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .05);
}

h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 20px; }
.subtitle { color: var(--muted); margin: 0 0 22px; }

/* --- Bottoni e badge -------------------------------------------------- */
.btn {
  display: inline-block; background: var(--brand); color: #fff; border: none;
  border-radius: 9px; padding: 10px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn--ghost { background: var(--brand-soft); color: var(--brand-dark); }
.btn--ghost:hover { background: #e0e7ff; color: var(--brand-dark); }
.btn--ok { background: var(--ok); }
.btn--ok:hover { background: #15803d; }
.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #b91c1c; }
.btn--small { padding: 6px 12px; font-size: 13px; }

.badge {
  display: inline-block; border-radius: 999px; padding: 3px 11px;
  font-size: 12px; font-weight: 600;
}
.badge--ok { background: #dcfce7; color: #166534; }
.badge--warn { background: #fef3c7; color: #92400e; }
.badge--danger { background: #fee2e2; color: #991b1b; }
.badge--muted { background: #f1f5f9; color: #475569; }

/* --- Barra progresso --------------------------------------------------- */
.progressbar {
  background: #e2e8f0; border-radius: 999px; height: 12px; overflow: hidden;
}
.progressbar > span {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width .4s ease;
}

/* --- Dashboard: volumi --------------------------------------------------- */
.volume-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 30px 0 4px;
}
.volume-head .volume-num {
  background: var(--brand-dark); color: #fff; border-radius: 999px;
  padding: 3px 12px; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase;
}
.lesson-code {
  font-family: Consolas, monospace; font-size: 12px; color: var(--muted);
  background: #f1f5f9; border-radius: 5px; padding: 1px 6px; white-space: nowrap;
}
.lesson-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* --- Lezione: scheda didattica ------------------------------------------- */
.lesson-info { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; }
.objectives-card { background: var(--brand-soft); border-color: #c7d2fe; }
.objectives-card ul { margin: 8px 0 0; padding-left: 22px; }
.objectives-card li { margin-bottom: 4px; }
.homework-card {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 18px;
}

/* --- Dashboard: moduli -------------------------------------------------- */
.module-card { margin-bottom: 16px; }
.module-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.module-head .icon { font-size: 22px; }
.module-head h2 { margin: 0; }
.module-head .count { color: var(--muted); font-size: 13px; margin-left: auto; }
.module-desc { color: var(--muted); font-size: 14px; margin: 6px 0 12px; }
ul.lesson-list { list-style: none; margin: 0; padding: 0; }
ul.lesson-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-top: 1px solid var(--line); font-size: 15px;
}
ul.lesson-list li .state { width: 22px; text-align: center; }
ul.lesson-list li .quiz-link { margin-left: auto; font-size: 13px; white-space: nowrap; }

/* --- Lezione ------------------------------------------------------------ */
.lesson-content h2 { margin-top: 26px; color: var(--brand-dark); }
.lesson-content p { font-size: 16px; }
.lesson-content li { font-size: 16px; margin-bottom: 4px; }
.lesson-content strong { color: var(--brand-dark); }
.lesson-nav {
  display: flex; justify-content: space-between; gap: 10px; margin-top: 24px;
  flex-wrap: wrap;
}
.lesson-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; align-items: center; }

/* --- Quiz ---------------------------------------------------------------- */
.question { margin-bottom: 22px; }
.question .qtext { font-weight: 600; font-size: 16px; margin-bottom: 10px; }
.question label {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  margin-bottom: 7px; cursor: pointer; background: var(--card); font-size: 15px;
}
.question label:hover { border-color: var(--brand); background: var(--brand-soft); }
.question textarea {
  width: 100%; min-height: 110px; border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; font-size: 15px; font-family: inherit;
  background: var(--card); color: var(--ink);
}
.question textarea:focus, .question input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.ai-feedback {
  background: var(--brand-soft); border: 1px solid #c7d2fe;
  border-radius: var(--radius); padding: 18px 20px; margin-top: 18px;
}
.ai-feedback h2, .ai-feedback h3 { margin-top: 12px; color: var(--brand-dark); }
.score-pill {
  display: inline-block; font-size: 30px; font-weight: 700; color: var(--brand-dark);
}

/* --- Form ------------------------------------------------------------- */
form.stacked label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
form.stacked input[type="text"], form.stacked input[type="email"],
form.stacked input[type="password"], form.stacked input[type="date"],
form.stacked input[type="number"], form.stacked select, form.stacked textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; font-size: 15px; font-family: inherit;
  background: var(--card); color: var(--ink);
}
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > div { flex: 1 1 180px; }
.error-box {
  background: #fee2e2; color: #991b1b; border: 1px solid #fecaca;
  border-radius: 9px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.notice-box {
  background: #dcfce7; color: #166534; border: 1px solid #bbf7d0;
  border-radius: 9px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px;
}
.notice-box code { background: #fff; padding: 2px 7px; border-radius: 5px; font-size: 14px; }

/* --- Tabelle admin ------------------------------------------------------ */
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td {
  text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line);
}
table.data th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.data tr:hover td { background: #f8faff; }

/* --- Wiki ------------------------------------------------------------------ */
.wiki-search { display: flex; gap: 8px; margin-bottom: 18px; }
.wiki-search input[type="search"] {
  flex: 1 1 auto; min-width: 0; border: 1px solid var(--line); border-radius: 9px;
  padding: 11px 13px; font-size: 15px; font-family: inherit;
}
.wiki-search input[type="search"]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px rgba(79,70,229,.15); }
.wiki-group { display: flex; gap: 16px; }
.wiki-letter {
  flex: 0 0 34px; height: 34px; border-radius: 9px; background: var(--brand-soft);
  color: var(--brand-dark); font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
ul.wiki-list { list-style: none; margin: 4px 0 0; padding: 0; flex: 1 1 auto; }
ul.wiki-list li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
ul.wiki-list li:last-child { border-bottom: none; }
.wiki-summary { color: var(--muted); font-size: 13px; }
.wiki-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.wiki-chip {
  display: inline-block; background: var(--brand-soft); color: var(--brand-dark);
  border: 1px solid #c7d2fe; border-radius: 999px; padding: 6px 14px;
  font-size: 13px; font-weight: 600;
}
.wiki-chip:hover { background: #e0e7ff; text-decoration: none; }

/* --- Login --------------------------------------------------------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-dark), var(--accent));
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 34px 32px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-card h1 { font-size: 24px; margin-bottom: 2px; }
.login-card .tagline { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 4px; }
.login-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 11px 12px; font-size: 15px;
}
.login-card .btn { width: 100%; margin-top: 20px; padding: 12px; }
.login-plans { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }

/* --- Mobile ---------------------------------------------------------------
   Il portale è pensato mobile-first per studenti che seguono dal telefono:
   niente scroll orizzontale, tap target comodi, tabelle scrollabili. */
@media (max-width: 640px) {
  .container { padding: 18px 14px 90px; }
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }

  /* Header compatto: tagline nascosta, voci su una riga comoda */
  .site-header { padding: 0 12px; }
  .site-header .inner { min-height: 52px; padding: 8px 0; row-gap: 4px; }
  .site-header .logo { font-size: 17px; }
  .site-header .logo small { display: none; }
  .site-header nav { gap: 10px; flex-wrap: wrap; }
  .site-header .userbox { display: none; }  /* il nome utente non serve sul telefono */
  .site-header nav a, .btn-logout { padding: 6px 8px; }

  .card { padding: 16px 14px; }

  /* Elenco lezioni: le righe possono andare a capo senza rompersi */
  ul.lesson-list li { flex-wrap: wrap; row-gap: 2px; padding: 10px 2px; }
  ul.lesson-list li a { min-height: 28px; }
  ul.lesson-list li .quiz-link { margin-left: 32px; }

  /* Navigazione lezioni: bottoni a tutta larghezza, uno sotto l'altro */
  .lesson-nav { flex-direction: column; }
  .lesson-nav .btn { display: block; width: 100%; text-align: center; }
  .lesson-actions .btn { width: 100%; text-align: center; }
  .lesson-actions form { width: 100%; }

  /* Tabelle admin: scroll orizzontale dentro la card, mai sulla pagina */
  table.data { display: block; overflow-x: auto; white-space: nowrap; }

  .volume-head { margin-top: 24px; }
  .score-pill { font-size: 26px; }
}

/* Touch target minimi anche su schermi medi */
@media (max-width: 900px) {
  .btn, .btn--small { min-height: 40px; }
}

/* --- Tema scuro: ritocchi sui colori fissi --------------------------------
   Le variabili ridefinite in cima coprono il grosso; qui i componenti che
   usavano tinte esplicite (badge, box, accenti indaco su fondo chiaro). */
.theme-fab {
  position: fixed; top: 14px; right: 14px; z-index: 1100;
  background: rgba(255,255,255,.16); color: #fff; border: none;
  border-radius: 999px; padding: 8px 11px; cursor: pointer; font-size: 16px;
}
.theme-fab:hover { background: rgba(255,255,255,.3); }

html[data-theme="dark"] .lesson-content h2,
html[data-theme="dark"] .lesson-content strong,
html[data-theme="dark"] .ai-feedback h2,
html[data-theme="dark"] .ai-feedback h3,
html[data-theme="dark"] .score-pill,
html[data-theme="dark"] .wiki-letter { color: #a5b4fc; }

html[data-theme="dark"] .btn--ghost { color: #c7d2fe; }
html[data-theme="dark"] .btn--ghost:hover { background: #3a3a6e; color: #e0e7ff; }
html[data-theme="dark"] .wiki-chip { color: #c7d2fe; border-color: #4c4f8a; }
html[data-theme="dark"] .wiki-chip:hover { background: #3a3a6e; }
html[data-theme="dark"] .objectives-card,
html[data-theme="dark"] .ai-feedback { border-color: #4c4f8a; }
html[data-theme="dark"] .objectives-card strong,
html[data-theme="dark"] .ai-feedback strong { color: #c7d2fe; }

html[data-theme="dark"] .badge--ok { background: #14532d; color: #bbf7d0; }
html[data-theme="dark"] .badge--warn { background: #78350f; color: #fde68a; }
html[data-theme="dark"] .badge--danger { background: #7f1d1d; color: #fecaca; }
html[data-theme="dark"] .badge--muted { background: #334155; color: #cbd5e1; }

html[data-theme="dark"] .notice-box { background: #052e16; color: #bbf7d0; border-color: #166534; }
html[data-theme="dark"] .notice-box code { background: #1e293b; color: #e2e8f0; }
html[data-theme="dark"] .error-box { background: #450a0a; color: #fecaca; border-color: #7f1d1d; }
html[data-theme="dark"] .homework-card { background: #2a2107; border-color: #78350f; }

html[data-theme="dark"] .progressbar { background: #334155; }
html[data-theme="dark"] .lesson-code { background: #334155; color: #cbd5e1; }
html[data-theme="dark"] table.data tr:hover td { background: #24324a; }
html[data-theme="dark"] .question label:hover { border-color: var(--brand); background: #2b2b55; }
html[data-theme="dark"] .login-card { background: var(--card); }
html[data-theme="dark"] .login-card input { background: #0f172a; color: var(--ink); border-color: var(--line); }
