:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --text: #1f2330;
  --muted: #667085;
  --border: #e3e6ef;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --ok: #059669;
  --ok-soft: #e7f7f0;
  --warn: #b45309;
  --warn-soft: #fef4e6;
  --err: #dc2626;
  --err-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141b;
    --surface: #1a1d27;
    --surface-2: #222634;
    --text: #e8eaf2;
    --muted: #9aa1b5;
    --border: #2d3242;
    --accent: #8b85ff;
    --accent-soft: #262a48;
    --ok: #34d399;
    --ok-soft: #133328;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --err: #f87171;
    --err-soft: #3b1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* ---- barra superiore ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand img { width: 30px; height: 30px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; align-items: center; margin-left: auto; }
.nav a, .nav button.linklike {
  color: var(--muted); padding: .4rem .7rem; border-radius: 10px; font-weight: 500; font-size: .95rem;
}
.nav a:hover, .nav button.linklike:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.who { color: var(--muted); font-size: .9rem; padding: 0 .4rem; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

/* ---- bottoni e form ---- */
.btn, button {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: 10px;
  padding: .55rem 1rem; font-weight: 600;
  background: var(--accent); color: #fff;
  text-decoration: none;
}
.btn:hover, button:hover { filter: brightness(1.07); text-decoration: none; }
.btn.ghost, button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover, button.ghost:hover { background: var(--surface-2); filter: none; }
.btn.danger, button.danger { background: var(--err); }
.btn.ok, button.ok { background: var(--ok); }
.btn.small, button.small { padding: .3rem .65rem; font-size: .85rem; border-radius: 8px; }
.btn.big, button.big { padding: .8rem 1.4rem; font-size: 1.05rem; }
button.linklike { background: none; border: 0; }
form.inline { display: inline; }

label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .95rem; }
input[type=text], input[type=password], input[type=number], input[type=file], select, textarea {
  font: inherit; width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type=color] { width: 3rem; height: 2.4rem; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: none; }
.field { margin-bottom: 1rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.row > .grow { flex: 1 1 180px; }

/* ---- pannelli ---- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.panel > h2:first-child { margin-bottom: 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }

.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.flash.err { background: var(--err-soft); color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, transparent); }

.badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge.new { background: var(--accent); color: #fff; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }

/* ---- accesso ---- */
.login-wrap { max-width: 440px; margin: 6vh auto 0; }
.login-wrap .panel { padding: 2rem; }
.login-logo { display: flex; justify-content: center; margin-bottom: 1rem; }
.login-logo img { width: 64px; height: 64px; }
.login-wrap h1 { text-align: center; }
.login-wrap .sub { text-align: center; color: var(--muted); margin-bottom: 1.5rem; }

/* ---- catalogo ---- */
.hello { margin-bottom: 1.25rem; }
.tabs { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .75rem; }
.tab {
  --c: var(--accent);
  white-space: nowrap; padding: .5rem .9rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600;
}
.tab:hover { text-decoration: none; border-color: var(--c); }
.tab.active { background: var(--c); border-color: var(--c); color: #fff; }
.tab .count { opacity: .7; font-weight: 500; margin-left: .2rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.chip { padding: .3rem .75rem; border-radius: 999px; font-size: .88rem; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.chip.active { background: var(--accent-soft); color: var(--accent); }
.chip:hover { text-decoration: none; color: var(--text); }

.materia-group { margin-bottom: 2rem; }
.materia-group h2 { display: flex; align-items: center; gap: .5rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.card {
  --c: var(--accent);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; color: var(--text); box-shadow: var(--shadow);
  border-top: 4px solid var(--c);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover { transform: translateY(-2px); text-decoration: none; box-shadow: 0 8px 24px rgba(16, 24, 40, .12); }
.card-top { display: flex; gap: .35rem; margin-bottom: .5rem; flex-wrap: wrap; }
.card h3 { margin-bottom: .3rem; }
.card p { font-size: .92rem; flex: 1; }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; font-size: .88rem; }
.tipo { color: var(--muted); }
.score { font-weight: 700; padding: .1rem .5rem; border-radius: 8px; }
.s-high { background: var(--ok-soft); color: var(--ok); }
.s-mid { background: var(--warn-soft); color: var(--warn); }
.s-low { background: var(--err-soft); color: var(--err); }
.done { color: var(--ok); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---- visualizzatore ---- */
body.viewer .container { max-width: none; padding: 0; }
.viewer-bar {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.viewer-title { display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 0; }
.viewer-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pkg-frame { display: block; width: 100%; height: calc(100vh - 118px); border: 0; background: #fff; }
.viewer-body { max-width: 1000px; margin: 1.25rem auto; padding: 0 1rem; }
.viewer-body video, .viewer-body img, .viewer-body audio { max-width: 100%; display: block; margin: 0 auto 1rem; border-radius: 10px; }
.doc-frame { width: 100%; height: calc(100vh - 230px); border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  padding: .75rem 1.25rem; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; z-index: 50;
  background: var(--ok); color: #fff; max-width: 90vw;
}
.toast.warn { background: var(--warn); }
.toast.err { background: var(--err); }

/* ---- quiz ---- */
.quiz { max-width: 820px; margin: 0 auto; }
.domanda { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.domanda legend { font-weight: 700; color: var(--accent); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; padding: 0; margin-bottom: .3rem; }
.domanda fieldset { border: 0; padding: 0; margin: 0; }
.domanda .testo { font-size: 1.08rem; font-weight: 600; margin-bottom: .75rem; white-space: pre-line; }
.domanda img { max-width: 100%; border-radius: 10px; margin-bottom: .75rem; }
.opzione {
  display: flex; align-items: center; gap: .6rem; font-weight: 500;
  padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 10px; margin-bottom: .45rem; cursor: pointer;
}
.opzione:hover { background: var(--surface-2); }
.opzione:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opzione input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); margin: 0; }
.esito-box { text-align: center; padding: 2rem 1rem; }
.esito-box .big-score { font-size: 3rem; font-weight: 800; line-height: 1; margin: .5rem 0; }
.correzione { border-left: 4px solid var(--border); }
.correzione.giusta { border-left-color: var(--ok); }
.correzione.sbagliata { border-left-color: var(--err); }
.correzione .riga { font-size: .95rem; margin: .15rem 0; }

/* ---- tabelle ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; background: var(--surface-2); }
tr:hover td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
tr.off td { opacity: .5; }
.matrix th.rot { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; text-transform: none; padding: .6rem .35rem; font-weight: 600; letter-spacing: 0; font-size: .82rem; vertical-align: bottom; }
.matrix td.cell { text-align: center; min-width: 52px; }
.matrix td.cell a { display: inline-block; min-width: 44px; }
.matrix td.sticky, .matrix th.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.actions { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.stat .n { font-size: 2rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .9rem; }
.cols { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }

pre.code { background: var(--surface-2); padding: 1rem; border-radius: 10px; overflow: auto; font-size: .85rem; max-height: 480px; }
details summary { cursor: pointer; font-weight: 600; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.25rem; text-align: center; background: var(--surface-2); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.switch-line { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

@media (max-width: 600px) {
  h1 { font-size: 1.4rem; }
  .nav { margin-left: 0; }
  .pkg-frame { height: calc(100vh - 150px); }
}
