/* ============================================================
   Lawyer Chat — виджет в стиле сайта
   Использует CSS-переменные темы (--color-*)
   ============================================================ */

/* ── Container ── */
.lwchat {
  --lw-accent: var(--color-accent, #1e40af);
  --lw-accent-hover: var(--color-accent-hover, #1d4ed8);
  --lw-bg: var(--color-bg, #fafafa);
  --lw-surface: var(--color-surface, #ffffff);
  --lw-text: var(--color-text, #1a1a2e);
  --lw-muted: var(--color-text-muted, #64748b);
  --lw-border: var(--color-border, #e2e8f0);
  --lw-radius: 1rem;
  --lw-panel-w: 380px;
  --lw-panel-h: 540px;

  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 9999;
  font-family: var(--font-sans, "Inter", system-ui, -apple-system, sans-serif);
  font-size: 14px;
  line-height: 1.5;
  color: var(--lw-text);
}

/* ── FAB ── */
.lwchat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--lw-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .18);
  transition: background .2s, transform .2s, box-shadow .2s;
}
.lwchat-fab:hover {
  background: var(--lw-accent-hover);
  transform: scale(1.06);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .22);
}

.lwchat-fab-icon { width: 24px; height: 24px; transition: opacity .2s, transform .2s; }
.lwchat-fab-icon--close { position: absolute; opacity: 0; transform: rotate(-90deg) scale(.6); }

[data-state="open"] .lwchat-fab-icon--chat  { opacity: 0; transform: rotate(90deg) scale(.6); }
[data-state="open"] .lwchat-fab-icon--close { opacity: 1; transform: rotate(0) scale(1); }

/* Badge */
.lwchat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  pointer-events: none;
}

/* ── Panel ── */
.lwchat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: var(--lw-panel-w);
  height: var(--lw-panel-h);
  max-height: calc(100dvh - 120px);
  border-radius: var(--lw-radius);
  background: var(--lw-surface);
  border: 1px solid var(--lw-border);
  box-shadow: 0 12px 48px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.96);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}

[data-state="open"] .lwchat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ── */
.lwchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--lw-accent);
  color: #fff;
  flex-shrink: 0;
}
.lwchat-header__info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.lwchat-header__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.lwchat-header__avatar svg { width: 18px; height: 18px; color: #fff; }
.lwchat-header__title { font-weight: 600; font-size: 15px; }
.lwchat-header__status { font-size: 12px; opacity: .82; }
.lwchat-header__close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background .15s;
}
.lwchat-header__close:hover { background: rgba(255,255,255,.18); }
.lwchat-header__close svg { width: 20px; height: 20px; }

/* ── Messages ── */
.lwchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--lw-bg);
  scroll-behavior: smooth;
}

.lwchat-greeting {
  padding: 10px 14px;
  border-radius: 12px 12px 12px 4px;
  background: var(--lw-surface);
  border: 1px solid var(--lw-border);
  color: var(--lw-muted);
  font-size: 13px;
  max-width: 85%;
  align-self: flex-start;
}
.lwchat-greeting:empty { display: none; }

/* Bubbles */
.lwchat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  word-break: break-word;
  position: relative;
  animation: lwchat-fadein .2s ease;
}
@keyframes lwchat-fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.lwchat-msg--visitor {
  align-self: flex-end;
  background: var(--lw-accent);
  color: #fff;
  border-radius: 12px 12px 4px 12px;
}
.lwchat-msg--agent {
  align-self: flex-start;
  background: var(--lw-surface);
  border: 1px solid var(--lw-border);
  color: var(--lw-text);
  border-radius: 12px 12px 12px 4px;
}
.lwchat-msg__time {
  display: block;
  font-size: 11px;
  margin-top: 4px;
  opacity: .6;
}
.lwchat-msg--visitor .lwchat-msg__time { text-align: right; }

/* Typing indicator */
.lwchat-typing {
  align-self: flex-start;
  display: none;
  gap: 4px;
  padding: 10px 16px;
  border-radius: 12px 12px 12px 4px;
  background: var(--lw-surface);
  border: 1px solid var(--lw-border);
}
.lwchat-typing.is-visible { display: flex; }
.lwchat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--lw-muted);
  animation: lwchat-bounce .6s infinite alternate;
}
.lwchat-typing span:nth-child(2) { animation-delay: .15s; }
.lwchat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes lwchat-bounce { to { transform: translateY(-4px); opacity: .4; } }

/* ── File preview ── */
.lwchat-file-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  margin: 0;
  border-top: 1px solid var(--lw-border);
  background: var(--lw-bg);
  flex-shrink: 0;
}
.lwchat-file-preview__info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.lwchat-file-preview__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--lw-accent);
}
.lwchat-file-preview__name {
  font-size: 13px;
  font-weight: 500;
  color: var(--lw-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.lwchat-file-preview__size {
  font-size: 11px;
  color: var(--lw-muted);
  flex-shrink: 0;
}
.lwchat-file-preview__remove {
  background: none;
  border: none;
  color: var(--lw-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color .15s;
}
.lwchat-file-preview__remove:hover { color: #ef4444; }
.lwchat-file-preview__remove svg { width: 16px; height: 16px; }

/* ── Input ── */
.lwchat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 12px 12px;
  border-top: 1px solid var(--lw-border);
  background: var(--lw-surface);
  flex-shrink: 0;
}
.lwchat-input__file-native {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
.lwchat-input__attach {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--lw-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.lwchat-input__attach:hover {
  color: var(--lw-accent);
  background: var(--lw-bg);
}
.lwchat-input__attach svg { width: 18px; height: 18px; }
.lwchat-input__field {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--lw-text);
  padding: 0;
}
.lwchat-input__field::placeholder { color: var(--lw-muted); }
.lwchat-input__send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--lw-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, opacity .15s;
}
.lwchat-input__send:disabled { opacity: .4; cursor: default; }
.lwchat-input__send:not(:disabled):hover { background: var(--lw-accent-hover); }
.lwchat-input__send svg { width: 16px; height: 16px; }

/* File in message bubble */
.lwchat-msg__file {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0,0,0,.06);
  font-size: 12px;
  text-decoration: none;
  color: inherit;
  transition: background .15s;
}
.lwchat-msg--visitor .lwchat-msg__file { background: rgba(255,255,255,.18); }
.lwchat-msg__file:hover { background: rgba(0,0,0,.1); }
.lwchat-msg--visitor .lwchat-msg__file:hover { background: rgba(255,255,255,.28); }
.lwchat-msg__file svg { width: 14px; height: 14px; flex-shrink: 0; }
.lwchat-msg__file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.lwchat-msg__img {
  margin-top: 6px;
  max-width: 100%;
  border-radius: 8px;
  cursor: pointer;
}
.lwchat-msg--visitor .lwchat-msg__img { border: 1px solid rgba(255,255,255,.2); }

/* ── Mobile ── */
@media (max-width: 480px) {
  .lwchat-panel {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    border: none;
  }
  [data-state="open"] .lwchat-fab { display: none; }
}
