/* Carpool chat: conversation transcript (bubbles + media grid) and the media
   lightbox. Everything is prefixed .kk-chat-* / .kk-lb__* so nothing leaks into
   the rest of the admin. Loaded after dark.css and mobile.css so this file's own
   dark-mode and responsive rules win by source order at equal specificity. */

/* ---------------------------------------------------------------- scroll shell */
.kk-chat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(68vh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scroll-behavior: smooth;
}
.kk-chat--compact {
  max-height: none;
  overflow: visible;
}

/* -------------------------------------------------------------------- toolbar */
.kk-chat-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eef0f7;
}
.kk-chat-toolbar__stamp {
  font-size: 11.5px;
  color: #a2a7b5;
  margin-left: auto;
}
.kk-chat-toolbar__live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.kk-chat-toolbar__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c3c7d2;
  flex: 0 0 8px;
}
.kk-chat-toolbar__live[aria-pressed='true'] .kk-chat-toolbar__dot {
  background: #2dce89;
  box-shadow: 0 0 0 3px rgba(45, 206, 137, 0.18);
}

/* --------------------------------------------------------------------- banner */
.kk-chat-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 auto 14px;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 100%;
}
.kk-chat-banner--closed {
  background: #fff8e6;
  border: 1px solid #f6e0a8;
  color: #8a6b1f;
}
.kk-chat-banner i {
  margin-top: 2px;
  flex: 0 0 auto;
}

/* -------------------------------------------------------------- day separator */
.kk-chat-day {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 10px;
}
.kk-chat-day::before,
.kk-chat-day::after {
  content: '';
  flex: 1;
  border-top: 1px solid #eef0f7;
}
.kk-chat-day span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #a2a7b5;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ row / side */
.kk-chat-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 12px;
}
.kk-chat-row.kk-chat-run {
  margin-top: 2px;
}
.kk-chat-row--customer {
  justify-content: flex-start;
}
.kk-chat-row--porter {
  justify-content: flex-end;
}

/* --------------------------------------------------------------------- avatar */
.kk-chat-ava {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
}
.kk-chat-ava__img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* ------------------------------------------------------------ column / who */
.kk-chat-col {
  min-width: 0;
  max-width: 72%;
  display: flex;
  flex-direction: column;
}
.kk-chat-row--porter .kk-chat-col {
  align-items: flex-end;
}
.kk-chat-who {
  font-size: 12px;
  font-weight: 600;
  color: #33374d;
  margin-bottom: 3px;
}
.kk-chat-who__role {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #a2a7b5;
}

/* --------------------------------------------------------------------- bubble */
.kk-chat-bubble {
  min-width: 0;
  padding: 9px 13px;
  border-radius: 14px;
  background: #f4f5fa;
  border: 1px solid #eef0f7;
  color: #4a4f63;
}
.kk-chat-row--customer .kk-chat-bubble {
  border-bottom-left-radius: 5px;
}
/* The accent tint is a CSS variable the theme's dark mode redefines, so the porter
   bubble re-skins navy -> teal in dark mode with no dark-mode colour of its own. */
.kk-chat-row--porter .kk-chat-bubble {
  background: var(--primary-transparentcolor, #f0eefb);
  border-color: transparent;
  border-bottom-right-radius: 5px;
}
.kk-chat-bubble--media-only {
  padding: 5px;
}

.kk-chat-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 13.5px;
  line-height: 1.5;
}
.kk-chat-text a {
  word-break: break-all;
}

/* ----------------------------------------------------------------- media grid */
.kk-chat-media {
  display: grid;
  gap: 4px;
  margin-top: 7px;
}
.kk-chat-bubble--media-only .kk-chat-media {
  margin-top: 0;
}
/* A DEFINITE width, not just max-width. Porter bubbles sit in a flex column with
   align-items:flex-end, so they are shrink-to-fit; a `1fr` grid has no intrinsic
   size and would resolve to 0 there, which with aspect-ratio:1 collapses the tile
   to nothing. Text in the same bubble hides the bug, so only attachment-only
   messages break. max-width keeps it responsive inside the column cap. */
.kk-chat-media--1 {
  grid-template-columns: 1fr;
  width: 260px;
  max-width: 100%;
}
.kk-chat-media--2 {
  grid-template-columns: repeat(2, 1fr);
  width: 300px;
  max-width: 100%;
}
.kk-chat-media--3plus {
  grid-template-columns: repeat(3, 1fr);
  width: 330px;
  max-width: 100%;
}

.kk-chat-thumb {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 9px;
  overflow: hidden;
  aspect-ratio: 1;
  background: #e9ebf3;
  cursor: zoom-in;
  display: block;
  width: 100%;
}
.kk-chat-thumb__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.kk-chat-thumb--video {
  cursor: pointer;
  background: linear-gradient(135deg, #33374d 0%, #1b1e2b 100%);
}
.kk-chat-thumb__play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.kk-chat-thumb__cap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 6px 4px;
  font-size: 10px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.kk-chat-thumb:hover {
  opacity: 0.9;
}
.kk-chat-thumb:focus-visible {
  outline: 2px solid var(--primary-bg-color, #6259ca);
  outline-offset: 2px;
}

/* ----------------------------------------------------------------------- meta */
.kk-chat-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 3px;
  font-size: 10.5px;
  color: #a2a7b5;
}
.kk-chat-read {
  color: var(--primary-bg-color, #6259ca);
}
.kk-chat-read--sent {
  color: #c3c7d2;
}

/* ------------------------------------------------------------ misc / rail */
.kk-chat-pagehint {
  font-size: 11px;
  color: #a2a7b5;
  text-align: center;
  margin: 10px 0 0;
}
.kk-chat-empty {
  font-size: 13px;
  color: #a2a7b5;
  margin: 0;
}
.kk-chat-rail__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.kk-chat-cell-ava {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}
.kk-chat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #6b7084;
  margin-right: 10px;
}

/* ------------------------------------------------------------------- lightbox */
.kk-lb {
  position: fixed;
  inset: 0;
  /* Above everything the theme can put on screen: .modal is 9999, react-toastify
     is 9999, and #global-loader is 50000. (The TanStack devtools button sits at
     100000, but that only exists in dev builds.) */
  z-index: 60000;
  background: rgba(6, 8, 16, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 20px 76px;
  animation: kk-lb-in 0.16s ease-out;
}
@keyframes kk-lb-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.kk-lb__stage {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.kk-lb__img,
.kk-lb__video {
  max-width: 100%;
  max-height: calc(100vh - 140px);
  border-radius: 8px;
  display: block;
  background: #000;
}
.kk-lb__fail {
  color: #c4c7d1;
  text-align: center;
  font-size: 13px;
}
.kk-lb__fail i {
  display: block;
  font-size: 26px;
  margin-bottom: 8px;
}
.kk-lb__close,
.kk-lb__nav {
  position: absolute;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
}
.kk-lb__close:hover,
.kk-lb__nav:hover {
  background: rgba(255, 255, 255, 0.22);
}
.kk-lb__close:focus-visible,
.kk-lb__nav:focus-visible,
.kk-lb__dl:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.kk-lb__close {
  top: 14px;
  right: 16px;
}
.kk-lb__nav--prev {
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
}
.kk-lb__nav--next {
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}
.kk-lb__bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 20px;
  color: #c4c7d1;
  font-size: 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}
.kk-lb__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
  font-weight: 600;
}
.kk-lb__meta {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
}
.kk-lb__dl {
  color: #fff !important;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.kk-lb__dl:hover {
  opacity: 0.85;
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  .kk-lb {
    animation: none;
  }
  .kk-chat {
    scroll-behavior: auto;
  }
}

/* ----------------------------------------------------------------- responsive */
@media (max-width: 575.98px) {
  .kk-chat {
    max-height: none;
  }
  .kk-chat-col {
    max-width: 88%;
  }
  .kk-chat-who__role {
    display: none;
  }
  .kk-chat-media--3plus {
    grid-template-columns: repeat(2, 1fr);
  }
  .kk-chat-toolbar__stamp {
    margin-left: 0;
    width: 100%;
  }
  .kk-lb {
    padding: 52px 10px 84px;
  }
  .kk-lb__bar {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ------------------------------------------------------------------ dark mode */
body.dark-theme .kk-chat-bubble {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: #c4c7d1;
}
body.dark-theme .kk-chat-row--porter .kk-chat-bubble {
  background: var(--primary-transparentcolor);
  border-color: transparent;
}
body.dark-theme .kk-chat-who {
  color: #e6e7ee;
}
body.dark-theme .kk-chat-day span,
body.dark-theme .kk-chat-toolbar__stamp {
  color: #8a8f9e;
}
body.dark-theme .kk-chat-day::before,
body.dark-theme .kk-chat-day::after,
body.dark-theme .kk-chat-toolbar {
  border-color: rgba(255, 255, 255, 0.08);
}
body.dark-theme .kk-chat-banner--closed {
  background: rgba(255, 193, 7, 0.08);
  border-color: rgba(255, 193, 7, 0.22);
  color: #e8d9a8;
}
body.dark-theme .kk-chat-thumb {
  background: rgba(255, 255, 255, 0.05);
}
body.dark-theme .kk-chat-read--sent {
  color: #4c5160;
}
body.dark-theme .kk-chat-pill {
  color: #a9aebd;
}
