:root {
  --cw-green: #0f9f6e;
  --cw-green-dark: #087f5b;
  --cw-blue: #2454d6;
  --cw-ink: #0f172a;
  --cw-muted: #64748b;
  --cw-line: #d9e2ef;
  --cw-bg: #f5f7fb;
  --cw-card: #ffffff;
}

.cw-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9999;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cw-green), var(--cw-green-dark));
  color: white;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .28);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.cw-launcher:hover { transform: translateY(-1px); }
.cw-launcher svg { width: 28px; height: 28px; }
.cw-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #dc2626;
  color: white;
  border: 2px solid white;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  padding: 0 6px;
}
.cw-badge.show { display: inline-flex; }

.cw-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 9998;
  width: min(420px, calc(100vw - 28px));
  height: min(680px, calc(100vh - 118px));
  background: var(--cw-card);
  border: 1px solid var(--cw-line);
  border-radius: 14px;
  box-shadow: 0 28px 90px rgba(15, 23, 42, .32);
  overflow: hidden;
  display: none;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.cw-panel.open { display: grid; }
.cw-panel.cw-dragover::after {
  content: "Rilascia qui per allegare alla chat";
  position: absolute;
  inset: 58px 10px 58px;
  border: 2px dashed var(--cw-blue);
  border-radius: 12px;
  background: rgba(239,246,255,.92);
  color: var(--cw-blue);
  display: grid;
  place-items: center;
  font-weight: 900;
  z-index: 3;
  pointer-events: none;
}
.cw-head {
  background: linear-gradient(135deg, var(--cw-green), var(--cw-green-dark));
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.cw-title strong { display: block; font-size: 16px; }
.cw-title span { display: block; font-size: 12px; opacity: .88; margin-top: 2px; }
.cw-head-actions { display: flex; gap: 6px; align-items: center; }
.cw-icon-btn {
  border: 1px solid rgba(255,255,255,.32);
  background: rgba(255,255,255,.12);
  color: white;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-weight: 900;
}
.cw-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #eff6ff;
  border-bottom: 1px solid var(--cw-line);
}
.cw-tab {
  border: 0;
  background: transparent;
  color: var(--cw-blue);
  font-weight: 900;
  padding: 10px;
  cursor: pointer;
}
.cw-tab.active { background: white; color: var(--cw-ink); }

.cw-list,
.cw-chat {
  min-height: 0;
  overflow: auto;
  background: var(--cw-bg);
}
.cw-list { padding: 10px; display: grid; gap: 8px; align-content: start; }
.cw-thread {
  border: 1px solid var(--cw-line);
  background: white;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  text-align: left;
}
.cw-thread:hover { border-color: #9ec5fe; }
.cw-thread.active { border-color: var(--cw-green); box-shadow: 0 6px 18px rgba(15,159,110,.14); }
.cw-thread-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: start;
}
.cw-thread strong {
  display: block;
  color: var(--cw-ink);
  line-height: 1.25;
  font-size: 13px;
}
.cw-thread small {
  display: block;
  color: var(--cw-muted);
  margin-top: 5px;
  font-size: 11px;
}
.cw-unread {
  display: inline-flex;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  background: #dc2626;
  color: white;
  font-size: 11px;
  font-weight: 900;
  padding: 0 6px;
}
.cw-last {
  margin-top: 7px;
  color: var(--cw-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-empty {
  border: 1px dashed #cbd5e1;
  background: white;
  color: var(--cw-muted);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  font-size: 13px;
}
.cw-empty-action {
  display: grid;
  gap: 8px;
}
.cw-empty-action strong {
  color: var(--cw-ink);
  font-size: 14px;
}
.cw-empty-action span {
  line-height: 1.35;
}
.cw-empty-action a {
  width: max-content;
  max-width: 100%;
  justify-self: center;
  border-radius: 999px;
  background: var(--cw-blue);
  color: white;
  padding: 8px 12px;
  font-weight: 900;
  text-decoration: none;
  font-size: 12px;
}

.cw-chat { display: none; grid-template-rows: auto minmax(0, 1fr); }
.cw-chat.active { display: grid; }
.cw-chat-bar {
  background: white;
  border-bottom: 1px solid var(--cw-line);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}
.cw-chat-bar button {
  border: 1px solid var(--cw-line);
  background: #f8fafc;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}
.cw-chat-name strong { display: block; font-size: 13px; }
.cw-chat-name span { display: block; color: var(--cw-muted); font-size: 11px; margin-top: 2px; }
.cw-messages {
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cw-msg {
  max-width: 86%;
  background: white;
  border: 1px solid var(--cw-line);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 2px 8px rgba(15,23,42,.04);
}
.cw-msg.mine {
  align-self: flex-end;
  background: #dcfce7;
  border-color: #b8efc7;
}
.cw-msg-meta {
  color: var(--cw-muted);
  font-size: 10px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.cw-msg-body { white-space: pre-wrap; line-height: 1.38; font-size: 13px; color: var(--cw-ink); }
.cw-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 6px;
  margin-top: 8px;
}
.cw-att-link {
  border: 1px solid var(--cw-line);
  background: #f8fafc;
  border-radius: 7px;
  color: var(--cw-blue);
  padding: 5px 7px;
  font-size: 11px;
  font-weight: 800;
  text-decoration: none;
}
.cw-att-preview {
  min-width: 0;
  border: 1px solid var(--cw-line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
  color: var(--cw-blue);
  text-decoration: none;
  font-size: 11px;
  font-weight: 800;
}
.cw-att-preview.image {
  display: grid;
  grid-template-rows: 86px auto;
}
.cw-att-preview.image img {
  width: 100%;
  height: 86px;
  object-fit: cover;
  background: #e2e8f0;
}
.cw-att-preview.image span,
.cw-att-preview.pdf span:last-child {
  padding: 6px 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cw-att-preview.pdf {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
}
.cw-pdf-icon {
  align-self: stretch;
  display: grid;
  place-items: center;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 10px;
  font-weight: 900;
}

.cw-composer {
  border-top: 1px solid var(--cw-line);
  background: white;
  padding: 10px;
  display: none;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
}
.cw-composer.active { display: grid; }
.cw-emoji-panel,
.cw-file-list,
.cw-mention-suggest {
  grid-column: 1 / -1;
}
.cw-emoji-panel {
  border: 1px solid var(--cw-line);
  border-radius: 10px;
  background: #fff;
  padding: 7px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(31px, 1fr));
  gap: 5px;
  max-height: 138px;
  overflow: auto;
}
.cw-emoji-panel[hidden] { display: none; }
.cw-emoji-panel button {
  border: 1px solid transparent;
  background: #f8fafc;
  border-radius: 8px;
  min-height: 31px;
  cursor: pointer;
  font-size: 17px;
}
.cw-emoji-panel button:hover { border-color: #93b4ff; background: #eff6ff; }
.cw-mention-suggest {
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 14px 30px rgba(15, 23, 42, .14);
  display: grid;
  gap: 4px;
  max-height: 152px;
  overflow: auto;
  padding: 6px;
}
.cw-mention-suggest.hidden { display: none; }
.cw-mention-suggest button {
  border: 0;
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  display: grid;
  gap: 2px;
  padding: 7px 8px;
  text-align: left;
}
.cw-mention-suggest button:hover {
  background: #eff6ff;
}
.cw-mention-suggest strong {
  color: var(--cw-blue);
  font-size: 12px;
  line-height: 1.2;
}
.cw-mention-suggest span {
  color: var(--cw-muted);
  font-size: 11px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cw-file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cw-file-chip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--cw-line);
  background: #f8fafc;
  border-radius: 999px;
  padding: 5px 7px 5px 9px;
  color: var(--cw-ink);
  font-size: 11px;
  font-weight: 800;
}
.cw-file-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cw-file-chip button {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: #fee2e2;
  color: #b91c1c;
  cursor: pointer;
  font-weight: 900;
}
.cw-tool {
  align-self: end;
  min-width: 42px;
  width: auto;
  height: 42px;
  padding: 0 8px;
  border: 1px solid var(--cw-line);
  border-radius: 10px;
  background: #f8fafc;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 900;
}
.cw-composer textarea {
  min-height: 42px;
  max-height: 110px;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 10px 11px;
  font: inherit;
}
.cw-send {
  align-self: end;
  min-width: 52px;
  width: auto;
  height: 44px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--cw-green);
  color: white;
  font-weight: 900;
  cursor: pointer;
}
.cw-footer {
  border-top: 1px solid var(--cw-line);
  background: white;
  padding: 8px 10px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
}
.cw-footer a {
  color: var(--cw-blue);
  font-weight: 900;
  text-decoration: none;
  font-size: 12px;
}
.cw-status { color: var(--cw-muted); font-size: 11px; }

.cw-toast {
  position: fixed;
  right: 92px;
  bottom: 30px;
  z-index: 9997;
  max-width: min(340px, calc(100vw - 120px));
  background: #0f172a;
  color: white;
  border-radius: 10px;
  padding: 11px 13px;
  box-shadow: 0 16px 40px rgba(15,23,42,.25);
  opacity: 0;
  transform: translateY(8px);
  transition: .18s ease;
  pointer-events: none;
}
.cw-toast.show { opacity: 1; transform: translateY(0); }
.cw-toast strong { display: block; margin-bottom: 3px; }
.cw-toast span { font-size: 12px; opacity: .86; }

@media (max-width: 560px) {
  .cw-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 84px;
    height: min(680px, calc(100vh - 104px));
  }
  .cw-launcher { right: 16px; bottom: 16px; }
  .cw-toast { right: 82px; bottom: 22px; max-width: calc(100vw - 104px); }
}
