/**
 * MilMit Chat - Modern Animated Frontend Styles
 * Performance & SEO Optimized (Hardware-Accelerated, Zero Cumulative Layout Shift)
 */

:root {
  --mmc-accent: #2563eb;
  --mmc-accent-hover: #1d4ed8;
  --mmc-accent-light: rgba(37, 99, 235, 0.1);
  --mmc-font: inherit;
  --mmc-bg: #ffffff;
  --mmc-text: #1e293b;
  --mmc-text-muted: #64748b;
  --mmc-border: #e2e8f0;
  --mmc-radius-lg: 20px;
  --mmc-radius-md: 12px;
  --mmc-radius-sm: 8px;
  --mmc-shadow-launcher: 0 10px 25px -5px rgba(37, 99, 235, 0.4), 0 8px 10px -6px rgba(37, 99, 235, 0.3);
  --mmc-shadow-panel: 0 20px 40px -10px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.05);
}

/* Base Widget Container (Fixed, GPU Layer, Zero Layout Shift) */
.mmc,
.mmc button,
.mmc input,
.mmc textarea,
.mmc select {
  font-family: var(--mmc-font, inherit);
}

.mmc {
  position: fixed;
  z-index: 999999;
  bottom: 24px;
  right: 24px;
  direction: rtl;
  text-align: right;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

.mmc *, .mmc *::before, .mmc *::after {
  box-sizing: inherit;
}

/* Strictly Hide All Hidden Elements (Prevents display:flex override) */
.mmc [hidden],
.mmc-panel [hidden],
.mmc-chat[hidden],
.mmc-profile[hidden],
.mmc-typing-indicator[hidden],
.mmc-rec-bar[hidden],
.mmc-toast[hidden],
.mmc-badge[hidden] {
  display: none !important;
}

/* Position Left or Right */
.mmc[data-position="left"] {
  left: 24px !important;
  right: auto !important;
}
.mmc[data-position="right"] {
  right: 24px !important;
  left: auto !important;
}

/* Floating Launcher Button */
.mmc-launch {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--mmc-accent);
  color: #ffffff;
  box-shadow: var(--mmc-shadow-launcher);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.28s ease, background-color 0.2s ease;
  will-change: transform;
}

.mmc-launch:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 14px 28px -4px rgba(37, 99, 235, 0.5), 0 10px 14px -6px rgba(37, 99, 235, 0.4);
}

.mmc-launch:active {
  transform: scale(0.96) translateY(0);
}

/* Ambient Pulse (Calls attention gently without hurting performance) */
@keyframes mmc-ambient-pulse {
  0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.45); }
  70% { box-shadow: 0 0 0 14px rgba(37, 99, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}

.mmc:not(.is-open) .mmc-launch {
  animation: mmc-ambient-pulse 3s infinite 2s;
}

/* Launcher Icon Transition (Morphing effect) */
.mmc-launch-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
}

.mmc-launch-icon-open {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.mmc-launch-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.mmc.is-open .mmc-launch-icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.mmc.is-open .mmc-launch-icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Unread Badge */
.mmc-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
  animation: mmc-badge-pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes mmc-badge-pop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* Chat Panel */
.mmc-panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 110px);
  background: var(--mmc-bg);
  border-radius: var(--mmc-radius-lg);
  box-shadow: var(--mmc-shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.07);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.92) translateY(24px);
  transform-origin: bottom right;
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
  pointer-events: none;
  will-change: transform, opacity;
}

.mmc[data-position="left"] .mmc-panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.mmc.is-open .mmc-panel {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* Header */
.mmc-header {
  padding: 16px 20px;
  background: var(--mmc-accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.mmc-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mmc-status-indicator {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mmc-status-dot {
  width: 10px;
  height: 10px;
  background-color: #22c55e;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 8px #22c55e;
}
.mmc-status-dot.is-offline { background:#94a3b8; box-shadow:none; animation:none; }
.mmc-msg.is-pending { opacity:.72; }
.mmc-msg.is-failed { background:#b91c1c; cursor:pointer; }
.mmc-msg-meta:is(button) { border:0; padding:0; background:transparent; color:inherit; cursor:pointer; font:inherit; }
.mmc-privacy { margin:0; color:var(--mmc-text-muted); font-size:11px; line-height:1.6; }
.mmc-chat-menu { display:flex; gap:4px; padding:5px 10px; border-top:1px solid var(--mmc-border); background:#fff; overflow-x:auto; }
.mmc-chat-menu button { border:0; background:transparent; color:var(--mmc-text-muted); font:inherit; font-size:10px; white-space:nowrap; cursor:pointer; }

.mmc-header-text {
  display: flex;
  flex-direction: column;
}

.mmc-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.mmc-subtitle {
  font-size: 12px;
  opacity: 0.88;
  margin-top: 2px;
}

.mmc-btn-close {
  background: rgba(255, 255, 255, 0.16);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.mmc-btn-close:hover {
  background: rgba(255, 255, 255, 0.26);
  transform: scale(1.05);
}

/* Toast Notifications (Replaces native alert) */
.mmc-toast {
  position: absolute;
  top: 72px;
  left: 16px;
  right: 16px;
  z-index: 100;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: var(--mmc-radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  animation: mmc-toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mmc-toast.is-success {
  background: #dcfce7;
  color: #166534;
  border-color: #bbf7d0;
}

@keyframes mmc-toast-in {
  0% { opacity: 0; transform: translateY(-10px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Onboarding Profile Screen */
.mmc-profile {
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  overflow-y: auto;
  background: #ffffff;
}

.mmc-profile-hero {
  text-align: center;
  margin-bottom: 8px;
}

.mmc-profile-avatar {
  width: 64px;
  height: 64px;
  background: var(--mmc-accent-light);
  color: var(--mmc-accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mmc-profile-desc {
  font-size: 13px;
  color: var(--mmc-text-muted);
  line-height: 1.6;
  margin: 0;
}

.mmc-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mmc-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--mmc-text);
}

.mmc-input {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--mmc-border);
  border-radius: var(--mmc-radius-md);
  background: #f8fafc;
  color: var(--mmc-text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.mmc-input:focus {
  background: #ffffff;
  border-color: var(--mmc-accent);
  box-shadow: 0 0 0 3px var(--mmc-accent-light);
}

.mmc-btn-primary {
  margin-top: 8px;
  width: 100%;
  padding: 13px;
  background: var(--mmc-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--mmc-radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.18s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.mmc-btn-primary:hover {
  background: var(--mmc-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.mmc-btn-primary:active {
  transform: translateY(0);
}

/* Chat Screen */
.mmc-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: calc(100% - 68px);
  overflow: hidden;
  background: #f8fafc;
}
.mmc-chat[hidden] {
  display: none !important;
}

/* Messages Scrollable Area */
.mmc-messages {
  flex: 1;
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Modern Scrollbars */
.mmc-messages::-webkit-scrollbar,
.mmc-profile::-webkit-scrollbar {
  width: 5px;
}
.mmc-messages::-webkit-scrollbar-thumb,
.mmc-profile::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 10px;
}

/* Message Bubbles */
.mmc-msg {
  position: relative;
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  animation: mmc-msg-in 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
}

@keyframes mmc-msg-in {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Visitor / Sender (Me) */
.mmc-msg.me {
  align-self: flex-start;
  margin-right: auto;
  background: var(--mmc-accent);
  color: #ffffff;
  border-bottom-left-radius: 4px;
}

/* Support Agent / Receiver (Them) */
.mmc-msg.them {
  align-self: flex-end;
  margin-left: auto;
  background: #ffffff;
  color: var(--mmc-text);
  border: 1px solid var(--mmc-border);
  border-bottom-right-radius: 4px;
}

.mmc-msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.75;
}

.mmc-msg img {
  max-width: 100%;
  border-radius: var(--mmc-radius-sm);
  display: block;
  margin-top: 4px;
}

.mmc-msg audio {
  max-width: 240px;
  height: 38px;
  margin-top: 6px;
  outline: none;
}

.mmc-msg a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

/* Typing Indicator */
.mmc-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 18px;
  background: transparent;
  color: var(--mmc-text-muted);
  font-size: 12px;
  animation: mmc-msg-in 0.2s ease;
}
.mmc-typing-indicator[hidden] {
  display: none !important;
}

.mmc-typing-indicator small {
  margin-right: 6px;
}

.mmc-dot {
  width: 6px;
  height: 6px;
  background-color: var(--mmc-text-muted);
  border-radius: 50%;
  opacity: 0.6;
  animation: mmc-typing-wave 1.4s infinite ease-in-out;
}

.mmc-dot:nth-child(1) { animation-delay: 0s; }
.mmc-dot:nth-child(2) { animation-delay: 0.2s; }
.mmc-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes mmc-typing-wave {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Audio Recording Bar */
.mmc-rec-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #fef2f2;
  border-top: 1px solid #fee2e2;
  animation: mmc-toast-in 0.25s ease;
}
.mmc-rec-bar[hidden] {
  display: none !important;
}

.mmc-rec-live {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #991b1b;
  font-weight: 500;
}

.mmc-rec-pulsing-dot {
  width: 10px;
  height: 10px;
  background: #dc2626;
  border-radius: 50%;
  animation: mmc-rec-dot-pulse 1.2s infinite ease-in-out;
}

@keyframes mmc-rec-dot-pulse {
  0% { transform: scale(0.9); opacity: 1; box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
  50% { transform: scale(1.15); opacity: 0.8; box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
  100% { transform: scale(0.9); opacity: 1; box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.mmc-rec-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-right: 4px;
}

.mmc-rec-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mmc-rec-cancel, .mmc-rec-finish {
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}

.mmc-rec-cancel {
  background: #fee2e2;
  color: #dc2626;
}
.mmc-rec-cancel:hover {
  background: #fecaca;
  transform: scale(1.08);
}

.mmc-rec-finish {
  background: #dc2626;
  color: #ffffff;
}
.mmc-rec-finish:hover {
  background: #b91c1c;
  transform: scale(1.08);
}

/* Footer & Input Area */
.mmc-footer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 14px;
  background: #ffffff;
  border-top: 1px solid var(--mmc-border);
  flex-shrink: 0;
}

.mmc-action-btn {
  background: none;
  border: none;
  color: var(--mmc-text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s, transform 0.15s;
  flex-shrink: 0;
}

.mmc-action-btn:hover {
  color: var(--mmc-accent);
  background-color: var(--mmc-accent-light);
  transform: scale(1.06);
}

.mmc-textarea-wrapper {
  flex: 1;
  min-height: 38px;
  display: flex;
  align-items: center;
}

.mmc-textarea {
  width: 100%;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  border: 1px solid var(--mmc-border);
  border-radius: 18px;
  background: #f8fafc;
  color: var(--mmc-text);
  resize: none;
  max-height: 90px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.mmc-textarea:focus {
  background: #ffffff;
  border-color: var(--mmc-accent);
  box-shadow: 0 0 0 2px var(--mmc-accent-light);
}

.mmc-send-btn {
  width: 38px;
  height: 38px;
  background: var(--mmc-accent);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, background-color 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.mmc-send-btn:hover {
  background: var(--mmc-accent-hover);
  transform: scale(1.06);
}

.mmc-send-btn:active {
  transform: scale(0.94);
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  .mmc {
    bottom: 16px;
    right: 16px;
  }
  .mmc[data-position="left"] {
    left: 16px !important;
  }
  .mmc-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
    transform-origin: center bottom;
  }
  .mmc.is-open .mmc-panel {
    transform: translateY(0);
  }
}

/* Accessible controls, uploads and modern mobile view */
.mmc-label small{color:var(--mmc-text-muted);font-size:11px;font-weight:400}
.mmc-chat-menu{gap:4px;padding:6px 10px max(6px,env(safe-area-inset-bottom))}
.mmc-chat-menu button{min-height:36px;font-size:12px;padding:6px 9px;border-radius:8px}
.mmc-chat-menu button:hover{background:#f1f5f9;color:var(--mmc-text)}
.mmc-upload-card{display:grid;grid-template-columns:1fr auto;gap:7px;padding:10px 14px;background:#fff;border-top:1px solid var(--mmc-border);font-size:11px}
.mmc-upload-card[hidden]{display:none}.mmc-upload-card>img{width:42px;height:42px;object-fit:cover;border-radius:7px;grid-row:1/3}.mmc-upload-info{display:flex;justify-content:space-between;gap:8px;grid-column:1/-1}.mmc-upload-card>img:not([hidden])+.mmc-upload-info{grid-column:2/-1}.mmc-upload-info strong{max-width:65%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mmc-upload-card progress{width:100%;accent-color:var(--mmc-accent)}.mmc-upload-card button{border:0;background:transparent;color:var(--mmc-accent);cursor:pointer}
.mmc-waveform{height:30px;display:flex;align-items:center;justify-content:center;gap:2px;flex:1}.mmc-waveform i{display:block;width:2px;height:4px;max-height:28px;border-radius:2px;background:#dc2626;transition:height .08s linear}
.mmc-confirm[hidden]{display:none}.mmc-confirm{position:absolute;inset:0;z-index:120;display:grid;place-items:center;padding:18px;background:rgba(15,23,42,.5);backdrop-filter:blur(2px)}.mmc-confirm-box{background:#fff;border-radius:14px;padding:20px;width:100%;box-shadow:0 20px 50px rgba(15,23,42,.25);outline:0}.mmc-confirm-box strong{font-size:15px}.mmc-confirm-box p{font-size:12px;color:var(--mmc-text-muted);line-height:1.7}.mmc-confirm-box>div{display:flex;justify-content:flex-end;gap:8px}.mmc-confirm-box button{min-height:38px;border:1px solid var(--mmc-border);border-radius:8px;background:#fff;padding:7px 14px;cursor:pointer}.mmc-confirm-box [data-mmc-confirm-ok]{background:#b91c1c;border-color:#b91c1c;color:#fff}
.mmc :is(button,input,textarea,a):focus-visible{outline:3px solid var(--mmc-accent);outline-offset:2px}
@media(max-width:480px){.mmc-panel{height:100dvh;max-height:100dvh}.mmc-footer{padding-bottom:max(10px,env(safe-area-inset-bottom))}}
@media(prefers-reduced-motion:reduce){.mmc *,.mmc *::before,.mmc *::after{animation-duration:.01ms!important;animation-iteration-count:1!important;scroll-behavior:auto!important;transition-duration:.01ms!important}}
/* Kept outside the viewport so bots that only skip display:none fields still fill it. */
.mmc-honeypot{position:absolute!important;inset-inline-start:-10000px!important;width:1px!important;height:1px!important;overflow:hidden!important;opacity:0!important;pointer-events:none!important}
