/**
 * Bagback Sovereign Concierge — Tot Universal Chat Widget Styling
 * Built to Eng. Mohamed Osama's strict specifications:
 * - Pure luxury dark-mode responsive interface
 * - Strict Cairo font parity & balanced line spacing (1.72 line-height)
 * - Harmonious Arabic & English natural bubble alignment
 * - Styled bullet lists and accent highlights without raw unicode emojis
 * - Responsive 44px touch targets on mobile
 */

:root {
  --tot-font: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --tot-accent: #06B6D4;
  --tot-accent-glow: rgba(6, 182, 212, 0.45);
  --tot-accent-light: rgba(6, 182, 212, 0.14);
  --tot-header-bg: linear-gradient(135deg, #0e7490, #06b6d4);
  --tot-surface: #08222b;
  --tot-bg: #041217;
  --tot-border: rgba(6, 182, 212, 0.28);
  --tot-text-hi: #f8fafc;
  --tot-text-mid: #cbd5e1;
  --tot-text-muted: #94a3b8;
  --tot-user-bubble: var(--tot-accent);
  --tot-bot-bubble: rgba(15, 23, 42, 0.88);
  --tot-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.85), 0 0 25px -5px var(--tot-accent-glow);
}

/* ─────────────────────────────────────────────────────────────
   1. Floating Transparent Mascot (NO Box, NO Frame, NO Circle)
   ───────────────────────────────────────────────────────────── */
#tot-widget-mascot-launcher {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 999998;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: auto;
  font-family: var(--tot-font);
  user-select: none;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

[dir="rtl"] #tot-widget-mascot-launcher,
html[lang="ar"] #tot-widget-mascot-launcher {
  right: auto;
  left: 22px;
  align-items: flex-start;
}

/* Free-floating Mascot Character (Transparent, Free Standing) */
.tot-mascot-free-character {
  position: relative;
  background: transparent !important;
  border: none !important;
  padding: 0;
  cursor: pointer;
  outline: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.5));
}

.tot-mascot-free-character:hover {
  transform: scale(1.08) translateY(-4px);
  filter: drop-shadow(0 16px 24px var(--tot-accent-glow));
}

.tot-mascot-free-character:active {
  transform: scale(0.96) translateY(2px);
}

.tot-mascot-sprite-img {
  width: 78px;
  height: 82px;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
  image-rendering: auto;
}

/* Green Live Online Dot */
.tot-mascot-online-dot {
  position: absolute;
  bottom: 8px;
  right: 6px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #10b981;
  border: 2.5px solid #090d16;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.85);
}

[dir="rtl"] .tot-mascot-online-dot,
html[lang="ar"] .tot-mascot-online-dot {
  right: auto;
  left: 6px;
}

/* Subtle Soft Dismiss Cross (Appears on Hover only) */
.tot-mascot-hover-dismiss {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #cbd5e1;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, background 0.2s;
  z-index: 10;
}

[dir="rtl"] .tot-mascot-hover-dismiss,
html[lang="ar"] .tot-mascot-hover-dismiss {
  left: auto;
  right: -6px;
}

.tot-mascot-free-character:hover .tot-mascot-hover-dismiss {
  opacity: 1;
  pointer-events: auto;
}

.tot-mascot-hover-dismiss:hover {
  background: #ef4444;
  color: #fff;
  border-color: #ef4444;
}

/* ─────────────────────────────────────────────────────────────
   2. Main Chat Modal Window
   ───────────────────────────────────────────────────────────── */
#tot-widget-modal {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 384px;
  max-width: calc(100vw - 28px);
  height: 600px;
  max-height: calc(100vh - 40px);
  background: var(--tot-surface);
  border: 1px solid var(--tot-border);
  border-radius: 24px;
  box-shadow: var(--tot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  font-family: var(--tot-font);
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(0.96);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.25s;
}

[dir="rtl"] #tot-widget-modal,
html[lang="ar"] #tot-widget-modal {
  right: auto;
  left: 24px;
}

#tot-widget-modal.tot-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ─────────────────────────────────────────────────────────────
   3. Chat Header (Strict Specification: Title + EN/AR, Trash, History, Close)
   ───────────────────────────────────────────────────────────── */
.tot-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: var(--tot-header-bg);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.tot-header-title-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tot-header-avatar-img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.tot-header-main-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.2px;
  color: #ffffff;
  line-height: 1.25;
}

.tot-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tot-header-btn {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--tot-font);
  font-size: 12px;
  font-weight: 800;
  padding: 0;
}

.tot-header-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.05);
}

.tot-header-btn.tot-lang-toggle-btn {
  width: 38px;
  font-size: 11px;
}

.tot-header-btn.tot-header-close-btn:hover {
  background: #ef4444;
  border-color: #ef4444;
}

/* ─────────────────────────────────────────────────────────────
   4. Chat Messages Scroll Area
   ───────────────────────────────────────────────────────────── */
.tot-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--tot-bg);
  scroll-behavior: smooth;
}

.tot-modal-body::-webkit-scrollbar {
  width: 5px;
}

.tot-modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}

/* Message Bubble */
.tot-message-row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: totFadeIn 0.22s ease-out;
}

@keyframes totFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.tot-message-row.tot-msg-user {
  align-self: flex-end;
}

.tot-message-row.tot-msg-assistant {
  align-self: flex-start;
}

.tot-bubble {
  padding: 12px 15px;
  border-radius: 17px;
  font-size: 14px;
  line-height: 1.72;
  word-break: break-word;
  text-align: start;
}

.tot-bubble strong {
  color: var(--tot-accent);
  font-weight: 700;
}

.tot-msg-user .tot-bubble {
  background: var(--tot-user-bubble);
  color: #0b0f19;
  font-weight: 700;
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .tot-msg-user .tot-bubble,
html[lang="ar"] .tot-msg-user .tot-bubble {
  border-bottom-right-radius: 17px;
  border-bottom-left-radius: 4px;
}

.tot-msg-assistant .tot-bubble {
  background: var(--tot-bot-bubble);
  color: var(--tot-text-hi);
  border: 1px solid var(--tot-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

[dir="rtl"] .tot-msg-assistant .tot-bubble,
html[lang="ar"] .tot-msg-assistant .tot-bubble {
  border-bottom-left-radius: 17px;
  border-bottom-right-radius: 4px;
}

/* Clean Formatted Bullet Rows */
.tot-bullet-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 5px 0;
  text-align: start;
}

.tot-bullet-dot {
  color: var(--tot-accent);
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
  font-weight: 800;
}

.tot-bullet-text {
  flex: 1;
  line-height: 1.7;
}

.tot-inline-link {
  color: var(--tot-accent);
  text-decoration: underline;
  font-weight: 700;
  transition: opacity 0.2s;
}

.tot-inline-link:hover {
  opacity: 0.85;
}

/* Typing Indicator */
.tot-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--tot-bot-bubble);
  border: 1px solid var(--tot-border);
  border-radius: 16px;
  width: fit-content;
}

.tot-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tot-accent);
  opacity: 0.6;
  animation: totDotBounce 1.4s infinite ease-in-out;
}

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

@keyframes totDotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* ─────────────────────────────────────────────────────────────
   5. Tot Action Buttons (Audio Speak, Regenerate, Like, Dislike)
   ───────────────────────────────────────────────────────────── */
.tot-action-buttons-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 0 4px;
}

.tot-action-btn {
  background: transparent;
  border: none;
  color: var(--tot-text-muted);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  padding: 0;
}

.tot-action-btn:hover {
  color: var(--tot-accent);
  background: rgba(255, 255, 255, 0.08);
}

.tot-action-btn.tot-active-speak {
  color: #10b981;
  animation: totPulseBtn 1.2s infinite;
}

@keyframes totPulseBtn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.tot-action-btn.tot-liked {
  color: #10b981;
}

.tot-action-btn.tot-disliked {
  color: #ef4444;
}

/* Follow-up Smart Chips (Strictly Exactly 2 Questions) */
.tot-followup-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.tot-followup-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--tot-border);
  color: var(--tot-accent);
  border-radius: 12px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--tot-font);
  text-align: start;
}

.tot-followup-chip:hover {
  background: var(--tot-accent-light);
  border-color: var(--tot-accent);
  transform: translateY(-1px);
}

/* ─────────────────────────────────────────────────────────────
   6. The 4 Pinned Questions (2 Columns, 2 Words Each)
   ───────────────────────────────────────────────────────────── */
.tot-starter-questions-panel {
  padding: 10px 14px 6px;
  background: rgba(15, 23, 42, 0.75);
  border-top: 1px solid var(--tot-border);
  flex-shrink: 0;
}

.tot-starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.tot-starter-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--tot-border);
  border-radius: 11px;
  padding: 9px 8px;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--tot-accent);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--tot-font);
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tot-starter-btn:hover {
  background: var(--tot-accent-light);
  border-color: var(--tot-accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* ─────────────────────────────────────────────────────────────
   7. Input Container (Attach, Mic, Textarea, Send)
   ───────────────────────────────────────────────────────────── */
.tot-modal-input-form {
  padding: 10px 14px 14px;
  background: var(--tot-surface);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.tot-attached-file-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--tot-accent);
  border-radius: 8px;
  padding: 4px 10px;
  margin-bottom: 7px;
  font-size: 11.5px;
  color: var(--tot-text-hi);
  font-weight: 600;
}

.tot-remove-file-btn {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  padding: 0 4px;
}

.tot-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--tot-border);
  border-radius: 14px;
  padding: 5px 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tot-input-bar:focus-within {
  border-color: var(--tot-accent);
  box-shadow: 0 0 12px var(--tot-accent-light);
}

.tot-tool-icon-btn {
  background: transparent;
  border: none;
  color: var(--tot-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
  padding: 0;
}

.tot-tool-icon-btn:hover {
  color: var(--tot-accent);
  background: rgba(255, 255, 255, 0.08);
}

.tot-tool-icon-btn.tot-recording {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.18);
  animation: totMicPulse 1.2s infinite;
}

@keyframes totMicPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

.tot-textarea-wrap {
  flex: 1;
  display: flex;
  align-items: center;
}

#tot-chat-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--tot-text-hi);
  font-family: var(--tot-font);
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  max-height: 100px;
  padding: 6px 4px;
}

#tot-chat-input::placeholder {
  color: var(--tot-text-muted);
}

.tot-send-submit-btn {
  background: var(--tot-accent);
  border: none;
  color: #090d16;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  font-weight: 800;
}

.tot-send-submit-btn:hover {
  filter: brightness(1.12);
  transform: scale(1.04);
}

.tot-send-submit-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ─────────────────────────────────────────────────────────────
   8. History Side Drawer
   ───────────────────────────────────────────────────────────── */
.tot-history-drawer {
  position: absolute;
  inset: 0;
  background: var(--tot-surface);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

[dir="rtl"] .tot-history-drawer,
html[lang="ar"] .tot-history-drawer {
  transform: translateX(-100%);
}

.tot-history-drawer.tot-drawer-open {
  transform: translateX(0);
}

.tot-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--tot-border);
  background: rgba(0, 0, 0, 0.25);
}

.tot-history-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 800;
  color: var(--tot-text-hi);
}

.tot-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tot-history-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--tot-border);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--tot-text-mid);
  font-size: 12.5px;
  text-align: start;
}

.tot-history-item:hover {
  background: var(--tot-accent-light);
  border-color: var(--tot-accent);
  color: var(--tot-text-hi);
}

.tot-new-chat-btn {
  margin: 12px;
  background: var(--tot-accent);
  color: #090d16;
  border: none;
  border-radius: 12px;
  padding: 10px;
  font-family: var(--tot-font);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter 0.2s;
}

.tot-new-chat-btn:hover {
  filter: brightness(1.1);
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  #tot-widget-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    left: 0;
    border-radius: 0;
  }
}
