:root {
  --line: #2f2f2f;
  --muted: #a1a1aa;
  --text: #ececec;
  --text-soft: #d4d4d8;
  --red: #ef4444;
  --green: #22c55e;
  --yellow: #f5b400;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --card: #1f1f1f;
  --card-2: #171717;
  --card-3: #2a2a2a;
  --bg: #212121;
  --shadow-lg: 0 18px 60px rgba(0, 0, 0, 0.38);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.24);
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --rail-width: 64px;
  --archive-sidebar-width: 300px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  min-width: 0;
}

html,
body {
  width: 100%;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.app {
  width: 100%;
  min-width: 980px;
  height: calc(100vh - 16px);
  min-height: calc(100vh - 16px);
  background: var(--card-2);
  border: 1px solid #2a2a2a;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: grid;
  grid-template-columns: var(--rail-width) var(--archive-sidebar-width) minmax(0, 1fr);
  box-shadow: var(--shadow-lg);
}

.left-rail {
  width: var(--rail-width);
  min-width: var(--rail-width);
  max-width: var(--rail-width);
  background: var(--card-2);
  border-right: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 12px;
  min-height: 0;
}

.rail-bottom {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid #2a2a2a;
  width: calc(100% - 16px);
}

/* Biarkan ukuran rail/icon mengikuti layout/components global
   agar sama persis dengan halaman dashboard dan halaman lain */

.rail-icon.active {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.26);
  color: #ffffff;
}

.rail-icon.flash {
  color: #93c5fd;
}

.archive-sidebar {
  width: var(--archive-sidebar-width);
  min-width: var(--archive-sidebar-width);
  max-width: var(--archive-sidebar-width);
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  height: 60px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.archive-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.sidebar-tools {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}

.search-box {
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1px solid #343434;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
  gap: 10px;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.search-box:focus-within {
  border-color: rgba(59, 130, 246, 0.42);
  background: #232323;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

.search-box input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.search-box input::placeholder {
  color: #8f8f98;
}

.search-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 18px;
  color: #c9c9d0;
  opacity: 0.92;
}

.search-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
}

.archive-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.archive-item {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid #2f2f2f;
  background: var(--card);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.archive-item:hover {
  background: #262626;
  border-color: #3a3a3a;
  transform: translateY(-1px);
}

.archive-item.active {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.26);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.08);
}

.archive-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.archive-user {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 1;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #ffffff;
  flex-shrink: 0;
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-name {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.user-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-time {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: #b8b8c2;
  padding-top: 2px;
  white-space: nowrap;
}

.archive-preview {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.deep-match-hint {
  font-size: 12px;
  font-weight: 700;
  color: #93c5fd;
  font-style: italic;
}

.search-hl {
  background: rgba(245, 180, 0, 0.26);
  color: #fff3c2;
  border-radius: 4px;
  padding: 0 3px;
}

.archive-preview .search-hl {
  background: rgba(245, 180, 0, 0.3);
  color: #ffe7a0;
  font-weight: 700;
}

.bubble .search-hl {
  background: rgba(245, 180, 0, 0.24);
  color: inherit;
  padding: 1px 3px;
  border-radius: 4px;
}

.bubble.right .search-hl {
  background: rgba(255, 255, 255, 0.18);
}

.search-target-flash {
  animation: searchTargetPulse 2.5s ease-out;
}

.search-target-flash .bubble {
  box-shadow: 0 0 0 2px rgba(245, 180, 0, 0.4);
}

@keyframes searchTargetPulse {
  0% {
    background: rgba(245, 180, 0, 0.14);
  }
  30% {
    background: rgba(245, 180, 0, 0.09);
  }
  100% {
    background: transparent;
  }
}

.main {
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-detail {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: 60px minmax(0, 1fr) auto;
}

.detail-head {
  height: 60px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}

.detail-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.detail-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-status {
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 999px;
  color: #dbe7ff;
  border: 1px solid rgba(59, 130, 246, 0.22);
  background: rgba(59, 130, 246, 0.12);
  white-space: nowrap;
}

.detail-status.is-banned {
  color: #ffd5d5;
  border-color: rgba(239, 68, 68, 0.22);
  background: rgba(239, 68, 68, 0.12);
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 22px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

.message-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message-block.left {
  align-items: flex-start;
}

.message-block.right {
  align-items: flex-end;
}

.sender-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 40px;
  line-height: 1.2;
}

.sender-name.right {
  margin-left: 0;
  margin-right: 40px;
  text-align: right;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: fit-content;
  max-width: min(80%, 760px);
}

.message-row.right {
  flex-direction: row-reverse;
}

.bubble-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
}

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble.left {
  background: #2a2a2a;
  color: var(--text);
  border: 1px solid #343434;
  border-top-left-radius: 8px;
}

.bubble.right {
  background: linear-gradient(180deg, #2f6fed 0%, #2563eb 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top-right-radius: 8px;
}

/* =========================================
   IMAGE MESSAGE IN ARCHIVE
   ========================================= */

.bubble.bubble-media {
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
  max-width: min(220px, 60vw);
  background: transparent;
  border: 0;
  box-shadow: none;
  white-space: normal;
  line-height: 0;
}

.bubble.bubble-media.has-caption {
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
}

.bubble.left.bubble-media.has-caption {
  background: #2a2a2a;
  border: 1px solid #343434;
}

.bubble.right.bubble-media.has-caption {
  background: linear-gradient(180deg, #2f6fed 0%, #2563eb 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.bubble-image-wrap {
  width: 100%;
  max-width: 100%;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  line-height: 0;
  cursor: zoom-in;
  background: #161616;
}

.bubble.bubble-media.has-caption .bubble-image-wrap {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.bubble-image-wrap img {
  width: 100%;
  max-height: min(220px, 46vh);
  object-fit: cover;
  display: block;
  background: #101010;
  border-radius: inherit;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.bubble-image-wrap:hover img {
  filter: brightness(0.98);
  transform: scale(1.01);
}

.bubble-image-caption {
  padding: 8px 11px 10px;
  font-size: 13px;
  line-height: 1.42;
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble.left.bubble-media .bubble-image-caption,
.bubble.right.bubble-media .bubble-image-caption {
  color: #ffffff;
}

/* Lightbox */

.image-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  padding: 20px;
  background: rgba(5, 7, 11, 0.76);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.image-lightbox.visible {
  display: flex;
}

.image-lightbox img {
  max-width: min(94vw, 1180px);
  max-height: calc(100vh - 48px);
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.28);
  cursor: default;
}

.lightbox-toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 10000;
}

.lightbox-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(23, 23, 23, 0.78);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  text-decoration: none;
}

.lightbox-btn:hover {
  background: rgba(42, 42, 42, 0.92);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.lightbox-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tiny-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.avatar-spacer {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  visibility: hidden;
  pointer-events: none;
}

.agent-avatar {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  color: #fff;
  background: radial-gradient(circle at 30% 30%, #f8d866, #7a100d 60%, #1a0d0b 100%);
  border: 2px solid #d39b1b;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.customer {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
}

.agent {
  background: linear-gradient(180deg, #8b5cf6 0%, #6d3ae8 100%);
}

.archive-list > .system-line {
  align-self: center;
  text-align: center;
  color: #d9dbe5;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  background: var(--card);
  border: 1px solid #343434;
  padding: 9px 14px;
  border-radius: 999px;
  max-width: 100%;
  word-break: break-word;
}

.messages .system-line {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  text-align: center;
  line-height: 1.4;
  background: #262626;
  border: 1px solid #343434;
  padding: 8px 12px;
  border-radius: 999px;
  margin-top: 8px;
  max-width: 100%;
  word-break: break-word;
}

.messages .system-line.system-line-separator {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  margin: 8px 0 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.messages .system-line.system-line-separator::before,
.messages .system-line.system-line-separator::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: #343434;
  min-width: 24px;
}

.messages .system-line.system-line-separator > .system-line-separator__label {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  background: #262626;
  border: 1px solid #343434;
  padding: 8px 12px;
  border-radius: 999px;
  line-height: 1;
  white-space: nowrap;
}

.messages .system-line.system-line-event {
  align-self: flex-end;
  display: block;
  width: fit-content;
  margin-top: 8px;
  margin-left: auto;
  margin-right: 40px;
  max-width: min(calc(78% - 40px), 520px);
  background: transparent;
  border: 0;
  padding: 0;
  border-radius: 0;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
  text-align: right;
  color: var(--muted);
  white-space: normal;
  word-break: break-word;
}

.archived-box {
  border-top: 1px solid var(--line);
  background: var(--card-2);
  padding: 18px 22px;
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.archive-center {
  text-align: center;
}

.archive-center h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
  color: #f7f8fc;
  letter-spacing: 0.01em;
}

.open-chat-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 126px;
  height: 38px;
  padding: 0 18px;
  background: #2f6fed;
  color: #ffffff;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
}

.open-chat-btn:hover {
  background: #3b7cff;
  transform: translateY(-1px);
}

.open-chat-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
  transform: none;
}

.archive-list::-webkit-scrollbar,
.messages::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.archive-list::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track {
  background: transparent;
}

.archive-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.archive-list::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid transparent;
  background-clip: padding-box;
}

@media (max-width: 1200px) {
  .app {
    grid-template-columns: var(--rail-width) 290px minmax(0, 1fr);
  }

  .archive-sidebar {
    width: 290px;
    min-width: 290px;
    max-width: 290px;
  }
}

@media (max-width: 980px) {
  body {
    padding: 0;
  }

  .app {
    min-width: 0;
    min-height: 100vh;
    height: 100vh;
    border-radius: 0;
    grid-template-columns: var(--rail-width) 280px minmax(0, 1fr);
  }

  .archive-sidebar {
    width: 280px;
    min-width: 280px;
    max-width: 280px;
  }

  .messages {
    padding: 20px 18px;
  }

  .message-row {
    max-width: 86%;
  }
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
  }

  .archive-sidebar {
    display: none;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  .detail-head,
  .archived-box {
    padding-left: 16px;
    padding-right: 16px;
  }

  .messages {
    padding: 18px 14px;
  }

  .message-row {
    max-width: 94%;
  }

  .sender-name {
    margin-left: 36px;
  }

  .sender-name.right {
    margin-right: 36px;
  }

  .bubble.bubble-media {
    max-width: min(70vw, 220px);
  }

  .image-lightbox {
    padding: 14px;
  }

  .lightbox-toolbar {
    top: 12px;
    right: 12px;
  }

  .lightbox-btn {
    width: 38px;
    height: 38px;
    border-radius: 11px;
  }
}

/* =========================================
   MESSAGE TIMESTAMP + READ STATUS
   ========================================= */

.bubble-footer {
  display: inline-flex;
  float: right;
  clear: right;
  align-items: center;
  gap: 2px;
  margin: 5px 0 -3px 6px;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.bubble-footer-spacer {
  display: inline-block;
  width: 0;
  height: 1px;
  vertical-align: baseline;
  pointer-events: none;
  user-select: none;
}

.bubble-time {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.bubble.right .bubble-time {
  color: rgba(255, 255, 255, 0.55);
}

.bubble-check {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
}

.bubble-check svg {
  width: 18px;
  height: 11px;
}

.bubble-check.is-sent {
  color: rgba(255, 255, 255, 0.5);
}

.bubble-check.is-read {
  color: #60a5fa;
}

/* Footer di caption gambar */
.bubble-image-caption .bubble-footer {
  margin: 2px 0 -3px 8px;
}

/* Footer overlay untuk gambar tanpa caption */
.bubble-footer-overlay {
  position: absolute;
  right: 6px;
  bottom: 5px;
  margin: 0;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: none;
}

.bubble-footer-overlay .bubble-time {
  color: rgba(255, 255, 255, 0.88);
}

.bubble-footer-overlay .bubble-check.is-sent {
  color: rgba(255, 255, 255, 0.62);
}

.bubble-footer-overlay .bubble-check.is-read {
  color: #60a5fa;
}

/* =========================================
   DATE SEPARATOR
   ========================================= */

.date-separator {
  align-self: center;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #9ca3af;
  padding: 6px 14px;
  margin: 8px 0 4px;
  letter-spacing: 0.02em;
}

/* =========================================
   RAIL PROFILE AVATAR
   Samakan avatar sidebar profile di arsip
   dengan dashboard / halaman lain
   ========================================= */
.rail-icon .rail-avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.rail-icon.has-avatar {
  padding: 0;
  overflow: hidden;
}

.rail-icon.has-avatar svg {
  display: none;
}