/* ═══════════════════════════════════════════════════════════════
   BarkatBot AI Chat — Right-Side Drawer v3
   Professional slide-in panel, fully responsive
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ─────────────────────────────────── */
:root {
  --bb-gold: #c4a747;
  --bb-gold-dark: #a8893a;
  --bb-gold-light: #d4b95a;
  --bb-bg-dark: #0c1021;
  --bb-bg-darker: #080b16;
  --bb-bg-panel: #111628;
  --bb-bg-bubble-bot: #181e35;
  --bb-bg-input: #141a30;
  --bb-text-primary: #e8edf5;
  --bb-text-secondary: #8892ab;
  --bb-text-muted: #5a6380;
  --bb-border: rgba(196, 167, 71, 0.1);
  --bb-border-focus: rgba(196, 167, 71, 0.35);
  --bb-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  --bb-radius: 16px;
  --bb-transition: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  --bb-drawer-width: 420px;
}

/* ── FAB Button ────────────────────────────────────────────── */
.barkatbot-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bb-gold) 0%, var(--bb-gold-dark) 100%);
  box-shadow:
    0 4px 20px rgba(196, 167, 71, 0.3),
    0 2px 8px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.25s ease,
              opacity 0.3s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.barkatbot-fab:hover {
  transform: scale(1.08);
  box-shadow:
    0 6px 28px rgba(196, 167, 71, 0.4),
    0 3px 12px rgba(0, 0, 0, 0.3);
}

.barkatbot-fab:active {
  transform: scale(0.95);
}

.barkatbot-fab svg {
  width: 28px;
  height: 28px;
  fill: #0a0e1a;
  transition: transform 0.3s ease, opacity 0.2s ease;
}

/* Swap icons when open */
.barkatbot-fab .bb-icon-chat { display: block; }
.barkatbot-fab .bb-icon-close { display: none; }
.barkatbot-fab.is-open .bb-icon-chat { display: none; }
.barkatbot-fab.is-open .bb-icon-close { display: block; }

/* Hide FAB instantly when drawer is open */
.barkatbot-fab.is-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: none;
  transform: scale(0.8);
}

/* FAB entrance bounce animation */
.bb-fab-entrance {
  animation: bb-fab-bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes bb-fab-bounce {
  0% {
    opacity: 0;
    transform: scale(0.3) translateY(20px);
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ── Overlay / Backdrop ────────────────────────────────────── */
.barkatbot-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
  -webkit-tap-highlight-color: transparent;
}

.barkatbot-overlay.is-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0s linear 0s;
}

/* ── Drawer Window ─────────────────────────────────────────── */
.barkatbot-window {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--bb-drawer-width);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh; /* dynamic viewport for mobile keyboards */
  z-index: 10000;
  display: flex;
  flex-direction: column;
  background: var(--bb-bg-dark);
  border-left: 1px solid var(--bb-border);
  box-shadow: var(--bb-shadow);

  /* Slide in from right */
  transform: translateX(100%);
  transition: transform var(--bb-transition);
  will-change: transform;
}

.barkatbot-window.is-open {
  transform: translateX(0);
}

/* ── Header ────────────────────────────────────────────────── */
.barkatbot-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #12182e 0%, #0e1325 100%);
  border-bottom: 1px solid var(--bb-border);
  flex-shrink: 0;
  min-height: 50px;
  /* iPhone safe area */
  padding-top: max(10px, env(safe-area-inset-top));
}

.barkatbot-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--bb-gold), var(--bb-gold-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.barkatbot-header-avatar svg {
  width: 18px;
  height: 18px;
  fill: #0a0e1a;
}

.barkatbot-header-info {
  flex: 1;
  min-width: 0;
}

.barkatbot-header-name {
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--bb-text-primary);
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.barkatbot-header-status {
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: 11px;
  color: #4cd964;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.barkatbot-header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4cd964;
  flex-shrink: 0;
  animation: bb-status-pulse 2s ease-in-out infinite;
}

@keyframes bb-status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.barkatbot-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.barkatbot-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--bb-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.barkatbot-header-btn:hover {
  background: rgba(196, 167, 71, 0.12);
  color: var(--bb-gold);
}

.barkatbot-header-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ── Messages Area ─────────────────────────────────────────── */
.barkatbot-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  background: var(--bb-bg-darker);
  min-height: 0;
}

.barkatbot-messages::-webkit-scrollbar {
  width: 5px;
}

.barkatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.barkatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(196, 167, 71, 0.15);
  border-radius: 10px;
}

.barkatbot-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(196, 167, 71, 0.3);
}

/* ── Message Row ───────────────────────────────────────────── */
.barkatbot-msg {
  display: flex;
  gap: 8px;
  max-width: 90%;
  animation: bb-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes bb-msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.barkatbot-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.barkatbot-msg--bot {
  align-self: flex-start;
}

.barkatbot-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.barkatbot-msg--bot .barkatbot-msg-avatar {
  background: linear-gradient(135deg, var(--bb-gold), var(--bb-gold-dark));
}

.barkatbot-msg--bot .barkatbot-msg-avatar svg {
  width: 14px;
  height: 14px;
  fill: #0a0e1a;
}

.barkatbot-msg--user .barkatbot-msg-avatar {
  background: rgba(196, 167, 71, 0.12);
  color: var(--bb-gold);
  font-size: 11px;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
}

.barkatbot-msg-content {
  min-width: 0;
}

.barkatbot-msg-bubble {
  padding: 8px 12px;
  border-radius: var(--bb-radius);
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: clamp(12px, 1.1vw, 13.5px);
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: break-word;
}

.barkatbot-msg--bot .barkatbot-msg-bubble {
  background: var(--bb-bg-bubble-bot);
  color: var(--bb-text-primary);
  border-bottom-left-radius: 6px;
  border: 1px solid rgba(196, 167, 71, 0.06);
}

.barkatbot-msg--user .barkatbot-msg-bubble {
  background: linear-gradient(135deg, var(--bb-gold), #b89a3f);
  color: #0a0e1a;
  border-bottom-right-radius: 6px;
  font-weight: 500;
}

.barkatbot-msg--bot .barkatbot-msg-bubble strong {
  color: var(--bb-gold);
  font-weight: 700;
}

.barkatbot-msg--bot .barkatbot-msg-bubble ul,
.barkatbot-msg--bot .barkatbot-msg-bubble ol {
  margin: 4px 0;
  padding-left: 16px;
}

.barkatbot-msg--bot .barkatbot-msg-bubble li {
  margin-bottom: 2px;
}

.barkatbot-msg--bot .barkatbot-msg-bubble p {
  margin: 0 0 4px 0;
}

.barkatbot-msg--bot .barkatbot-msg-bubble p:last-child {
  margin-bottom: 0;
}

/* Markdown links inside bot bubbles */
.barkatbot-msg--bot .barkatbot-msg-bubble .bb-md-link {
  color: var(--bb-gold);
  text-decoration: none;
  border-bottom: 1px solid rgba(196, 167, 71, 0.3);
  transition: border-color 0.2s, color 0.2s;
}

.barkatbot-msg--bot .barkatbot-msg-bubble .bb-md-link:hover {
  color: var(--bb-gold-light);
  border-bottom-color: var(--bb-gold-light);
}

.barkatbot-msg--bot .barkatbot-msg-bubble code {
  background: rgba(196, 167, 71, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--bb-gold-light);
}

.barkatbot-msg-time {
  font-size: 9px;
  color: var(--bb-text-muted);
  margin-top: 2px;
  padding: 0 4px;
}

.barkatbot-msg--user .barkatbot-msg-time {
  text-align: right;
}

/* ── Typing Indicator ──────────────────────────────────────── */
.barkatbot-typing {
  display: none;
  align-self: flex-start;
  gap: 10px;
  max-width: 90%;
  padding: 4px 0;
}

.barkatbot-typing.is-visible {
  display: flex;
}

.barkatbot-typing-dots {
  background: var(--bb-bg-bubble-bot);
  border: 1px solid rgba(196, 167, 71, 0.06);
  border-radius: var(--bb-radius);
  border-bottom-left-radius: 6px;
  padding: 8px 14px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.barkatbot-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bb-gold);
  opacity: 0.35;
  animation: bb-dot-bounce 1.4s ease-in-out infinite;
}

.barkatbot-typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.barkatbot-typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes bb-dot-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ── Welcome / Suggestions ─────────────────────────────────── */
.barkatbot-welcome {
  padding: 4px 0 2px;
}

.barkatbot-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.barkatbot-suggestions::-webkit-scrollbar {
  display: none;
}

.barkatbot-suggestion {
  background: rgba(196, 167, 71, 0.07);
  border: 1px solid rgba(196, 167, 71, 0.16);
  border-radius: 16px;
  padding: 5px 11px;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: 11px;
  color: var(--bb-gold);
  cursor: pointer;
  transition: all 0.2s ease;
  /* Allow wrapping instead of nowrap */
  white-space: normal;
  text-align: left;
  line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
}

.barkatbot-suggestion:hover {
  background: rgba(196, 167, 71, 0.15);
  border-color: rgba(196, 167, 71, 0.3);
  transform: translateY(-1px);
}

.barkatbot-suggestion:active {
  transform: scale(0.97);
}

/* ── Input Area ────────────────────────────────────────────── */
.barkatbot-input-area {
  padding: 8px 14px;
  border-top: 1px solid var(--bb-border);
  background: var(--bb-bg-panel);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  /* iPhone home indicator */
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.barkatbot-input-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

.barkatbot-input {
  width: 100%;
  min-height: 38px;
  max-height: 100px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid rgba(196, 167, 71, 0.12);
  background: var(--bb-bg-input);
  color: var(--bb-text-primary);
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: clamp(14px, 1.3vw, 15px);
  line-height: 1.45;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  overflow-y: auto;
  -webkit-appearance: none;
}

.barkatbot-input::placeholder {
  color: var(--bb-text-muted);
}

.barkatbot-input:focus {
  border-color: var(--bb-border-focus);
}

.barkatbot-send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 10px;
  border: none;
  background: rgba(196, 167, 71, 0.15);
  color: var(--bb-gold);
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  opacity: 0.4;
}

.barkatbot-send.is-active {
  background: linear-gradient(135deg, var(--bb-gold), var(--bb-gold-dark));
  color: #0a0e1a;
  opacity: 1;
  cursor: pointer;
}

.barkatbot-send.is-active:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(196, 167, 71, 0.3);
}

.barkatbot-send.is-active:active {
  transform: scale(0.95);
}

.barkatbot-send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ── Powered By ────────────────────────────────────────────── */
.barkatbot-powered {
  text-align: center;
  padding: 4px 0 2px;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: 9px;
  color: var(--bb-text-muted);
  background: var(--bb-bg-panel);
  border-top: 1px solid rgba(196, 167, 71, 0.05);
  flex-shrink: 0;
}

/* ── Error Message ─────────────────────────────────────────── */
.barkatbot-error {
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.15);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 12px;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  color: #ff6b6b;
  margin: 4px 0;
  animation: bb-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.barkatbot-error svg {
  width: 14px;
  height: 14px;
  fill: #ff6b6b;
  vertical-align: -2px;
  margin-right: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --bb-drawer-width: min(380px, 90vw);
  }

  .barkatbot-fab {
    bottom: 24px;
    right: 20px;
    width: 56px;
    height: 56px;
  }

  .barkatbot-fab svg {
    width: 26px;
    height: 26px;
  }
}

/* ── Medium laptops (769px – 1024px) ───────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --bb-drawer-width: min(400px, 85vw);
  }
}

/* ── Mobile (≤ 576px) — Full-width drawer ──────────────────── */
@media (max-width: 576px) {
  :root {
    --bb-drawer-width: 100vw;
    --bb-radius: 12px;
  }

  .barkatbot-fab {
    bottom: 18px;
    right: 14px;
    width: 48px;
    height: 48px;
  }

  .barkatbot-fab svg {
    width: 22px;
    height: 22px;
  }

  .barkatbot-window {
    border-left: none;
    border-radius: 0;
  }

  .barkatbot-header {
    padding: 8px 12px;
    min-height: 44px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .barkatbot-header-avatar {
    width: 30px;
    height: 30px;
    border-radius: 8px;
  }

  .barkatbot-header-avatar svg {
    width: 16px;
    height: 16px;
  }

  .barkatbot-header-name {
    font-size: 13px;
  }

  .barkatbot-header-status {
    font-size: 10px;
  }

  .barkatbot-messages {
    padding: 10px 10px;
  }

  .barkatbot-msg {
    max-width: 94%;
    gap: 6px;
  }

  .barkatbot-msg-bubble {
    font-size: 12.5px;
    padding: 7px 10px;
  }

  .barkatbot-msg-avatar {
    width: 22px;
    height: 22px;
    border-radius: 6px;
  }

  .barkatbot-msg--bot .barkatbot-msg-avatar svg {
    width: 12px;
    height: 12px;
  }

  .barkatbot-msg--user .barkatbot-msg-avatar {
    font-size: 10px;
  }

  .barkatbot-input-area {
    padding: 6px 10px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .barkatbot-input {
    font-size: 16px; /* Prevent iOS zoom on focus */
    min-height: 36px;
    padding: 8px 10px;
    border-radius: 10px;
  }

  .barkatbot-send {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 8px;
  }

  .barkatbot-send svg {
    width: 16px;
    height: 16px;
  }

  .barkatbot-suggestion {
    font-size: 10.5px;
    padding: 4px 9px;
  }

  .barkatbot-powered {
    padding: 3px 0 2px;
    padding-bottom: max(3px, env(safe-area-inset-bottom));
  }

  .barkatbot-typing {
    max-width: 94%;
  }

  .barkatbot-typing-dots {
    padding: 6px 10px;
  }

  .barkatbot-header-btn {
    width: 28px;
    height: 28px;
  }

  .barkatbot-header-btn svg {
    width: 14px;
    height: 14px;
  }

  .barkatbot-suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 5px;
    margin-top: 6px;
  }

  .barkatbot-suggestion {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* ── Very small screens (≤ 375px) ──────────────────────────── */
@media (max-width: 375px) {
  .barkatbot-header {
    padding: 6px 10px;
  }

  .barkatbot-messages {
    padding: 8px 8px;
  }

  .barkatbot-input-area {
    padding: 5px 8px;
  }

  .barkatbot-suggestions {
    gap: 3px;
  }

  .barkatbot-suggestion {
    font-size: 10px;
    padding: 3px 8px;
  }
}

/* ── Landscape mobile ──────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .barkatbot-header {
    padding: 6px 10px;
    min-height: 40px;
  }

  .barkatbot-header-avatar {
    width: 28px;
    height: 28px;
  }

  .barkatbot-input-area {
    padding: 5px 10px;
  }

  .barkatbot-msg-bubble {
    font-size: 12px;
    padding: 6px 10px;
  }
}

/* ── Desktop large (≥ 1200px) ──────────────────────────────── */
@media (min-width: 1200px) {
  :root {
    --bb-drawer-width: min(440px, 30vw);
  }
}

/* ── Ultra-wide (≥ 1800px) ─────────────────────────────────── */
@media (min-width: 1800px) {
  :root {
    --bb-drawer-width: min(460px, 25vw);
  }
}

/* ── Dark mode preference respect ──────────────────────────── */
@media (prefers-color-scheme: dark) {
  .barkatbot-fab {
    box-shadow:
      0 4px 20px rgba(196, 167, 71, 0.35),
      0 2px 10px rgba(0, 0, 0, 0.4);
  }
}
