/* Drobne uzupełnienia ponad Tailwind */

:root {
  --scrollbar-thumb: #cbd5e1; /* slate-300 */
  --scrollbar-track: #f8fafc; /* slate-50 */
}

/* Uniwersalny, smukły scrollbar (chatList + messagesContainer) */
#chatList::-webkit-scrollbar,
#messagesContainer::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#chatList::-webkit-scrollbar-thumb,
#messagesContainer::-webkit-scrollbar-thumb {
  background-color: #cbd5e1; /* slate-300 */
  border-radius: 9999px;
  transition: background-color 0.2s ease;
}

#chatList::-webkit-scrollbar-thumb:hover,
#messagesContainer::-webkit-scrollbar-thumb:hover {
  background-color: #94a3b8; /* slate-400 */
}

#chatList::-webkit-scrollbar-track,
#messagesContainer::-webkit-scrollbar-track {
  background-color: transparent;
}

#chatList,
#messagesContainer {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

/* Animacje wejścia bąbelków */
.bubble-enter {
  animation: bubbleIn 220ms ease-out both;
}
@keyframes bubbleIn {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* --- DESKTOP: płynne zwijanie/rozwinięcie sidebara (>= lg) --- */
@media (min-width: 1024px) {
  #sidebar {
    transition: width 300ms ease, min-width 300ms ease, max-width 300ms ease,
      padding 300ms ease, border-width 300ms ease, border-color 300ms ease;
    will-change: width;
    overflow: hidden;
  }

  #sidebar > * {
    transition: opacity 200ms ease;
  }

  .sidebar-collapsed #sidebar {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-right-width: 0 !important;
  }
  .sidebar-collapsed #sidebar > * {
    opacity: 0;
    pointer-events: none;
  }

  #toggleSidebarBtn i {
    transition: transform 200ms ease;
  }
  .sidebar-collapsed #toggleSidebarBtn i {
    transform: rotate(180deg);
  }

  .sidebar-collapsed #showSidebarBtn {
    display: inline-flex !important;
  }
}

/* Mobilny overlay + blokada scrolla */
.no-scroll {
  overflow: hidden;
}

/* Dół kompozytora bezpieczny dla notcha / gestów */
.composer-safe {
  padding-bottom: max(env(safe-area-inset-bottom), 0.5rem);
}

/* Ulepszone autogrow max wysokości na mobile */
@media (max-width: 639.98px) {
  #messageInput {
    max-height: 40vh;
  }
}

/* Drobne poprawki spacingu na mobile */
@media (max-width: 639.98px) {
  #messagesContainer {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* Preferencje dostępności */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* =========================================================
   POPRAWKI WYŚWIETLANIA BĄBELKÓW
   ========================================================= */

.message-row {
  align-items: flex-start;
  gap: 0.5rem;
}

.message-avatar {
  flex: 0 0 auto;
}

.message-bubble {
  min-width: 0;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
  text-wrap: pretty;
}

.message-content {
  white-space: pre-wrap;
}

.message-content img,
.message-content video,
.message-content iframe {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 0.5rem;
}

.message-content pre,
.message-content code,
.message-content kbd,
.message-content samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.message-meta {
  opacity: 0.75;
  font-size: 10px;
  margin-top: 0.25rem;
  text-align: right;
}

/* Tablet */
@media (min-width: 768px) {
  .message-bubble {
    max-width: 70%;
  }
}

/* Desktop: pełna szerokość w wrapperze */
@media (min-width: 1024px) {
  .message-bubble {
    max-width: 100%;
  }
}

/* Mobile */
@media (max-width: 767.98px) {
  .message-bubble {
    max-width: 88%;
  }
}

/* Wrapper dla wiadomości – desktop: marginesy 5% */
@media (min-width: 1024px) {
  .chat-messages-wrapper {
    max-width: none;
    padding-left: 5%;
    padding-right: 5%;
  }
}
.chat-messages-wrapper {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

/* =========================================================
   ANIMACJA "PISANIA" (3 kropki)
   ========================================================= */

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 14px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background-color: #94a3b8; /* slate-400 */
  display: inline-block;
  animation: typingBlink 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBlink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* =========================================================
   OCENY ROZMÓW (zielony / pomarańczowy / czerwony)
   ========================================================= */

/* Punkty/kropki w liście czatów */
.chat-rating-dot {
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.chat-rating-dot.green {
  background-color: #16a34a;
} /* green-600 */
.chat-rating-dot.orange {
  background-color: #f59e0b;
} /* amber-500 */
.chat-rating-dot.red {
  background-color: #dc2626;
} /* red-600 */
.chat-rating-dot.none {
  background: linear-gradient(
    135deg,
    #e2e8f0 25%,
    #f8fafc 25%,
    #f8fafc 50%,
    #e2e8f0 50%,
    #e2e8f0 75%,
    #f8fafc 75%,
    #f8fafc 100%
  );
  background-size: 8px 8px;
}

/* Toolbar ocen w nagłówku */
#ratingToolbar {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rating-btn {
  width: 34px;
  height: 28px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e2e8f0; /* slate-200 */
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: transform 120ms ease, box-shadow 120ms ease,
    border-color 120ms ease;
}
.rating-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}
.rating-btn.active {
  border-color: transparent;
  color: white;
}
.rating-btn.green.active {
  background-color: #16a34a;
} /* green-600 */
.rating-btn.orange.active {
  background-color: #f59e0b;
} /* amber-500 */
.rating-btn.red.active {
  background-color: #dc2626;
} /* red-600 */

.rating-btn .dot {
  width: 10px;
  height: 10px;
  border-radius: 9999px;
}
.rating-btn.green .dot {
  background-color: #16a34a;
}
.rating-btn.orange .dot {
  background-color: #f59e0b;
}
.rating-btn.red .dot {
  background-color: #dc2626;
}

/* Popover z notatką (dla pomarańczowej oceny) — DOMYŚLNIE przy toolbarze */
.rating-popover {
  position: absolute;
  top: 38px;
  right: 0;
  width: min(92vw, 360px);
  background: #ffffff;
  border: 1px solid #e2e8f0; /* slate-200 */
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.12);
  border-radius: 14px;
  padding: 10px;
  z-index: 50;

  /* --- kluczowe ustawienia wysokości i układu --- */
  display: flex; /* 👈 panel rośnie w pionie */
  flex-direction: column; /*    label, textarea, actions w kolumnie */
  max-height: 50vh; /* limit wysokości panelu na desktopie */
  overflow: auto;
  overscroll-behavior: contain;
}
.rating-popover textarea {
  width: 100%;
  /* textarea wypełnia dostępną przestrzeń i "pcha" panel do max-height */
  flex: 1 1 auto; /* 👈 klucz: adaptuje wysokość panelu */
  min-height: 120px;
  height: auto;
  max-height: none; /* brak twardego sufitu na desktopie */
  overflow: auto;

  border: 1px solid #e5e7eb; /* slate-200 */
  border-radius: 10px;
  padding: 8px 10px;
  resize: vertical;
}
.rating-popover .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}
.rating-popover .btn {
  font-size: 12px;
  line-height: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
}
.rating-popover .btn.primary {
  background: #2563eb; /* brand-600 */
  color: white;
  border-color: #2563eb;
}

/* MOBILE: top-sheet — pełna szerokość przy górze ekranu */
@media (max-width: 639.98px) {
  .rating-popover {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: auto;
    top: max(64px, calc(env(safe-area-inset-top) + 12px));
    width: auto;

    /* 👇 ZMIENIASZ TĘ WARTOŚĆ, by regulować MAKS. wysokość panelu na mobile */
    max-height: 85vh;

    border-radius: 16px;
    padding: 12px;
  }
  .rating-popover textarea {
    /* Na mobile nadal wypełnia panel;
       nie nakładamy max-height, bo limit trzyma max-height panelu (85vh) */
    flex: 1 1 auto;
    min-height: 140px; /* startowa wysokość */
    max-height: none;
  }
}
