:root {
  --ink: #16233a;
  --ink-soft: #3b4a63;
  --paper: #f5f4ef;
  --card: #ffffff;
  --line: #e2dfd6;
  --muted: #6f7787;
  --amber: #d9932a;
  --amber-deep: #b8771a;
  --green: #2f7d4f;
  --red: #b3392f;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--ink); }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* Barra superiore */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--ink); color: #fff;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px; min-height: 56px;
}
.top h1 { font-size: 18px; font-weight: 600; margin: 0; flex: 1; letter-spacing: -0.01em; }
.top .sub { display: block; font-size: 12px; font-weight: 400; opacity: 0.7; }
.top button { background: transparent; border: 0; color: #fff; padding: 8px; border-radius: 8px; }
.top button:active { background: rgba(255,255,255,0.15); }
.top select {
  background: rgba(255,255,255,0.12); color: #fff; border: 0; border-radius: 8px;
  padding: 6px 8px; max-width: 46vw;
}
.top select option { color: var(--ink); }

.screen { flex: 1; padding: 16px 16px calc(24px + var(--safe-bottom)); }

/* Login */
.login { max-width: 380px; margin: 10vh auto 0; }
.login .mark { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 20px; display: block; }
.login h2 { text-align: center; font-size: 24px; margin: 0 0 4px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 24px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--ink-soft); }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.row { display: flex; gap: 10px; }
.row .field { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px 16px; border-radius: 12px; border: 0;
  background: var(--ink); color: #fff; font-weight: 600;
}
.btn:disabled { opacity: 0.5; }
.btn.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.amber { background: var(--amber); color: #1d1405; }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--line); }
.btn.slim { width: auto; padding: 9px 14px; font-size: 14px; }
.actions { display: flex; gap: 10px; margin-top: 12px; }
.actions .btn { flex: 1; }

.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.error { background: #fbe9e6; color: var(--red); padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-size: 14px; }
.ok { background: #e6f2ea; color: var(--green); padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-size: 14px; }

/* Tabs inbox */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button {
  flex: 1; padding: 8px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); font-size: 14px;
}
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Lista email */
.list { display: flex; flex-direction: column; gap: 8px; }
.mail {
  background: var(--card); border-radius: var(--radius); padding: 12px 14px;
  border-left: 4px solid transparent; text-align: left; width: 100%; border-top: 0; border-right: 0; border-bottom: 0;
}
.mail.unread { border-left-color: var(--amber); }
.mail .who { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.mail .who b { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail .subj { font-weight: 600; margin: 4px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail .prev { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mail .tag { font-size: 12px; color: var(--green); margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

/* Dettaglio email */
.detail .head { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.detail .head h2 { font-size: 18px; margin: 0 0 6px; line-height: 1.3; }
.detail .meta { font-size: 13px; color: var(--muted); }
.detail .summary { margin: 10px 0 0; padding: 10px 12px; background: #fff7e8; border-radius: 10px; font-size: 14px; color: #5a3d0a; }
.detail .body {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.55; max-height: 40vh; overflow: auto;
}
.detail .body.full { max-height: none; }
.showmore { background: none; border: 0; color: var(--ink-soft); padding: 8px 0; font-size: 14px; text-decoration: underline; }

/* Risposta vocale: l'elemento centrale dell'app */
.reply { margin-top: 16px; }
.reply h3 { font-size: 15px; margin: 0 0 8px; color: var(--ink-soft); font-weight: 600; }
.mic-wrap { display: flex; flex-direction: column; align-items: center; padding: 12px 0 4px; }
.mic {
  width: 96px; height: 96px; border-radius: 50%; border: 0;
  background: var(--amber); color: #1d1405;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(217,147,42,0.35);
  transition: transform 0.15s;
}
.mic:active { transform: scale(0.95); }
.mic svg { width: 40px; height: 40px; }
.mic.rec { background: var(--red); color: #fff; animation: pulse 1.2s ease-in-out infinite; box-shadow: 0 6px 20px rgba(179,57,47,0.4); }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .mic.rec { animation: none; } }
.mic-label { margin-top: 10px; font-size: 14px; color: var(--muted); text-align: center; }
.mic-label.rec { color: var(--red); font-weight: 600; font-variant-numeric: tabular-nums; }

.steps { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; }
.card h4 { margin: 0 0 8px; font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.card textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 90px; line-height: 1.5; background: #fcfbf8; }
.card textarea.draft { min-height: 220px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
.btn.secondary .spinner { border-color: rgba(0,0,0,0.15); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }
.working { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 6px 0; }
.working .spinner { border-color: var(--line); border-top-color: var(--ink); }

/* Caselle */
.acc { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.acc .info { flex: 1; min-width: 0; }
.acc .info b { display: block; }
.acc .info span { font-size: 13px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; }
.acc .info .err { color: var(--red); }
details.adv { margin: 4px 0 14px; }
details.adv summary { color: var(--ink-soft); font-size: 14px; cursor: pointer; padding: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  z-index: 50; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.toast.bad { background: var(--red); }
