/* POLARIS web app — stessi colori dell'app Windows e del sito */
:root {
  --bg: #F4F5FB; --panel: #FFFFFF; --ink: #1B1E2E; --muted: #6F758E;
  --line: #E5E7F0; --line2: #CFD3E2; --hover: #EEF0FA; --soft: #F7F8FD;
  --accent: #6366F1; --accent2: #14B8A6; --accent-soft: #ECECFE; --accent-ink: #4F46E5;
  --good: #16A34A; --good-soft: #E7F7EE; --bad: #DC2626; --bad-soft: #FDECEC; --warn-soft: #FFF4E2; --warn: #8A5A00;
  --shadow: 0 10px 30px rgba(30, 34, 80, .10), 0 2px 6px rgba(30, 34, 80, .06);
  --radius: 16px; --side: 248px; --top: 56px; --bottom: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F111A; --panel: #171A26; --ink: #E6E8F2; --muted: #8A90A8;
    --line: #262A3A; --line2: #353A4E; --hover: #1F2333; --soft: #13151F;
    --accent: #818CF8; --accent2: #2DD4BF; --accent-soft: #23264A; --accent-ink: #A5B4FC;
    --good: #34C77B; --good-soft: #13291F; --bad: #F87171; --bad-soft: #2E1719; --warn-soft: #3A2E1A; --warn: #F0AA45;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F111A; --panel: #171A26; --ink: #E6E8F2; --muted: #8A90A8;
  --line: #262A3A; --line2: #353A4E; --hover: #1F2333; --soft: #13151F;
  --accent: #818CF8; --accent2: #2DD4BF; --accent-soft: #23264A; --accent-ink: #A5B4FC;
  --good: #34C77B; --good-soft: #13291F; --bad: #F87171; --bad-soft: #2E1719; --warn-soft: #3A2E1A; --warn: #F0AA45;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.grad { background: linear-gradient(120deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- avvio */
.boot { height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--muted); }

/* ---------------------------------------------------------------- bottoni e campi */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em; min-height: 44px;
  padding: .6em 1.15em; border-radius: 12px; font-weight: 700; font-size: .95rem; text-decoration: none;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.full { width: 100%; }
.btn.small { min-height: 36px; padding: .35em .85em; font-size: .88rem; }
.btn:disabled { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 1px solid transparent;
  background: transparent; cursor: pointer; font-size: 1.2rem; flex: none;
}
.icon-btn:hover { background: var(--hover); }
:is(.btn, .icon-btn, a, input, select, textarea, summary):focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

label.field { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: .6em .85em; border-radius: 12px; border: 1px solid var(--line2);
  background: var(--panel); font-size: 16px; font-weight: 500;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea.input { resize: vertical; line-height: 1.5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 14px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.error { background: var(--bad-soft); color: var(--bad); border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: .92rem; }
.note { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: .9rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.tag { display: inline-block; background: var(--accent-soft); color: var(--accent-ink); border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 700; }

/* ---------------------------------------------------------------- schermate di accesso */
.gate { height: 100dvh; overflow-y: auto; padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b)); display: grid; place-items: center; }
.gate-box { width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 28px 24px; box-shadow: var(--shadow); }
.gate-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.gate-head canvas { width: 64px; height: 64px; flex: none; }
.gate-head h1 { margin: 0; font-size: 1.45rem; }
.gate-head p { margin: 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tabs button { border: 0; background: transparent; border-radius: 9px; padding: 9px; font-weight: 700; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.steps { margin: 0 0 16px; padding-left: 1.3em; display: grid; gap: 8px; }
.pw { position: relative; }
.pw .input { padding-right: 84px; }
.pw button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: var(--hover); border-radius: 8px; padding: 5px 9px; font-size: .8rem; font-weight: 700; cursor: pointer; }

/* ---------------------------------------------------------------- struttura dell'app */
.app { display: grid; grid-template-columns: var(--side) 1fr; height: 100dvh; }
.side {
  background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: calc(18px + var(--safe-t)) 14px 14px; gap: 4px; overflow-y: auto;
}
.side .brand { display: grid; justify-items: center; text-align: center; margin-bottom: 10px; }
.side .brand canvas { width: 104px; height: 104px; }
.side .brand b { font-size: 1.25rem; letter-spacing: .02em; }
.chip {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--soft); cursor: pointer; text-align: left; margin-bottom: 12px;
}
.chip:hover { border-color: var(--accent); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); font-size: .9rem; }
.chip b { display: block; font-size: .92rem; line-height: 1.2; }
.chip small { color: var(--muted); font-size: .76rem; line-height: 1.2; display: block; }
.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 0; background: transparent;
  cursor: pointer; font-weight: 600; color: var(--muted); text-align: left; width: 100%; position: relative; }
.nav .ico { font-size: 1.15rem; width: 24px; text-align: center; }
.nav:hover { background: var(--hover); color: var(--ink); }
.nav[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 999px; font-size: .72rem; padding: 1px 7px; font-weight: 800; }
.side .spacer { flex: 1; }
.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 18px 8px; min-height: var(--top); border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .mini { display: none; width: 34px; height: 34px; }
.page { flex: 1; overflow-y: auto; padding: 20px; -webkit-overflow-scrolling: touch; }
.page-in { max-width: 860px; margin: 0 auto; }
.bottom { display: none; }
.mobile-only { display: none; }
@media (max-width: 860px) { .mobile-only { display: grid; } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar .mini { display: block; }
  .page { padding: 16px; }
  .bottom {
    display: grid; grid-template-columns: repeat(6, 1fr); background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: var(--safe-b); flex: none;
  }
  .bottom button { border: 0; background: transparent; display: grid; justify-items: center; gap: 1px; padding: 8px 0 6px; cursor: pointer;
    color: var(--muted); font-size: .66rem; font-weight: 700; position: relative; min-height: var(--bottom); }
  .bottom .ico { font-size: 1.25rem; line-height: 1.3; }
  .bottom button[aria-current="page"] { color: var(--accent-ink); }
  .bottom button[aria-current="page"] .ico { transform: translateY(-1px); }
  .bottom .badge { position: absolute; top: 4px; right: calc(50% - 22px); margin: 0; font-size: .62rem; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- chat */
.chat { display: flex; flex-direction: column; height: 100%; }
.chat .page { display: flex; flex-direction: column; }
.msgs { display: grid; gap: 14px; max-width: 860px; width: 100%; margin: 0 auto; padding-bottom: 8px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg canvas { width: 34px; height: 34px; flex: none; margin-top: 2px; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px; padding: 10px 14px; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.msg.me { justify-content: flex-end; }
.msg.me .bubble { background: var(--accent); color: #fff; border-color: transparent; border-radius: 16px 4px 16px 16px; max-width: 85%; white-space: pre-wrap; }
.msg.me .bubble .att { background: rgba(255,255,255,.2); color: #fff; }
.bubble > :last-child { margin-bottom: 0; }
.bubble .meta { display: flex; gap: 6px; margin-top: 6px; }
.bubble .meta button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: .8rem; font-weight: 700; padding: 4px 6px; border-radius: 8px; }
.bubble .meta button:hover { background: var(--hover); color: var(--ink); }
.bubble ul, .bubble ol { padding-left: 1.3em; margin: 0 0 .8em; }
.bubble h2, .bubble h3, .bubble h4 { font-size: 1.02rem; margin: .8em 0 .4em; }
.md code, .bubble code { background: var(--hover); padding: 1px 5px; border-radius: 6px; font-family: ui-monospace, Consolas, monospace; font-size: .88em; }
.code { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 0 0 .8em; background: var(--soft); }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 12px; font-size: .78rem; color: var(--muted); border-bottom: 1px solid var(--line); }
.code-bar button { border: 0; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.code-bar button:hover { background: var(--hover); color: var(--ink); }
.code pre { margin: 0; padding: 12px; overflow-x: auto; font-size: .86rem; line-height: 1.5; }
.code pre code { background: none; padding: 0; }
.table { overflow-x: auto; margin: 0 0 .8em; }
.table table { border-collapse: collapse; font-size: .9rem; }
.table th, .table td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.table th { background: var(--soft); }
blockquote { margin: 0 0 .8em; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.status-line { color: var(--muted); font-size: .9rem; font-style: italic; }
.welcome { text-align: center; padding: 20px 0 8px; display: grid; justify-items: center; }
.welcome canvas { width: 120px; height: 120px; }
.welcome h2 { margin-top: 6px; }
.sugg { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.sugg button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.sugg button:hover { border-color: var(--accent); color: var(--accent-ink); }
.composer { padding: 10px 16px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--panel); }
@media (max-width: 860px) { .composer { padding-bottom: 10px; } }
.composer-in { max-width: 860px; margin: 0 auto; }
.atts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.att { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent-ink); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: .82rem; font-weight: 700; max-width: 100%; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att button { border: 0; background: transparent; cursor: pointer; color: inherit; font-weight: 800; padding: 0 6px; }
.compose-row { display: flex; gap: 6px; align-items: flex-end; background: var(--soft); border: 1px solid var(--line2); border-radius: 16px; padding: 4px; }
.compose-row:focus-within { border-color: var(--accent); }
.compose-row textarea { flex: 1; border: 0; background: transparent; resize: none; padding: 10px 6px; max-height: 160px; min-height: 44px; outline: none; font-size: 16px; line-height: 1.45; }
.send { background: var(--accent); color: #fff; border-radius: 12px; }
.send:hover { background: var(--accent-ink); }
.rec { background: var(--bad) !important; color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--bad) 25%, transparent); } }
.head-tools { display: flex; gap: 6px; align-items: center; }
.head-tools select { min-height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px; font-weight: 600; font-size: .88rem; }

/* ---------------------------------------------------------------- quiz, carte, esercizi, file, progressi */
.options { display: grid; gap: 10px; margin: 14px 0; }
.option { text-align: left; border: 1.5px solid var(--line); background: var(--panel); border-radius: 14px; padding: 12px 14px; cursor: pointer; font-weight: 600; display: flex; gap: 10px; }
.option b { color: var(--accent-ink); }
.option:hover:not(:disabled) { border-color: var(--accent); }
.option.ok { border-color: var(--good); background: var(--good-soft); }
.option.ko { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; }
.progress { height: 8px; background: var(--hover); border-radius: 999px; overflow: hidden; margin: 6px 0 14px; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; transition: width .3s; }
.explain { border-radius: 12px; padding: 12px 14px; background: var(--soft); border: 1px solid var(--line); }
.score { font-size: 3rem; font-weight: 800; line-height: 1; }
.list { display: grid; gap: 10px; }
.item { display: flex; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; }
.item .grow { flex: 1; min-width: 0; }
.item .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.click { cursor: pointer; text-align: left; width: 100%; font: inherit; }
.item.click:hover { border-color: var(--accent); }
.flash { perspective: 1200px; margin: 10px 0 14px; }
.flash-in { position: relative; min-height: 240px; transition: transform .45s; transform-style: preserve-3d; cursor: pointer; }
.flash.flipped .flash-in { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; border-radius: 20px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 1px solid var(--line); background: var(--panel); font-size: 1.15rem; font-weight: 600; overflow-y: auto; }
.face.back { transform: rotateY(180deg); background: var(--soft); font-weight: 500; font-size: 1.05rem; }
.face small { position: absolute; top: 12px; left: 16px; color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grades .btn { flex-direction: column; gap: 0; padding: .5em .3em; font-size: .85rem; white-space: normal; }
.grades small { font-weight: 500; color: var(--muted); font-size: .72rem; }
.editor { width: 100%; min-height: 240px; font: 14px/1.5 ui-monospace, Consolas, "Cascadia Code", monospace; padding: 12px; border-radius: 12px; border: 1px solid var(--line2);
  background: var(--soft); resize: vertical; tab-size: 4; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.editor:focus { outline: none; border-color: var(--accent); }
.output { white-space: pre-wrap; font: 13px/1.5 ui-monospace, Consolas, monospace; background: #0F111A; color: #D7DBEA; border-radius: 12px; padding: 12px; max-height: 300px; overflow: auto; margin: 0; }
.output .err { color: #F87171; }
.preview { width: 100%; height: 320px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.grade-box { border-radius: 14px; padding: 14px 16px; margin-top: 12px; }
.grade-box.ok { background: var(--good-soft); }
.grade-box.ko { background: var(--warn-soft); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.tile b { display: block; font-size: 1.7rem; line-height: 1.1; }
.tile span { color: var(--muted); font-size: .85rem; font-weight: 600; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 140px; margin: 10px 0 4px; }
.bars div { display: grid; justify-items: center; gap: 4px; align-self: end; font-size: .75rem; color: var(--muted); font-weight: 700; }
.bars i { display: block; width: 100%; max-width: 36px; border-radius: 8px 8px 4px 4px; background: linear-gradient(180deg, var(--accent), var(--accent2)); min-height: 4px; }
.meter { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; margin-bottom: 10px; font-size: .92rem; }
.meter .progress { grid-column: 1 / -1; margin: 0; }
.drop { border: 2px dashed var(--line2); border-radius: 16px; padding: 22px; text-align: center; cursor: pointer; background: var(--panel); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.section { margin-bottom: 22px; }
.section > h2 { font-size: 1.05rem; }

/* ---------------------------------------------------------------- finestre */
dialog.sheet { border: 1px solid var(--line); border-radius: 22px; padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 24px);
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
dialog.sheet::backdrop { background: rgba(15, 17, 26, .55); backdrop-filter: blur(3px); }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 0 22px; }
.sheet-head h2 { flex: 1; margin: 0; }
.sheet-body { padding: 14px 22px 22px; overflow-y: auto; max-height: calc(100dvh - 100px); }
.menu-list { display: grid; gap: 6px; }
.menu-list button, .menu-list a { display: flex; gap: 12px; align-items: center; width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); text-align: left; }
.menu-list button:hover, .menu-list a:hover { border-color: var(--accent); }
.menu-list .r { margin-left: auto; color: var(--muted); font-weight: 500; font-size: .85rem; }
@media (max-width: 560px) {
  dialog.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 92dvh; }
  .sheet-body { padding-bottom: calc(22px + var(--safe-b)); }
}

.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 32px);
  transition: opacity .25s, transform .25s; z-index: 100; text-align: center; font-size: .92rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.spin { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes rot { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .flash-in, .progress i { transition: none; } .rec, .spin { animation: none; } }
