/* Setter PYW: dashboard. Tre colonne su desktop, una alla volta su iPhone. Tema chiaro e scuro. */

:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f3f2ee;
  --panel: #ffffff;
  --panel-2: #f8f7f4;
  --hover: #f1f0ec;
  --line: #e4e2dc;
  --line-strong: #d3d0c8;
  --text: #1b1d1c;
  --text-2: #3d413f;
  --muted: #6c706d;
  --faint: #9a9e9a;

  --accent: #1e5741;
  --accent-hover: #174634;
  --accent-ink: #ffffff;
  --accent-soft: #e4efe9;
  --accent-text: #1e5741;

  --bubble-in: #ffffff;
  --bubble-out: #e3efe8;
  --chat-bg: #efeee9;

  --ok: #1d7a4c;
  --ok-soft: #e2f2e9;
  --warn: #9a5b00;
  --warn-soft: #fcf0d9;
  --warn-line: #ecc77f;
  --danger: #b4261b;
  --danger-soft: #fbe9e7;
  --info: #2c5a92;
  --info-soft: #e6eef8;

  --shadow-1: 0 1px 2px rgba(20, 24, 22, 0.06);
  --shadow-2: 0 8px 28px rgba(20, 24, 22, 0.14);
  --radius: 12px;
  --radius-sm: 8px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111312;
    --panel: #181b19;
    --panel-2: #1d201e;
    --hover: #222624;
    --line: #2a2e2c;
    --line-strong: #383d3a;
    --text: #e7e9e6;
    --text-2: #c9cdc9;
    --muted: #9ba19c;
    --faint: #6f756f;

    --accent: #5aae86;
    --accent-hover: #6cbf96;
    --accent-ink: #0b1712;
    --accent-soft: #1c2f26;
    --accent-text: #7cc6a1;

    --bubble-in: #212523;
    --bubble-out: #1d3529;
    --chat-bg: #141716;

    --ok: #6cc596;
    --ok-soft: #1a2e23;
    --warn: #e7b04f;
    --warn-soft: #32270f;
    --warn-line: #6a5219;
    --danger: #f08174;
    --danger-soft: #3a1c19;
    --info: #8db4e6;
    --info-soft: #1b2636;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 10px 32px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}
#app { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
.ico { flex: none; display: block; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.warn-text { color: var(--warn); }
.tb-spacer { flex: 1 1 auto; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- avvio e login ---------- */
.boot { height: 100%; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.boot-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); opacity: 0.85; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.5; } }

.login { min-height: 100%; display: grid; place-items: center; padding: calc(24px + var(--sat)) 20px calc(24px + var(--sab)); }
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px 28px;
  box-shadow: var(--shadow-1);
  display: grid;
  gap: 14px;
}
.login-card h1 { font-size: 22px; }
.login-logo { border-radius: 13px; }
.form-err { color: var(--danger); font-size: 13px; }

/* ---------- struttura ---------- */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--sat);
  padding-left: var(--sal);
  padding-right: var(--sar);
  overflow: hidden;
  overflow: clip; /* niente scroll del documento (anche da scrollIntoView) */
}
.main { flex: 1 1 auto; min-height: 0; display: flex; }
.workspace {
  position: relative;
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 372px;
  min-height: 0;
}
.workspace[data-has-lead="no"] { grid-template-columns: 340px minmax(0, 1fr); }
.workspace[data-has-lead="no"] .lead-pane { display: none; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.list-pane { border-right: 1px solid var(--line); }
.lead-pane { border-left: 1px solid var(--line); }
.drawer-back { display: none; }
.center-fill { flex: 1; display: grid; place-items: center; padding: 40px; }

/* ---------- barra in alto ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.tb-brand { display: flex; align-items: center; gap: 10px; flex: none; order: 0; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--text); font-weight: 680; font-size: 15px; letter-spacing: -0.01em; }
.brand img { border-radius: 7px; }
.tb-status { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.tb-status::-webkit-scrollbar { display: none; }
.tb-status { order: 1; }
.tb-actions { display: flex; align-items: center; gap: 4px; flex: none; order: 2; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12.5px;
  white-space: nowrap;
  text-decoration: none;
}
a.chip:hover, button.chip:hover { background: var(--hover); border-color: var(--line-strong); }
.chip-label { font-weight: 600; color: var(--text); }
.chip-state { color: var(--muted); }
.chip-plain b { color: var(--text); font-weight: 650; }
.chip .sep { width: 1px; height: 14px; background: var(--line-strong); }
.chip-cta { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.chip-cta:hover { filter: brightness(0.97); }
.chip-group { display: inline-flex; gap: 6px; flex: none; }
.chip-btn { height: auto; min-height: 30px; padding: 4px 10px; white-space: normal; text-align: left; }
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--faint); }
.dot.t-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.t-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.t-danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot.t-muted { background: var(--faint); }

/* ---------- bottoni ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-weight: 560;
  font-size: 13.5px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }
.btn-soft { background: var(--accent-soft); color: var(--accent-text); }
.btn-soft:not(:disabled):hover { filter: brightness(0.97); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:not(:disabled):hover, .btn-ghost.on { background: var(--hover); color: var(--text); }
.btn-ghost-danger { color: var(--danger); }
.btn-ghost-danger:not(:disabled):hover { background: var(--danger-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-icon { width: 34px; padding: 0; }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn-icon.btn-sm { width: 28px; }
.btn-block { width: 100%; height: 42px; font-size: 15px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.spin {
  display: inline-block;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
  opacity: 0.75;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- pillole e badge ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--hover);
  color: var(--text-2);
}
.pill.t-ok { background: var(--ok-soft); color: var(--ok); }
.pill.t-warn { background: var(--warn-soft); color: var(--warn); }
.pill.t-danger { background: var(--danger-soft); color: var(--danger); }
.pill.t-info { background: var(--info-soft); color: var(--info); }
.pill.t-accent { background: var(--accent-soft); color: var(--accent-text); }
.pill.t-muted { background: transparent; color: var(--faint); box-shadow: inset 0 0 0 1px var(--line); }
.badge {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 700;
}
.badge.t-accent { background: var(--accent); color: var(--accent-ink); }
.badge.t-warn { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn-line); }
.badge-mini { position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; display: grid; place-items: center; }

.avatar {
  position: relative;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: hsl(var(--h) 32% 28%);
  background: hsl(var(--h) 30% 88%);
}
@media (prefers-color-scheme: dark) {
  .avatar { color: hsl(var(--h) 35% 82%); background: hsl(var(--h) 18% 24%); }
}
.avatar-ch {
  position: absolute;
  right: -5px;
  bottom: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel);
  box-shadow: 0 0 0 1.5px var(--panel);
}
.ch { display: inline-grid; place-items: center; color: var(--muted); }
.ch-whatsapp { color: #1f9d55; }
.ch-email { color: var(--info); }
.ch-nota { color: var(--warn); }
@media (prefers-color-scheme: dark) { .ch-whatsapp { color: #57c787; } }

/* ---------- elenco ---------- */
.list-head { flex: none; padding: 12px 12px 0; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.list-title { display: flex; align-items: center; gap: 8px; }
.list-title h2 { font-size: 18px; }
.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 4px 0 11px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); background: var(--panel); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; height: 100%; color: var(--text); }
.search input::-webkit-search-cancel-button { opacity: 0.5; }
.search-filter { position: relative; width: 32px; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); display: grid; place-items: center; }
.search-filter:hover, .search-filter.on { background: var(--hover); color: var(--text); }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters select { flex: 1 1 30%; min-width: 0; }
.tabs { display: flex; gap: 2px; margin: 0 -4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 8px 9px 10px;
  color: var(--muted);
  font-weight: 560;
  font-size: 13px;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.tab-n { font-size: 11px; font-weight: 700; padding: 0 6px; height: 17px; border-radius: 99px; background: var(--hover); color: var(--text-2); display: inline-grid; place-items: center; }
.tab-n.t-warn { background: var(--warn-soft); color: var(--warn); }
.bulk { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--accent-soft); color: var(--accent-text); font-size: 12.5px; font-weight: 560; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 6px calc(10px + var(--sab)); -webkit-overflow-scrolling: touch; }

.li {
  width: 100%;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 10px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.li + .li { margin-top: 1px; }
.li:hover { background: var(--hover); }
.li.active { background: var(--accent-soft); }
.li.selected { background: var(--accent-soft); }
.li-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.li-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.li-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-time { flex: none; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.li.unread .li-time { color: var(--accent-text); font-weight: 650; }
.li-preview { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li.unread .li-preview { color: var(--text-2); }
.li.unread .li-name { font-weight: 700; }
.li-prefix { color: var(--faint); }
.li-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; flex-wrap: wrap; }
.mode-tag { font-size: 11px; color: var(--faint); font-weight: 560; }
.mode-tag.m-auto { color: var(--accent-text); }
.mode-tag.m-manuale { color: var(--muted); }
.li-call, .li-queued { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--ok); font-weight: 600; font-variant-numeric: tabular-nums; }
.li-queued { color: var(--muted); }
.check { flex: none; width: 22px; height: 22px; margin: 9px; border-radius: 6px; border: 1.5px solid var(--line-strong); display: grid; place-items: center; }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.skel-row { display: flex; gap: 11px; padding: 12px 10px; align-items: center; }
.skel { display: block; height: 11px; border-radius: 6px; background: var(--hover); animation: pulse 1.4s ease-in-out infinite; }
.skel-av { width: 40px; height: 40px; border-radius: 50%; flex: none; }
.skel-lines { flex: 1; display: grid; gap: 8px; }
.skel.short { width: 60%; }

.empty { margin: auto; padding: 40px 24px; display: grid; justify-items: center; gap: 8px; text-align: center; max-width: 340px; }
.empty-ico { width: 52px; height: 52px; border-radius: 16px; background: var(--hover); display: grid; place-items: center; color: var(--muted); margin-bottom: 4px; }
.empty-title { font-weight: 640; font-size: 15px; }
.empty-text { color: var(--muted); font-size: 13px; display: grid; gap: 10px; justify-items: center; }

/* ---------- chat ---------- */
.chat-pane { background: var(--chat-bg); }
.chat-empty { display: grid; place-items: center; }
.chat-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.back-btn { display: none; }
.chat-who { display: flex; align-items: center; gap: 10px; min-width: 0; border: 0; background: transparent; padding: 2px 4px; border-radius: 8px; text-align: left; }
.chat-who:hover { background: var(--hover); }
.chat-who-text { display: grid; min-width: 0; }
.chat-name { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.dotsep { color: var(--faint); }
.mode-select { flex: none; }
.mode-select select {
  width: auto;
  height: 30px;
  padding: 0 26px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background-color: var(--panel-2);
  font-size: 12.5px;
  font-weight: 600;
}
.panel-btn { display: none; }

.banner { flex: none; display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
.banner.t-warn { background: var(--warn-soft); color: var(--warn); }
.banner.t-ok { background: var(--ok-soft); color: var(--ok); }
.banner span { flex: 1; min-width: 0; }
.banner-link { font-weight: 650; color: inherit; white-space: nowrap; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.chat-inner { max-width: 760px; margin: 0 auto; padding: 16px 16px 20px; display: flex; flex-direction: column; gap: 4px; min-height: 100%; }
.day-sep { display: flex; justify-content: center; margin: 14px 0 8px; }
.day-sep span { font-size: 11.5px; font-weight: 600; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px; }
.sys { display: flex; justify-content: center; margin: 6px 0; }
.sys span { font-size: 12px; color: var(--muted); text-align: center; max-width: 90%; }
.sys b { color: var(--text-2); font-weight: 600; }

.msg { display: flex; flex-direction: column; max-width: min(78%, 560px); margin: 2px 0; }
.msg.in { align-self: flex-start; align-items: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble {
  position: relative;
  padding: 8px 11px 6px;
  border-radius: 14px;
  background: var(--bubble-in);
  box-shadow: var(--shadow-1);
  min-width: 90px;
}
.msg.in .bubble { border-top-left-radius: 5px; }
.msg.out .bubble { background: var(--bubble-out); border-top-right-radius: 5px; }
.msg.st-in_coda .bubble { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.msg.st-fallito .bubble, .msg.st-bloccato .bubble { box-shadow: inset 0 0 0 1.5px var(--danger); }
.msg.st-scartato .bubble { opacity: 0.55; }
.msg.st-scartato .b-text { text-decoration: line-through; }
.b-subj { display: flex; align-items: center; gap: 5px; font-weight: 640; font-size: 13px; margin-bottom: 4px; color: var(--text); }
.b-text { font-size: 14.5px; line-height: 1.42; }
.b-foot { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px; margin-top: 3px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.b-dual { color: var(--faint); }
.mst { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); }
.mst.read { color: #2f8fd8; }
.mst.bad { color: var(--danger); font-weight: 600; }
.msg-err { font-size: 12px; color: var(--danger); margin-top: 3px; max-width: 100%; }
.note-msg { align-self: center; display: flex; gap: 8px; max-width: 86%; background: var(--warn-soft); color: var(--text-2); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 6px 0; }
.note-msg .ico { color: var(--warn); margin-top: 2px; }

.draft {
  align-self: flex-end;
  width: min(92%, 560px);
  margin: 8px 0;
  padding: 12px 12px 10px;
  border-radius: 14px;
  background: var(--panel);
  border: 1.5px solid var(--warn-line);
  box-shadow: 0 0 0 4px var(--warn-soft);
  display: grid;
  gap: 8px;
}
.draft-suggestion { border-color: var(--info); box-shadow: 0 0 0 4px var(--info-soft); }
.draft-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.draft-kind { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conf { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.conf.t-ok { color: var(--ok); }
.conf.t-warn { color: var(--warn); }
.conf.t-danger { color: var(--danger); }
.draft-reason { font-size: 12.5px; color: var(--muted); font-style: italic; }
.draft-slot { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ok); font-weight: 600; background: var(--ok-soft); padding: 6px 9px; border-radius: 8px; }
.draft-body { background: var(--bubble-out); border-radius: 10px; padding: 9px 11px; font-size: 14.5px; line-height: 1.42; }
.draft-edit { width: 100%; resize: vertical; border-radius: 10px; border: 1.5px solid var(--accent); background: var(--panel); padding: 9px 11px; font-size: 14.5px; line-height: 1.42; outline: none; }
.draft-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.draft-foot { text-align: right; }

/* compositore */
.composer {
  flex: none;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px 12px calc(10px + var(--sab));
  display: grid;
  gap: 7px;
}
.composer-hint { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.composer-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.composer-to { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-subject { height: 36px; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-row textarea {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 40vh;
  resize: none;
  padding: 9px 12px;
  border-radius: 20px;
  line-height: 1.4;
}
.suggest-btn { width: auto; height: 40px; padding: 0 11px; border-radius: 20px; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; }
.toggle-chip { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); font-size: 12px; font-weight: 560; color: var(--text-2); }
.toggle-chip.on { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }

/* controllo a segmenti */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--hover); max-width: 100%; }
.seg-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px; border: 0; background: transparent; height: 30px; padding: 0 12px; border-radius: 7px; font-weight: 580; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg-btn:hover:not(:disabled) { color: var(--text); }
.seg-btn.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow-1); }
.seg-btn:disabled { opacity: 0.4; cursor: default; }
.seg-sm .seg-btn { height: 26px; padding: 0 9px; font-size: 12.5px; }
.sec .seg { display: flex; }

/* ---------- campi ---------- */
input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], input[type="time"], input:not([type]), select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 36px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
textarea { height: auto; padding: 8px 10px; line-height: 1.45; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled, textarea:disabled { background: var(--panel-2); color: var(--muted); }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.input-unit { position: relative; display: flex; align-items: center; }
.input-unit input { padding-right: 52px; }
.input-unit input[type="number"] { -moz-appearance: textfield; }
.input-unit input::-webkit-inner-spin-button { opacity: 0.4; }
.unit { position: absolute; right: 10px; font-size: 12px; color: var(--faint); pointer-events: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { flex: none; width: 38px; height: 22px; border-radius: 99px; background: var(--line-strong); position: relative; transition: background 0.15s; }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }
.days { display: flex; flex-wrap: wrap; gap: 5px; }
.day { min-width: 44px; height: 32px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); font-size: 12.5px; font-weight: 600; color: var(--muted); }
.day.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- scheda lead ---------- */
.lead-head { flex: none; display: flex; align-items: center; gap: 8px; min-height: 58px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.lead-head h2 { font-size: 15px; }
.lead-close { display: none; }
.lead-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(24px + var(--sab)); }
.lead-card { display: grid; }
.lead-hero { display: flex; gap: 12px; align-items: center; padding: 16px 16px 14px; }
.lead-name { font-size: 18px; font-weight: 680; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.sec { padding: 14px 16px; border-top: 1px solid var(--line); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.sec-head h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.sec-body { display: grid; gap: 10px; }
.savebar { display: flex; justify-content: flex-end; gap: 6px; padding-top: 2px; }
.kv { margin: 0; display: grid; gap: 0; }
.kv-row { display: grid; grid-template-columns: minmax(90px, 40%) 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.kv-row:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); overflow-wrap: anywhere; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv-inline { display: flex; flex-wrap: wrap; gap: 8px; }
.wa { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 560; color: var(--muted); }
.wa-si { color: var(--ok); }
.wa-no { color: var(--danger); }
.quote { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; line-height: 1.5; }
.clock { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.clock b { font-weight: 700; }
.callbox { display: grid; gap: 10px; background: var(--ok-soft); border-radius: 10px; padding: 12px; }
.call-when { display: flex; gap: 10px; align-items: flex-start; color: var(--ok); }
.call-when > div { color: var(--text); font-size: 13.5px; }
.call-link { display: flex; gap: 6px; flex-wrap: wrap; }
.slots { display: grid; gap: 6px; }
.slots-head { display: flex; align-items: center; justify-content: space-between; }
.slot { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; text-align: left; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--panel); }
.slot:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.slot-main { font-weight: 600; font-size: 13.5px; }
.slot-sub { grid-column: 1; font-size: 12px; color: var(--muted); }
.raw { margin-top: 10px; font-size: 13px; }
.raw summary { cursor: pointer; color: var(--accent-text); font-weight: 560; }
.raw .pre { margin-top: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 320px; overflow: auto; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; }
.tl { position: relative; display: flex; gap: 10px; padding: 0 0 12px 0; }
.tl::before { content: ""; position: absolute; left: 4px; top: 12px; bottom: 0; width: 1px; background: var(--line); }
.tl:last-child::before { display: none; }
.tl-dot { flex: none; width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--line-strong); }
.tl-call_fissata .tl-dot, .tl-messaggio_approvato .tl-dot { background: var(--ok); }
.tl-escalation .tl-dot, .tl-no_show .tl-dot, .tl-invio_bloccato .tl-dot, .tl-invio_fallito .tl-dot, .tl-errore .tl-dot { background: var(--danger); }
.tl-lead_creato .tl-dot, .tl-cambio_canale .tl-dot { background: var(--accent); }
.tl-body { flex: 1; min-width: 0; font-size: 13px; }
.tl-top { display: flex; justify-content: space-between; gap: 8px; }
.tl-top b { font-weight: 600; }
.tl-top time { flex: none; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.tl-text { color: var(--muted); overflow-wrap: anywhere; }

/* ---------- pagine (impostazioni, WhatsApp) ---------- */
.page { flex: 1; min-width: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 0 calc(32px + var(--sab)); }
.page-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.page-head h2 { font-size: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; align-content: start; }
.card h3 { font-size: 15px; }
.card h4 { font-size: 13px; margin-top: 6px; color: var(--text-2); }
.settings-grid { max-width: 1120px; margin: 20px auto 0; padding: 0 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(400px, 100%), 1fr)); gap: 16px; align-items: start; }
.wa-card { max-width: 520px; margin: 24px auto; }
.qr-wrap { display: grid; justify-items: center; gap: 16px; padding: 8px; }
.qr { width: min(280px, 72vw); height: auto; aspect-ratio: 1; border-radius: 12px; background: #fff; padding: 10px; border: 1px solid var(--line); image-rendering: pixelated; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 14px; }

/* ---------- dialoghi e toast ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 14, 12, 0.42);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade 0.12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(480px, 100%);
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px 18px; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 4px 18px 16px; overflow-y: auto; display: grid; gap: 12px; }
.modal-body > p { color: var(--text-2); line-height: 1.5; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px calc(14px + var(--sab)); border-top: 1px solid var(--line); background: var(--panel-2); }

.toasts { position: fixed; left: 50%; bottom: calc(20px + var(--sab)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: min(420px, calc(100% - 32px)); }
.toast {
  padding: 10px 16px;
  border-radius: 12px;
  background: #1f2321;
  color: #f1f3f1;
  font-size: 13.5px;
  font-weight: 520;
  box-shadow: var(--shadow-2);
  animation: rise 0.18s ease-out;
  text-align: center;
}
.toast.t-ok { background: #1c4d38; }
.toast.t-danger { background: #8e2219; }
.toast.t-warn { background: #6b4a10; }
.toast.t-accent { background: #1e5741; }
@media (prefers-color-scheme: dark) {
  .toast { background: #2a2f2c; }
  .toast.t-ok, .toast.t-accent { background: #24503c; }
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- utility responsive ---------- */
.show-sm { display: none; }

/* Schermi medi: scheda lead come pannello laterale sopra la chat. */
@media (max-width: 1279px) {
  .workspace, .workspace[data-has-lead="no"] { grid-template-columns: 320px minmax(0, 1fr); }
  .lead-pane {
    position: absolute;
    z-index: 20;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(400px, 92vw);
    transform: translateX(105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-2);
    border-left: 1px solid var(--line);
  }
  .workspace[data-view="scheda"] .lead-pane { transform: none; }
  .workspace[data-view="scheda"] .drawer-back { display: block; position: absolute; inset: 0; z-index: 19; background: rgba(10, 14, 12, 0.18); }
  .panel-btn { display: inline-flex; }
  .lead-close { display: inline-flex; }
}

@media (max-width: 1080px) {
  .chip-state { display: none; }
}

/* Telefono: una colonna alla volta. */
@media (max-width: 899px) {
  body { font-size: 15px; }
  /* niente zoom di iOS sui campi */
  input, select, textarea, .search input { font-size: 16px !important; }
  .topbar { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px 6px; }
  .tb-brand { flex: 1 1 auto; min-width: 0; }
  .tb-actions { order: 1; }
  .tb-status { order: 2; flex-basis: calc(100% + 24px); margin: 0 -12px; padding: 2px 12px 4px; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex; }
  .app[data-view="chat"] .topbar, .app[data-view="scheda"] .topbar { display: none; }

  .workspace, .workspace[data-has-lead="no"] { grid-template-columns: minmax(0, 1fr); }
  .list-pane, .chat-pane, .lead-pane { display: none; border: 0; }
  .workspace[data-view="list"] .list-pane { display: flex; }
  .workspace[data-view="chat"] .chat-pane { display: flex; }
  .workspace[data-view="scheda"] .lead-pane { display: flex; position: static; transform: none; width: auto; box-shadow: none; }
  .workspace[data-view="scheda"] .drawer-back { display: none; }
  .workspace[data-has-lead="no"] .lead-pane { display: none; }

  .back-btn { display: inline-flex; margin-left: -6px; }
  .chat-head { padding: 6px 10px; gap: 4px; }
  .chat-who { padding: 2px; }
  .chat-inner { padding: 12px 10px 16px; }
  .msg { max-width: 86%; }
  .draft { width: 100%; }
  .composer { padding: 8px 10px calc(8px + var(--sab)); }
  .composer-row textarea { font-size: 16px; }
  .mode-select select { height: 32px; padding-left: 10px; }
  .li { padding: 11px 10px; }
  .btn { height: 38px; }
  .btn-sm { height: 32px; }
  .btn-icon { width: 38px; }
  .btn-icon.btn-sm { width: 32px; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); padding: 0 12px; margin-top: 12px; gap: 12px; }
  .page-head { padding: 10px 12px; }
  .card { padding: 16px 14px; }
  .modal-back { place-items: end stretch; padding: 0; }
  .modal { width: 100%; max-height: calc(100dvh - 40px - var(--sat)); border-radius: 18px 18px 0 0; animation: rise 0.2s ease-out; }
  .toasts { bottom: calc(84px + var(--sab)); }
}

@media (max-width: 520px) {
  .hide-xs { display: none !important; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .grid3 > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}

@media (hover: none) {
  .li:hover, .btn-ghost:not(:disabled):hover { background: transparent; }
  .li.active { background: var(--accent-soft); }
  .li:active { background: var(--hover); }
}

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

/* ---------- correzioni 07/11: barra in alto, avvisi, schede, orologio del lead ---------- */
.chip-compact { padding: 0 8px; gap: 5px; }
.tb-services { display: inline-flex; gap: 4px; flex: none; align-items: center; }
@media (min-width: 900px) {
  /* su desktop la barra va a capo invece di nascondere i contatori fuori schermo */
  .tb-status { flex-wrap: wrap; overflow: visible; row-gap: 4px; }
}
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; text-align: left; }
.toast-text { flex: 1 1 auto; min-width: 0; }
.toast-btn { flex: none; border: 0; border-radius: 8px; padding: 5px 9px; background: rgba(255, 255, 255, 0.16); color: inherit; font: inherit; font-size: 12.5px; font-weight: 650; }
.toast-btn:hover { background: rgba(255, 255, 255, 0.26); }
.toast-x { flex: none; border: 0; background: transparent; color: inherit; opacity: 0.75; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; }
.toast-x:hover { opacity: 1; background: rgba(255, 255, 255, 0.14); }
.tabs { flex-wrap: wrap; }
.tab { padding: 8px 7px 10px; font-size: 12.5px; gap: 5px; }
.chat-clock { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--accent-text); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.draft-to { font-size: 12px; color: var(--muted); margin: 0; }
.draft-to b { color: var(--text-2); font-weight: 600; }
.draft-subject { width: 100%; }
.composer-switch { font-size: 12px; color: var(--warn); padding: 2px 2px 0; }
.slot-other { display: grid; gap: 6px; padding-top: 6px; border-top: 1px dashed var(--line); margin-top: 4px; }
.slot-other-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.slot-other-row input { flex: 1 1 180px; min-width: 0; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.profile-opt { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); padding: 8px 10px; text-align: left; color: var(--text-2); font: inherit; font-size: 13px; }
.profile-opt.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.profile-opt small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
