/* Empire Chat — CSS */

.empire-chat {
  --ec-bg: #ffffff;
  --ec-panel: rgba(0,0,0,.04);
  --ec-panel2: rgba(0,0,0,.025);
  --ec-border: rgba(15,23,42,.10);
  --ec-text: #1e293b;
  --ec-muted: #64748b;
  --ec-accent: #22c55e;
  --ec-accentHover: #16a34a;
  --ec-accentText: #fff;
  --ec-msgBg: rgba(0,0,0,.025);
  --ec-msgBorder: rgba(0,0,0,.07);
  --ec-msgMeBg: rgba(34,197,94,.06);
  --ec-msgMeBorder: rgba(34,197,94,.20);
  --ec-inputBg: #fff;
  --ec-inputBorder: rgba(15,23,42,.12);
  --ec-link: #16a34a;
  --ec-shadow: 0 8px 24px rgba(0,0,0,.06);
  --ec-headBg: linear-gradient(180deg, rgba(0,0,0,.03) 0%, transparent 100%);
}

[data-theme="dark"] .empire-chat {
  --ec-bg: #191b22;
  --ec-panel: rgba(255,255,255,.04);
  --ec-panel2: rgba(255,255,255,.025);
  --ec-border: rgba(255,255,255,.08);
  --ec-text: #e2e5ea;
  --ec-muted: #9da3ad;
  --ec-accent: #22c55e;
  --ec-accentHover: #4ade80;
  --ec-accentText: #000;
  --ec-msgBg: rgba(255,255,255,.035);
  --ec-msgBorder: rgba(255,255,255,.06);
  --ec-msgMeBg: rgba(34,197,94,.08);
  --ec-msgMeBorder: rgba(34,197,94,.25);
  --ec-inputBg: #15171d;
  --ec-inputBorder: rgba(255,255,255,.10);
  --ec-link: #4ade80;
  --ec-shadow: 0 8px 24px rgba(0,0,0,.35);
  --ec-headBg: linear-gradient(180deg, rgba(255,255,255,.03) 0%, transparent 100%);
}

.empire-chat {
  width: 100%;
  max-width: 300px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ec-bg);
  color: var(--ec-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Status */
.empire-chat__status { font-size: 11px; color: var(--ec-muted); }
.empire-chat__status--online { color: var(--ec-accent); }

/* Messages */
.empire-chat__messages-wrap { position: relative; flex: 1 1 auto; display: flex; min-height: 0; }
.empire-chat__messages { padding: 10px; flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; background: var(--ec-bg); }

.empire-chat__down {
  position: absolute; right: 10px; bottom: 10px;
  border-radius: 999px;
  border: 1px solid var(--ec-border);
  background: var(--ec-bg);
  color: var(--ec-text);
  font-weight: 800;
  cursor: pointer;
  padding: 6px 10px;
  font-size: 11px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.empire-chat__down:hover { border-color: rgba(34,197,94,.4); }

/* Message */
.empire-chat__msg {
  padding: 9px 10px;
  background: var(--ec-msgBg);
  border: 1px solid var(--ec-msgBorder);
  border-radius: 12px;
  margin-bottom: 8px;
}
.empire-chat__msg--me { border-color: var(--ec-msgMeBorder); background: var(--ec-msgMeBg); }

.empire-chat__meta { display:flex; justify-content:space-between; gap:8px; font-size:11px; margin-bottom:4px; }
.empire-chat__user { font-weight: 850; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empire-chat__time { color: var(--ec-muted); white-space: nowrap; font-size: 10px; }

.empire-chat__text { font-size: 13px; line-height: 1.45; word-break: break-word; }
.empire-chat__text a { color: var(--ec-link); text-decoration: underline; text-underline-offset: 2px; }

.empire-chat__quote {
  padding: 6px 8px;
  margin-bottom: 6px;
  border-left: 3px solid var(--ec-accent);
  background: var(--ec-panel);
  border-radius: 0 8px 8px 0;
  font-size: 12px;
  color: var(--ec-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Actions (Ответить) — красивее */
.empire-chat__actions { margin-top: 6px; display: flex; gap: 8px; }
.empire-chat__act {
  border: 1px solid var(--ec-border);
  background: var(--ec-panel2);
  color: var(--ec-text);
  font-weight: 800;
  cursor: pointer;
  padding: 5px 10px;
  font-size: 11px;
  border-radius: 999px;
  transition: background .15s, border-color .15s, transform .1s;
}
.empire-chat__act:hover { background: var(--ec-panel); border-color: rgba(34,197,94,.35); }
.empire-chat__act:active { transform: translateY(1px); }
.empire-chat__act--del { color: #ef4444; border-color: rgba(239,68,68,.2); }
.empire-chat__act--del:hover { background: rgba(239,68,68,.08); border-color: rgba(239,68,68,.35); color: #dc2626; }

/* Bottom */
.empire-chat__bottom {
  padding: 10px;
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--ec-border);
  background: var(--ec-panel2);
}

.empire-chat__reply {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px;
  border-radius: 12px;
  border: 1px solid rgba(34,197,94,.45);
  border-left: 3px solid var(--ec-accent);
  background: rgba(34,197,94,.08);
  font-size: 11px;
}
.empire-chat__reply-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empire-chat__reply-cancel {
  border-radius: 10px;
  border: 1px solid var(--ec-border);
  background: transparent;
  color: var(--ec-text);
  cursor: pointer;
  padding: 2px 8px;
  font-size: 16px;
  line-height: 1;
}
.empire-chat__reply-cancel:hover { background: rgba(239,68,68,.12); color: #ef4444; border-color: rgba(239,68,68,.3); }

.empire-chat__tools { display:flex; align-items:center; justify-content:center; gap: 8px; flex-wrap: wrap; }

.empire-chat__emoji { display:flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.empire-chat__emoji button {
  border-radius: 10px;
  border: 1px solid var(--ec-border);
  background: var(--ec-panel2);
  cursor: pointer;
  padding: 5px 7px;
  font-size: 14px;
  line-height: 1;
  transition: background .15s, transform .1s, border-color .15s;
}
.empire-chat__emoji button:hover { background: var(--ec-panel); border-color: rgba(34,197,94,.25); transform: scale(1.08); }

.empire-chat__btn {
  border-radius: 999px;
  border: 1px solid var(--ec-border);
  background: var(--ec-panel);
  color: var(--ec-text);
  font-weight: 900;
  cursor: pointer;
  padding: 7px 12px;
  font-size: 12px;
  line-height: 1;
  transition: background .15s, border-color .15s, transform .1s;
}
.empire-chat__btn:hover { background: var(--ec-panel2); border-color: rgba(34,197,94,.35); }
.empire-chat__btn:active { transform: translateY(1px); }

.empire-chat__btn--light {
  background: transparent;
  border-color: rgba(100,116,139,.35);
  color: var(--ec-muted);
}
.empire-chat__btn--light:hover {
  background: rgba(100,116,139,.10);
  border-color: rgba(100,116,139,.55);
  color: var(--ec-text);
}

.empire-chat__input {
  width: 100%;
  resize: none;
  border-radius: 14px;
  border: 1px solid var(--ec-inputBorder) !important;
  background: var(--ec-inputBg) !important;
  color: var(--ec-text) !important;
  padding: 10px 12px;
  outline: none;
  font-size: 13px;
  font-family: inherit;
}
.empire-chat__input:focus { border-color: rgba(34,197,94,.65) !important; box-shadow: 0 0 0 3px rgba(34,197,94,.12); }

.empire-chat__send {
  border-radius: 14px;
  border: 1px solid var(--ec-accent);
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  color: #fff;
  font-weight: 950;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  transition: box-shadow .15s, transform .1s;
}
.empire-chat__send:hover { box-shadow: 0 10px 26px rgba(34,197,94,.30); transform: translateY(-1px); }
.empire-chat__send:active { transform: translateY(0); }

/* Badge (если используешь) */
.empire-chat__badge {
  border-radius: 999px;
  border: 1px solid var(--ec-accent);
  background: var(--ec-accent);
  color: var(--ec-accentText);
  font-weight: 950;
  cursor: pointer;
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1;
  justify-self: start;
}

/* Не наследовать uppercase */
.empire-chat button,
.empire-chat textarea {
  text-transform: none !important;
  letter-spacing: normal !important;
}

/* Overlay */
.eg-chat-overlay{
  position: fixed; inset: 0;
  z-index: 2147483000;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}
.eg-chat-overlay--active { opacity: 1; visibility: visible; }

/* Panel */
.eg-chat-panel{
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%) scale(.98);
  z-index: 2147483001;

  width: 420px;
  max-width: calc(100vw - 24px);

  height: 560px;
  max-height: calc(100vh - 40px);

  display:flex;
  flex-direction: column;

  background: var(--ec-bg, #fff);
  border: 1px solid var(--ec-border, rgba(15,23,42,.10));
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,.22);

  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease, transform .2s ease;
  overflow: hidden;
  user-select: none;
}
.eg-chat-panel--open{
  transform: translate(-50%,-50%) scale(1);
  opacity: 1; visibility: visible; pointer-events: auto;
}

/* Dragging: только transition off */
.eg-chat-panel--dragging{ transition:none !important; }

/* Manual-mode (после drag) — без translate */
.eg-chat-panel.eg-chat-panel--manual,
.eg-chat-panel.eg-chat-panel--manual.eg-chat-panel--open{
  transform:none !important;
}

.eg-chat-panel__head{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ec-border, rgba(15,23,42,.10));
  background: var(--ec-headBg, linear-gradient(180deg, rgba(0,0,0,.03) 0%, transparent 100%));
  flex-shrink:0;
  cursor: grab;
}
.eg-chat-panel__head:active{ cursor: grabbing; }

.eg-chat-panel__title{
  display:flex;
  align-items:center;
  gap: 8px;
  font-weight: 900;
  font-size: 15px;
  color: var(--ec-text, #1e293b);
}
.eg-chat-panel__title svg{ color: #22c55e; flex-shrink: 0; }

.eg-chat-panel__head-actions{
  display:flex;
  align-items:center;
  gap: 8px;
  flex-shrink: 0;
}

/* Кнопка-иконка (звук) */
.eg-chat-panel__iconbtn{
  width: 40px; height: 32px;
  border-radius: 12px;
  border: 1px solid rgba(15,23,42,.18);
  background: rgba(255,255,255,.70);
  color: #0f172a;
  cursor: pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 15px;
  line-height: 1;
  transition: background .15s, border-color .15s, transform .1s, color .15s;
}
.eg-chat-panel__iconbtn:hover{
  background: rgba(34,197,94,.12);
  border-color: rgba(34,197,94,.35);
  transform: translateY(-1px);
}
.eg-chat-panel__iconbtn:active{ transform: translateY(0); }

/* Close — крестик фикс */
.eg-chat-panel__close{
  width: 40px; height: 32px;
  border-radius: 12px;
  border: 1px solid rgba(15,23,42,.18);
  background: rgba(255,255,255,.70);
  color: #0f172a;
  cursor: pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  transition: background .15s, border-color .15s, transform .1s, color .15s;
}
.eg-chat-panel__close svg{ width: 18px; height: 18px; display:block; }
.eg-chat-panel__close svg path{
  stroke: currentColor !important;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.eg-chat-panel__close:hover{
  background: rgba(239,68,68,.14);
  border-color: rgba(239,68,68,.35);
  color: #ef4444;
  transform: translateY(-1px);
}
.eg-chat-panel__close:active{ transform: translateY(0); }

/* Chat inside panel */
.eg-chat-panel .empire-chat{
  flex: 1;
  height: 100%;
  max-width:none;
  border:none;
  border-radius:0;
  box-shadow:none;
  user-select:text;
}

/* Dark panel buttons */
[data-theme="dark"] .eg-chat-panel{
  background:#191b22;
  border-color: rgba(255,255,255,.10);
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
}
[data-theme="dark"] .eg-chat-panel__title{ color:#e2e5ea; }

[data-theme="dark"] .eg-chat-panel__iconbtn,
[data-theme="dark"] .eg-chat-panel__close{
  border-color: rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: #e2e8f0;
}
[data-theme="dark"] .eg-chat-panel__iconbtn:hover{
  background: rgba(34,197,94,.20);
  border-color: rgba(34,197,94,.35);
}
[data-theme="dark"] .eg-chat-panel__close:hover{
  background: rgba(239,68,68,.22);
  border-color: rgba(239,68,68,.35);
  color: #ef4444;
}

/* Mobile */
@media (max-width: 768px){
  .eg-chat-panel{
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    top: auto; left: 8px; right: 8px; bottom: 8px;
    transform: translateY(30px) scale(.98);
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
    border-radius: 18px;
  }
  .eg-chat-panel--open{ transform: translateY(0) scale(1); }
  .eg-chat-panel__head{ cursor: default; }
}