:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-soft: #f7f8f8;
  --surface-muted: #eef2f0;
  --line: #e4e8e6;
  --line-strong: #cfd8d4;
  --text: #1f2925;
  --muted: #697873;
  --muted-strong: #51615b;
  --accent: #0f6154;
  --accent-strong: #0a4d43;
  --accent-soft: #edf7f4;
  --whatsapp: #178b76;
  --outlook: #4f73d9;
  --agent-bubble: #e4f3ed;
  --agent-bubble-line: #d0e5dc;
  --automation-bubble: #fff5df;
  --automation-bubble-line: #ead7a9;
  --automation-text: #69501a;
  --warning: #b66a16;
  --danger: #b93535;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

button, input, textarea, select { font: inherit; }

button {
  border: 0;
  cursor: pointer;
}

.inbox-shell {
  position: relative;
  display: grid;
  grid-template-columns: 360px minmax(480px, 1fr) 300px;
  height: 100vh;
  min-height: 620px;
  overflow: hidden;
  background: var(--surface);
}

.new-message-toast {
  position: fixed;
  z-index: 20;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #bde5d7;
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--accent-strong);
  background: #f1fbf6;
  box-shadow: 0 14px 34px rgba(20, 35, 29, 0.14);
  font-size: 13px;
}

.new-message-toast span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--whatsapp);
  font-weight: 600;
}

.new-message-toast span::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--whatsapp);
}

.new-message-toast strong {
  font-weight: 540;
}

.inbox-sidebar,
.conversation-panel,
.context-panel {
  min-width: 0;
  min-height: 0;
}

.inbox-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.sidebar-header,
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-header {
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand-lockup,
.auth-brand,
.chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-lockup h1,
.auth-brand h1,
.chat-title h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-lockup h1,
.auth-brand h1 {
  font-size: 18px;
  font-weight: 540;
  line-height: 1.1;
}

.brand-lockup p,
.auth-brand p,
.chat-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-mark,
.avatar {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  font-weight: 540;
}

.product-mark {
  position: relative;
  width: 26px;
  height: 26px;
  color: #ffffff;
  background: var(--accent);
  border: 0;
  font-size: 0;
}

.product-mark::before {
  content: "";
  width: 14px;
  height: 10px;
  border: 2px solid #ffffff;
  border-radius: 5px;
}

.product-mark::after {
  content: "";
  position: absolute;
  left: 9px;
  bottom: 6px;
  width: 6px;
  height: 6px;
  border-left: 2px solid #ffffff;
  border-bottom: 2px solid #ffffff;
  transform: rotate(-28deg);
}

.avatar {
  width: 32px;
  height: 32px;
  color: var(--muted-strong);
  background: #eef2f0;
  font-size: 11px;
}

.avatar.whatsapp { color: var(--accent-strong); background: var(--accent-soft); }
.avatar.outlook { color: #3358be; background: #eef2ff; }
.avatar.large { width: 36px; height: 36px; font-size: 12px; }

.icon-button {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted-strong);
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 500;
}

.filter-panel {
  padding: 12px 14px;
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.search-box {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.search-box input,
.input,
.reply-row textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.search-box input,
.input {
  border-radius: var(--radius);
  padding: 9px 10px;
  font-size: 13px;
}

.search-box input:focus,
.input:focus,
.reply-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 97, 84, 0.12);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.filter-pill,
.mode-action {
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--muted-strong);
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 500;
}

.filter-pill.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.conversation-list {
  flex: 1;
  overflow: auto;
  padding: 0;
}

.conversation-card {
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 11px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}

.conversation-card:hover {
  background: var(--surface-soft);
}

.conversation-card.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.conversation-card.unread .conversation-line strong {
  color: var(--accent-strong);
  font-weight: 540;
}

.conversation-card.unread {
  background: #f0fbf6;
}

.conversation-card.unread::after {
  content: "";
  position: absolute;
  inset: 8px auto 8px 0;
  width: 3px;
  border-radius: 999px;
  background: var(--whatsapp);
}

.conversation-card.unread .conversation-preview,
.conversation-card.unread .conversation-line time {
  color: var(--whatsapp);
  font-weight: 560;
}

.conversation-card.new-message {
  animation: new-message-pulse 1.2s ease-out 2;
}

.conversation-body {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.conversation-line,
.conversation-time,
.conversation-meta,
.message-top,
.message-foot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conversation-line {
  justify-content: space-between;
}

.conversation-time {
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.conversation-line strong,
.chat-title h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-line strong {
  font-size: 13px;
  font-weight: 520;
  line-height: 1.25;
}

.conversation-line time,
.message-top time,
.event-row time {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.conversation-subject,
.conversation-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.conversation-preview {
  color: var(--muted-strong);
}

.conversation-meta {
  flex-wrap: wrap;
  gap: 5px;
}

.channel-badge,
.mode-pill,
.assignee,
.status-dot,
.message-foot span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.channel-badge,
.mode-pill,
.assignee {
  padding: 4px 7px;
  border: 1px solid transparent;
}

.channel-badge {
  color: var(--accent-strong);
  background: #eef8f5;
}

.channel-badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.channel-badge.whatsapp::before { background: var(--whatsapp); }
.channel-badge.outlook::before { background: var(--outlook); }

.mode-pill {
  background: #f2f5f3;
}

.mode-pill.auto {
  color: var(--automation-text);
  background: var(--automation-bubble);
  border-color: var(--automation-bubble-line);
}
.mode-pill.human {
  color: var(--text);
  background: #eef2f0;
}
.mode-pill.paused {
  color: var(--warning);
  background: #fff4e8;
}
.mode-pill.closed {
  color: var(--danger);
  background: #fff0f0;
}

.assignee {
  color: var(--muted-strong);
  background: #ffffff;
  border-color: var(--line);
}

.unread-count {
  min-width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  padding: 0 5px;
  color: #ffffff;
  background: var(--whatsapp);
  font-size: 11px;
  font-weight: 650;
  line-height: 1;
}

.hubspot-card .button-secondary {
  justify-content: center;
  margin-top: 10px;
  text-decoration: none;
}

.button-secondary {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 11px;
  color: var(--accent-strong);
  background: #ffffff;
  font-size: 12px;
  font-weight: 540;
}

.button-secondary:disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: var(--surface-soft);
}

.integration-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.full-width {
  width: 100%;
}

@keyframes new-message-pulse {
  0% { box-shadow: inset 3px 0 0 var(--whatsapp), 0 0 0 0 rgba(23, 139, 118, 0.26); }
  100% { box-shadow: inset 3px 0 0 var(--whatsapp), 0 0 0 10px rgba(23, 139, 118, 0); }
}

.conversation-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--surface-muted);
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.chat-title {
  min-width: 0;
}

.chat-title h2 {
  font-size: 16px;
  font-weight: 540;
  line-height: 1.2;
}

.crm-name-suggestion {
  margin-top: 7px;
  border: 1px solid rgba(13, 122, 103, 0.22);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--accent-strong);
  background: rgba(231, 247, 242, 0.92);
  font-size: 11px;
  font-weight: 540;
}

.crm-name-suggestion:hover {
  border-color: rgba(13, 122, 103, 0.38);
  background: #dcf4ed;
}

.chat-badges {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.messages {
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background:
    linear-gradient(rgba(244, 248, 246, 0.78), rgba(244, 248, 246, 0.78)),
    url("/assets/sbs-inbox-bg-20260729.png") center / 860px auto repeat;
}

.message {
  width: fit-content;
  max-width: min(68%, 720px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px 7px;
  background: #ffffff;
  box-shadow: none;
  font-size: 13px;
  line-height: 1.42;
}

.message.outbound {
  align-self: flex-end;
  background: var(--agent-bubble);
  border-color: var(--agent-bubble-line);
}

.message.automation {
  border-style: solid;
}

.message.outbound.automation {
  background: var(--automation-bubble);
  border-color: var(--automation-bubble-line);
}

.message.outbound.automation .message-top strong {
  color: var(--automation-text);
}

.message-top {
  justify-content: space-between;
  margin-bottom: 5px;
}

.message-top strong {
  font-size: 12px;
  font-weight: 520;
  color: var(--muted-strong);
}

.message h3 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 520;
  line-height: 1.35;
}

.message-text {
  white-space: normal;
  overflow-wrap: anywhere;
}

.attachments {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.attachment-card {
  display: grid;
  gap: 6px;
  max-width: 320px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted-strong);
  font-size: 12px;
}

.attachment-card.unavailable {
  max-width: 360px;
  border-style: dashed;
  background: #f8faf9;
}

.attachment-card strong {
  font-weight: 540;
  color: var(--text);
}

.attachment-card.unavailable strong {
  color: var(--muted-strong);
}

.attachment-card.unavailable span {
  color: var(--muted);
}

.attachment-card a {
  color: var(--accent);
  text-decoration: none;
}

.attachment-card img,
.attachment-card video {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  object-fit: contain;
  background: var(--surface-muted);
}

.attachment-card .attachment-fallback {
  display: none;
  color: var(--accent);
  font-weight: 520;
}

.attachment-card.broken img {
  display: none;
}

.attachment-card.broken .attachment-fallback {
  display: inline;
}

.attachment-card audio {
  width: 100%;
}

.message-foot {
  justify-content: flex-end;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.status-dot {
  position: relative;
  padding-left: 10px;
  color: var(--muted);
}

.status-dot::before {
  content: "";
  position: absolute;
  left: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}

.status-dot.sent::before,
.status-dot.delivered::before,
.status-dot.read::before,
.status-dot.received::before {
  background: var(--accent);
}

.status-dot.queued::before,
.status-dot.processing::before {
  background: var(--warning);
}

.status-dot.failed::before {
  background: var(--danger);
}

.composer {
  display: grid;
  gap: 10px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

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

.mode-action:hover,
.filter-pill:hover,
.icon-button:hover {
  background: var(--surface-soft);
}

.mode-action.danger {
  color: var(--danger);
}

.reply-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.reply-row textarea {
  min-height: 58px;
  max-height: 180px;
  resize: vertical;
  border-radius: var(--radius);
  padding: 10px 11px;
  font-size: 13px;
  line-height: 1.4;
}

.button-primary {
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 540;
  white-space: nowrap;
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-primary:disabled {
  cursor: wait;
  opacity: 0.68;
}

.context-panel {
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.context-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.context-section h3 {
  margin: 0 0 14px;
  font-size: 13px;
  letter-spacing: 0;
  font-weight: 540;
  color: var(--muted-strong);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 8px 0;
  background: transparent;
}

.stat span,
.contact-list dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  font-weight: 520;
  line-height: 1;
}

.contact-list {
  margin: 0;
  display: grid;
  gap: 10px;
}

.contact-list div {
  min-width: 0;
}

.contact-list dd {
  margin: 3px 0 0;
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.event-list {
  display: grid;
  gap: 11px;
}

.event-row {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr);
  gap: 9px;
}

.event-row > span {
  width: 9px;
  height: 9px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.event-row strong {
  display: block;
  font-size: 12px;
  font-weight: 520;
  overflow-wrap: anywhere;
}

.event-row time {
  display: block;
  margin-top: 2px;
}

.empty-state,
.conversation-empty {
  color: var(--muted);
  font-size: 14px;
}

.empty-state {
  padding: 18px 12px;
}

.empty-state.compact {
  padding: 0;
  font-size: 13px;
}

.conversation-empty {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 32px;
  text-align: center;
  background: var(--surface-soft);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 97, 84, 0.10), transparent 36%),
    var(--bg);
}

.auth-card {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(23, 35, 31, 0.10);
}

.auth-form {
  display: grid;
  gap: 11px;
  margin-top: 18px;
}

.notice {
  margin-top: 16px;
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 600;
}

.notice.danger {
  color: var(--danger);
  background: #fde7e7;
}

@media (max-width: 1180px) {
  .inbox-shell {
    grid-template-columns: 300px minmax(420px, 1fr);
  }

  .context-panel {
    display: none;
  }
}

@media (max-width: 780px) {
  .inbox-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .inbox-sidebar,
  .context-panel {
    display: block;
    border: 0;
  }

  .conversation-list {
    max-height: 42vh;
  }

  .conversation-panel {
    min-height: 72vh;
  }

  .chat-header,
  .reply-row {
    grid-template-columns: 1fr;
  }

  .chat-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .message {
    max-width: 92%;
  }

  .reply-row {
    display: grid;
  }

  .send-button {
    width: 100%;
  }
}
