/* WonderWell Scuole — design system v2
   Phones (<600): header + bottom tab bar · Tablets (600–1023): header + top tabs · Laptop/iPad landscape (≥1024): sidebar.
   Contrast checked: light and dark text colours ≥ 4.5:1 (WCAG AA). */
:root {
  color-scheme: light dark;
  --ink: #1F1B24; --muted: #6B6475; --bg: #FAF8F5; --surface: #FFFFFF; --line: #E7E2DC; --soft: #F3EFEA; --field: #FFFFFF; --field-line: #CFC8C0;
  --accent: #8E3B5E;                                     /* per school; server keeps it ≥ 4.5 with white text */
  --accent-ink: var(--accent);                           /* accent used as TEXT */
  --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--surface));
  --ok: #2E7D4F;   --ok-soft: #E8F3EC;
  --warn: #A15C00; --warn-soft: #FBF1E2;
  --bad: #B3261E;  --bad-soft: #FBEAE9;
  --info: #2F5D8A; --info-soft: #E9F0F7;
  --r: 16px; --r-sm: 11px;
  --shadow: 0 1px 2px rgba(31,27,36,.05), 0 6px 20px rgba(31,27,36,.05);
  --shadow-lg: 0 24px 60px rgba(31,27,36,.22);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;   /* no web fonts: nothing sent to third parties */
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #F2EEF3; --muted: #B3ABBA; --bg: #141116; --surface: #1E1A21; --line: #332D38; --soft: #28232C; --field: #18151B; --field-line: #4A4351;
    --accent-ink: color-mix(in srgb, var(--accent) 50%, white);
    --accent-soft: color-mix(in srgb, var(--accent) 24%, var(--surface));
    --ok: #7BCB9A; --ok-soft: #1B2E23; --warn: #E9B266; --warn-soft: #33261A; --bad: #F2948D; --bad-soft: #3A1F1E; --info: #8DB8E3; --info-soft: #1A2836;
    --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 24px 60px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
body { min-height: 100dvh; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.015em; }
h1 { font-size: 1.6rem; font-weight: 750; } h2 { font-size: 1.12rem; font-weight: 700; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent-ink); }
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); } .small { font-size: .875rem; }
.hidden { display: none !important; }
.cap::first-letter { text-transform: uppercase; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, white); outline-offset: 2px; border-radius: 6px; }

/* ================= LAYOUT ================= */
.trial { background: var(--warn-soft); color: var(--warn); font-size: .8rem; font-weight: 650; text-align: center; padding: .35rem 1rem; }
.app { min-height: 100dvh; }
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; max-width: 1200px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; flex: 1; }
.logo { width: 40px; height: 40px; border-radius: 12px; flex: none; object-fit: contain; background: var(--surface); }
.logo.letter { display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 750; font-size: 1.15rem; }
.brand-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-role { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--soft); color: var(--ink); font-weight: 700; cursor: pointer; flex: none; }

/* tablet: top tabs */
.tabs { display: none; max-width: 1200px; margin: 0 auto; gap: .15rem; overflow-x: auto; padding: 0 .75rem; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: .4rem; border: 0; background: none; padding: .7rem .8rem; border-bottom: 2.5px solid transparent;
  color: var(--muted); font-weight: 600; white-space: nowrap; cursor: pointer; min-height: 46px; }
.tab svg.i { width: 18px; height: 18px; }
.tab[aria-current="page"] { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* phone: bottom bar */
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line); padding: 0 .25rem var(--safe-b); }
.bottom button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--nav-h);
  border: 0; background: none; color: var(--muted); font-size: .7rem; font-weight: 650; cursor: pointer; }
.bottom button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bottom button[aria-current="page"] { color: var(--accent-ink); }
.bottom button[aria-current="page"] svg.i { stroke-width: 2.4; }

/* laptop / iPad landscape: sidebar */
.side { display: none; }
main { max-width: 1200px; margin: 0 auto; padding: 1.1rem 1rem calc(var(--nav-h) + var(--safe-b) + 1.5rem); animation: in .18s ease-out; }
.app.no-nav main { padding-bottom: calc(var(--safe-b) + 2rem); }
.page-h { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin: .25rem 0 1rem; }
.page-h h1 { margin: 0; flex: 1; min-width: 0; }
@keyframes in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (min-width: 600px) {
  .tabs { display: flex; }
  .bottom { display: none; }
  main { padding: 1.5rem 1.5rem 3rem; }
  .top-in { padding: .7rem 1.5rem; }
}
@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: 256px minmax(0, 1fr); }
  .top, .tabs { display: none; }
  .side { display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; padding: 1.1rem .8rem; background: var(--surface);
    border-right: 1px solid var(--line); overflow-y: auto; }
  .side .brand { flex: none; padding: .3rem .5rem 1.1rem; }
  .side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .side nav button { display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left; border: 0; background: none; padding: .65rem .75rem;
    border-radius: 10px; color: var(--muted); font-weight: 600; cursor: pointer; min-height: 44px; }
  .side nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
  .side .me { border-top: 1px solid var(--line); padding: .8rem .5rem 0; display: flex; align-items: center; gap: .6rem; }
  main { padding: 2rem 2.25rem 3rem; width: 100%; }
  .trial { grid-column: 1 / -1; }
}

/* ================= BUILDING BLOCKS ================= */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 1.05rem 1.15rem; margin-bottom: 1rem; min-width: 0; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid > .card { margin-bottom: 0; }
.grid + .grid, .grid + .card, .card + .grid { margin-top: 1rem; }
@media (min-width: 760px) { .g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1180px) { .g3 { grid-template-columns: repeat(3, 1fr); } }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: .5rem .75rem; padding: .75rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list > li:first-child { border-top: 0; }
.list > li > .grow { flex: 1 1 200px; }
.grow { flex: 1; min-width: 0; }
.ttl { font-weight: 650; overflow-wrap: break-word; hyphens: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); font-weight: 650; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap;
  transition: transform .08s, background .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 38px; padding: .35rem .75rem; font-size: .875rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { min-width: 44px; padding: .5rem; }
@media (hover: hover) {
  .btn:hover { background: var(--soft); } .btn.primary:hover { background: var(--accent); filter: brightness(1.08); }
  .side nav button:hover:not([aria-current="page"]) { background: var(--soft); color: var(--ink); }
  .lesson:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
}

label.f { display: block; margin-bottom: .85rem; }
label.f > span { display: block; font-size: .875rem; font-weight: 650; margin-bottom: .3rem; }
input:not([type=checkbox]):not([type=color]):not([type=file]), select, textarea { width: 100%; min-height: 46px; padding: .6rem .8rem; border: 1px solid var(--field-line);
  border-radius: var(--r-sm); background: var(--field); font-size: 16px; /* 16px stops iPhone zooming in */ }
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=color] { width: 56px; height: 46px; border: 1px solid var(--field-line); border-radius: var(--r-sm); padding: 3px; background: var(--field); }
input[type=file] { max-width: 100%; }
.form-row { display: grid; gap: 0 .75rem; }
@media (min-width: 560px) { .form-row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }

.pill { display: inline-flex; align-items: center; padding: .16rem .6rem; border-radius: 99px; font-size: .76rem; font-weight: 700; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.info { background: var(--info-soft); color: var(--info); }
.pill.acc { background: var(--accent-soft); color: var(--accent-ink); }
.empty { text-align: center; color: var(--muted); padding: 1.6rem .5rem; }
.note { background: var(--info-soft); color: var(--info); border-radius: var(--r-sm); padding: .7rem .85rem; font-size: .92rem; margin-bottom: .85rem; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: .75rem; }

/* skeleton while loading */
.sk { border-radius: var(--r); background: linear-gradient(90deg, var(--soft) 25%, color-mix(in srgb, var(--soft) 40%, var(--surface)) 50%, var(--soft) 75%);
  background-size: 300% 100%; animation: sk 1.2s infinite linear; margin-bottom: 1rem; }
@keyframes sk { from { background-position: 100% 0; } to { background-position: -200% 0; } }

/* ================= KPI + BARS ================= */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: .85rem 1rem; box-shadow: var(--shadow); min-width: 0; }
.kpi b { display: block; font-size: 1.75rem; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .8rem; color: var(--muted); }
.kpi.hero { background: var(--accent); border-color: var(--accent); color: #fff; } .kpi.hero span { color: #fff; opacity: .92; }
.bar { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.low > i { background: var(--warn); }

/* ================= WEEK ================= */
.weeknav { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.weeknav h2 { margin: 0; flex: 1; text-align: center; font-size: 1rem; }
.week { display: block; }
.day { margin-bottom: 1.1rem; min-width: 0; }
.day.none:not(.today) { display: none; }
.day-h { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: 0 0 .45rem; font-weight: 700; font-size: .95rem; }
.day.today .day-h { color: var(--accent-ink); }
.lesson { display: flex; align-items: center; gap: .8rem; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); border-radius: 13px; padding: .75rem .9rem; margin-bottom: .5rem; cursor: pointer; box-shadow: var(--shadow); color: var(--ink); min-width: 0; }
.lesson.closed { border-left-color: var(--line); opacity: .65; cursor: default; }
.lesson .time { font-variant-numeric: tabular-nums; font-weight: 750; min-width: 3.1rem; }
.lesson .grow > * { overflow-wrap: break-word; hyphens: auto; }
@media (min-width: 1280px) {           /* big screens: a real 7-column calendar */
  .week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .6rem; align-items: start; }
  .week .day, .week .day.none { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: .6rem; min-height: 180px; margin: 0; }
  .week .day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
  .week .day-h { font-size: .85rem; }
  .week .lesson { flex-direction: column; align-items: flex-start; gap: .25rem; padding: .55rem .6rem; box-shadow: none; }
  .week .lesson .time { min-width: 0; font-size: .85rem; }
  .week .lesson .ttl { font-size: .9rem; }
  .week .none-txt { display: block; }
  main { max-width: 1480px; }
}
.none-txt { display: block; }
}
.none-txt { display: none; color: var(--muted); font-size: .85rem; padding: .3rem; }

/* ================= ATTENDANCE ================= */
.att li { cursor: pointer; user-select: none; -webkit-user-select: none; flex-wrap: nowrap; min-height: 58px; }
.att .who { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.toggle { min-width: 104px; text-align: center; padding: .55rem .6rem; border-radius: 12px; font-weight: 750; font-size: .9rem; border: 0; cursor: pointer; transition: background .15s, color .15s; }
.toggle.on { background: var(--ok-soft); color: var(--ok); }
.toggle.off { background: var(--bad-soft); color: var(--bad); }
.toggle:disabled { cursor: default; }
.sticky-save { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + .75rem); margin-top: 1rem; }
.app.no-nav .sticky-save { bottom: calc(var(--safe-b) + .75rem); }
@media (min-width: 600px) { .sticky-save { bottom: 1rem; } .att-wrap { max-width: 720px; } }

/* ================= FAMILY ================= */
.hello { font-size: 1.5rem; font-weight: 750; margin: .2rem 0 1rem; }
.next { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, black)); color: #fff; border-radius: var(--r); padding: 1.1rem 1.2rem; margin-bottom: .8rem; }
.next small { opacity: .92; display: block; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; }
.next b { display: block; font-size: 1.3rem; margin: .25rem 0; }
.next b::first-letter { text-transform: uppercase; }
.cancel .ttl { text-decoration: line-through; color: var(--muted); }
.notice { border-top: 1px solid var(--line); padding: .85rem 0; }
.notice:first-child, .row + .notice { border-top: 0; padding-top: 0; }
.notice p { white-space: pre-wrap; margin: .35rem 0 0; overflow-wrap: anywhere; }

/* ================= AUTH ================= */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; }
.auth-box { width: 100%; max-width: 420px; }
.auth .card { padding: 1.6rem; }
.wordmark { display: flex; align-items: center; gap: .65rem; margin-bottom: 1.25rem; }
.wordmark .logo { width: 46px; height: 46px; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2rem; margin: .2rem 0 .6rem; }
.hero-side { display: none; }
@media (min-width: 900px) {
  .auth { grid-template-columns: 1.1fr 1fr; padding: 0; place-items: stretch; }
  .hero-side { display: flex; flex-direction: column; justify-content: center; padding: 4rem; color: #fff;
    background: radial-gradient(120% 120% at 0% 0%, color-mix(in srgb, var(--accent) 80%, white) 0%, var(--accent) 45%, color-mix(in srgb, var(--accent) 60%, black) 100%); }
  .hero-side h1 { font-size: 2.4rem; max-width: 14ch; }
  .hero-side ul { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .8rem; font-size: 1.05rem; }
  .hero-side li { display: flex; gap: .6rem; align-items: center; }
  .auth-main { display: grid; place-items: center; padding: 2rem; }
}

/* ================= DIALOGS / SHEETS / TOAST ================= */
dialog { border: 0; border-radius: 20px; padding: 0; width: min(540px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); box-shadow: var(--shadow-lg);
  background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(20,17,22,.5); }
.dlg { padding: 1.3rem 1.3rem 1.1rem; }
.dlg-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
@media (max-width: 599px) {          /* phones: dialogs slide up from the bottom like native sheets */
  dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 92dvh; animation: up .2s ease-out; }
  .dlg { padding-bottom: calc(1.1rem + var(--safe-b)); }
  .dlg-actions .btn { flex: 1; }
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.checks { max-height: 46dvh; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); padding: .25rem .8rem; }
.checks label { display: flex; gap: .7rem; align-items: center; padding: .55rem 0; border-top: 1px solid var(--line); min-height: 46px; cursor: pointer; }
.checks label:first-child { border-top: 0; }
.checks input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.copybox { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; background: var(--soft); padding: .65rem .75rem; border-radius: 9px; }
.sheet-list button { display: flex; align-items: center; gap: .8rem; width: 100%; border: 0; background: none; padding: .85rem .4rem; border-top: 1px solid var(--line);
  font-weight: 600; cursor: pointer; text-align: left; color: var(--ink); min-height: 52px; }
.sheet-list button:first-child { border-top: 0; }
.sheet-list button[aria-current="page"] { color: var(--accent-ink); }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 1rem); transform: translate(-50%, 10px); background: var(--ink); color: var(--bg);
  padding: .75rem 1.1rem; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 60; max-width: calc(100vw - 2rem);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #B3261E; color: #fff; }
@media (min-width: 600px) { #toast { bottom: 1.5rem; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* language switch IT | EN */
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.lang button { border: 0; background: var(--surface); color: var(--muted); font-weight: 700; font-size: .8rem; padding: .45rem .65rem; min-height: 36px; min-width: 40px; cursor: pointer; }
.lang button[aria-pressed="true"] { background: var(--accent); color: #fff; }
