html,
body {
  overflow: hidden;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.nav-panel,
.thread-list-panel,
.conversation-panel,
.details-panel {
  min-height: 0;
  overflow: hidden;
}

.thread-list-panel {
  display: flex;
  flex-direction: column;
}

.thread-list-panel .panel-header {
  flex: 0 0 72px;
}

.thread-list {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conversation-panel {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.timeline {
  flex: 1 1 0;
  height: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.composer {
  flex: 0 0 auto;
  max-height: 45vh;
  overflow-y: auto;
}

.details-panel {
  height: 100%;
  overflow-y: auto;
}

.message-media img {
  width: auto;
  height: auto;
  object-fit: contain;
}

.schedule-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  font-size: 13px;
}

#masterSchedulePanel {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

#masterScheduleDateTime {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.composer-tools {
  position: relative;
}

.master-emoji-panel {
  position: absolute;
  left: 0;
  bottom: 38px;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(8, 34px);
  gap: 3px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px #0002;
}

.master-emoji-panel button {
  border: 0;
  border-radius: 5px;
  background: transparent;
  padding: 5px;
  cursor: pointer;
  font-size: 19px;
}

.master-emoji-panel button:hover {
  background: #eef2f7;
}

.channel-select-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode-radios {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.mode-radios label {
  cursor: pointer;
}

.composer.mode-whatsapp #templateArea {
  display: block !important;
}

.message-row.inbound .message {
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #111827;
}

.message-row.outbound .message {
  background: #2563eb;
  border-color: #1d4ed8;
  color: #fff;
}

.message-row.outbound .message-meta {
  color: #dbeafe;
}

.message-row.channel-whatsapp.outbound .message {
  background: #168a50;
  border-color: #10713f;
}

.message-row.channel-whatsapp.outbound .message-meta {
  color: #dcfce7;
}

.message-row.internal {
  justify-content: center;
}

.message-row.internal .message {
  min-width: 220px;
  max-width: 65%;
  background: #fff4cc;
  border-color: #e9bb39;
  color: #503b00;
  text-align: center;
}

.message-archive-button {
  display: block;
  margin: 6px auto 0;
  padding: 2px 8px;
  border: 1px solid currentColor;
  border-radius: 5px;
  background: #ffffffdd;
  color: #4b5563;
  cursor: pointer;
  font-size: 11px;
}

.snippet-button {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

.master-snippet-panel {
  position: fixed;
  z-index: 10000;
  width: min(430px, 70vw);
  max-height: 330px;
  overflow-y: auto;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px #0002;
}

.snippet-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}

.snippet-filter,
.snippet-item {
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

.snippet-filter {
  border-radius: 12px;
  padding: 3px 8px;
}

.snippet-filter.active {
  background: #dbeafe;
  color: #1d4ed8;
}

.snippet-item {
  display: block;
  width: 100%;
  margin: 5px 0;
  padding: 8px;
  border-radius: 6px;
  text-align: left;
}

.snippet-item:hover {
  background: #eff6ff;
}

.snippet-item strong,
.snippet-item small {
  display: block;
}

.master-routing-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px 16px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
}

.master-routing-header strong {
  color: var(--ink);
}

#masterToCountry {
  margin-left: 6px;
  color: var(--ink);
  font-weight: 600;
}

#masterToCountry img {
  width: 18px;
  height: 13px;
  margin: 0 4px 0 2px;
  border: 1px solid #d1d5db;
  border-radius: 2px;
  object-fit: cover;
  vertical-align: -2px;
}

.sending-as {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.internal-comment-hint {
  padding: 0 12px 7px;
  color: var(--muted);
  font-size: 11px;
}

.message-row {
  flex-direction: column;
}

.message-row.inbound {
  align-items: flex-start;
}

.message-row.outbound {
  align-items: flex-end;
}

.message-row.internal {
  align-items: center;
}

.message-archive-button {
  margin: 4px 8px 0;
  padding: 2px 7px;
  border-color: #d1d5db;
  background: transparent;
  color: #6b7280;
}

.mobile-back {
  display: none;
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  padding: 5px 9px 5px 0;
  font-size: 26px;
  cursor: pointer;
}

body.master-mobile .app-shell {
  display: block;
  width: 100%;
}

body.master-mobile .nav-panel,
body.master-mobile .details-panel {
  display: none !important;
}

body.master-mobile .thread-list-panel,
body.master-mobile.mobile-chat .conversation-panel {
  width: 100%;
  height: 100%;
  border: 0;
}

body.master-mobile:not(.mobile-chat) .conversation-panel,
body.master-mobile.mobile-chat .thread-list-panel {
  display: none !important;
}

body.master-mobile .thread-list-panel {
  display: flex;
}

body.master-mobile.mobile-chat .conversation-panel {
  display: flex;
}

body.master-mobile .mobile-back {
  display: block;
}

body.master-mobile .conversation-header {
  height: 62px;
  padding: 8px 12px;
}

body.master-mobile .header-actions {
  display: none;
}

body.master-mobile .timeline {
  padding: 10px;
}

body.master-mobile .message {
  max-width: 88%;
}

body.master-mobile .composer {
  margin: 0;
  max-height: 52vh;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
}

body.master-mobile .master-routing-header {
  grid-template-columns: 1fr;
  gap: 3px;
}

body.master-mobile .composer-toolbar,
body.master-mobile .schedule-controls {
  align-items: flex-start;
}

body.master-mobile .mode-radios {
  gap: 8px;
}

body.master-mobile .sending-as {
  width: 100%;
  margin: 3px 0 0;
}

@media (max-width: 900px) {
  body:not(.master-mobile) .app-shell {
    grid-template-columns: 1fr;
  }
}

.snippet-item small {
  margin-top: 3px;
  color: var(--muted);
}
