.chat {
  position: relative;
  container: chat / inline-size;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface-cream);
}

.chat__header {
  --header-bg: var(--surface);
  --header-text: var(--text);
  --header-muted: var(--text-muted);
  --header-hover: var(--surface-soft);

  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-height);
  padding: 10px 20px;
  color: var(--header-text);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  transition: background var(--duration) var(--ease);
}

.chat__header--dark {
  --header-text: #fff;
  --header-muted: rgb(255 255 255 / 72%);
  --header-hover: rgb(255 255 255 / 10%);
}

.chat__header--light {
  --header-text: var(--ink-900);
  --header-muted: rgb(23 19 15 / 68%);
  --header-hover: rgb(255 255 255 / 22%);
}

.chat__header--sapphire {
  --header-bg: var(--package-sapphire);
}

.chat__header--ruby {
  --header-bg: var(--package-ruby);
}

.chat__header--onyx {
  --header-bg: var(--package-onyx);
}

.chat__package {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  margin-right: 4px;
  padding: 0 8px;
  vertical-align: 1px;
  border-radius: var(--radius-xs);
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
  color: var(--header-text);
  background: rgb(255 255 255 / 18%);
  border: 1px solid rgb(255 255 255 / 30%);
}

.chat__identity {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 4px;
  border-radius: var(--radius-md);
  text-align: left;
}

.chat__identity:hover {
  background: var(--header-hover);
}

.chat__identity-text {
  display: grid;
  min-width: 0;
}

.chat__name-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat__name {
  overflow: hidden;
  font-size: var(--fs-lg);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat__subtitle {
  overflow: hidden;
  font-size: var(--fs-md);
  color: var(--header-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px 0 12px;
  border-radius: var(--radius-md);
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-btn--baru {
  color: var(--blue-500);
  background: var(--blue-100);
  border-color: #d3e1f6;
}
.status-btn--follow_up {
  color: var(--orange-600);
  background: var(--orange-100);
  border-color: #f5dcae;
}
.status-btn--menunggu_pembayaran {
  color: var(--purple-500);
  background: var(--purple-100);
  border-color: #e6d3f3;
}
.status-btn--closing {
  color: var(--gold-700);
  background: #f6eedd;
  border-color: #ead8b3;
}
.status-btn--selesai {
  color: var(--green-500);
  background: var(--green-100);
  border-color: #cfe7d8;
}
.status-btn--tidak_deal {
  color: var(--red-500);
  background: var(--red-100);
  border-color: #f4d2cb;
}
.status-btn--on_progress {
  color: var(--blue-500);
  background: var(--blue-100);
  border-color: #d3e1f6;
}
.status-btn--unsolved {
  color: var(--orange-600);
  background: var(--orange-100);
  border-color: #f5dcae;
}
.status-btn--solved {
  color: var(--green-500);
  background: var(--green-100);
  border-color: #cfe7d8;
}
.status-btn--spam {
  color: var(--red-500);
  background: var(--red-100);
  border-color: #f4d2cb;
}

.status-btn__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.assign-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px 0 6px;
  border-radius: var(--radius-md);
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.assign-btn:hover,
.assign-btn[aria-expanded="true"] {
  background: var(--surface-soft);
}

.assign-btn--empty {
  padding-left: 12px;
  color: var(--gold-700);
  border-style: dashed;
}

.assign-btn__extra {
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--surface-muted);
}

.chat__thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.thread-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 8px 0 20px;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-muted);
}

.thread-divider::before,
.thread-divider::after {
  flex: 1;
  height: 1px;
  background: var(--border);
  content: "";
}

.thread-divider__label {
  max-width: 80%;
  padding: 4px 14px;
  text-align: center;
  border-radius: var(--radius-full);
  background: var(--surface-pill);
}

.thread-divider--closing {
  color: var(--gold-700);
}

.thread-divider--closing::before,
.thread-divider--closing::after {
  background: repeating-linear-gradient(90deg, var(--gold-500) 0 6px, transparent 6px 10px);
}

.thread-divider--closing .thread-divider__label {
  background: #f6eedd;
}

.message {
  display: flex;
  margin-bottom: 16px;
}

.message--out {
  justify-content: flex-end;
}

.message__bubble {
  position: relative;
  max-width: min(560px, 78%);
  padding: 10px 14px 8px;
  border-radius: var(--radius-lg);
  font-size: var(--fs-base);
  line-height: 1.45;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
}

.message__template-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--gold-700);
}

.message--out .message__bubble {
  background: var(--bubble-out);
  border-color: var(--bubble-out-border);
}

.message__signature {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--bubble-out-border);
  font-size: var(--fs-md);
  font-style: italic;
  color: var(--gold-700);
}

.message__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 6px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

.message__tick--read {
  color: var(--blue-500);
}

.message__tick--failed {
  color: var(--red-500);
}

.message__copy {
  position: absolute;
  top: 8px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.message--in .message__copy {
  right: -40px;
}

.message--out .message__copy {
  left: -40px;
}

.message__bubble:hover .message__copy,
.message__copy:focus-visible {
  opacity: 1;
}

.message__sticker {
  font-size: 64px;
  line-height: 1;
}

.message--sticker .message__bubble {
  padding: 4px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.message__image {
  display: block;
  max-width: 280px;
  max-height: 260px;
  margin-bottom: 4px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.message__file,
.message__audio {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: rgb(255 255 255 / 60%);
  border: 1px solid var(--border);
}

.message__file-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  color: var(--gold-700);
  background: #f6eedd;
}

.message__file-text {
  display: grid;
}

.message__file-name {
  font-weight: 600;
  line-height: 1.3;
}

.message__file-size {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.message__wave {
  flex: 1;
  height: 24px;
  background: repeating-linear-gradient(90deg, var(--gold-500) 0 3px, transparent 3px 6px);
  mask: linear-gradient(180deg, transparent 20%, #000 20% 80%, transparent 80%);
  opacity: 0.7;
}

.mention {
  font-weight: 700;
  color: var(--blue-500);
}

.chat__composer {
  position: relative;
  padding: 12px 24px 18px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer-hint {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 5px 12px;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  color: var(--text-muted);
  background: var(--surface-cream);
}

.composer-hint__key {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--radius-xs);
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

.composer-hint__key:hover:not(:disabled) {
  border-color: var(--gold-500);
}

.composer-hint__key:disabled {
  opacity: 0.4;
}

.composer-note-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--gold-700);
  background: #fffbea;
  border: 1px dashed #e7cf8f;
}

.composer-note-bar__close {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.composer-note-bar__close:hover {
  background: #f6eccd;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer-row .icon-btn {
  width: 42px;
  height: 46px;
}

.composer-input {
  flex: 1;
  min-height: 46px;
  max-height: 160px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  line-height: 1.45;
  background: var(--surface-cream);
  border: 1px solid var(--border);
  resize: none;
}

.composer-input::placeholder {
  overflow: hidden;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-input:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: var(--focus-ring);
}

.composer-input.is-note {
  background: #fffbea;
  border-color: #e7cf8f;
}

.send-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 46px;
  border-radius: var(--radius-md);
  color: var(--ink-900);
  background: var(--gold-gradient);
  box-shadow: var(--shadow-sm);
}

.send-btn:disabled {
  opacity: 0.5;
}

.recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 46px;
  padding: 0 8px 0 16px;
  border-radius: var(--radius-md);
  background: var(--red-100);
}

.recording-bar__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red-500);
  animation: pulse 1.2s ease-in-out infinite;
}

.recording-bar__label {
  flex: 1;
  font-weight: 600;
  color: var(--red-500);
}

.composer-lock {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-cream);
  border: 1px solid var(--border);
}

.composer-lock__icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--gold-700);
  background: #f6eedd;
}

.composer-lock__text {
  flex: 1;
  min-width: 200px;
}

.composer-lock__title {
  font-weight: 700;
}

.composer-lock__desc {
  font-size: var(--fs-md);
  color: var(--text-muted);
}

.composer-lock__actions {
  display: flex;
  gap: 8px;
}

.palette {
  position: absolute;
  right: 24px;
  bottom: calc(100% - 8px);
  left: 24px;
  z-index: 20;
  max-height: 440px;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--duration) var(--ease);
}

.palette--narrow {
  right: auto;
  width: min(460px, calc(100% - 48px));
}

.palette__header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.palette__tabs {
  display: flex;
  gap: 4px;
}

.palette__tab {
  height: 28px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-muted);
}

.palette__tab[aria-selected="true"] {
  color: #fff;
  background: var(--ink-900);
}

.palette__item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}

.palette__item:last-child {
  border-bottom: 0;
}

.palette__item:hover,
.palette__item.is-highlighted {
  background: var(--surface-active);
}

.palette__command {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  color: var(--gold-700);
  background: #f6eedd;
}

.palette__text {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
}

.palette__vars {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.palette__var {
  padding: 1px 8px;
  border-radius: var(--radius-xs);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--purple-500);
  background: var(--purple-100);
}

.palette__empty {
  padding: 24px 18px;
  text-align: center;
  color: var(--text-muted);
}

.palette__person {
  display: grid;
  flex: 1;
}

.palette__person-role {
  font-size: var(--fs-md);
  color: var(--text-muted);
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
}

.sticker-grid__item {
  display: grid;
  place-items: center;
  height: 64px;
  border-radius: var(--radius-md);
  font-size: 34px;
}

.sticker-grid__item:hover {
  background: var(--surface-muted);
}

.only-mobile {
  display: none;
}

@container chat (max-width: 640px) {
  .chat__header {
    padding-inline: 16px;
  }

  .assign-btn {
    padding-right: 6px;
  }

  .assign-btn__name {
    display: none;
  }

  .chat__thread {
    padding-inline: 20px;
  }

  .chat__composer {
    padding-inline: 16px;
  }
}

@container chat (max-width: 560px) {
  .chat__name-line .badge {
    display: none;
  }

  .status-btn__label {
    max-width: 110px;
  }

  .chat__actions {
    gap: 6px;
  }
}

@media (max-width: 767px) {
  .only-mobile {
    display: inline-grid;
  }

  .chat__header {
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 10px 12px;
  }

  .chat__identity {
    flex-basis: calc(100% - 52px);
  }

  .chat__actions {
    justify-content: flex-end;
    width: 100%;
  }

  .chat__thread {
    padding: 16px;
  }

  .chat__composer {
    padding: 10px 12px 12px;
  }

  .palette {
    right: 12px;
    left: 12px;
  }

  .message__bubble {
    max-width: 88%;
  }
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}
