/* دردشة دعم مكعب — واجهة عائمة قابلة للتكبير، RTL، هوية داكنة تركوازية */
.mk-chat {
  --mkc-bg: #061018;
  --mkc-panel: #0a1a24;
  --mkc-panel-2: #0d2230;
  --mkc-line: rgba(45, 212, 191, 0.2);
  --mkc-teal: var(--mk-teal, #2dd4bf);
  --mkc-teal-dim: rgba(45, 212, 191, 0.14);
  --mkc-text: #e8faf6;
  --mkc-muted: rgba(232, 250, 246, 0.58);
  --mkc-visitor: rgba(45, 212, 191, 0.16);
  --mkc-visitor-border: rgba(45, 212, 191, 0.32);
  --mkc-admin: rgba(255, 255, 255, 0.1);
  --mkc-admin-border: rgba(255, 255, 255, 0.14);
  --mkc-danger: #fda4af;
  --mkc-warn: #fcd34d;
  --mkc-radius: 20px;
  --mkc-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
  position: fixed;
  inset-inline-end: max(18px, env(safe-area-inset-right));
  inset-block-end: max(18px, env(safe-area-inset-bottom));
  z-index: 80;
  font-family: var(--mk-font, "Cairo", system-ui, sans-serif);
  color: var(--mkc-text);
}

.mk-chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* FAB */
.mk-chat-fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 52px;
  padding: 0.75rem 1.15rem;
  border: 1px solid var(--mkc-line);
  border-radius: 999px;
  background: linear-gradient(155deg, rgba(45, 212, 191, 0.28), rgba(7, 20, 28, 0.96));
  color: var(--mkc-text);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.mk-chat-fab:hover {
  border-color: var(--mkc-teal);
  transform: translateY(-2px);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.48);
}
.mk-chat-fab:focus-visible {
  outline: 2px solid var(--mkc-teal);
  outline-offset: 3px;
}
.mk-chat-fab-dot {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #f43f5e;
  inset-block-start: 7px;
  inset-inline-end: 11px;
  box-shadow: 0 0 0 3px rgba(7, 20, 28, 0.85);
}
.mk-chat-fab span:last-child {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}
.mk-chat.is-open .mk-chat-fab {
  display: none;
}

/* Backdrop (expanded) */
.mk-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 12, 0.62);
  backdrop-filter: blur(4px);
  z-index: 0;
}
.mk-chat-backdrop[hidden] {
  display: none !important;
}

/* Panel — widget */
.mk-chat-panel {
  position: absolute;
  inset-inline-end: 0;
  inset-block-end: calc(100% + 14px);
  width: min(440px, calc(100vw - 28px));
  height: min(680px, calc(100dvh - 100px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(45, 212, 191, 0.1), transparent 55%),
    linear-gradient(180deg, var(--mkc-panel-2) 0%, var(--mkc-panel) 42%, var(--mkc-bg) 100%);
  border: 1px solid var(--mkc-line);
  border-radius: var(--mkc-radius);
  overflow: hidden;
  box-shadow: var(--mkc-shadow);
  z-index: 1;
}
.mk-chat-panel[hidden] {
  display: none !important;
}

/* Expanded — desktop centered modal */
.mk-chat.is-expanded .mk-chat-panel {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 48px));
  height: min(820px, calc(100dvh - 48px));
  border-radius: 22px;
}
.mk-chat.is-expanded .mk-chat-backdrop {
  display: block !important;
}
.mk-chat.is-expanded .mk-chat-ico-expand {
  display: none;
}
.mk-chat.is-expanded .mk-chat-ico-collapse {
  display: block !important;
}

/* Header */
.mk-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1rem 0.9rem;
  border-bottom: 1px solid var(--mkc-line);
  background: rgba(0, 0, 0, 0.16);
}
.mk-chat-head-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.mk-chat-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--mkc-teal-dim);
  color: var(--mkc-teal);
  border: 1px solid rgba(45, 212, 191, 0.28);
}
.mk-chat-head-text {
  min-width: 0;
}
.mk-chat-head h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  font-family: var(--mk-display, "El Messiri", sans-serif);
  line-height: 1.25;
}
.mk-chat-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  margin-top: 0.28rem;
}
.mk-chat-sub {
  margin: 0;
  color: var(--mkc-muted);
  font-size: 0.78rem;
  line-height: 1.3;
}
.mk-chat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.4;
  border: 1px solid transparent;
}
.mk-chat-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.mk-chat-badge[data-status="idle"],
.mk-chat-badge[data-status="new"] {
  color: #5eead4;
  background: rgba(45, 212, 191, 0.12);
  border-color: rgba(45, 212, 191, 0.28);
}
.mk-chat-badge[data-status="open"] {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(96, 165, 250, 0.3);
}
.mk-chat-badge[data-status="closed"] {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(251, 113, 133, 0.28);
}

.mk-chat-head-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: 0 0 auto;
}
.mk-chat-icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--mkc-text);
  cursor: pointer;
  transition: background 0.15s ease;
}
.mk-chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}
.mk-chat-icon-btn:focus-visible {
  outline: 2px solid var(--mkc-teal);
  outline-offset: 2px;
}
.mk-chat-ico-collapse[hidden] {
  display: none !important;
}

/* Body / messages */
.mk-chat-body {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 28%),
    transparent;
}
.mk-chat-user {
  margin: 0;
  padding: 0.55rem 1.1rem;
  font-size: 0.8rem;
  color: var(--mkc-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  background: rgba(45, 212, 191, 0.05);
}
.mk-chat-user strong {
  color: var(--mkc-teal);
  font-weight: 800;
}
.mk-chat-user[hidden] {
  display: none !important;
}

.mk-chat-msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 1rem 1.05rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(45, 212, 191, 0.35) transparent;
}
.mk-chat-msgs::-webkit-scrollbar {
  width: 8px;
}
.mk-chat-msgs::-webkit-scrollbar-track {
  background: transparent;
}
.mk-chat-msgs::-webkit-scrollbar-thumb {
  background: rgba(45, 212, 191, 0.28);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.mk-chat-empty {
  margin: auto;
  max-width: 28rem;
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--mkc-muted);
}
.mk-chat-empty p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.7;
}
.mk-chat-empty[hidden] {
  display: none !important;
}

.mk-chat-day {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.35rem 0 0.15rem;
  color: var(--mkc-muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.mk-chat-day::before,
.mk-chat-day::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}
.mk-chat-day span {
  flex: 0 0 auto;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.mk-chat-bubble {
  max-width: min(88%, 36rem);
  padding: 0.72rem 0.95rem 0.5rem;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 0.95rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}
.mk-chat-bubble.is-visitor {
  align-self: flex-start; /* يمين في RTL */
  background: var(--mkc-visitor);
  border: 1px solid var(--mkc-visitor-border);
  border-bottom-right-radius: 6px;
}
.mk-chat-bubble.is-admin {
  align-self: flex-end; /* يسار في RTL */
  background: var(--mkc-admin);
  border: 1px solid var(--mkc-admin-border);
  border-bottom-left-radius: 6px;
}
.mk-chat-bubble.is-system {
  align-self: center;
  max-width: 94%;
  text-align: center;
  color: var(--mkc-muted);
  font-size: 0.82rem;
  line-height: 1.55;
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  box-shadow: none;
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
}
.mk-chat-bubble-body {
  unicode-bidi: plaintext;
  display: block;
}
.mk-chat-meta {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.7rem;
  line-height: 1.2;
  color: var(--mkc-muted);
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}
.mk-chat-bubble.is-visitor .mk-chat-meta {
  text-align: start;
}
.mk-chat-bubble.is-admin .mk-chat-meta {
  text-align: end;
}
.mk-chat-bubble.is-system .mk-chat-meta {
  display: none;
}

/* Footer / compose — صف مضغوط بأسلوب واتساب */
.mk-chat-footer {
  border-top: 1px solid var(--mkc-line);
  background: rgba(0, 0, 0, 0.22);
  flex: 0 0 auto;
}
.mk-chat-login-gate {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem 0.9rem;
}
.mk-chat-login-gate[hidden] {
  display: none !important;
}
.mk-chat-login-gate p {
  margin: 0;
  color: var(--mkc-muted);
  font-size: 0.9rem;
  line-height: 1.55;
}
.mk-chat-form {
  display: grid;
  gap: 0.35rem;
  padding: 0.65rem 0.75rem 0.7rem;
}
.mk-chat-form[hidden] {
  display: none !important;
}
.mk-chat-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: end;
}
.mk-chat-compose textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  border: 1px solid var(--mkc-line);
  border-radius: 22px;
  background: rgba(4, 14, 20, 0.9);
  color: var(--mkc-text);
  padding: 0.65rem 0.95rem;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  resize: none;
  field-sizing: content;
}
.mk-chat-compose textarea::placeholder {
  color: rgba(232, 250, 246, 0.38);
}
.mk-chat-compose textarea:focus {
  outline: none;
  border-color: rgba(45, 212, 191, 0.55);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.12);
}
.mk-chat-compose textarea:disabled {
  opacity: 0.55;
}
.mk-chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  box-sizing: border-box;
  height: 44px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.95rem;
  border: 0;
  border-radius: 22px;
  background: linear-gradient(160deg, #5eead4, var(--mkc-teal));
  color: #04201c;
  font-weight: 800;
  font-size: 0.88rem;
  line-height: 1;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
  flex: 0 0 auto;
}
.mk-chat-send:hover:not(:disabled) {
  filter: brightness(1.05);
}
.mk-chat-send:active:not(:disabled) {
  transform: translateY(1px);
}
.mk-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.mk-chat-send:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.mk-chat-send-link {
  text-decoration: none;
  width: 100%;
  min-height: 44px;
  height: auto;
  border-radius: 14px;
}
.mk-chat-hint {
  margin: 0;
  min-height: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--mkc-danger);
}
.mk-chat-hint[hidden],
.mk-chat-hint:empty {
  display: none !important;
}
.mk-chat-hint.is-ok {
  color: var(--mkc-teal);
}
.mk-chat-keys {
  margin: 0;
  font-size: 0.68rem;
  line-height: 1.3;
  color: rgba(232, 250, 246, 0.38);
}
.mk-chat-offline .mk-chat-hint {
  color: var(--mkc-warn);
}

/* Mobile */
@media (max-width: 640px) {
  .mk-chat {
    inset-inline-end: 12px;
    inset-block-end: 12px;
  }
  .mk-chat-panel {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    height: min(86dvh, 720px);
    border-radius: 20px 20px 0 0;
  }
  .mk-chat.is-expanded .mk-chat-panel {
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    width: 100%;
    height: 100dvh;
    height: 100svh;
    border-radius: 0;
    padding-block-start: env(safe-area-inset-top);
    padding-block-end: env(safe-area-inset-bottom);
  }
  .mk-chat-fab span:last-child {
    display: none;
  }
  .mk-chat-fab {
    width: 54px;
    height: 54px;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
  }
  .mk-chat-bubble {
    max-width: 90%;
  }
  .mk-chat-form {
    padding: 0.55rem 0.65rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  }
  .mk-chat-compose {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }
  .mk-chat-send {
    width: 44px;
    padding: 0;
    border-radius: 50%;
  }
  .mk-chat-send [data-mk-chat-send-label] {
    display: none;
  }
  .mk-chat-keys {
    display: none;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .mk-chat-panel {
    width: min(460px, calc(100vw - 28px));
  }
  .mk-chat.is-expanded .mk-chat-panel {
    width: min(640px, calc(100vw - 40px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .mk-chat-fab,
  .mk-chat-send,
  .mk-chat-icon-btn {
    transition: none;
  }
  .mk-chat-msgs {
    scroll-behavior: auto;
  }
}
