:root {
  --bg: #f6f6f8;
  --card: #ffffff;
  --ink: #16151a;
  --muted: #6b6874;
  --line: #e4e2e9;
  --accent: #6c4df6;
  --accent-soft: #efeaff;
  --ok: #1a7f52;
  --ok-soft: #e6f5ee;
  --warn: #9a6300;
  --warn-soft: #fdf1dc;
  --err: #b3261e;
  --err-soft: #fdeceb;
  --rec: #d92d20;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 18, 30, .06), 0 8px 24px rgba(20, 18, 30, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.hidden { display: none !important; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.01em; }
.login-card p.sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 550;
  transition: filter .12s ease, opacity .12s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: #cfcbd8; filter: none; }
.btn.wide { width: 100%; }
.btn.big { padding: 15px 26px; font-size: 16px; border-radius: 12px; }

.err-msg { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------- chrome ---------- */
.topbar {
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 650; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #c3c0cb; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--err); }
.linkbtn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13.5px; }
.linkbtn:hover { color: var(--ink); }

.page { max-width: 720px; margin: 0 auto; padding: 40px 20px 80px; }

/* ---------- home ---------- */
.hello { font-size: 26px; letter-spacing: -.02em; margin: 0 0 4px; }
.hello-sub { color: var(--muted); margin: 0 0 28px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 30px; font-weight: 620; letter-spacing: -.03em; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.queue {
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  gap: 26px;
  box-shadow: var(--shadow);
}
.queue div span { color: var(--muted); font-size: 13px; }
.queue div b { display: block; font-size: 19px; font-weight: 600; }
.start-wrap { margin-top: 32px; }

/* ---------- chiamata ---------- */
.callcard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 26px 22px;
}
.company { font-size: 23px; font-weight: 620; letter-spacing: -.02em; margin: 0; }
.meta { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.meta a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.phone {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 18px;
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -.02em;
  text-decoration: none;
  color: var(--ink);
}
.phone small { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

.section { margin-top: 26px; }
.section > h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.microw { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.microw select {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
  max-width: 100%;
}
.microw select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.small { padding: 8px 14px; font-size: 13.5px; border-radius: 10px; }
.mic-hint { margin: -6px 0 0; color: var(--muted); font-size: 12.5px; }

.level {
  height: 6px;
  border-radius: 999px;
  background: #ece9f3;
  overflow: hidden;
  margin-bottom: 14px;
}
.level i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .06s linear;
}

.reffields { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.flab { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.reffields input, .reffields select {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  outline: none;
  line-height: 44px;
}
/* il select nativo e' piu' basso e ha un suo bordo: lo si azzera e si rimette
   la freccia disegnata, cosi' resta identico ai due campi del nome. */
.reffields select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%236b6874' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.reffields input:focus, .reffields select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.recrow { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.recbtn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 13px 20px;
  cursor: pointer;
  font-weight: 550;
}
.recbtn:hover { border-color: #cfcbd8; }
.recbtn.recording { border-color: var(--rec); color: var(--rec); background: #fff6f5; }
.recbtn.recording { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(217, 45, 32, .28); } 50% { box-shadow: 0 0 0 6px rgba(217, 45, 32, 0); } }
.job-state { font-size: 13.5px; color: var(--muted); }

textarea.notes {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  outline: none;
  line-height: 1.6;
}
textarea.notes:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.notes::placeholder { color: #b3afbd; }

.outcomes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.outcome {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.outcome:hover { border-color: #cfcbd8; }
.outcome b { display: block; font-weight: 550; }
.outcome span { color: var(--muted); font-size: 12.5px; }
.outcome.sel { border-color: var(--accent); background: var(--accent-soft); }
.outcome.sel span { color: #6a5aa8; }

.emailrow { display: flex; gap: 10px; }
.emailrow input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-size: 15.5px;
}
.emailrow input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sugg { margin-top: 9px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sugg .lab { font-size: 12.5px; color: var(--muted); }
.pill {
  border: 1px dashed var(--accent);
  color: var(--accent);
  background: #fff;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.pill:hover { background: var(--accent-soft); }

.note { margin-top: 10px; border-radius: 12px; padding: 11px 14px; font-size: 13.5px; }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.note.attenzione { background: var(--warn-soft); color: var(--warn); }
.note.errore { background: var(--err-soft); color: var(--err); }
.note ul { margin: 0; padding-left: 18px; }
.note .fixrow { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.note button {
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  cursor: pointer;
}

.footer-actions {
  margin-top: 28px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.saved-hint { font-size: 13px; color: var(--muted); }

/* il contesto vuoto non blocca il clic (da li' passa lo sblocco admin),
   ma il bottone si spegne: la strada giusta e' un esito rapido. */
.btn.spento { opacity: .38; box-shadow: none; }
.btn.spento:hover { filter: none; }
#nointeresse.conferma {
  border-color: var(--err);
  color: var(--err);
  background: var(--err-soft);
}

/* ---------- alert contesto vuoto ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 21, 26, .45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(20, 18, 30, .28);
  padding: 26px 26px 22px;
  border-top: 4px solid var(--warn);
}
.modal h2 { margin: 0 0 8px; font-size: 19px; letter-spacing: -.01em; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.modal .field input { border-radius: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

.done {
  text-align: center;
  padding: 60px 20px;
}
.done h2 { font-size: 22px; margin: 0 0 8px; }
.done p { color: var(--muted); margin: 0 0 24px; }

@media (max-width: 620px) {
  .stats { grid-template-columns: 1fr; }
  .outcomes, .reffields { grid-template-columns: 1fr; }
  .queue { flex-direction: column; gap: 12px; }
}

/* ---------- archivio registrazioni ---------- */
.arch { display: grid; grid-template-columns: 340px 1fr; min-height: calc(100vh - 56px); }
.arch-list { border-right: 1px solid var(--line); background: var(--card); overflow-y: auto; }
.arch-search { padding: 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.arch-search input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; outline: none; background: #fff;
}
.arch-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.arch-item {
  display: block; width: 100%; text-align: left; background: none;
  border: none; border-bottom: 1px solid var(--line); padding: 13px 16px; cursor: pointer;
}
.arch-item:hover { background: #faf9fc; }
.arch-item.sel { background: var(--accent-soft); }
.arch-item b { display: block; font-weight: 580; }
.arch-item span { display: block; color: var(--muted); font-size: 13px; }
.arch-meta { color: var(--muted); font-size: 12.5px; }
.arch-detail { padding: 32px 34px 70px; max-width: 780px; }
.arch-empty { color: var(--muted); padding: 26px 16px; font-size: 14px; }
.arch-head h1 { font-size: 22px; letter-spacing: -.02em; margin: 0 0 4px; }
.arch-head p { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.arch-call {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.arch-call-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.arch-call-top span { color: var(--muted); font-size: 13px; }
.arch-dett { margin: 6px 0 0; font-size: 13.5px; color: var(--muted); }
.arch-rec { margin-top: 12px; }
.arch-rec audio { width: 100%; height: 38px; display: block; margin-bottom: 5px; }
.arch-testo {
  margin-top: 12px; background: #faf9fc; border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; font-size: 14px; line-height: 1.6;
  white-space: pre-wrap;
}
.arch-testo.vuoto { color: var(--muted); font-style: italic; }
@media (max-width: 820px) {
  .arch { grid-template-columns: 1fr; }
  .arch-list { border-right: none; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .arch-detail { padding: 22px 18px 60px; }
}
