:root {
  --brand: #6C5CE7;
  --brand-2: #8E7CFF;
  --on-brand: #fff;
  --pink: #FF6FB1;
  --bg: #F3F2FB;
  --surface: #FFFFFF;
  --surface-2: #ECEAF8;
  --text: #1B1838;
  --muted: #5F5C7D;
  --line: rgba(27, 24, 56, .09);
  --danger: #D63A5B;
  --ok: #1F9D6B;
  --bubble-in: #FFFFFF;
  --glass: rgba(255, 255, 255, .78);
  --shadow: 0 10px 30px rgba(60, 40, 160, .14);
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --app-h: 100vh;
  --radius: 20px;
  --tabs-h: 74px;
}
[data-theme="dark"] {
  --brand: #8E7CFF;
  --on-brand: #120d33;
  --bg: #0F0D1F;
  --surface: #1A1733;
  --surface-2: #25214A;
  --text: #F1EFFF;
  --muted: #A7A3CC;
  --line: rgba(255, 255, 255, .09);
  --danger: #FF6F8D;
  --bubble-in: #25214A;
  --glass: rgba(26, 23, 51, .78);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 0; }
h1, h2, h3, p { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.splash { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(160deg, var(--brand), var(--pink)); z-index: 50; transition: opacity .3s; }
.splash.off { opacity: 0; pointer-events: none; }
.splash .mark { width: 76px; height: 76px; border-radius: 24px; display: grid; place-items: center; background: rgba(255,255,255,.2); color: #fff; backdrop-filter: blur(8px); animation: pop 1.2s ease-in-out infinite alternate; }
@keyframes pop { to { transform: scale(1.08); } }

#app { height: var(--app-h); display: flex; flex-direction: column; position: relative; overflow: hidden; }
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; animation: in .22s ease-out; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } }

/* intestazione con sfumatura */
.hero { padding: calc(var(--top) + 14px) 20px 22px; background: linear-gradient(150deg, var(--brand) 0%, #8E7CFF 55%, var(--pink) 130%); color: #fff; border-radius: 0 0 28px 28px; box-shadow: var(--shadow); position: relative; z-index: 2; }
.hero h1 { font-size: 26px; letter-spacing: -.02em; font-weight: 800; }
.hero p { opacity: .9; font-size: 14px; margin-top: 2px; }
.hero .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
[data-theme="dark"] .hero { color: #fff; background: linear-gradient(150deg, #4B3FB8 0%, #6a58e8 60%, #b0407f 140%); }

.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px calc(var(--tabs-h) + var(--bottom) + 24px); }
.scroll.noTabs { padding-bottom: calc(var(--bottom) + 24px); }

/* barra in basso */
.tabs { position: absolute; left: 14px; right: 14px; bottom: calc(var(--bottom) + 12px); height: 62px; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--glass); backdrop-filter: blur(18px) saturate(1.5); -webkit-backdrop-filter: blur(18px) saturate(1.5); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); z-index: 5; padding: 6px; gap: 4px; }
.tab { border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 600; color: var(--muted); min-height: 44px; position: relative; transition: background .2s, color .2s; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: #4332C4; background: color-mix(in srgb, var(--brand) 14%, transparent); }
.badge { background: var(--pink); color: #fff; border-radius: 99px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.tab .badge { position: absolute; top: 2px; right: calc(50% - 26px); }

/* avatar */
.av { width: 50px; height: 50px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 19px; background-size: cover; background-position: center; position: relative; }
.av.sm { width: 40px; height: 40px; font-size: 16px; }
.av.xl { width: 112px; height: 112px; font-size: 42px; box-shadow: 0 0 0 4px rgba(255,255,255,.55), var(--shadow); }
.av .dot { position: absolute; right: 0; bottom: 0; width: 14px; height: 14px; border-radius: 50%; background: var(--ok); border: 3px solid var(--surface); }

/* righe di elenco */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--surface); border-radius: var(--radius); padding: 12px 14px; min-height: 66px; box-shadow: 0 1px 0 var(--line); transition: transform .12s; }
.item:active { transform: scale(.98); }
.item .mid { flex: 1; min-width: 0; }
.item .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; color: var(--muted); font-size: 12px; }
.sec { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 6px 8px; }

/* pulsanti */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px; border-radius: 16px; font-weight: 700; background: var(--surface-2); color: var(--text); transition: transform .12s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--on-brand); box-shadow: 0 8px 20px color-mix(in srgb, var(--brand) 40%, transparent); }
[data-theme="light"] .btn.primary { color: #fff; }
.btn.glass { background: rgba(255,255,255,.2); color: #fff; backdrop-filter: blur(8px); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; }
.iconbtn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: inherit; background: rgba(255,255,255,.18); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn.flat { background: transparent; }

/* scheda codice */
.codecard { background: var(--surface); border-radius: 24px; padding: 18px; box-shadow: var(--shadow); margin: -14px 0 0; position: relative; z-index: 3; text-align: center; }
.codecard .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.code { font: 800 34px/1.1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .06em; margin: 6px 0 14px; color: var(--text); background: linear-gradient(135deg, var(--brand), var(--pink)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; font-variant-numeric: tabular-nums; }
.codecard .actions { display: flex; gap: 10px; }
.codecard .actions .btn { flex: 1; padding: 0 10px; }

/* campi */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; color: var(--muted); }
.input { width: 100%; min-height: 52px; border-radius: 16px; border: 2px solid transparent; background: var(--surface); padding: 0 16px; outline: none; transition: border-color .15s; }
.input:focus { border-color: var(--brand); }
.input.big { font: 700 24px ui-monospace, Menlo, monospace; letter-spacing: .08em; text-align: center; }
.error { color: var(--danger); font-weight: 600; min-height: 22px; margin-bottom: 8px; }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; }

.empty { text-align: center; padding: 36px 24px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.empty .art { width: 92px; height: 92px; border-radius: 30px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--brand), var(--pink)); box-shadow: var(--shadow); }
.empty .art svg { width: 44px; height: 44px; }
.empty h2 { color: var(--text); font-size: 20px; }

.skel { height: 66px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: sh 1.2s linear infinite; margin-bottom: 8px; }
@keyframes sh { to { background-position: -200% 0; } }

/* conversazione */
.chathead { display: flex; align-items: center; gap: 8px; padding: calc(var(--top) + 8px) 10px 10px; background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-bottom: 1px solid var(--line); z-index: 3; }
.chathead .who { flex: 1; min-width: 0; }
.chathead .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chathead .who small { color: var(--muted); }
.chathead .iconbtn { background: var(--surface-2); color: var(--brand); }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; background: radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--brand) 9%, transparent), transparent 55%), var(--bg); }
.bub { max-width: 80%; padding: 9px 13px 6px; border-radius: 20px; background: var(--bubble-in); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; box-shadow: 0 1px 0 var(--line); align-self: flex-start; border-bottom-left-radius: 6px; animation: in .15s ease-out; }
.bub.me { align-self: flex-end; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-bottom-left-radius: 20px; border-bottom-right-radius: 6px; }
[data-theme="dark"] .bub.me { color: #120d33; }
.bub time { display: block; font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border-radius: 99px; padding: 3px 12px; margin: 8px 0; }
.typing { color: var(--muted); font-size: 13px; padding: 0 16px 4px; min-height: 20px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(var(--bottom) + 8px); background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-top: 1px solid var(--line); }
.composer .input { min-height: 46px; border-radius: 23px; flex: 1; }
.send { width: 46px; height: 46px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; display: grid; place-items: center; flex: none; }
[data-theme="dark"] .send { color: #120d33; }
.send svg { width: 22px; height: 22px; }

/* profilo */
.profile { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: 6px; }
.profile .editav { position: relative; }
.profile .cam { position: absolute; right: -2px; bottom: -2px; width: 38px; height: 38px; border-radius: 50%; background: var(--surface); color: var(--brand); display: grid; place-items: center; box-shadow: var(--shadow); }
.profile .cam svg { width: 20px; height: 20px; }

/* chiamata */
.call { position: fixed; inset: 0; z-index: 40; background: linear-gradient(170deg, #2a2070, #14102e 70%); color: #fff; display: flex; flex-direction: column; align-items: center; padding: calc(var(--top) + 40px) 24px calc(var(--bottom) + 36px); animation: in .2s; }
.call video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call .remote { z-index: 0; }
.call .local { z-index: 1; inset: auto; right: 16px; top: calc(var(--top) + 16px); width: 96px; height: 136px; border-radius: 18px; border: 2px solid rgba(255,255,255,.6); box-shadow: var(--shadow); transform: scaleX(-1); }
.call .info { position: relative; z-index: 2; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 40px; text-shadow: 0 1px 8px rgba(0,0,0,.4); }
.call .info h2 { font-size: 28px; }
.call .info .av { width: 128px; height: 128px; font-size: 48px; }
.call .pulse::before, .call .pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); animation: ring 1.8s ease-out infinite; }
.call .pulse::after { animation-delay: .9s; }
@keyframes ring { to { transform: scale(1.7); opacity: 0; } }
.call .controls { position: relative; z-index: 2; margin-top: auto; display: flex; gap: 22px; align-items: center; }
.cbtn { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.2); backdrop-filter: blur(10px); color: #fff; }
.cbtn svg { width: 28px; height: 28px; }
.cbtn.off { background: #fff; color: #222; }
.cbtn.end { background: #ef4565; }
.cbtn.ok { background: #1fc27d; }
.cbtn .sr { position: absolute; }

.toast { position: fixed; left: 50%; top: calc(var(--top) + 14px); transform: translateX(-50%); max-width: 90%; background: #1B1838; color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); animation: in .2s; }
.toast.err { background: var(--danger); }
.sheetback { position: fixed; inset: 0; z-index: 30; background: rgba(10,8,30,.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: flex-end; }
.sheet { width: 100%; background: var(--surface); border-radius: 28px 28px 0 0; padding: 22px 18px calc(var(--bottom) + 22px); animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin-bottom: 14px; }
.sheet .btn { margin-top: 8px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 700px) { #app { max-width: 480px; margin: 0 auto; box-shadow: 0 0 60px rgba(0,0,0,.2); } .call, .sheetback { left: 50%; right: auto; width: 480px; transform: translateX(-50%); } }
[data-theme="dark"] .tab[aria-current="page"] { color: #C4BBFF; }
.btn.pill { min-height: 44px; padding: 0 16px; background: #fff; color: #4332C4; box-shadow: 0 6px 16px rgba(0,0,0,.18); font-size: 15px; }
.btn.pill svg, .btn.primary svg, .btn svg { width: 20px; height: 20px; }
.call.vid .av-wrap { display: none; }
.call.vid .info { margin-top: 0; align-self: flex-start; align-items: flex-start; text-align: left; }
.call.vid .info h2 { font-size: 22px; }
.call.vid::after { content: ""; position: absolute; inset: auto 0 0 0; height: 220px; background: linear-gradient(transparent, rgba(0,0,0,.55)); z-index: 1; pointer-events: none; }
.btn.pill { white-space: nowrap; flex: none; }
.hero .row > div { min-width: 0; }
.item[for] { cursor: pointer; }

.codecard .actions .btn { white-space: nowrap; font-size: 15px; gap: 6px; }
.item .sub.wrap { white-space: normal; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 30px; border-radius: 99px; background: var(--surface-2); position: relative; flex: none; margin: 0; border: 0; cursor: pointer; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(22px); }
[data-theme="dark"] .switch:not(:checked) { background: #3a3566; }
.item .name.wrap { white-space: normal; }

/* ingresso dal browser */
.hero.login { text-align: center; padding-top: calc(var(--top) + 38px); padding-bottom: 30px; }
.hero.login .mark { width: 72px; height: 72px; border-radius: 24px; margin: 0 auto 14px; display: grid; place-items: center; background: rgba(255,255,255,.2); backdrop-filter: blur(8px); }
.hero.login .mark svg { width: 38px; height: 38px; }
.hero.login p { margin-top: 6px; }
.btn.big { min-height: 56px; font-size: 17px; }
.note { color: var(--muted); font-size: 14px; text-align: center; margin: 12px 4px; }
.note.small { font-size: 13px; }
.note a, .linkbtn { color: var(--brand); }
[data-theme="light"] .note a, [data-theme="light"] .linkbtn { color: #4332C4; }
.linkbtn { display: block; width: 100%; min-height: 44px; margin-top: 6px; text-decoration: underline; font-weight: 600; }
.linkbtn.danger { color: var(--danger); margin-top: 14px; }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: #0F7A52; padding: 0 10px; }
[data-theme="dark"] .badge.ok { color: #62E0B0; }
.item.warn { background: color-mix(in srgb, #FDCB6E 22%, var(--surface)); }
.steps { margin: 18px 4px; padding-left: 22px; color: var(--text); display: flex; flex-direction: column; gap: 8px; }
.codecard .code { word-break: keep-all; }
@media (min-width: 700px) {
  body { background: radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--brand) 20%, var(--bg)), var(--bg) 55%); }
  #app { max-width: 520px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); background: var(--bg); }
  .call, .sheetback { width: 520px; }
}
.or { text-align: center; color: var(--muted); font-size: 13px; font-weight: 600; margin: 16px 0 10px; display: flex; align-items: center; gap: 10px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.error:empty { min-height: 0; margin: 0; }
