/* ===== Lezioni – componenti e app shell ===== */

/* ---------- pulsanti ---------- */
button, .btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 13px; border-radius: var(--r); cursor: pointer; display: inline-flex; align-items: center; gap: 7px; line-height: 1.3; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), color var(--dur); text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--line-2); background: var(--card-2); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn.disabled { opacity: .5; cursor: default; transform: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--sh-sm); }
button.primary:hover, .btn.primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
button.secondary, .btn.secondary { background: var(--accent-bg); border-color: transparent; color: var(--accent-fg); }
button.secondary:hover, .btn.secondary:hover { background: var(--hl); border-color: var(--accent-ring); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
button.ghost:hover, .btn.ghost:hover { background: var(--card-3); color: var(--text); }
button.danger, .btn.danger { color: var(--err); }
button.danger:hover { background: var(--err-bg); border-color: var(--err); }
button.danger.solid { background: var(--err); border-color: var(--err); color: #fff; }
button.rec, .btn.rec { background: var(--rec); border-color: var(--rec); color: #fff; font-size: var(--fs-lg); padding: 12px 24px; border-radius: var(--r-md); box-shadow: 0 8px 24px rgba(225, 29, 72, .28); font-weight: 600; }
button.rec:hover { filter: brightness(1.06); }
button.small, .btn.small { padding: 4px 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); gap: 5px; }
button.icon, .btn.icon { padding: 7px; width: 34px; height: 34px; justify-content: center; border-radius: var(--r); }
button.icon.small, .btn.icon.small { width: 28px; height: 28px; padding: 4px; }
button.active, .btn.active { background: var(--accent-bg); border-color: var(--accent-ring); color: var(--accent-fg); }
.btn-group { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); overflow: hidden; }
.btn-group > button, .btn-group > .btn, .btn-group > span { border: none !important; border-radius: 0 !important; }
.btn-group > * + * { border-left: 1px solid var(--line) !important; }

/* tooltip da attributo data-tip */
[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 7px); transform: translateX(-50%) translateY(-2px); background: #0f172a; color: #fff; padding: 5px 9px; border-radius: 7px; font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity var(--dur), transform var(--dur); z-index: 80; box-shadow: var(--sh-md); }
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); transition-delay: .25s; }
[data-tip].tip-left::after { left: auto; right: 0; transform: translateY(-2px); }
[data-tip].tip-left:hover::after { transform: translateY(0); }
[data-tip].tip-top::after { top: auto; bottom: calc(100% + 7px); }

/* ---------- campi ---------- */
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 11px; width: 100%; transition: border-color var(--dur), box-shadow var(--dur); }
input:hover, select:hover, textarea:hover { border-color: var(--line-2); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); margin-right: 6px; }
input[type=range] { padding: 0; border: none; background: none; accent-color: var(--accent); }
label { display: block; font-size: var(--fs-sm); color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field { margin-bottom: var(--sp-3); }
.hint { font-size: var(--fs-xs); color: var(--muted); margin-top: 4px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

/* ---------- chip, badge, status ---------- */
.chip, .badge { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 500; padding: 2px 9px; border-radius: var(--r-full); background: var(--card-3); border: 1px solid transparent; color: var(--text-2); line-height: 1.6; }
.chip.mono { font-family: var(--mono); }
.chip.done, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.chip.pending, .chip.waiting, .badge.warn { background: var(--warn-bg); color: var(--warn); }
.chip.processing, .badge.info { background: var(--accent-bg); color: var(--accent-fg); }
.chip.recording, .badge.rec { background: var(--rec-bg); color: var(--rec); }
.chip.error, .badge.err { background: var(--err-bg); color: var(--err); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 600; padding: 2px 9px; border-radius: var(--r-full); white-space: nowrap; background: var(--card-3); color: var(--text-2); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.recording { background: var(--rec-bg); color: var(--rec); }
.status.recording::before { animation: blink 1.1s infinite; }
.status.done { background: var(--ok-bg); color: var(--ok); }
.status.partial { background: var(--warn-bg); color: var(--warn); }
.status.error { background: var(--err-bg); color: var(--err); }
.ctag { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 600; padding: 2px 10px; border-radius: var(--r-full); background: color-mix(in srgb, var(--cc, var(--accent)) 14%, transparent); color: var(--cc, var(--accent)); }
.ctag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cc, var(--accent)); }
.cdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--cc, var(--accent)); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--rec); margin-right: 6px; animation: blink 1.1s infinite; vertical-align: 0; }
@keyframes blink { 50% { opacity: .25; } }
.kbd { display: inline-block; font: 500 11.5px/1 var(--mono); padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line-2); border-bottom-width: 2px; background: var(--card-2); color: var(--text-2); min-width: 20px; text-align: center; }

/* ---------- card ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-5) var(--sp-5); margin-bottom: var(--sp-4); box-shadow: var(--sh-sm); }
.card > h2:first-child { margin-bottom: var(--sp-4); }
.card h3 { margin: var(--sp-4) 0 var(--sp-2); font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.card-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-head h2 { flex: 1; margin: 0; }
.card.flat { box-shadow: none; }
.card.pad-sm { padding: var(--sp-4); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: var(--sp-4); overflow-x: auto; scrollbar-width: none; position: relative; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: none; border-radius: var(--r-sm) var(--r-sm) 0 0; background: none; color: var(--muted); padding: 10px 13px; font-weight: 500; position: relative; gap: 7px; white-space: nowrap; }
.tabs button:hover { color: var(--text); background: var(--card-2); }
.tabs button.active { color: var(--accent-fg); }
.tabs button.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); animation: tabin var(--dur-slow) var(--ease); }
@keyframes tabin { from { transform: scaleX(.4); opacity: 0; } to { transform: scaleX(1); opacity: 1; } }
.tabs button .tab-chk { color: var(--ok); font-size: 11px; }

/* ---------- segmented ---------- */
.mv-seg, .seg { display: inline-flex; flex-wrap: nowrap; gap: 2px; padding: 3px; border-radius: var(--r); background: var(--card-3); border: 1px solid var(--line); }
.mv-seg button, .seg button { border: none; background: transparent; padding: 5px 11px; border-radius: 7px; font-weight: 500; color: var(--muted); font-size: var(--fs-sm); }
.mv-seg button:hover, .seg button:hover { color: var(--text); background: transparent; }
.mv-seg button.active, .seg button.active { background: var(--card); color: var(--text); box-shadow: var(--sh-sm); font-weight: 600; }

/* ---------- tabelle ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; position: sticky; top: 0; background: var(--card); z-index: 1; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--card-2); }
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); }

/* ---------- banner, toast ---------- */
.banner { margin: var(--sp-3) var(--sp-5) 0; padding: 10px 14px; border-radius: var(--r); background: var(--err-bg); color: var(--err); border: 1px solid color-mix(in srgb, var(--err) 35%, transparent); font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 300; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: #0f172a; color: #fff; padding: 10px 14px; border-radius: var(--r); box-shadow: var(--sh-lg); max-width: 380px; font-size: var(--fs-sm); animation: toastin var(--dur-slow) var(--ease); border-left: 3px solid var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 250; background: rgba(2, 6, 23, .55); backdrop-filter: blur(4px); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; animation: fadein var(--dur) var(--ease); }
.modal.hidden { display: none; }
.modal-box { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-lg); width: min(680px, 100%); max-height: 80vh; overflow: hidden; display: flex; flex-direction: column; animation: popin var(--dur-slow) var(--ease); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes popin { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; font-size: var(--fs-lg); }
.modal-body { padding: 14px 18px; overflow: auto; }

/* ---------- command palette ---------- */
.cmdk-input { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.cmdk-input input { border: none; background: transparent; font-size: var(--fs-lg); padding: 4px 0; box-shadow: none !important; }
.cmdk-list { overflow: auto; max-height: 60vh; padding: 6px; }
.cmdk-group { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 700; padding: 10px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r); cursor: pointer; color: var(--text); }
.cmdk-item .lucide { color: var(--muted); }
.cmdk-item.active, .cmdk-item:hover { background: var(--accent-bg); color: var(--accent-fg); }
.cmdk-item.active .lucide { color: var(--accent-fg); }
.cmdk-item .cmdk-sub { color: var(--muted); font-size: var(--fs-xs); margin-left: auto; white-space: nowrap; }
.cmdk-empty { padding: 24px; text-align: center; color: var(--muted); }
.cmdk-foot { display: flex; gap: 14px; padding: 8px 16px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); }

/* ---------- stati ---------- */
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-state svg.ill { width: 120px; height: 90px; opacity: .9; }
.empty-state b { color: var(--text); font-size: var(--fs-md); }
.skeleton { background: linear-gradient(90deg, var(--card-3) 25%, var(--card-2) 37%, var(--card-3) 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); min-height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.sk-page { display: flex; flex-direction: column; gap: 12px; padding: 8px 0; }
.sk-page .skeleton:nth-child(1) { height: 32px; width: 40%; } .sk-page .skeleton:nth-child(2) { height: 16px; width: 70%; } .sk-page .skeleton:nth-child(3) { height: 220px; }
details summary { cursor: pointer; color: var(--muted); }
details summary::marker { color: var(--faint); }
code.inline { background: var(--card-3); padding: 1px 6px; border-radius: 5px; font-family: var(--mono); font-size: var(--fs-sm); }
pre.prompt { white-space: pre-wrap; background: var(--card-3); padding: 12px 14px; border-radius: var(--r); font-size: var(--fs-sm); line-height: 1.5; }
.log { background: var(--card-3); padding: 10px; border-radius: var(--r); max-height: 300px; overflow: auto; font-family: var(--mono); font-size: var(--fs-xs); white-space: pre-wrap; }
.result { padding: 12px 0; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: none; }
.result mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 3px; }

/* ---------- markdown ---------- */
.md { line-height: 1.65; }
.md h1 { font-size: var(--fs-xl); margin: 0 0 12px; } .md h2 { font-size: var(--fs-lg); margin: 24px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); } .md h3 { font-size: var(--fs-md); margin: 18px 0 8px; } .md h4 { font-size: var(--fs); margin: 14px 0 6px; color: var(--text-2); }
.md p { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; margin: 6px 0 10px; }
.md li { margin: 3px 0; }
.md table { margin: 10px 0; font-size: var(--fs-sm); } .md th, .md td { border: 1px solid var(--line); } .md th { position: static; }
.md pre { background: var(--card-3); padding: 10px; border-radius: var(--r); overflow: auto; }
.md blockquote { border-left: 3px solid var(--accent); margin: 10px 0; padding: 6px 14px; color: var(--text-2); background: var(--accent-bg); border-radius: 0 var(--r) var(--r) 0; }
.md img { border-radius: var(--r); }
.md .mermaid { background: var(--card); padding: 10px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r); }
.md .mermaid svg { max-width: 100%; height: auto; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* ============================================================ APP SHELL ============================================================ */
.app { display: flex; height: 100vh; width: 100vw; overflow: hidden; }
.sb { width: var(--sb-w); flex: 0 0 auto; background: var(--sb-bg); color: var(--sb-text); display: flex; flex-direction: column; border-right: 1px solid var(--sb-line); transition: width var(--dur-slow) var(--ease); overflow: hidden; }
.app.sb-mini .sb { width: var(--sb-mini); }
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 12px; color: #fff; font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.01em; text-decoration: none !important; }
.sb-logo { width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(135deg, var(--rec), #f97316); display: inline-flex; align-items: center; justify-content: center; color: #fff; flex: 0 0 auto; box-shadow: 0 6px 16px rgba(225, 29, 72, .35); }
.sb-logo .lucide { width: 18px; height: 18px; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; }
.sb-nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--r); color: var(--sb-text); font-weight: 500; text-decoration: none !important; transition: background var(--dur), color var(--dur); white-space: nowrap; }
.sb-nav a .lucide { width: 19px; height: 19px; color: var(--sb-muted); transition: color var(--dur); }
.sb-nav a:hover { background: var(--sb-active); color: #fff; }
.sb-nav a.active { background: var(--sb-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sb-nav a.active .lucide, .sb-nav a:hover .lucide { color: #fff; }
.app.sb-mini .sb-nav a { justify-content: center; padding: 10px; }
.app.sb-mini .sb-nav a span, .app.sb-mini .sb-name, .app.sb-mini .sb-status .lbl, .app.sb-mini .sb-sec-title { display: none; }
.sb-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--sb-line); display: flex; flex-direction: column; gap: 8px; }
.sb-status { display: flex; flex-direction: column; gap: 6px; }
.sb-pill { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--r); background: var(--sb-bg-2); font-size: var(--fs-xs); color: var(--sb-text); text-decoration: none !important; border: 1px solid var(--sb-line); min-height: 34px; }
.sb-pill .lucide { width: 16px; height: 16px; color: var(--sb-muted); flex: 0 0 auto; }
.sb-pill .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-pill.rec { color: #fff; background: rgba(225, 29, 72, .18); border-color: rgba(225, 29, 72, .45); font-weight: 600; }
.sb-pill.rec .lucide { color: var(--rec); animation: blink 1.1s infinite; }
.sb-pill.ok .lucide { color: var(--ok); } .sb-pill.warn .lucide { color: var(--warn); } .sb-pill.err .lucide { color: var(--err); } .sb-pill.busy .lucide { color: var(--accent-h); animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.app.sb-mini .sb-pill { justify-content: center; padding: 7px; }
.sb-tools { display: flex; gap: 4px; justify-content: space-between; }
.sb-tools button { background: transparent; border-color: transparent; color: var(--sb-muted); width: 32px; height: 32px; padding: 6px; justify-content: center; }
.sb-tools button:hover { background: var(--sb-active); color: #fff; }
.app.sb-mini .sb-tools { flex-direction: column; align-items: center; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar { display: none; }
main { flex: 1; min-height: 0; overflow: auto; padding: var(--sp-5) var(--sp-6) 90px; scroll-behavior: smooth; }
main > .page { max-width: var(--content-max); margin: 0 auto; }
main.ws { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
main.ws > .page { max-width: none; margin: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: flex-end; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }
.page-head h1 { flex: 1; }
.page-head .sub { color: var(--muted); font-size: var(--fs-sm); margin-top: 4px; }

/* mobile: barra di navigazione in basso, stato in alto */
@media (max-width: 900px) {
  :root { --topbar-h: 48px; }
  .app { flex-direction: column; }
  .sb { width: 100% !important; order: 2; flex-direction: row; align-items: center; border-right: none; border-top: 1px solid var(--sb-line); padding: 0 6px; height: 58px; }
  .sb-brand, .sb-foot .sb-status, .sb-tools #sb-toggle { display: none; }
  .sb-nav { flex-direction: row; flex: 1; justify-content: space-around; padding: 4px; gap: 0; }
  .sb-nav a { flex-direction: column; gap: 3px; font-size: 10.5px; padding: 6px 8px; }
  .sb-nav a.active { box-shadow: none; }
  .sb-foot { margin: 0; padding: 0; border: none; }
  .sb-tools { flex-direction: row; }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 0 10px; height: var(--topbar-h); background: var(--card); border-bottom: 1px solid var(--line); flex: 0 0 auto; overflow-x: auto; scrollbar-width: none; }
  .topbar .sb-pill { background: var(--card-3); border-color: var(--line); color: var(--text); flex: 0 0 auto; }
  .topbar .sb-pill.rec { background: var(--rec-bg); color: var(--rec); }
  .main-wrap { height: auto; flex: 1; min-height: 0; }
  main { padding: var(--sp-3) var(--sp-3) 90px; }
}

/* ---------- lettore audio fluttuante ---------- */
.fplayer { position: fixed; left: calc(var(--sb-w) + (100vw - var(--sb-w)) / 2); transform: translateX(-50%); bottom: 14px; z-index: 60; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-lg); width: min(760px, calc(100vw - var(--sb-w) - 48px)); transition: left var(--dur-slow) var(--ease), width var(--dur-slow) var(--ease); }
.app.sb-mini .fplayer { left: calc(var(--sb-mini) + (100vw - var(--sb-mini)) / 2); width: min(760px, calc(100vw - var(--sb-mini) - 48px)); }
.fplayer input[type=range] { flex: 1; min-width: 120px; }
.fplayer .time { font-family: var(--mono); font-size: var(--fs-sm); min-width: 140px; text-align: center; font-variant-numeric: tabular-nums; }
.fplayer select { width: auto; padding: 5px 26px 5px 8px; font-size: var(--fs-sm); }
.fplayer.mini { width: auto; padding: 6px 10px; }
.fplayer.mini .fp-full { display: none; }
.fplayer:not(.mini) .fp-mini-time { display: none; }
@media (max-width: 900px) { .fplayer { left: 50%; width: calc(100vw - 20px); bottom: 68px; } .fplayer .time { min-width: 0; } }
