/* AFFiNCO Lead Chat */
.afc-root {
  --afc-accent: #E64A2E;
  --afc-bg: #0c111c;
  --afc-head: #111827;
  --afc-surface: #161e2e;
  --afc-border: rgba(255, 255, 255, .09);
  --afc-text: #eef2f8;
  --afc-muted: #94a0b4;
  --afc-chip: rgba(255, 255, 255, .04);
  --afc-shadow: 0 24px 60px rgba(2, 6, 23, .45), 0 2px 8px rgba(2, 6, 23, .3);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--afc-text);
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
}
.afc-root.afc-theme-light {
  --afc-bg: #ffffff;
  --afc-head: #ffffff;
  --afc-surface: #f2f5f9;
  --afc-border: #e2e8f0;
  --afc-text: #1a202c;
  --afc-muted: #64748b;
  --afc-chip: #ffffff;
  --afc-shadow: 0 24px 60px rgba(15, 23, 42, .18), 0 2px 8px rgba(15, 23, 42, .08);
}
.afc-root *, .afc-root *::before, .afc-root *::after { box-sizing: border-box; }
.afc-root button, .afc-root input, .afc-root textarea { font: inherit; color: inherit; margin: 0; }
.afc-root a { color: var(--afc-accent); }

/* ---------- placement ---------- */
.afc-floating { position: fixed; bottom: 20px; z-index: 2147483000; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.afc-floating.afc-pos-right { right: 20px; }
.afc-floating.afc-pos-left { left: 20px; align-items: flex-start; }
.afc-floating .afc-panel { width: 384px; height: min(620px, calc(100vh - 110px)); }
.afc-inline { width: 100%; max-width: 560px; margin: 0 auto; }
.afc-inline .afc-panel { height: 600px; max-height: 85vh; }

/* ---------- panel ---------- */
.afc-panel {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--afc-bg); border: 1px solid var(--afc-border); border-radius: 18px;
  box-shadow: var(--afc-shadow);
  transform-origin: bottom right;
  animation: afc-pop .22s ease-out;
}
.afc-pos-left .afc-panel { transform-origin: bottom left; }
.afc-panel[hidden] { display: none !important; }
@keyframes afc-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.afc-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 12px 16px; background: var(--afc-head); border-bottom: 1px solid var(--afc-border); }
.afc-avatar, .afc-launcher-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; border: 2px solid var(--afc-accent); }
.afc-initial { display: inline-flex; align-items: center; justify-content: center; background: var(--afc-accent); color: #fff; font-weight: 700; font-size: 17px; }
.afc-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.afc-who strong { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.afc-who span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--afc-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.afc-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); flex: 0 0 auto; }
.afc-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--afc-muted); cursor: pointer; padding: 0; }
.afc-icon:hover, .afc-icon:focus-visible { background: var(--afc-surface); color: var(--afc-text); }

.afc-progress { padding: 0 16px 10px; background: var(--afc-head); border-bottom: 1px solid var(--afc-border); }
.afc-bar { height: 3px; border-radius: 3px; background: var(--afc-border); overflow: hidden; }
.afc-bar span { display: block; height: 100%; width: 4%; background: var(--afc-accent); border-radius: 3px; transition: width .4s ease; }
.afc-stage { display: block; margin-top: 7px; font-size: 11.5px; color: var(--afc-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- messages ---------- */
.afc-log { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; overscroll-behavior: contain; }
.afc-msg { max-width: 86%; padding: 10px 13px; border-radius: 14px; word-wrap: break-word; overflow-wrap: anywhere; animation: afc-in .2s ease-out; }
@keyframes afc-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.afc-bot { align-self: flex-start; background: var(--afc-surface); border: 1px solid var(--afc-border); border-top-left-radius: 4px; }
.afc-me { align-self: flex-end; background: var(--afc-accent); color: #fff; border-top-right-radius: 4px; font-weight: 500; white-space: pre-wrap; }
.afc-bot a { font-weight: 600; text-decoration: underline; }
.afc-typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.afc-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--afc-muted); animation: afc-blink 1s infinite ease-in-out; }
.afc-typing span:nth-child(2) { animation-delay: .15s; }
.afc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes afc-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.afc-summary { max-width: 100%; width: 100%; padding: 6px 12px; }
.afc-summary dl { margin: 0; display: grid; grid-template-columns: auto 1fr; }
.afc-summary dt, .afc-summary dd { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--afc-border); font-size: 13px; }
.afc-summary dt { color: var(--afc-muted); padding-right: 12px; white-space: nowrap; }
.afc-summary dd { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.afc-summary dd span { white-space: pre-wrap; }
.afc-summary dt:last-of-type, .afc-summary dd:last-of-type { border-bottom: 0; }
.afc-edit { border: 0; background: none; color: var(--afc-accent); font-size: 12px; font-weight: 600; cursor: pointer; padding: 0 2px; flex: 0 0 auto; }
.afc-edit:hover { text-decoration: underline; }

/* ---------- input area ---------- */
.afc-input { padding: 10px 14px 12px; border-top: 1px solid var(--afc-border); max-height: 46%; overflow-y: auto; }
.afc-input:empty { display: none; }
.afc-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.afc-chip {
  border: 1px solid color-mix(in srgb, var(--afc-accent) 45%, var(--afc-border)); background: var(--afc-chip);
  border-radius: 999px; padding: 8px 13px; font-size: 13px; font-weight: 600; cursor: pointer; text-align: left;
  transition: background .15s, border-color .15s, transform .1s;
}
.afc-chip:hover, .afc-chip:focus-visible { background: color-mix(in srgb, var(--afc-accent) 16%, transparent); border-color: var(--afc-accent); }
.afc-chip:active { transform: scale(.98); }
.afc-form { display: flex; flex-direction: column; gap: 6px; }
.afc-row { display: flex; gap: 8px; align-items: flex-end; }
.afc-field {
  flex: 1; min-width: 0; resize: none; border: 1px solid var(--afc-border); background: var(--afc-surface);
  border-radius: 12px; padding: 10px 12px; font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.afc-field::placeholder { color: var(--afc-muted); opacity: .85; }
.afc-field:focus { border-color: var(--afc-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--afc-accent) 22%, transparent); }
.afc-field[aria-invalid="true"] { border-color: #ef4444; }
.afc-send { flex: 0 0 auto; width: 42px; height: 42px; border: 0; border-radius: 12px; background: var(--afc-accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.afc-send:hover { filter: brightness(1.08); }
.afc-err { margin: 0; min-height: 0; font-size: 12px; color: #f87171; }
.afc-err:empty { display: none; }
.afc-skip { align-self: flex-start; border: 0; background: none; color: var(--afc-muted); font-size: 12.5px; text-decoration: underline; cursor: pointer; padding: 2px 0; }
.afc-skip:hover { color: var(--afc-text); }
.afc-actions { display: flex; flex-direction: column; gap: 8px; }
.afc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  border: 1px solid var(--afc-accent); background: var(--afc-accent); color: #fff !important; border-radius: 12px;
  padding: 11px 14px; font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none !important;
}
.afc-btn:hover { filter: brightness(1.07); }
.afc-btn:disabled { opacity: .65; cursor: progress; }
.afc-btn-ghost { background: transparent; color: var(--afc-text) !important; border-color: var(--afc-border); font-weight: 600; }
.afc-btn-ghost:hover { background: var(--afc-surface); filter: none; }

.afc-foot { display: flex; justify-content: space-between; gap: 8px; padding: 8px 16px 10px; font-size: 11.5px; color: var(--afc-muted); border-top: 1px solid var(--afc-border); }
.afc-foot a { color: var(--afc-muted); text-decoration: underline; }
.afc-foot a:hover { color: var(--afc-text); }
.afc-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

/* ---------- launcher ---------- */
.afc-launcher {
  display: inline-flex; align-items: center; gap: 10px; border: 0; cursor: pointer;
  background: var(--afc-accent); color: #fff; border-radius: 999px; padding: 7px 16px 7px 7px;
  font-weight: 700; font-size: 14.5px; box-shadow: 0 10px 30px color-mix(in srgb, var(--afc-accent) 40%, transparent), 0 2px 6px rgba(0, 0, 0, .2);
  transition: transform .15s, box-shadow .15s;
}
.afc-launcher:hover { transform: translateY(-1px); }
.afc-launcher .afc-launcher-avatar { width: 36px; height: 36px; border-color: rgba(255, 255, 255, .8); }
.afc-launcher .afc-initial { background: rgba(255, 255, 255, .22); }
.afc-chev { display: inline-flex; transition: transform .2s; }
.afc-open .afc-chev { transform: rotate(180deg); }
.afc-root :focus-visible { outline: 2px solid var(--afc-accent); outline-offset: 2px; }

/* ---------- mobile ---------- */
@media (max-width: 520px) {
  .afc-floating { bottom: 14px; }
  .afc-floating.afc-pos-right { right: 14px; }
  .afc-floating.afc-pos-left { left: 14px; }
  .afc-floating.afc-open { left: 0; right: 0; bottom: 0; top: 0; gap: 0; }
  .afc-floating.afc-open .afc-panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
  .afc-floating.afc-open .afc-launcher { display: none; }
  .afc-field { font-size: 16px; } /* stops iOS zoom */
}
@media (prefers-reduced-motion: reduce) {
  .afc-root *, .afc-panel { animation: none !important; transition: none !important; }
}
@media print { .afc-host { display: none !important; } }
