.ticket-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}
.ticket-tabs button.active {
  background: #00a884;
  color: #fff;
}
.ticket-tabs + .ticket-layout {
  height: auto;
  flex: 1;
  min-height: 0;
}
.wa-number {
  display: block;
  font-size: 1.1rem !important;
  margin: 0.5rem 0;
}
.chat-head {
  flex-wrap: wrap;
}
.chat-head select {
  width: auto;
  max-width: 180px;
}

main > header {
  padding: 0.75rem 1.8rem !important;
  min-height: 88px;
}

main > header h1 {
  font-size: 2rem;
  line-height: 1.05;
}

main > header small {
  line-height: 1;
}

#content:has(.ticket-layout) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ticket-layout {
  min-height: 0;
}

.ticket-list,
.messages {
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.chat {
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-head {
  padding: 0.65rem 0.8rem;
  gap: 0.4rem;
}

.chat-contact {
  min-width: 150px;
}

.chat-head .badge {
  white-space: nowrap;
}

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid #d9e0e7;
  color: #344054;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background: #e1e7ed;
  color: #087f5b;
  transform: translateY(-1px);
}

.ui-icon {
  width: 21px;
  height: 21px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.composer {
  padding: 0.6rem !important;
  align-items: stretch;
}

.composer textarea {
  min-height: 58px;
  max-height: 120px;
}

.composer-actions {
  align-self: stretch;
}

.composer .icon-select {
  grid-column: auto;
  width: 48px;
  max-width: 48px;
  padding: 0.45rem;
}

.composer .attach {
  margin: 0;
  padding: 0;
}

.send-icon {
  background: #00a884;
  color: #fff;
  border-color: #00a884;
}

.send-icon:hover {
  background: #008f70;
  color: #fff;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
  background-color: #efeae2;
  background-image: radial-gradient(#d8d2c7 0.7px, transparent 0.7px);
  background-size: 18px 18px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 0.38rem;
  flex: 0 0 auto;
  min-height: 0;
  height: auto;
}

.message-row.me {
  justify-content: flex-end;
}

.message-avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  border-radius: 50%;
  background: #d8e9e5;
  color: #087f5b;
  font-size: 0.7rem;
  font-weight: 800;
}

.message {
  align-self: auto;
  flex: 0 0 auto;
  width: fit-content;
  height: auto !important;
  min-height: 0 !important;
  max-width: min(68%, 620px);
  padding: 0.38rem 0.55rem 0.28rem;
  margin: 0;
  border-radius: 4px 12px 12px 12px;
  background: #fff;
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.14);
  line-height: 1.38;
  text-align: left;
  overflow-wrap: anywhere;
  word-break: normal;
}

.message.me {
  align-self: auto;
  margin-left: 0;
  border-radius: 12px 4px 12px 12px;
  background: #d9fdd3;
}

.message-content,
.formatted-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.42;
}

.message-content {
  display: block;
  white-space: normal;
}

.message-signature {
  display: block;
  margin-bottom: 0.12rem;
  font-weight: 700;
  color: #008069;
}

.message-time {
  display: block;
  margin-top: 0.25rem;
  text-align: right;
  font-size: 0.68rem;
  color: #667085;
}

.quoted-message {
  display: grid;
  gap: 0.15rem;
  margin-bottom: 0.4rem;
  padding: 0.4rem 0.55rem;
  border-left: 3px solid #00a884;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.06);
  font-size: 0.82rem;
}

.quoted-message span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-image {
  display: block;
}

.media-image img,
.message video {
  display: block;
  max-width: 100%;
  max-height: 360px;
  border-radius: 8px;
}

.message audio {
  max-width: min(100%, 340px);
}

.document-card {
  min-width: min(360px, 65vw);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.72);
}

.document-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #e9eef3;
  color: #d92d20;
}

.document-info {
  min-width: 0;
}

.document-info strong,
.document-info small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-card > a {
  display: grid;
  place-items: center;
  padding: 0.35rem;
  border-radius: 8px;
  color: #344054;
}

.document-card > a:hover {
  background: #dfe6ec;
  color: #008069;
}

.message code {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
}

.quick-table table {
  table-layout: fixed;
}

.quick-table th:first-child,
.quick-table td:first-child {
  width: 190px;
}

.quick-table th:last-child,
.quick-table td:last-child {
  width: 160px;
}

.quick-table td {
  vertical-align: top;
}

.quick-actions button {
  display: block;
  width: 100%;
  margin-bottom: 0.4rem;
}

.quick-editor {
  min-height: 320px;
  resize: vertical;
  white-space: pre-wrap;
  line-height: 1.4;
}

.quick-message-preview {
  width: min(var(--wa-preview-width, 300px), 100%);
  min-height: 80px;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: #d9fdd3;
  color: #172033;
  font-family: Arial, sans-serif;
  font-size: 14px;
  line-height: 1.22;
  box-shadow: 0 1px 1px #0002;
}

.preview-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.preview-toolbar label {
  min-width: 190px;
  margin: 0;
}

.draft-preview-panel {
  grid-column: 1 / -1;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.draft-preview-panel summary {
  cursor: pointer;
  font-weight: 600;
}

.draft-preview-panel label {
  max-width: 260px;
  margin: 0.55rem 0;
}

.draft-mobile-preview {
  width: min(var(--wa-preview-width, 300px), 100%);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: #d9fdd3;
  color: #172033;
  font-family: Arial, sans-serif;
  font-size: 14px;
  line-height: 1.22;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.character-total {
  display: block;
  margin-top: 0.4rem;
}

.ticket {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 0.7rem;
  align-items: start;
  padding: 0.85rem 1rem;
}

.ticket-content {
  min-width: 0;
}

.contact-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  display: grid !important;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: #dbe7e4;
  color: #087f5b;
  font-size: 0.82rem;
  font-weight: 750;
  flex: none;
}

.contact-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-avatar {
  width: 42px;
  height: 42px;
}

.ticket.unread {
  background: #eefbf7;
}

.ticket.unread b {
  font-weight: 800;
}

.ticket-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.ticket-row time {
  margin-left: auto;
  color: #64748b;
  font-size: 0.75rem;
  white-space: nowrap;
}

.ticket-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #475569;
}

.ticket-unread {
  margin-left: auto;
  min-width: 1.45rem;
  height: 1.45rem;
  padding: 0 0.35rem;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #00a884;
  color: #fff;
  font-size: 0.72rem;
  font-style: normal;
  flex: none;
}

.ticket-assignment {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.35rem;
}

.ticket-assignment small {
  color: #64748b;
  flex: 1;
}

.ticket-assignee {
  width: 165px;
  max-width: 48%;
  padding: 0.38rem 0.5rem;
  font-size: 0.82rem;
  background: #fff;
}

aside {
  overflow: hidden !important;
}

aside .brand {
  flex: none;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
}

aside nav {
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.header-actions #identity {
  white-space: nowrap;
}
.service-status {
  white-space: nowrap;
}
.service-status.online {
  color: #087f5b;
}
.service-status.disconnected {
  color: #9a6700;
}
.service-status.offline {
  color: #c62828;
}

.notification-bell {
  position: relative;
  background: #edf1f5;
  color: #253247;
}

.notification-bell span {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  background: #64748b;
  color: #fff;
  font-size: 0.7rem;
}

.notification-bell.has-unread span {
  background: #dc2626;
}

@media (max-width: 800px) {
  body {
    overflow-x: hidden;
  }
  #app:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100dvh;
  }
  aside {
    position: sticky;
    top: 0;
    z-index: 20;
    width: 100%;
    height: auto !important;
    padding: 0.35rem !important;
  }
  aside nav {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    scrollbar-width: thin;
  }
  aside nav button {
    flex: 0 0 auto;
    padding: 0.55rem 0.7rem;
    white-space: nowrap;
    font-size: 0.85rem;
  }
  main {
    width: 100%;
    min-width: 0;
    height: auto !important;
    min-height: 0;
    padding: 0.5rem !important;
    overflow: visible !important;
  }
  main > header {
    margin: 0 0 0.55rem !important;
    min-height: 0;
    padding: 0.65rem !important;
    gap: 0.5rem;
    align-items: flex-start;
  }
  main > header h1 {
    font-size: 1.35rem;
  }
  .header-actions {
    gap: 0.35rem;
  }
  .header-actions button {
    padding: 0.5rem 0.6rem;
    font-size: 0.82rem;
  }
  .header-actions #identity {
    max-width: 105px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.78rem;
  }
  .ticket-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-bottom: 0.4rem;
  }
  .ticket-tabs button {
    flex: 0 0 auto;
    padding: 0.55rem 0.7rem;
    font-size: 0.85rem;
  }
  #content:has(.ticket-layout) {
    height: calc(100dvh - 170px);
    min-height: 560px;
    overflow: hidden;
  }
  .ticket-tabs + .ticket-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(180px, 38%) minmax(300px, 62%);
    width: 100%;
    height: 100%;
    min-height: 0;
  }
  .ticket-list {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .ticket {
    padding: 0.65rem 0.75rem;
  }
  .ticket-assignee {
    width: 145px;
  }
  .chat {
    min-height: 0;
  }
  .chat-head {
    padding: 0.45rem;
  }
  .chat-contact {
    width: calc(100% - 70px);
  }
  .messages {
    padding: 0.55rem;
  }
  .message {
    max-width: 86%;
    font-size: 0.9rem;
  }
  .composer {
    grid-template-columns: minmax(0, 1fr) auto !important;
    padding: 0.4rem !important;
  }
  .composer textarea {
    min-width: 0;
    min-height: 48px;
  }
  .composer-actions {
    gap: 0.25rem;
  }
  .icon-btn {
    width: 38px;
    height: 38px;
  }
  dialog {
    width: calc(100vw - 1rem);
    max-height: 92dvh;
    overflow-y: auto;
  }
  #modalForm {
    padding: 0.85rem;
  }
  .table {
    max-width: 100%;
  }
  .quick-table table,
  .quick-table tbody,
  .quick-table tr,
  .quick-table td {
    display: block;
    width: 100% !important;
  }
  .quick-table thead {
    display: none;
  }
  .quick-table tr {
    padding: 0.7rem;
    border-bottom: 1px solid var(--line);
  }
  .quick-table td {
    padding: 0.35rem 0;
    border: 0;
  }
  .quick-message-preview {
    width: min(var(--wa-preview-width, 300px), 100%);
  }

  .preview-toolbar {
    display: grid;
    align-items: stretch;
  }
  .quick-actions {
    display: flex !important;
    gap: 0.4rem;
  }
  .quick-actions button {
    display: inline-block;
    margin: 0;
  }
}

@media (max-width: 430px) {
  main > header small,
  .header-actions #identity {
    display: none;
  }
  .notification-bell {
    width: auto;
  }
  .chat-head .badge {
    display: none;
  }
  .composer .icon-select {
    width: 40px;
  }
}
