/* uChat: stile comune alla app e al pannello del superadmin. */

:root {
  --bg: #f3f4fb;
  --surface: #ffffff;
  --surface-2: #f7f7fc;
  --text: #14132b;
  --muted: #646a85;
  --border: #e2e3f0;
  --primary: #5140d8;
  --primary-hover: #4232c2;
  --primary-soft: #e8e5ff;
  --on-primary: #ffffff;
  --ok: #138a4b;
  --ok-soft: #dcf7e8;
  --warn: #b25b00;
  --warn-soft: #fff1d6;
  --danger: #c4282d;
  --danger-soft: #fde3e3;
  --shadow: 0 1px 2px rgb(20 19 43 / .06), 0 6px 20px rgb(20 19 43 / .07);
  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0c1d;
    --surface: #17162d;
    --surface-2: #1e1d39;
    --text: #ecebf8;
    --muted: #9c9cb8;
    --border: #2c2b4a;
    --primary: #8d80ff;
    --primary-hover: #a59bff;
    --primary-soft: #26224d;
    --on-primary: #0d0c1d;
    --ok: #4ade80;
    --ok-soft: #123222;
    --warn: #fbbf24;
    --warn-soft: #3a2b0c;
    --danger: #f87171;
    --danger-soft: #3b1518;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
a { color: var(--primary); }
small, .muted { color: var(--muted); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.pre { white-space: pre-line; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- struttura ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; color: var(--text); text-decoration: none; }
.logo img { width: 30px; height: 30px; border-radius: 8px; }
.versione { font-size: .72rem; color: var(--muted); font-weight: 400; }

main { max-width: 880px; margin: 0 auto; padding: 16px 16px calc(90px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 9px; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .76rem; cursor: pointer; position: relative;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--primary); font-weight: 600; }
.tabs .pallino {
  position: absolute; top: 4px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: .7rem; line-height: 18px; font-weight: 700;
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card.piatta { box-shadow: none; }

.riga { display: flex; align-items: center; gap: 10px; }
.riga > svg { width: 24px; height: 24px; flex: none; color: var(--primary); }
.riga.wrap { flex-wrap: wrap; }
.colonna { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.lista { display: flex; flex-direction: column; gap: 10px; }
.vuoto { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- moduli ---------- */

label { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; font-weight: 600; margin-bottom: 12px; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
label.check input { margin-top: 3px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--primary); }
.campi2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .campi2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.piccolo { padding: 5px 12px; font-size: .85rem; }
.btn.largo { width: 100%; padding: 12px; }
.btn svg { width: 18px; height: 18px; }
.azioni { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.msg { padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: .92rem; }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.info { background: var(--primary-soft); color: var(--text); }
.msg.warn { background: var(--warn-soft); color: var(--text); }
.msg.ok { background: var(--ok-soft); color: var(--text); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge.online { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.online::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.occupato { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.attesa { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.no { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.credito {
  display: inline-flex; align-items: center; gap: 6px; margin-left: auto;
  padding: 5px 12px; border-radius: 999px; background: var(--primary-soft); color: var(--text);
  font-weight: 700; font-size: .9rem; border: 0; cursor: pointer; font-family: inherit;
}

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow); font-size: .92rem; max-width: calc(100vw - 32px); text-align: center;
}

/* Durante la chiamata i messaggi vanno in alto, lontano dai comandi. */
body:has(.chiamata) .toast { bottom: auto; top: calc(80px + env(safe-area-inset-top)); }

dialog.finestra {
  border: 0; border-radius: var(--radius); padding: 20px; width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
dialog.finestra::backdrop { background: rgb(10 10 25 / .55); }

/* ---------- accesso ---------- */

.accesso { max-width: 420px; margin: 0 auto; padding: 32px 16px; }
.accesso .logo { justify-content: center; font-size: 1.6rem; margin-bottom: 6px; }
.accesso .logo img { width: 48px; height: 48px; border-radius: 12px; }
.sottotitolo { text-align: center; color: var(--muted); margin-bottom: 20px; }
.scelta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.scelta label {
  margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); flex-direction: row; align-items: center; gap: 8px; cursor: pointer;
}
.scelta label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.cambia { text-align: center; margin-top: 14px; }
.link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

/* ---------- catalogo ---------- */

.presentazione-app { text-align: center; margin: 8px 0 18px; }
.presentazione-app h1 { font-size: 1.35rem; }
.topbar .btn { text-decoration: none; }

.cerca { margin-bottom: 14px; }
.docenti { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.docente { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.docente .testa { display: flex; gap: 12px; align-items: center; }
.docente .nome { font-weight: 700; font-size: 1.02rem; }
.docente .materie { color: var(--muted); font-size: .88rem; }
.docente .presentazione { font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.docente .piede { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.tariffa { font-weight: 700; }

/* Foto o video del docente nel catalogo, quando non è in linea. */
.vetrina {
  display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #000;
  border-radius: var(--radius-sm); margin-bottom: 4px;
}
img.vetrina { aspect-ratio: 4 / 3; }
dialog .vetrina { aspect-ratio: auto; max-height: 70vh; object-fit: contain; }

.avatar {
  width: 56px; height: 56px; border-radius: 50%; flex: none; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 1.1rem;
}
.avatar.piccolo { width: 40px; height: 40px; font-size: .9rem; }
.avatar.grande { width: 110px; height: 110px; font-size: 2rem; }

/* ---------- elenchi ---------- */

.voce { display: flex; gap: 12px; align-items: flex-start; }
.voce .corpo { flex: 1; min-width: 0; }
.voce .titolo { font-weight: 600; }
.voce .nota { font-size: .88rem; color: var(--muted); }
.voce .messaggio { font-size: .92rem; background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 6px; white-space: pre-line; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
td.importo, th.importo { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.piu { color: var(--ok); }
.meno { color: var(--danger); }
.tabella { overflow-x: auto; }

.grande-numero { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.riepilogo { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.riepilogo .card { margin: 0; }

.interruttore { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 600; cursor: pointer; }
.interruttore input { appearance: none; width: 46px; height: 26px; border-radius: 13px; background: var(--border); position: relative; cursor: pointer; padding: 0; border: 0; flex: none; }
.interruttore input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; }
.interruttore input:checked { background: var(--ok); }
.interruttore input:checked::after { left: 23px; }

.foto-profilo { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }

/* ---------- videochiamata ---------- */

.chiamata {
  position: fixed; inset: 0; z-index: 50; background: #07070f; color: #fff;
  display: flex; flex-direction: column; overflow: hidden;
}
.chiamata video { background: #000; }
.chiamata .remoto { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.chiamata .locale {
  position: absolute; right: 14px; bottom: calc(110px + env(safe-area-inset-bottom));
  width: min(30vw, 180px); aspect-ratio: 3 / 4; object-fit: cover; border-radius: 14px;
  border: 2px solid rgb(255 255 255 / .35); transform: scaleX(-1); z-index: 2; box-shadow: 0 6px 20px rgb(0 0 0 / .4);
}
@media (orientation: landscape) { .chiamata .locale { aspect-ratio: 4 / 3; width: min(22vw, 220px); } }
.chiamata .locale.posteriore { transform: none; }
.chiamata .barra {
  position: relative; z-index: 3; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(rgb(0 0 0 / .65), transparent);
}
.chiamata .barra .chi { font-weight: 700; font-size: 1.05rem; }
.chiamata .barra .stato { font-size: .85rem; opacity: .85; }
.contatori { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.contatori .resta { font-size: 1.4rem; font-weight: 800; line-height: 1.1; }
.contatori .resta.basso { color: #ffb74d; }
.contatori .resta.finale { color: #ff6b6b; }
.contatori small { color: rgb(255 255 255 / .75); display: block; }

.chiamata .attesa-video {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center; padding: 20px; z-index: 1;
}
.chiamata .attesa-video .avatar { width: 120px; height: 120px; font-size: 2.2rem; }
.squilla .avatar { animation: pulsa 1.4s ease-in-out infinite; }
@keyframes pulsa { 0%, 100% { box-shadow: 0 0 0 0 rgb(141 128 255 / .6); } 50% { box-shadow: 0 0 0 22px rgb(141 128 255 / 0); } }

.avviso-credito {
  position: relative; z-index: 3; margin: 0 16px; padding: 10px 14px; border-radius: 12px;
  background: #ffb74d; color: #1a1200; font-weight: 700; text-align: center; box-shadow: 0 6px 20px rgb(0 0 0 / .35);
}
.avviso-credito.finale { background: #ff6b6b; color: #1a0000; animation: lampeggia 1s step-end infinite; }
@keyframes lampeggia { 50% { opacity: .75; } }
.avviso-collegamento { position: relative; z-index: 3; margin: 8px 16px 0; padding: 8px 12px; border-radius: 12px; background: rgb(255 255 255 / .15); text-align: center; font-size: .9rem; }

.comandi {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; justify-content: center; gap: 18px;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgb(0 0 0 / .7));
}
.tondo {
  width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgb(255 255 255 / .18); color: #fff; backdrop-filter: blur(6px);
}
.tondo svg { width: 28px; height: 28px; }
.tondo.spento { background: #fff; color: #111; }
.tondo.rosso { background: #e53935; }
.tondo.verde { background: #2e9d57; }
.tondo .etichetta { position: absolute; }
.comando { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .78rem; color: rgb(255 255 255 / .85); }
