/* ---------------------------------------------------------------------------
   WA Studio — design tokens
--------------------------------------------------------------------------- */
:root {
  --bg: oklch(0.976 0.004 165);
  --surface: oklch(1 0 0);
  --sidebar: oklch(0.985 0.006 165);
  --border: oklch(0.905 0.012 165);
  --border-strong: oklch(0.84 0.016 165);

  --ink: oklch(0.26 0.02 170);
  --ink-soft: oklch(0.44 0.022 170);
  --ink-faint: oklch(0.55 0.02 170);

  --accent: oklch(0.52 0.135 152);          /* verde azione */
  --accent-hover: oklch(0.47 0.13 152);
  --accent-deep: oklch(0.38 0.075 175);     /* verde-teal profondo, titoli/selezioni */
  --accent-soft: oklch(0.955 0.028 152);    /* tinta di sfondo */
  --accent-soft-border: oklch(0.88 0.05 152);

  --danger: oklch(0.5 0.17 27);
  --danger-soft: oklch(0.96 0.02 27);
  --warn-soft: oklch(0.96 0.035 85);
  --warn-ink: oklch(0.44 0.09 75);

  --bubble-out: oklch(0.945 0.04 152);

  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;

  --shadow-drawer: -16px 0 48px oklch(0.3 0.02 170 / 0.14);
  --shadow-pop: 0 8px 28px oklch(0.3 0.02 170 / 0.12);

  --z-sticky: 10;
  --z-drawer-backdrop: 40;
  --z-drawer: 50;
  --z-toast: 60;
  --z-login: 70;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Struttura
--------------------------------------------------------------------------- */
.shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 236px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 14px 14px;
}

/* Blocco brand = selettore organizzazione: nome dell'org come titolo, «WA
   Studio» come sottotitolo; con più org il bottone apre il menu. */
.brand {
  position: relative;
  padding: 0 0 14px;
}

.brand-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  border-radius: var(--radius-m);
  text-align: left;
  cursor: pointer;
  transition: background 150ms var(--ease-out);
}
.brand-btn:disabled { cursor: default; }
.brand-btn:not(:disabled):hover { background: oklch(0.945 0.01 165); }
.brand-btn[aria-expanded="true"] { background: var(--accent-soft); }
.brand-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.brand-text { flex: 1; min-width: 0; }
.brand-text strong,
.brand-text span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text strong { font-size: 15px; letter-spacing: -0.01em; }
.brand-text span { font-size: 12px; color: var(--ink-soft); }

.brand-caret {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--ink-faint);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.org-menu {
  position: absolute;
  top: calc(100% - 8px);
  left: 0;
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: var(--z-sticky);
}
.org-menu-title {
  margin: 4px 8px 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.org-menu [role="menuitemradio"] {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.org-menu [role="menuitemradio"]:hover,
.org-menu [role="menuitemradio"]:focus-visible { background: var(--accent-soft); outline: none; }
.org-menu [aria-checked="true"] .org-item-text strong { color: var(--accent-deep); }
.org-item-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-deep);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.org-item-text { flex: 1; min-width: 0; }
.org-item-text strong {
  display: block;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.org-item-text span { display: block; font-size: 12px; color: var(--ink-soft); }
.org-check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-deep);
  color: white;
  font-weight: 700;
  font-size: 17px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-s);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 500;
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out);
}

.nav a svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav a:hover { background: oklch(0.945 0.01 165); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-deep); }

.conn-chip {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: border-color 150ms var(--ease-out);
}

.conn-chip:hover { border-color: var(--border-strong); }

.conn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
}

.conn-dot.ok { background: var(--accent); }
.conn-dot.warn { background: oklch(0.75 0.15 85); }
.conn-dot.err { background: var(--danger); }

.conn-text strong {
  display: block;
  font-size: 13px;
  line-height: 1.3;
}

.conn-text span {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.3;
}

.content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.view {
  max-width: 880px;
  padding: 28px 32px 48px;
}

.view-inbox {
  max-width: none;
  height: 100%;
  padding: 0;
}

/* ---------------------------------------------------------------------------
   Intestazioni di sezione
--------------------------------------------------------------------------- */
.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.view-head h1 {
  margin: 0 0 2px;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.view-head p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  max-width: 60ch;
}

/* ---------------------------------------------------------------------------
   Bottoni e controlli
--------------------------------------------------------------------------- */
.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-weight: 550;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out);
}

.btn:hover { background: oklch(0.965 0.006 165); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  color: var(--danger);
  border-color: oklch(0.85 0.06 27);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover { background: oklch(0.945 0.01 165); color: var(--ink); }

.btn-block { width: 100%; justify-content: center; }

input[type="text"], input[type="password"], input[type="number"],
input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  transition: border-color 150ms var(--ease-out);
}

input::placeholder, textarea::placeholder { color: var(--ink-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px oklch(0.52 0.135 152 / 0.15);
}

textarea { resize: vertical; min-height: 88px; }

.field { margin-bottom: 16px; }

.field > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
}

.field .hint {
  margin: 5px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
}

/* Interruttore attiva/disattiva */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: oklch(0.85 0.012 165);
  transition: background 180ms var(--ease-out);
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.25);
  transition: transform 180ms var(--ease-out);
}

.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------------------
   Pannelli, elenchi, stati vuoti
--------------------------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 20px 22px;
  margin-bottom: 18px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 650;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  overflow: hidden;
}

.item-list > li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
}

.item-list > li + li { border-top: 1px solid var(--border); }

.item-main { flex: 1; min-width: 0; }

.item-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 1px;
}

.item-sub {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.item-sub .kw {
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  color: var(--accent-deep);
  border-radius: 5px;
  padding: 0 5px;
  font-weight: 600;
}

.item-meta {
  font-size: 12.5px;
  color: var(--ink-faint);
  margin-top: 3px;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  border: none;
  background: transparent;
  padding: 7px;
  border-radius: var(--radius-s);
  cursor: pointer;
  color: var(--ink-faint);
  display: grid;
  place-items: center;
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out);
}

.icon-btn:hover { background: oklch(0.945 0.01 165); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 44px 32px;
  text-align: center;
}

.empty h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.empty p {
  margin: 0 auto 18px;
  color: var(--ink-soft);
  font-size: 14px;
  max-width: 46ch;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.5;
}

.badge.on { background: var(--accent-soft); color: var(--accent-deep); }
.badge.off { background: oklch(0.94 0.005 165); color: var(--ink-soft); }
.badge.pending { background: var(--warn-soft); color: var(--warn-ink); }
.badge.sent { background: var(--accent-soft); color: var(--accent-deep); }
.badge.error { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------------------
   Dashboard
--------------------------------------------------------------------------- */
.qr-box {
  display: flex;
  gap: 26px;
  align-items: center;
  flex-wrap: wrap;
}

.qr-box img {
  width: 232px;
  height: 232px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
}

.qr-steps {
  margin: 0;
  padding-left: 20px;
  color: var(--ink-soft);
  max-width: 44ch;
}

.qr-steps li { margin-bottom: 6px; }

.connected-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 18px;
  display: grid;
  place-items: center;
}

.connected-row .who { flex: 1; min-width: 0; }
.connected-row .who strong { display: block; }
.connected-row .who span { color: var(--ink-soft); font-size: 13.5px; }

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 26px;
  padding: 13px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  margin-bottom: 18px;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.summary-strip b {
  color: var(--ink);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activity-list li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}

.activity-list li:last-child { border-bottom: none; }

.activity-list .when {
  color: var(--ink-faint);
  font-size: 12.5px;
  flex-shrink: 0;
  width: 52px;
  padding-top: 1px;
  font-variant-numeric: tabular-nums;
}

.loading-note {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   Inbox
--------------------------------------------------------------------------- */
.inbox-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100%;
}

.chat-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

.chat-list-head {
  padding: 16px 16px 10px;
}

.chat-list-head h1 {
  margin: 0 0 10px;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 12px;
  overflow-y: auto;
  flex: 1;
}

.chat-list button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 10px;
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: background 150ms var(--ease-out);
}

.chat-list button:hover { background: oklch(0.96 0.006 165); }
.chat-list li.active button { background: var(--accent-soft); }

.chat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-row-top .name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-row-top .time {
  font-size: 11.5px;
  color: var(--ink-faint);
  flex-shrink: 0;
}

.chat-row-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 1px;
}

.chat-row-bottom .preview {
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-pill {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  flex-shrink: 0;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.chat-pane-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-pane-head strong { font-size: 15px; }
.chat-pane-head span { color: var(--ink-soft); font-size: 13px; margin-left: 8px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble {
  max-width: min(68%, 520px);
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble .btime {
  display: block;
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 3px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bubble.in {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.bubble.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border: 1px solid var(--accent-soft-border);
  border-bottom-right-radius: 5px;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  align-items: flex-end;
  position: relative; /* àncora del pannello emoji */
}

.composer textarea {
  min-height: 42px;
  max-height: 140px;
  flex: 1;
}

.composer select { width: 170px; flex-shrink: 0; }

.composer .icon-btn { flex-shrink: 0; height: 42px; width: 42px; }
.composer .icon-btn:disabled { opacity: 0.5; cursor: wait; }

/* Link «Apri allegato» nelle bolle dei messaggi con media */
.media-open {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Pannello emoji (stile Spoki), ancorato sopra il composer */
.emoji-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 16px;
  width: 340px;
  max-width: calc(100% - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 40, 30, 0.14);
  padding: 10px;
  z-index: 40;
}
.emoji-panel input { width: 100%; margin-bottom: 8px; }
.emoji-body { max-height: 264px; overflow-y: auto; overscroll-behavior: contain; }
.emoji-cat {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 8px 2px 4px;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); }
.emoji-item {
  border: none;
  background: transparent;
  font-size: 21px;
  line-height: 1.3;
  padding: 4px 0;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-item:hover { background: oklch(0.945 0.01 165); }
.emoji-empty { color: var(--ink-soft); font-size: 13px; padding: 8px 2px; }

.inbox-placeholder {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  text-align: center;
  padding: 40px;
}

/* ---------------------------------------------------------------------------
   Drawer (editor laterale)
--------------------------------------------------------------------------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0.2 0.02 170 / 0.32);
  z-index: var(--z-drawer-backdrop);
  opacity: 1;
  transition: opacity 200ms var(--ease-out);
}

.drawer-backdrop.closing { opacity: 0; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-drawer);
  z-index: var(--z-drawer);
  padding: 24px 26px 28px;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 240ms var(--ease-out);
}

.drawer.closing { transform: translateX(100%); }

@keyframes drawer-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer.opening { animation: drawer-in 240ms var(--ease-out); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.drawer-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  overflow: hidden;
  margin-bottom: 4px;
}

.seg label {
  padding: 7px 14px;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  color: var(--ink-soft);
  background: var(--surface);
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out);
}

.seg label + label { border-left: 1px solid var(--border-strong); }

.seg input { position: absolute; opacity: 0; pointer-events: none; }

.seg input:checked + span { color: var(--accent-deep); font-weight: 650; }
.seg label:has(input:checked) { background: var(--accent-soft); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }

.hook-url {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hook-url code {
  flex: 1;
  font-size: 12px;
  background: oklch(0.965 0.006 165);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 8px 10px;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------------
   Flow builder (automazioni)
--------------------------------------------------------------------------- */
.item-open {
  border: none;
  background: transparent;
  text-align: left;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.item-open:hover .item-title { color: var(--accent-deep); }

.flow-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.flow-name {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  border-color: transparent;
  background: transparent;
  max-width: 380px;
  padding: 6px 10px;
}

.flow-name:hover { border-color: var(--border-strong); background: var(--surface); }
.flow-name:focus { background: var(--surface); }

.unsaved {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--warn-ink);
  background: var(--warn-soft);
  padding: 3px 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.hook-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--ink-soft);
}

.hook-bar code {
  font-size: 12px;
  background: oklch(0.965 0.006 165);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  overflow-wrap: anywhere;
}

/* Input dei tag nella barra sotto l'header del flow editor */
.hook-bar .flow-tags {
  flex: 1;
  min-width: 220px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: oklch(0.965 0.006 165);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.hook-bar .flow-tags:focus {
  outline: none;
  border-color: var(--accent-soft-border);
  background: var(--surface);
}

/* Filtri per tag nella lista automazioni: chip a larghezza naturale, su più righe */
.auto-tagbar {
  flex-wrap: wrap;
  margin: 0 0 16px;
}
.auto-tagbar button { flex: 0 0 auto; }

.flow-canvas {
  overflow-x: auto;
  padding: 18px 8px 80px;
}

.flow-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.flow-line {
  width: 2px;
  height: 20px;
  background: var(--border-strong);
  flex-shrink: 0;
}

.flow-add {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-faint);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color 150ms var(--ease-out), color 150ms var(--ease-out), background 150ms var(--ease-out);
}

.flow-add svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.flow-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.step-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.step-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 340px;
  max-width: 86vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}

.step-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px oklch(0.3 0.02 170 / 0.07);
}

.trigger-card {
  border-color: var(--accent-soft-border);
  background: var(--accent-soft);
}

.trigger-card:hover { border-color: var(--accent); }

.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: oklch(0.955 0.008 165);
  color: var(--ink-soft);
}

.step-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.step-icon.trigger { background: var(--accent-deep); color: white; }
.step-icon.message { background: var(--accent-soft); color: var(--accent-deep); }
.step-icon.delay { background: var(--warn-soft); color: var(--warn-ink); }
.step-icon.waitReply { background: oklch(0.95 0.03 250); color: oklch(0.42 0.1 255); }
.step-icon.condition { background: oklch(0.95 0.03 300); color: oklch(0.42 0.1 305); }
.step-icon.tag { background: oklch(0.95 0.035 60); color: oklch(0.44 0.09 55); }
.step-icon.webhookOut { background: oklch(0.94 0.01 200); color: oklch(0.4 0.05 220); }

.step-text {
  flex: 1;
  min-width: 0;
}

.step-text strong {
  display: block;
  font-size: 13.5px;
}

.step-text > span {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.step-text .kw {
  background: oklch(1 0 0 / 0.7);
  border: 1px solid var(--accent-soft-border);
  color: var(--accent-deep);
  border-radius: 5px;
  padding: 0 4px;
  font-weight: 600;
}

.step-del { flex-shrink: 0; }

.branches {
  display: flex;
  align-items: flex-start;
  gap: 22px;
  margin-top: 14px;
  padding: 0 4px;
}

.branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 190px;
  padding: 12px 10px 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-m);
  background: oklch(0.985 0.003 165 / 0.6);
}

.branch .step-card { width: 280px; }

.branch-label {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  margin-bottom: 2px;
}

.branch-label.yes { background: var(--accent-soft); color: var(--accent-deep); }
.branch-label.no { background: oklch(0.94 0.005 165); color: var(--ink-soft); }

.type-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.type-list button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 150ms var(--ease-out), background 150ms var(--ease-out);
}

.type-list button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.type-list strong {
  display: block;
  font-size: 14px;
}

.type-list button > span:last-child span {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}

.radio-row input { width: auto; }

/* ---------------------------------------------------------------------------
   Login e toast
--------------------------------------------------------------------------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: var(--z-login);
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 34px 30px;
  text-align: center;
  box-shadow: var(--shadow-pop);
}

.login-card .brand-mark { margin: 0 auto 14px; width: 44px; height: 44px; font-size: 21px; }
.login-card h1 { margin: 0 0 4px; font-size: 19px; }
.login-card p { margin: 0 0 18px; color: var(--ink-soft); font-size: 14px; }
.login-card input { margin-bottom: 12px; }
.login-card .hint { margin: 0 0 12px; font-size: 12.5px; color: var(--ink-soft); }
.login-card .totp-qr { display: block; margin: 0 auto 12px; width: 200px; height: 200px; border: 1px solid var(--border); border-radius: 8px; }
.login-card .login-secret { word-break: break-all; }
.login-card .login-remember {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 14px; font-size: 13px; color: var(--ink-soft); text-align: left; cursor: pointer;
}
.login-card .login-remember input { margin: 0; width: auto; flex: 0 0 auto; }
.login-card .backup-codes {
  margin: 0 0 12px; padding: 12px 16px;
  background: var(--accent-soft); border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px; line-height: 1.7; letter-spacing: 1px;
  text-align: center; user-select: all;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: var(--z-toast);
  box-shadow: var(--shadow-pop);
  max-width: min(90vw, 480px);
  text-align: center;
}

.toast.error { background: var(--danger); }

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .sidebar { width: 68px; padding-inline: 8px; }
  .brand-text, .brand-caret, .conn-text { display: none; }
  .brand { padding-inline: 0; }
  .brand-btn { justify-content: center; padding: 6px 0; }
  .org-menu { top: 0; left: calc(100% + 6px); right: auto; width: 240px; } /* si apre a destra del rail */
  .nav a { justify-content: center; padding: 10px; font-size: 0; gap: 0; }
  .nav a svg { width: 21px; height: 21px; }
  .conn-chip { justify-content: center; padding: 10px 0; border: none; background: transparent; }
  .inbox-grid { grid-template-columns: 260px 1fr; }
  .view { padding: 20px 18px 40px; }
}

@media (max-width: 640px) {
  .inbox-grid { grid-template-columns: 1fr; }
  .chat-pane { display: none; }
  .inbox-grid.chat-open .chat-list-pane { display: none; }
  .inbox-grid.chat-open .chat-pane { display: flex; }
  .field-row { grid-template-columns: 1fr; }
}

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

/* ---------------------------------------------------------------------------
   Multiutente: box utente, logout, filtri inbox, assegnazioni
   --------------------------------------------------------------------------- */
.user-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 8px 10px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
}
.user-box + .conn-chip { margin-top: 10px; }
.user-info { flex: 1; min-width: 0; }
.user-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role { display: block; font-size: 11.5px; color: var(--ink-soft); }

/* Filtri dell'inbox */
.inbox-filters {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.inbox-filters button {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: all 150ms var(--ease-out);
}
.inbox-filters button:hover { border-color: var(--border-strong); color: var(--ink); }
.inbox-filters button.active {
  background: var(--accent-soft);
  border-color: var(--accent-soft-border);
  color: var(--accent-deep);
}

/* Badge assegnatario nella lista chat */
.chat-row-assignee { display: block; margin-top: 4px; }
.assignee-pill {
  display: inline-block;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: oklch(0.94 0.005 165);
  color: var(--ink-soft);
}
.assignee-pill.mine {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

/* Barra di assegnazione nell'intestazione della chat */
.chat-pane-head { display: flex; align-items: center; gap: 12px; }
/* Il titolo cede spazio al pulsante "copia link" e ai controlli a destra. */
.chat-pane-head > strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-chat-link { flex: none; margin-left: -6px; }
.assign-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.assign-bar span { margin-left: 0; }
.assign-select {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}
.assign-select select {
  width: auto;
  padding: 5px 8px;
  font-size: 13px;
}
.assign-tag {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 2px 8px;
  border-radius: 999px;
  background: oklch(0.94 0.005 165);
}
.assign-tag.mine { background: var(--accent-soft); color: var(--accent-deep); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------------------------------------------------------------------------
   Registro delle esecuzioni
   --------------------------------------------------------------------------- */
.log-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.log-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.log-toolbar .inbox-filters { margin-top: 0; flex: 0 0 auto; }
.log-toolbar #log-search,
.log-toolbar #contact-search { flex: 1; min-width: 180px; }

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  overflow: hidden;
  background: var(--surface);
}
.log-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.log-list li:last-child { border-bottom: none; }
.log-list li:nth-child(even) { background: oklch(0.985 0.003 165); }

.log-time {
  flex: 0 0 auto;
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  width: 108px;
  padding-top: 2px;
}
.badge.log-type { flex: 0 0 auto; margin-top: 1px; }
.badge.log-type.flow { background: var(--accent-soft); color: var(--accent-deep); }
.badge.log-type.scheduled { background: var(--warn-soft); color: var(--warn-ink); }
.badge.log-type.manual { background: oklch(0.93 0.03 250); color: oklch(0.42 0.09 260); }
.badge.log-type.webhook_in, .badge.log-type.webhook_out { background: oklch(0.93 0.035 300); color: oklch(0.42 0.1 300); }
.badge.log-type.system { background: oklch(0.94 0.005 165); color: var(--ink-soft); }

.log-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.log-event { font-size: 13px; color: var(--ink); }
.log-detail {
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-meta { font-size: 11.5px; color: var(--ink-faint); }

/* Azioni connessione WhatsApp in Dashboard */
.conn-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Pannello guardia invii */
.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-head-row h2 { margin: 0; }
.panel-sub { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; line-height: 1.5; }
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-deep);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}


/* ---- Menu variabili (@) ---- */
#var-menu {
  position: absolute;
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px oklch(0.3 0.02 170 / 0.14);
  padding: 6px;
  max-height: 260px;
  overflow-y: auto;
}
#var-menu .var-menu-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  padding: 4px 8px 6px;
}
#var-menu button {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  background: none;
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
#var-menu button:hover,
#var-menu button.sel { background: var(--accent-soft); }
#var-menu .var-menu-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--accent-deep);
  white-space: nowrap;
}
#var-menu .var-menu-label {
  font-size: 12.5px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Pannello contatto nell'Inbox (stile Spoki) ---- */
.contact-pane {
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
@media (min-width: 1200px) {
  .inbox-grid.chat-open { grid-template-columns: 300px 1fr 290px; }
  .inbox-grid.chat-open .contact-pane { display: flex; }
}
.cp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.cp-head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
}
.cp-body { padding: 14px 16px 20px; }
.cp-name {
  font-size: 16px;
  font-weight: 650;
  color: var(--accent-deep);
  margin-bottom: 8px;
}
.cp-optout {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: 2px;
}
.cp-sect {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin: 14px 0 6px;
}
.cp-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}
.cp-row .cp-label { color: var(--ink-soft); flex-shrink: 0; }
.cp-row span:last-child {
  text-align: right;
  overflow-wrap: anywhere;
}
.cp-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.cp-notes {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: pre-wrap;
}
.cp-actions { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.cp-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
}
.cp-empty .btn { margin-top: 10px; }
