/* Trascrittore — un registratore da tavolo: pannello in alluminio,
   un vu-meter, un tasto rosso. Il testo trascritto è in carattere da lettura. */

:root {
  --panel: #DADDD8;
  --plate: #ECEEEA;
  --plate-2: #E3E6E1;
  --ink: #1B2225;
  --soft: #56616A;
  --rule: #B5BBB6;
  --rec: #C4122F;
  --rec-deep: #8E0B21;
  --face: #EDE3B5;
  --face-ink: #2A2717;
  --signal: #1F5F64;
  --signal-ink: #FFFFFF;
  --ok: #2E6B3A;
  --warn: #8A5A00;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Noto Serif", Georgia, "Times New Roman", serif;

  --r-small: 6px;
  --r-plate: 14px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --panel: #1C2124;
    --plate: #252B2F;
    --plate-2: #2B3236;
    --ink: #E4E8E5;
    --soft: #9BA5A8;
    --rule: #3A4347;
    --rec: #E23B3F;
    --rec-deep: #A3161E;
    --face: #CDBF8B;
    --face-ink: #24210F;
    --signal: #79BFC2;
    --signal-ink: #0F2426;
    --ok: #8CC897;
    --warn: #E2B45A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --panel: #1C2124; --plate: #252B2F; --plate-2: #2B3236; --ink: #E4E8E5; --soft: #9BA5A8;
  --rule: #3A4347; --rec: #E23B3F; --rec-deep: #A3161E; --face: #CDBF8B; --face-ink: #24210F;
  --signal: #79BFC2; --signal-ink: #0F2426; --ok: #8CC897; --warn: #E2B45A; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--panel);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
a { color: var(--signal); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 16px;
  border-radius: var(--r-small); border: 1px solid var(--rule);
  background: var(--plate); color: var(--ink);
  font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--rec); color: var(--rec); }
.btn-danger.armed { background: var(--rec); color: #fff; }
.btn-wide { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.link-danger { background: none; border: 0; color: var(--rec); text-decoration: underline; cursor: pointer; padding: 8px; }

/* ---------- accesso ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.login-box {
  width: min(360px, 100%); background: var(--plate); border: 1px solid var(--rule);
  border-radius: var(--r-plate); padding: 28px 24px 24px;
}
.login-mark { width: 44px; height: 44px; color: var(--ink); }
.login-mark .dot { fill: var(--rec); }
.login h1 { margin: 12px 0 2px; font-size: 1.6rem; letter-spacing: -.01em; }
.login-sub { margin: 0 0 20px; color: var(--soft); }
.login label { display: block; font-weight: 600; margin-bottom: 6px; }
.login input {
  width: 100%; min-height: 48px; padding: 0 12px; border-radius: var(--r-small);
  border: 1px solid var(--rule); background: var(--panel);
}
.form-error { color: var(--rec); min-height: 1.5em; margin: 8px 0; }

/* ---------- struttura ---------- */
.app { max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter) 48px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 0 12px;
}
.brand { color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--rule); background: var(--plate);
  font-size: .85rem; cursor: pointer;
}
.pill-led { width: 9px; height: 9px; border-radius: 50%; background: var(--soft); }
.pill[data-state="ready"] .pill-led { background: var(--ok); }
.pill[data-state="busy"] .pill-led { background: var(--warn); }
.pill[data-state="warn"] .pill-led { background: var(--rec); }

.columns { display: grid; gap: 20px; }
@media (min-width: 900px) {
  .columns { grid-template-columns: minmax(340px, 420px) 1fr; align-items: start; gap: 32px; }
  .recorder { position: sticky; top: 12px; }
}

/* ---------- registratore ---------- */
.recorder {
  background: var(--plate);
  border: 1px solid var(--rule);
  border-radius: var(--r-plate);
  padding: 18px 18px 14px;
  text-align: center;
}
.meter {
  position: relative;
  background: var(--face);
  color: var(--face-ink);
  border-radius: 10px;
  box-shadow: inset 0 2px 0 rgba(0,0,0,.18), inset 0 0 0 1px rgba(0,0,0,.12);
  overflow: hidden;
}
#meter-svg { display: block; width: 100%; height: auto; }
#meter-scale line { stroke: var(--face-ink); stroke-width: 1.5; }
#meter-scale line.major { stroke-width: 2.2; }
#meter-scale .red { stroke: var(--rec); }
#meter-scale path.redzone { stroke: var(--rec); stroke-width: 7; fill: none; }
#meter-scale path.arc { stroke: var(--face-ink); stroke-width: 1.5; fill: none; }
#meter-scale text { fill: var(--face-ink); font: 600 13px var(--sans); text-anchor: middle; }
#meter-scale text.unit { font-size: 12px; font-weight: 500; opacity: .7; }
#meter-scale text.red { fill: var(--rec); stroke: none; }
#meter-needle { stroke: #151515; stroke-width: 2; stroke-linecap: round; transform-origin: 150px 172px; transform: rotate(-53deg); }
.meter-hub { fill: #2A2A2A; }
.meter-label { position: absolute; left: 12px; bottom: 6px; font-size: .78rem; opacity: .75; }
.peak-led {
  position: absolute; right: 12px; bottom: 9px; width: 10px; height: 10px; border-radius: 50%;
  background: rgba(0,0,0,.18); box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
.peak-led.on { background: var(--rec); box-shadow: 0 0 8px var(--rec); }

.timer {
  margin: 14px 0 0; font-size: 3.1rem; line-height: 1.1; font-weight: 300;
  font-variant-numeric: tabular-nums; letter-spacing: .02em;
}
.rec-hint { margin: 2px 0 12px; color: var(--soft); min-height: 1.5em; font-size: .95rem; }

.transport { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.transport .round-side:first-child { justify-self: end; }
.transport #btn-stop { justify-self: start; }
.rec-button {
  grid-column: 2;
  width: 96px; height: 96px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 0; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 35%, #F4F5F2, #B9BEB9 70%, #9AA09B);
  box-shadow: 0 2px 0 rgba(0,0,0,.25), inset 0 -2px 3px rgba(0,0,0,.2);
}
.rec-core {
  width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #F0475B, var(--rec) 55%, var(--rec-deep));
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.3);
  transition: border-radius .2s ease, width .2s ease, height .2s ease;
}
.recorder[data-state="recording"] .rec-core,
.recorder[data-state="paused"] .rec-core { width: 40px; height: 40px; border-radius: 8px; }
.recorder[data-state="recording"] .rec-button { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 2px 0 rgba(0,0,0,.25), 0 0 0 0 color-mix(in srgb, var(--rec) 45%, transparent); }
  50% { box-shadow: 0 2px 0 rgba(0,0,0,.25), 0 0 0 10px color-mix(in srgb, var(--rec) 0%, transparent); }
}
.recorder[data-state="recording"] .timer { color: var(--rec); }
.recorder[data-state="paused"] .timer { opacity: .55; }
.round-side { min-width: 84px; }

.upload { margin: 14px 0 4px; }
.upload p { margin: 6px 0 0; font-size: .9rem; color: var(--soft); }
.bar { height: 6px; background: var(--plate-2); border-radius: 3px; overflow: hidden; border: 1px solid var(--rule); }
.bar span { display: block; height: 100%; width: 0; background: var(--signal); transition: width .3s ease; }

.rec-options {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule); text-align: left;
}
.rec-options .field select { width: 100%; }
.rec-options .file-pick { width: 100%; }
.field { display: grid; gap: 4px; font-size: .85rem; color: var(--soft); }
.field select {
  min-height: 44px; padding: 0 10px; border-radius: var(--r-small);
  border: 1px solid var(--rule); background: var(--panel); color: var(--ink); font-size: 1rem;
}
.file-pick { position: relative; overflow: hidden; }
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- registrazioni non inviate ---------- */
.pending { margin-bottom: 16px; display: grid; gap: 8px; }
.pending-item {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-radius: var(--r-small);
  border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--plate));
}
.pending-item p { margin: 0; }
.pending-item .row { display: flex; gap: 8px; }

/* ---------- archivio ---------- */
.section-title { font-size: 1.05rem; margin: 6px 0 8px; }
.archive { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.archive li { border-bottom: 1px solid var(--rule); }
.archive a {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px 2px; color: var(--ink); text-decoration: none;
}
.archive a:hover .a-title { text-decoration: underline; }
.a-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.a-dur { font-variant-numeric: tabular-nums; color: var(--soft); font-size: .9rem; }
.a-sub { grid-column: 1 / -1; color: var(--soft); font-size: .88rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.a-snippet { grid-column: 1 / -1; font-family: var(--serif); color: var(--soft); font-size: .95rem;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.status { display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.done { color: var(--ok); }
.status.processing, .status.queued { color: var(--warn); }
.status.error { color: var(--rec); }
.mini-bar { width: 72px; height: 4px; background: var(--plate-2); border-radius: 2px; overflow: hidden; }
.mini-bar span { display: block; height: 100%; background: var(--warn); }
.empty { color: var(--soft); padding: 16px 0; max-width: 46ch; }

/* ---------- dettaglio ---------- */
.detail { padding-bottom: 24px; }
.back { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; text-decoration: none; font-weight: 600; }
.back::before { content: ""; width: 8px; height: 8px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }
.detail-title {
  display: block; width: 100%; margin: 4px 0 2px; padding: 4px 0;
  font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.25;
  background: transparent; border: 0; border-bottom: 1px dashed transparent; border-radius: 0;
}
.detail-title:hover, .detail-title:focus { border-bottom-color: var(--rule); outline: none; }
.detail-meta { margin: 0 0 12px; color: var(--soft); font-size: .92rem; }
.detail audio { width: 100%; margin-bottom: 12px; }
.progress { margin: 8px 0 16px; }
.progress p { margin: 6px 0 0; color: var(--soft); font-size: .92rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 18px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 4px; font-size: .95rem; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--signal); }

.transcript {
  font-family: var(--serif); font-size: 1.09rem; line-height: 1.68;
  max-width: 68ch; background: var(--plate); border: 1px solid var(--rule);
  border-radius: var(--r-plate); padding: 18px 20px; min-height: 120px;
}
.transcript:empty { display: none; }
.transcript p { margin: 0 0 1em; }
.transcript p:last-child { margin-bottom: 0; }
.seg { cursor: pointer; border-radius: 3px; }
@media (hover: hover) { .seg:hover { background: color-mix(in srgb, var(--signal) 12%, transparent); } }
.seg.now { background: color-mix(in srgb, var(--face) 75%, transparent); color: var(--face-ink); }
.transcript.times p { display: grid; grid-template-columns: auto 1fr; gap: 12px; margin-bottom: .5em; }
.ts {
  font-family: var(--sans); font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--signal);
  background: none; border: 0; padding: 4px 0 0; cursor: pointer; text-align: left;
}
.transcript .live { color: var(--soft); }
.caret { display: inline-block; width: .5em; height: 1em; vertical-align: -2px; background: var(--warn); margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.more { margin-top: 22px; border-top: 1px solid var(--rule); padding-top: 10px; }
.more summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--soft); font-weight: 600; }
.more-body { display: grid; gap: 16px; padding: 6px 0 4px; }
.retry-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }

/* ---------- impostazioni ---------- */
.sheet {
  width: min(460px, calc(100% - 2 * var(--gutter))); max-height: calc(100dvh - 32px);
  border: 1px solid var(--rule); border-radius: var(--r-plate); padding: 0;
  background: var(--plate); color: var(--ink);
}
.sheet::backdrop { background: rgba(10, 14, 16, .45); }
.sheet-body { padding: 20px; display: grid; gap: 14px; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet h3 { margin: 0 0 4px; font-size: 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .95rem; }
.kv dt { color: var(--soft); }
.kv dd { margin: 0; }
.warning { margin: 0; padding: 10px 12px; border-left: 3px solid var(--rec); background: var(--plate-2); font-size: .92rem; }
.phone-link { border-top: 1px solid var(--rule); padding-top: 14px; }
.phone-link p { margin: 0 0 8px; color: var(--soft); font-size: .92rem; }
.phone-link img { background: #fff; border-radius: 6px; padding: 4px; display: block; }
.url { font-variant-numeric: tabular-nums; color: var(--ink) !important; font-weight: 600; word-break: break-all; }
.small { font-size: .88rem; color: var(--soft); margin: 0; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; border-top: 1px solid var(--rule); padding-top: 14px; }

/* ---------- avvisi ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translate(-50%, 16px); max-width: calc(100% - 32px);
  background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: var(--r-small);
  font-size: .95rem; z-index: 10; pointer-events: none;
  opacity: 0; visibility: hidden; transition: transform .25s ease, opacity .25s ease, visibility .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

/* sul telefono, mentre leggi una trascrizione, il registratore si nasconde
   (a meno che non stia registrando o inviando) */
@media (max-width: 899px) {
  body.reading .recorder:not([data-state="recording"]):not([data-state="paused"]):not([data-state="uploading"]):not([data-state="starting"]) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
