/* Viola — mobile first. La base è il telefono: una colonna a tutto schermo,
   fogli che salgono dal basso, aree sicure per notch e barra home.
   Da 900px in su diventa a due pannelli. */
:root {
  --bg: #f4f0fa; --surface: #ffffff; --wall: #ebe4f6; --wall-dot: #d9cdee;
  --ink: #1c1230; --muted: #6c6282; --line: #e0d8ee;
  --accent: #6a2bd9; --accent-ink: #ffffff; --accent-soft: #e9defc;
  --online: #1f9d63; --danger: #c0324a;
  --font-display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #130c1f; --surface: #1d1430; --wall: #170f26; --wall-dot: #261a3d;
    --ink: #efe9fa; --muted: #a79bbf; --line: #30234a;
    --accent: #8f5cf2; --accent-ink: #ffffff; --accent-soft: #2e1f52;
    --online: #3ccf8b; --danger: #ff7a90;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body { background: var(--surface); color: var(--ink); font: 400 16px/1.45 var(--font-body); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- accesso ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--sat)) 20px calc(24px + var(--sab)); background: var(--bg); }
.authbox { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; }
.authbox .logo { border-radius: 20px; }
.authbox h1 { font: 700 34px/1 var(--font-display); letter-spacing: -0.02em; margin: 4px 0 0; }
.lead { color: var(--muted); margin: 0 0 6px; }
.auth .su { display: none; }
.auth.signup .su { display: flex; }
.auth.signup .su.code:not(.need) { display: none; }

/* ---------- struttura ---------- */
.app { height: 100dvh; position: relative; overflow: hidden; }
.side { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--surface); padding-left: var(--sal); padding-right: var(--sar); }
.main { position: absolute; inset: 0; display: flex; flex-direction: column; min-width: 0; transform: translateX(100%); visibility: hidden;
  background-color: var(--wall); background-image: radial-gradient(var(--wall-dot) 1.2px, transparent 1.3px); background-size: 22px 22px; }
body.in-chat .main { transform: none; visibility: visible; }
body.in-chat .side { visibility: hidden; }
@media (prefers-reduced-motion: no-preference) {
  .main { transition: transform .22s cubic-bezier(.2, .8, .2, 1), visibility 0s .22s; }
  body.in-chat .main { transition: transform .22s cubic-bezier(.2, .8, .2, 1); }
}
.desk { display: none; }

/* ---------- lista ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--sat)) 16px 8px; }
.mark { border-radius: 11px; flex: none; }
.brand h1 { font: 700 24px/1 var(--font-display); letter-spacing: -0.02em; margin: 0; flex: 1; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; font-size: 22px; line-height: 1; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.plain { background: transparent; color: var(--muted); }
.icon-btn:active { background: var(--accent-soft); color: var(--accent); }
.strip { display: flex; gap: 12px; padding: 2px 16px 10px; overflow-x: auto; scrollbar-width: none; flex: none; }
.strip::-webkit-scrollbar { display: none; }
.st { border: 0; background: transparent; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; width: 62px; flex: none; font-size: 11.5px; color: var(--muted); }
.st .ring { width: 54px; height: 54px; border-radius: 50%; border: 2.5px solid var(--accent); padding: 2px; display: grid; }
.st .ring > span { border-radius: 50%; display: grid; place-items: center; color: #fff; font: 700 18px/1 var(--font-display); }
.st.add .ring { border-style: dashed; border-color: var(--line); }
.st.add .ring > span { background: var(--accent-soft); color: var(--accent); font-size: 24px; font-weight: 500; }
.st b { font-weight: 500; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { margin: 0 16px 8px; flex: none; }
.search input, .field input, .field textarea { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 12px; font-size: 16px; }
::placeholder { color: var(--muted); opacity: 1; }
.tabs { display: flex; gap: 4px; padding: 0 12px 8px; overflow-x: auto; scrollbar-width: none; flex: none; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 7px 13px; border-radius: 999px; font-weight: 500; font-size: 14px; flex: none; }
.tabs button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 8px calc(88px + var(--sab)); display: flex; flex-direction: column; gap: 2px; }
.sect { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 12px 8px 4px; }
.row { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 8px; border-radius: 14px; min-height: 64px; }
.row:active { background: var(--bg); }
.row.on { background: var(--accent); color: var(--accent-ink); }
.row.on .sub, .row.on .when { color: inherit; opacity: .8; }
.av { width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font: 700 19px/1 var(--font-display); position: relative; }
.av.channel { border-radius: 15px; }
.av.virt { background: var(--accent-soft); color: var(--accent); }
.row.on .av.virt { background: rgba(255,255,255,.2); color: #fff; }
.av svg { width: 21px; height: 21px; }
.av .on-dot { position: absolute; right: 0; bottom: 0; width: 13px; height: 13px; border-radius: 50%; background: var(--online); border: 2.5px solid var(--surface); }
.rmain { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.rtop { display: flex; align-items: baseline; gap: 8px; }
.rname { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.rbot { display: flex; align-items: center; gap: 8px; }
.sub { color: var(--muted); font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 21px; height: 21px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 600; display: grid; place-items: center; flex: none; font-variant-numeric: tabular-nums; }
.row.on .badge { background: #fff; color: var(--accent); }
.kind { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; opacity: .75; flex: none; }
.empty { color: var(--muted); padding: 28px 16px; text-align: center; }
.note { margin: 0 16px 8px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 13.5px; flex: none; }
.fab { position: absolute; right: calc(18px + var(--sar)); bottom: calc(18px + var(--sab)); width: 58px; height: 58px; border-radius: 20px; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 8px 22px rgba(70, 20, 160, .35); }
.fab svg { width: 24px; height: 24px; }

/* ---------- conversazione ---------- */
.head { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 6px calc(4px + var(--sal)); background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.head .av { width: 40px; height: 40px; font-size: 16px; }
.htext { min-width: 0; flex: 1; }
.hname { font: 700 17px/1.2 var(--font-display); letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsub .live { color: var(--online); font-weight: 500; }
.hsub .typing { color: var(--accent); font-weight: 500; }
.pinbar { display: flex; align-items: center; gap: 6px; background: var(--surface); border-bottom: 1px solid var(--line); padding: 4px 8px 4px 14px; font-size: 14px; flex: none; }
.pinbar button.go { flex: 1; min-width: 0; min-height: 36px; border: 0; background: transparent; text-align: left; border-left: 3px solid var(--accent); padding: 1px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinbar b { color: var(--accent); }
.x { border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; width: 40px; height: 40px; flex: none; }
.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px calc(12px + var(--sar)) 12px calc(12px + var(--sal)); display: flex; flex-direction: column; gap: 7px; }
.day { align-self: center; margin: 8px 0 4px; }
.day span, .sys span { background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 500; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); }
.sys { align-self: center; text-align: center; }
.older { align-self: center; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; font-size: 14px; color: var(--accent); }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 86%; }
.msg.cont { margin-top: -3px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.flash .bub { outline: 2px solid var(--accent); outline-offset: 2px; }
.bub { background: var(--surface); border-radius: 18px 18px 18px 5px; padding: 8px 12px 6px; min-width: 0; max-width: 100%; box-shadow: 0 1px 0 var(--line); cursor: pointer; }
.msg.mine .bub { background: var(--accent); color: var(--accent-ink); border-radius: 18px 18px 5px 18px; box-shadow: none; }
.who { font-weight: 600; font-size: 13px; margin-bottom: 1px; }
.fw { font-size: 12px; font-style: italic; opacity: .75; }
.txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.txt.gone { font-style: italic; opacity: .7; }
.txt code { font-family: ui-monospace, Menlo, monospace; font-size: .92em; background: rgba(120, 90, 180, .18); border-radius: 4px; padding: 0 4px; }
.txt a { color: inherit; }
.tr { margin-top: 4px; padding-top: 4px; border-top: 1px dashed currentColor; font-size: 14.5px; opacity: .85; white-space: pre-wrap; }
.pic { display: block; max-width: 100%; width: 260px; max-height: 340px; object-fit: cover; border-radius: 12px; margin: 2px 0 4px; background: var(--accent-soft); min-height: 80px; }
.quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin: 2px 0 5px; font-size: 13.5px; background: var(--accent-soft); border-radius: 4px 8px 8px 4px; display: flex; flex-direction: column; color: var(--ink); }
.msg.mine .quote { border-left-color: #fff; background: rgba(255,255,255,.18); color: inherit; }
.quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; opacity: .85; }
.poll { display: flex; flex-direction: column; gap: 6px; min-width: 210px; margin-bottom: 2px; }
.poll b { font-weight: 600; }
.poll button { position: relative; overflow: hidden; border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 9px 10px; min-height: 42px; text-align: left; display: flex; justify-content: space-between; gap: 12px; color: inherit; font-variant-numeric: tabular-nums; }
.msg.mine .poll button { border-color: rgba(255,255,255,.4); }
.poll button i { position: absolute; inset: 0 auto 0 0; background: var(--accent); opacity: .16; }
.msg.mine .poll button i { background: #fff; opacity: .22; }
.poll button.me { border-color: currentColor; font-weight: 600; }
.poll button span { position: relative; }
.poll small { opacity: .7; }
.meta { display: flex; justify-content: flex-end; gap: 5px; font-size: 11px; opacity: .65; margin-top: 2px; font-variant-numeric: tabular-nums; }
.meta .read { opacity: 1; font-weight: 700; letter-spacing: -2px; padding-right: 2px; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.reacts button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 9px; font-size: 14px; font-variant-numeric: tabular-nums; min-height: 30px; }
.reacts button.me { border-color: var(--accent); background: var(--accent-soft); }

.foot { background: var(--surface); border-top: 1px solid var(--line); padding: 6px calc(8px + var(--sar)) calc(6px + var(--sab)) calc(4px + var(--sal)); display: flex; flex-direction: column; gap: 6px; flex: none; }
.replybar { display: flex; align-items: center; gap: 6px; border-left: 3px solid var(--accent); padding: 0 0 0 10px; margin-left: 8px; font-size: 14px; }
.replybar div { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.replybar b { color: var(--accent); }
.compose { display: flex; gap: 2px; align-items: flex-end; }
.compose textarea { flex: 1; min-width: 0; resize: none; border: 1px solid var(--line); background: var(--bg); border-radius: 22px; padding: 10px 14px; max-height: 132px; min-height: 44px; line-height: 1.4; font-size: 16px; margin: 0 4px; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .45; }
.send svg { width: 20px; height: 20px; }
.locked { color: var(--muted); text-align: center; font-size: 14px; padding: 10px 8px; }
.err { color: var(--danger); font-size: 14px; }
.welcome { margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 320px; }
.welcome h2 { font: 700 24px/1.15 var(--font-display); color: var(--ink); margin: 0 0 6px; text-wrap: balance; }
.toast { position: fixed; left: 50%; bottom: calc(84px + var(--sab)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); text-align: center; }

/* ---------- fogli dal basso ---------- */
dialog { border: 0; color: var(--ink); background: var(--surface); padding: 0; }
dialog::backdrop { background: rgba(20, 10, 40, .5); }
.sheet { margin: auto auto 0; width: 100%; max-width: 100%; max-height: 88dvh; border-radius: 22px 22px 0 0; padding: 8px 18px calc(16px + var(--sab)); overflow-y: auto; }
@media (prefers-reduced-motion: no-preference) { .sheet[open] { animation: up .22s cubic-bezier(.2, .8, .2, 1); } @keyframes up { from { transform: translateY(40px); opacity: .6; } } }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 12px; }
.sheet h2 { font: 700 21px/1.2 var(--font-display); margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 14px; margin: -6px 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.auth .field { margin: 0; }
.field label, .field legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; }
.field textarea { resize: none; }
fieldset.field { border: 0; padding: 0; margin: 0 0 12px; }
.kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 5px; }
.kinds label { border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; color: var(--ink); font-size: 15px; }
.kinds label small { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.kinds input, .swatches input { position: absolute; opacity: 0; }
.kinds label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.swatches { display: flex; gap: 12px; margin-top: 5px; }
.swatches label { width: 40px; height: 40px; border-radius: 50%; cursor: pointer; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatches label:has(input:checked) { box-shadow: 0 0 0 2.5px var(--accent); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.btn { border: 0; border-radius: 14px; padding: 12px 18px; min-height: 46px; font-weight: 600; background: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; color: var(--danger); margin-right: auto; }
.btn:disabled { opacity: .6; }
.emos { display: flex; justify-content: space-between; gap: 4px; margin-bottom: 8px; }
.emos button { flex: 1; border: 0; background: var(--bg); border-radius: 14px; font-size: 26px; padding: 8px 0; min-height: 52px; }
.emos button.me { background: var(--accent-soft); outline: 2px solid var(--accent); }
.opts { display: flex; flex-direction: column; }
.opts button, .opts label { border: 0; background: transparent; text-align: left; padding: 13px 8px; min-height: 48px; border-radius: 12px; font-size: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opts button:active { background: var(--bg); }
.opts .del { color: var(--danger); }
.opts select { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 16px; }
.picks { display: flex; flex-direction: column; gap: 2px; max-height: 46dvh; overflow-y: auto; margin-bottom: 10px; }
.stview { border-radius: 18px; color: #fff; min-height: 260px; display: grid; place-items: center; text-align: center; padding: 24px; font: 600 23px/1.3 var(--font-display); overflow-wrap: anywhere; white-space: pre-wrap; margin-bottom: 12px; }
.stwho { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
#aiOut { white-space: pre-wrap; margin-bottom: 12px; }
.viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; background: #000; margin: 0; }
.viewer[open] { display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100dvh; object-fit: contain; }
.viewer .icon-btn { position: absolute; top: calc(12px + var(--sat)); right: 14px; background: rgba(255,255,255,.18); color: #fff; }

/* ---------- da tablet in su: due pannelli ---------- */
@media (min-width: 900px) {
  body { background: var(--bg); }
  .app { display: grid; grid-template-columns: 370px minmax(0, 1fr); }
  .side, .main { position: relative; inset: auto; transform: none !important; visibility: visible !important; transition: none !important; }
  .side { border-right: 1px solid var(--line); }
  .back { display: none; }
  .desk { display: block; }
  .msgs { padding: 16px max(16px, calc((100% - 760px) / 2)); }
  .msg { max-width: min(74%, 520px); }
  .foot { padding-left: max(8px, calc((100% - 780px) / 2)); padding-right: max(8px, calc((100% - 780px) / 2)); }
  .sheet { margin: auto; max-width: 440px; border-radius: 22px; padding-bottom: 18px; }
  .grab { visibility: hidden; margin-bottom: 4px; }
  .row:hover { background: var(--bg); } .row.on:hover { background: var(--accent); }
}
