* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}
:root {
    --bg: #f2f2f7;
    --card: #ffffff;
    --ink: #000000;
    --muted: #8e8e93;
    --sep: rgba(60, 60, 67, .29);
    --fill: rgba(118, 118, 128, .12);
    --blue: #007aff;
    --green: #34c759;
    --red: #ff3b30;
    --on: #ffffff;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --card: #1c1c1e;
        --ink: #ffffff;
        --muted: #8e8e93;
        --sep: rgba(84, 84, 88, .65);
        --fill: rgba(118, 118, 128, .24);
        --blue: #0a84ff;
        --green: #30d158;
        --red: #ff453a;
        color-scheme: dark;
    }
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; }
[hidden] { display: none !important; }

.app {
    position: relative;
    width: min(680px, 100%);
    height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
header {
    flex: none;
    padding: calc(4px + env(safe-area-inset-top)) 16px 4px;
}
.titolo { display: flex; align-items: center; gap: 8px; min-height: 44px; }
h1 {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -.01em;
}
.titolo:has(.ricerca.aperta) h1 { display: none; }
.ricerca { display: flex; align-items: center; gap: 8px; }
.ricerca.aperta { flex: 1; }
#apri-cerca {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    color: var(--blue);
    display: grid;
    place-items: center;
}
#apri-cerca svg { width: 22px; height: 22px; }
.ricerca.aperta #apri-cerca { display: none; }
#cerca {
    flex: 1;
    width: 100%;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: var(--fill);
    padding: 0 12px;
    font-size: 16px;
}
#cerca:focus { outline: none; }
#chiudi-cerca {
    border: 0;
    background: none;
    color: var(--blue);
    font-size: 17px;
    padding: 0;
    min-height: 36px;
}
.fab {
    position: absolute;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 4;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--blue);
    color: var(--on);
    display: grid;
    place-items: center;
    box-shadow: 0 8px 20px rgba(0, 122, 255, .35);
}
.fab svg { width: 26px; height: 26px; transition: transform .2s ease; }
.fab[aria-expanded="true"] svg { transform: rotate(45deg); }
.barra { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; }
#conteggio { margin: 0; color: var(--muted); font-size: 13px; }
.filtri { display: flex; gap: 16px; }
.filtri button {
    border: 0;
    background: none;
    min-height: 28px;
    padding: 0;
    color: var(--muted);
    font-size: 15px;
    font-weight: 400;
}
.filtri button[aria-pressed="true"] {
    color: var(--blue);
    font-weight: 600;
}

.scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-bottom: calc(88px + env(safe-area-inset-bottom));
}
#stato-rete {
    margin: 0 16px 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--blue) 14%, var(--card));
    color: var(--ink);
    font-size: 14px;
}
#elenco {
    list-style: none;
    margin: 0 16px;
    padding: 0;
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
}
#elenco li { position: relative; }
#elenco li + li .riga { box-shadow: inset 0 .5px 0 var(--sep); }
.pista { position: relative; overflow: hidden; }
.gesto {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 84px;
    border: 0;
    color: var(--on);
    font-size: 15px;
    font-weight: 600;
}
.gesto.chiudi { left: 0; background: var(--green); }
.gesto.cancella { right: 0; background: var(--red); }
.riga {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    gap: 2px;
    min-height: 58px;
    padding: 8px 12px 8px 4px;
    background: var(--card);
    touch-action: pan-y;
    transition: transform .28s cubic-bezier(.2, .9, .3, 1);
}
.riga.trascina { transition: none; }
#elenco li.fatto .testo { color: var(--muted); text-decoration: line-through; }
#elenco li.scaduta .meta { color: var(--red); }
.check { display: grid; place-items: center; width: 44px; height: 44px; flex: none; }
.check input {
    appearance: none;
    width: 24px;
    height: 24px;
    margin: 0;
    border: 1.5px solid #c7c7cc;
    border-radius: 50%;
    background: transparent;
}
.check input:checked {
    border-color: var(--green);
    background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M5 12.5l5 5 9-11'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.corpo { min-width: 0; flex: 1; padding: 8px 0 4px; }
.testo { margin: 0; font-size: 17px; line-height: 1.3; white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { margin: 3px 0 0; color: var(--muted); font-size: 13px; line-height: 1.3; }
#vuoto { margin: 28px 32px; color: var(--muted); text-align: center; font-size: 15px; line-height: 1.4; }

#installa {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 16px 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--card);
}
#installa p { margin: 0; font-size: 15px; }
.installa-azioni { display: flex; gap: 8px; }
#installa button {
    min-height: 32px;
    border: 0;
    border-radius: 999px;
    padding: 0 12px;
    background: var(--blue);
    color: var(--on);
    font-weight: 600;
}
#installa-no { background: transparent; color: var(--blue); }
#composer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 16px 12px;
    padding: 12px;
    background: var(--card);
    border-radius: 12px;
}
.modo { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
#composer > label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.box { position: relative; }
textarea {
    width: 100%;
    min-height: 72px;
    resize: none;
    border: 0;
    border-radius: 18px;
    background: var(--fill);
    padding: 10px 48px 10px 14px;
    font-size: 16px;
    line-height: 1.35;
}
textarea:focus { outline: none; }
.mic {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--blue);
    display: grid;
    place-items: center;
}
.mic svg { width: 22px; height: 22px; }
.mic[aria-pressed="true"] { background: var(--blue); color: var(--on); }
.mic:disabled { opacity: .4; }
.mic-stato { min-height: 0; margin: 0; color: var(--blue); font-size: 13px; }
.mic-stato:empty { display: none; }
.campi { display: flex; gap: 8px; align-items: center; }
.campi label { display: flex; flex: 1; min-width: 0; margin: 0; }
.campi label:first-child { flex: none; }
.campi .etichetta {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}
.campi input {
    height: 34px;
    border: 0;
    border-radius: 10px;
    background: var(--fill);
    padding: 0 8px;
    font-size: 16px;
}
#scadenza { width: 9.4rem; }
.campi input:focus { outline: none; }
.box.stretto { display: block; flex: 1; min-width: 0; position: relative; }
.box.stretto .mic { width: 30px; height: 30px; right: 2px; bottom: 2px; }
.box.stretto .mic svg { width: 16px; height: 16px; }
.box.stretto input { width: 100%; padding-right: 34px; }
.censimento { margin: 0; color: var(--muted); font-size: 13px; }
.composer-azioni { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
#annulla, #aggiungi {
    min-height: 36px;
    border: 0;
    background: transparent;
    color: var(--blue);
    font-size: 17px;
    font-weight: 400;
    padding: 0 4px;
}
#aggiungi { font-weight: 600; }
#toast {
    position: fixed;
    left: 50%;
    bottom: calc(84px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    max-width: min(420px, calc(100% - 32px));
    margin: 0;
    padding: 12px 16px;
    border-radius: 14px;
    background: rgba(40, 40, 42, .94);
    color: #fff;
    font-size: 15px;
    z-index: 5;
}
.noscript { padding: 16px; }

.icone { display: flex; align-items: center; }
.icone button {
    position: relative;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    color: var(--blue);
    display: grid;
    place-items: center;
}
.icone svg { width: 22px; height: 22px; }
#avvisi-conteggio {
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--red);
    color: var(--on);
    font-size: 11px;
    font-weight: 600;
    line-height: 16px;
}
.schermo {
    min-height: 100dvh;
    padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}
.schermo h1 { font-size: 28px; font-weight: 700; }
.sottotitolo { margin: 0; max-width: 28rem; color: var(--muted); font-size: 15px; line-height: 1.4; }
.errore { min-height: 1.2em; margin: 0; color: var(--red); font-size: 14px; }
#inquadra, #primo-qui, .attiva button, #nuova-persona button, #nuovo-messaggio button, .foglio-testa button, #lista-persone button {
    border: 0;
    background: none;
    color: var(--blue);
    font-size: 17px;
    font-weight: 600;
    min-height: 44px;
}
#camera {
    width: min(100%, 320px);
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 16px;
    background: #000;
}
#primo, #primo-qr { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#primo-qr { width: 220px; height: 220px; border-radius: 12px; background: #fff; }
.attiva {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 16px 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--card);
}
.attiva p { margin: 0; font-size: 14px; line-height: 1.35; }
.attiva button { flex: none; }
.foglio {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    max-height: min(70dvh, 520px);
    overflow: auto;
    z-index: 5;
    padding: 8px 16px 16px;
    border-radius: 16px;
    background: var(--card);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
.foglio-testa { display: flex; align-items: center; justify-content: space-between; }
.foglio-testa p { margin: 0; font-size: 17px; font-weight: 600; }
#lista-avvisi, #lista-persone { list-style: none; margin: 0; padding: 0; }
#lista-avvisi li, #lista-persone li { padding: 10px 0; box-shadow: inset 0 -.5px 0 var(--sep); }
#lista-avvisi p, #lista-persone p { margin: 0; }
.foglio-etichetta { margin: 14px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.dispositivi { margin: 2px 0 0; color: var(--muted); font-size: 13px; white-space: pre-line; }
#lista-avvisi li.nuova .titolo { font-weight: 600; }
#nuova-persona, #nuovo-messaggio { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
#nome-persona, #destinatario, #titolo-messaggio, #testo-messaggio {
    width: 100%;
    border: 0;
    border-radius: 10px;
    background: var(--fill);
    font-size: 16px;
}
#nome-persona, #destinatario, #titolo-messaggio { height: 36px; padding: 0 10px; }
#testo-messaggio { padding: 8px 10px; resize: none; }
#qr-persona { width: 180px; height: 180px; margin: 8px auto; border-radius: 12px; background: #fff; }
@media (prefers-color-scheme: dark) {
    .check input { border-color: #636366; }
}
