/* Voce — interfaccia mobile-first, tema chiaro/scuro automatico. */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --ink: #171923;
  --muted: #5d6275;
  --line: #e3e5ee;
  --accent: #4f46e5;
  --accent-2: #eef0ff;
  --accent-ink: #ffffff;
  --danger: #c2362b;
  --danger-2: #fdeeec;
  --ok: #18794e;
  --ok-2: #e7f6ee;
  --warn: #9a5b00;
  --warn-2: #fff4e0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 40, .05), 0 6px 24px rgba(20, 22, 40, .06);
  --tap: 44px;
  --nav-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1c1f27;
    --surface-2: #252935;
    --ink: #eceef4;
    --muted: #a0a5b8;
    --line: #2e3240;
    --accent: #8b85ff;
    --accent-2: #2a2950;
    --accent-ink: #12121f;
    --danger: #ff8a7f;
    --danger-2: #3a1f1d;
    --ok: #5fd39a;
    --ok-2: #173226;
    --warn: #f5b850;
    --warn-2: #3a2c12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.08rem; }
code { font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
                   white-space: nowrap; border: 0; padding: 0; margin: -1px; }
.muted { color: var(--muted); }
.strong { font-weight: 650; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: .9rem; margin: 0; }
.lead { color: var(--muted); margin: -4px 0 16px; }
.opt { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; margin: 0; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ------------------------------------------------------------------ struttura */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.15rem;
         color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand-lg { font-size: 1.6rem; justify-content: center; width: 100%; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
        background: var(--accent); color: var(--accent-ink); }
.brand-lg .logo { width: 44px; height: 44px; border-radius: 13px; }
.logo svg { width: 22px; height: 22px; stroke-width: 2.6; }

.mainnav { display: flex; gap: 4px; margin-left: auto; }
.mainnav a {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 14px; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.mainnav a:hover { background: var(--surface-2); color: var(--ink); }
.mainnav a[aria-current="page"] { background: var(--accent-2); color: var(--accent); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff;
         font-size: .72rem; line-height: 20px; text-align: center; font-weight: 700; }
#activeBadge { background: var(--accent); color: var(--accent-ink); }

main { max-width: 820px; margin: 0 auto; padding: 20px 16px 48px; }
.page-title { font-size: 1.6rem; letter-spacing: -.02em; margin: 4px 0 16px; }

@media (max-width: 719px) {
  /* niente backdrop-filter qui: renderebbe la barra in basso "fissa" rispetto all'intestazione */
  .topbar { justify-content: center; padding-top: max(10px, env(safe-area-inset-top)); background: var(--bg);
            backdrop-filter: none; -webkit-backdrop-filter: none; }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; gap: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding: 4px 4px env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .mainnav a { flex-direction: column; justify-content: center; gap: 2px; padding: 0 2px; font-size: .72rem;
               border-radius: 12px; }
  .mainnav a svg { width: 22px; height: 22px; }
  .mainnav .badge { position: absolute; top: 4px; left: calc(50% + 6px); }
  main { padding-bottom: calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 1.4rem; }
  .desktop-only { display: none !important; }
}

/* ------------------------------------------------------------------ superfici */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack + .stack { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

/* ------------------------------------------------------------------ campi */
label { display: block; font-weight: 600; font-size: .95rem; }
label > input, label > textarea, label > select { display: block; margin-top: 6px; }
label small { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; font-size: .82rem; }
input, textarea, select {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
select { appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type=search] { -webkit-appearance: none; }
.form-error { margin: 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--danger-2); color: var(--danger);
              font-weight: 500; }

/* ------------------------------------------------------------------ pulsanti */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; white-space: nowrap;
  color: var(--ink); background: var(--surface-2); border: 1px solid transparent;
  transition: background .15s, transform .05s, opacity .15s;
}
.btn:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--ink) 8%); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.danger:hover { background: var(--danger-2); }
.btn.danger-solid { background: var(--danger); color: #fff; }
.btn.rec { background: var(--danger); color: #fff; }
.btn.rec.recording { animation: pulse 1.2s infinite; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.icon { width: var(--tap); padding: 0; }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 1.05rem; margin-top: 18px; }
.btn svg { width: 18px; height: 18px; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent; animation: spin .8s linear infinite; }
.btn.primary.busy::after { border-color: var(--accent-ink) transparent var(--accent-ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--danger) 25%, transparent); } }

.seg { display: flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: 13px; margin-bottom: 16px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
              font: inherit; font-weight: 650; cursor: pointer; padding: 0 10px; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg .count:empty { display: none; }
.seg .count { display: inline-block; min-width: 20px; border-radius: 10px; background: var(--danger); color: #fff;
              font-size: .72rem; line-height: 20px; margin-left: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--line); background: var(--surface);
        color: var(--ink); font: inherit; font-size: .9rem; cursor: pointer; }
.chip:hover, .chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-2); }

/* ------------------------------------------------------------------ crea */
.voice-row { display: flex; gap: 8px; }
.voice-row select { flex: 1; min-width: 0; }
.callout { margin: 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-2); color: var(--ink); }
.advanced { margin-top: 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 14px; }
.advanced summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; font-weight: 650;
                    color: var(--muted); list-style: none; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: ""; width: 8px; height: 8px; margin: 0 12px 0 2px; border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
.advanced[open] summary::before { transform: rotate(45deg); }
.advanced[open] { padding-bottom: 14px; }
.advanced .grid { margin: 4px 0 14px; }

.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; cursor: pointer;
        min-height: 150px; padding: 20px; border: 2px dashed var(--line); border-radius: var(--radius); font-weight: 500;
        background: var(--surface-2); transition: border-color .15s, background .15s; }
.drop svg { width: 30px; height: 30px; color: var(--accent); }
.drop strong { color: var(--accent); }
.drop small { color: var(--muted); }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-2); }
.drop:focus-within { border-color: var(--accent); }
.filelist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.filelist:empty { display: none; }
.filelist li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border-radius: var(--radius-sm);
               background: var(--surface-2); }
.filelist .fname { flex: 1; min-width: 0; }
.filelist .fname div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .fname small { color: var(--muted); }

/* ------------------------------------------------------------------ elenchi */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 14px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.list > li:first-child { border-top: 0; padding-top: 4px; }
.list:empty { display: none; }
.item-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.item-title { font-weight: 650; overflow-wrap: anywhere; }
.item-sub { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.owner { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border-radius: 8px; background: var(--surface-2);
         font-size: .8rem; color: var(--muted); font-weight: 600; }

.list.cards { display: flex; flex-direction: column; gap: 12px; }
.list.cards > li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
                   box-shadow: var(--shadow); }
.list.cards > li.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
audio { width: 100%; height: 44px; }

.state { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .8rem;
         font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.state.s-running, .state.s-loading, .state.s-encoding { background: var(--accent-2); color: var(--accent); }
.state.s-running::before { animation: blink 1.2s infinite; }
.state.s-done { background: var(--ok-2); color: var(--ok); }
.state.s-error, .state.s-deleting { background: var(--danger-2); color: var(--danger); }
.state.s-paused, .state.s-pausing, .state.s-interrupted { background: var(--warn-2); color: var(--warn); }
@keyframes blink { 50% { opacity: .25; } }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width .5s ease; }
.s-done + .progress > i, .progress.done > i { background: var(--ok); }
.status-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .9rem; color: var(--muted); }
.warnings { font-size: .88rem; }
.warnings summary { cursor: pointer; color: var(--warn); font-weight: 600; min-height: 32px; }
.warnings ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 220px; }
.toolbar select { flex: 0 1 220px; }

/* ------------------------------------------------------------------ voci */
.recbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.recbar .or { color: var(--muted); font-size: .9rem; }
.recbar label.btn { flex-direction: row; font-size: 1rem; }
#timer { min-width: 56px; font-weight: 600; }

/* ------------------------------------------------------------------ account */
.who { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.avatar { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--accent-2); color: var(--accent); }

/* ------------------------------------------------------------------ accesso */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
             padding: 28px 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.auth-card h1 { font-size: 1.35rem; }
.auth-card form, .auth-card #registerDone { margin-top: 10px; }
.big-check { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto; border-radius: 50%;
             background: var(--ok-2); color: var(--ok); }
.big-check svg { width: 32px; height: 32px; stroke-width: 2.5; }

/* ------------------------------------------------------------------ dialog e notifiche */
dialog { width: min(440px, calc(100vw - 32px)); border: 0; border-radius: 18px; padding: 22px; background: var(--surface);
         color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(2px); }
#dialogBody p { margin: 0 0 8px; }
#dialogBody p:last-child { margin: 0; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap-reverse; margin-top: 6px; }
@media (max-width: 479px) { .dialog-actions .btn { flex: 1; } }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px;
          width: min(480px, calc(100vw - 24px)); bottom: 20px; pointer-events: none; }
@media (max-width: 719px) { #toasts { bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); } }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px;
         background: var(--ink); color: var(--bg); box-shadow: 0 8px 30px rgba(0,0,0,.25); animation: toast-in .2s ease-out; }
.toast.bad { background: var(--danger); color: #fff; }
.toast a { color: inherit; font-weight: 700; }
.toast .t-msg { flex: 1; }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; padding: 4px; min-height: 32px; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.btn.disabled { opacity: .45; pointer-events: none; }
.seg button { display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.item-title .state, .item-title .owner { margin-left: 6px; vertical-align: 2px; }
.card .hint + .list, .card .hint + .empty { margin-top: 12px; }
