:root { color-scheme: light; font: 16px system-ui, sans-serif; color: #182b28; background: #edf3f1; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; display: flex; flex-direction: column; }
header { background: #123e37; color: white; padding: 18px 26px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.header-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.header-actions button { font-size: .875rem; white-space: nowrap; color: #123e37; }
.header-actions button:hover { background: #e4f3ee; }
header strong { font-size: 1.22rem; }
header span { font-size: .875rem; text-align: right; color: #dcf3ea; }
.sound-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; font-size: .875rem; }
.sound-controls input { width: 84px; margin: 0; padding: 0; accent-color: #b6ebd8; }
.sound-controls span { min-width: 4ch; font-variant-numeric: tabular-nums; }
#notice { margin: 0; padding: 10px 26px; background: #fff2ce; }
main { display: grid; grid-template-columns: minmax(245px, 330px) minmax(0, 1fr); flex: 1; min-height: 0; }
aside { background: white; padding: 22px 16px; border-right: 1px solid #d8e4e0; max-height: calc(100dvh - 75px); overflow: auto; }
h1, h2 { margin: 0 0 13px; font-size: 1.3rem; }
input, select, button { font: inherit; }
input, select { border: 1px solid #a8bdb6; border-radius: 8px; padding: 10px; width: 100%; min-width: 0; background: white; color: inherit; }
aside select { margin: 9px 0 15px; }
button { cursor: pointer; border: 1px solid #a8bdb6; color: inherit; background: white; padding: 8px 12px; border-radius: 8px; }
button:disabled { opacity: .6; cursor: wait; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #18736b; outline-offset: 2px; }
.chat-card { width: 100%; display: grid; text-align: left; padding: 12px; gap: 7px; margin-bottom: 5px; border-color: transparent; }
.chat-card:hover, .chat-card[aria-pressed=true] { background: #e4f3ee; }
.chat-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-weight: 680; }
small, .snippet { color: #4b655e; font-size: .875rem; font-weight: 400; }
.snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags, #labels { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 9px; font-size: .875rem; border-radius: 100px; border: 1px solid transparent; }
button.chip[aria-pressed=false] { background: white; border-color: currentColor; }
button.chip[aria-pressed=true]::before { content: '✓ '; }
.blue { color: #174571; background: #d9eafd; }
.violet { color: #523486; background: #ece2fc; }
.amber { color: #694400; background: #ffedc2; }
.green { color: #285534; background: #d9efda; }
.rose { color: #872a47; background: #fce0ea; }
.teal { color: #135851; background: #d1f0e9; }
.thread { display: grid; grid-template-rows: auto minmax(180px, 1fr) auto; height: calc(100dvh - 62px); }
.thread-head, form { background: white; padding: 16px 22px; border-bottom: 1px solid #d8e4e0; }
.conversation-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.conversation-heading h2 { margin: 0; }
.conversation-heading button { font-size: .875rem; padding: 4px 8px; }
#contact-avatar { position: relative; display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; overflow: hidden; border-radius: 50%; background: #d9efe6; color: #145f52; font-size: .85rem; font-weight: 700; }
#contact-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#messages { padding: 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.bubble { width: fit-content; max-width: min(84%, 650px); background: white; border-radius: 10px 10px 10px 2px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.own { align-self: flex-end; background: #d9efe6; border-radius: 10px 10px 2px 10px; }
.bubble small { display: block; text-align: right; margin-top: 5px; }
.delivery-ticks { margin-inline-start: 6px; color: #526964; letter-spacing: -0.12em; font-weight: 700; }
.delivery-ticks[data-delivery="read"] { color: #00649b; }
.attachment-card { display: grid; gap: 6px; }
.attachment-card button { justify-self: start; font-size: .875rem; }
.attachment-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-preview img, .attachment-preview video { display: block; max-width: 100%; max-height: 26rem; border-radius: 6px; }
.attachment-preview pre { margin: 0; padding: 8px; max-height: 18rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: #f4f8f6; border-radius: 6px; }
audio { max-width: 100%; }
.compose-row { display: flex; flex-wrap: wrap; gap: 8px; }
.compose-row input { flex: 1 1 200px; }
#send { background: #145f52; border-color: #145f52; color: white; }
[hidden] { display: none !important; }
@media(max-width: 650px) {
  main { display: block; }
  aside { max-height: 43dvh; border-right: 0; border-bottom: 1px solid #d8e4e0; }
  .thread { height: 65dvh; }
  header, .thread-head, form, #messages { padding-left: 14px; padding-right: 14px; }
}

.assignment { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; flex-wrap: wrap; }
.assignment select { width: auto; padding: 4px 8px; }
.assignment button { padding: 3px 8px; }
.assignee { font-size: .875rem; color: #145f52; font-weight: 650; }
dialog { border: 1px solid #a8bdb6; border-radius: 12px; width: min(480px, 94vw); max-height: 90dvh; color: #182b28; }
dialog::backdrop { background: #172e28ac; }
dialog h2, dialog h3 { margin: 0; }
.dialog-title, #members li { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
#members { list-style: none; padding: 0; }
#members li { padding: 8px 0; border-bottom: 1px solid #d8e4e0; }
.team-form { display: grid; gap: 10px; padding: 0; border: 0; }
.team-form label { display: grid; gap: 4px; }
.team-form [type=submit] { justify-self: start; background: #145f52; color: white; }
.login-intro, .login-help, .login-support { margin: 0; line-height: 1.5; }
.login-intro { font-weight: 600; }
.login-help, .login-support { color: #50635e; font-size: .875rem; }
.login-support { border-top: 1px solid #d8e4e0; padding-top: 12px; }
.login-support a { color: #145f52; }

.password-field { display: grid; gap: 4px; }
.password-input { position: relative; }
.password-input input { padding-right: 49px; }
.password-input button { position: absolute; right: 4px; top: 4px; bottom: 4px; display: grid; place-items: center; border: 0; padding: 0 9px; }
.password-input button:hover { background: #e4f3ee; }
.password-input button[aria-pressed="false"] .eye-slash { display: none; }
.member-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.member-actions button { font-size: .875rem; padding: 5px 8px; }

#staff-chat { width: min(790px, 96vw); margin: 82px max(2vw, 12px) auto auto; }
.staff-layout { display: grid; grid-template-columns: minmax(155px, 1fr) minmax(0, 2.4fr); gap: 14px; margin-top: 14px; }
.staff-sidebar { border-right: 1px solid #d8e4e0; padding-right: 12px; overflow: auto; max-height: 60vh; }
.staff-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#staff-threads { display: grid; gap: 4px; margin-top: 8px; }
#staff-threads button { text-align: left; overflow-wrap: anywhere; }
#staff-threads button[aria-pressed=true] { background: #d9efe6; }
#staff-people { display: grid; gap: 7px; max-height: 38vh; overflow: auto; }
#staff-people label { display: flex; align-items: center; }
#staff-people input { width: auto; }
#staff-messages { display: flex; flex-direction: column; gap: 8px; height: min(43dvh, 390px); overflow: auto; background: #edf3f1; border-radius: 8px; padding: 9px; margin: 8px 0; }
#staff-send { padding: 0; border: 0; }
#staff-text { flex: 1; }
#staff-status { color: #872a47; margin-bottom: 0; }
@media (max-width: 540px) {
  #staff-chat { margin: 8px auto auto; }
  .staff-layout { grid-template-columns: minmax(0, 1fr); }
  .staff-sidebar { max-height: 21dvh; border: 0; padding: 0; }
}

.inbox-heading { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.unread-badge { display: inline-block; justify-self: start; border-radius: 999px; background: #e8efec; color: #28463d; padding: 3px 8px; font-size: .8rem; font-weight: 700; }
.unread-badge.has-unread { background: #145f52; color: white; }

#whatsapp-unread { border: 1px solid transparent; }
#whatsapp-unread:hover { border-color: currentColor; }
#whatsapp-unread[aria-pressed=true] { box-shadow: inset 0 0 0 1px currentColor; }
#whatsapp-unread[aria-pressed=true]::before { content: '✓ '; }

main.has-notes { grid-template-columns: minmax(210px, 300px) minmax(0, 1fr) minmax(220px, 300px); }
#conversation-notes { border-left: 1px solid #d8e4e0; border-right: 0; min-width: 0; }
#notes-form { display: grid; gap: 7px; padding: 0 0 14px; }
#notes-form textarea { resize: vertical; width: 100%; padding: 8px; font: inherit; color: inherit; border: 1px solid #a8bdb6; border-radius: 8px; }
#notes-form input[type=file] { padding: 6px; font-size: .85rem; }
#notes-form button { justify-self: start; background: #145f52; color: white; }
#notes-status { font-size: .875rem; color: #28463d; }
.note-card { border-bottom: 1px solid #d8e4e0; padding: 10px 0; }
.note-card p { margin: 7px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-images { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.note-images img { display: block; width: 72px; height: 72px; object-fit: cover; border-radius: 6px; }
#notes-more { margin-top: 8px; }
@media (min-width: 651px) and (max-width: 820px) {
  main.has-notes { grid-template-columns: 175px minmax(0, 1fr) 190px; }
}
@media (max-width: 650px) {
  #conversation-notes { border-left: 0; max-height: none; }
}

.header-brand { display: flex; align-items: center; gap: 12px; }
#main-menu-toggle { color: #123e37; white-space: nowrap; font-size: .875rem; }
.desk-layout { display: flex; flex: 1; min-height: 0; position: relative; }
.desk-layout > main { min-width: 0; }
#main-menu {
  flex: 0 0 140px;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #f7fbf9;
  border-right: 1px solid #d8e4e0;
}
#main-menu button { text-align: left; border-color: transparent; background: transparent; }
#main-menu button:hover { background: #e4f3ee; }
#main-menu button[aria-pressed=true] { background: #ccece0; font-weight: 650; }
#sign-out { margin-top: 8px; }
@media (max-width: 820px) {
  #main-menu { position: absolute; z-index: 2; top: 0; left: 0; width: 165px; box-shadow: 0 6px 18px #123e3726; }
}
@media (max-width: 540px) {
  header { flex-wrap: wrap; gap: 8px; }
}
main.customers-view { grid-template-columns: minmax(0, 1fr); }
main.customers-view.has-notes { grid-template-columns: minmax(0, 1fr) minmax(230px, 32%); }
#customers-panel { min-width: 0; overflow: auto; padding: 22px; max-height: calc(100dvh - 75px); }
#customers-search { max-width: 480px; }
.customers-heading { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 12px; }
.customers-heading button { font-size: .875rem; }
#customers-list { margin-top: 14px; max-width: 850px; }
.customer-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #d8e4e0; padding: 6px 0; }
.customer-row > button { flex: 1; min-width: 0; text-align: left; overflow-wrap: anywhere; }
.customer-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.customer-actions button { font-size: .875rem; white-space: nowrap; }
.customer-row button[aria-pressed=true] { background: #e4f3ee; border-color: #18736b; }
.customer-row small { display: block; margin-top: 4px; }
#customers-more { margin-top: 12px; }
@media (max-width: 650px) { #customers-panel { padding: 14px; max-height: 55dvh; } }

.compose-row textarea { flex: 1 1 200px; min-width: 0; min-height: 42px; resize: vertical; font: inherit; color: inherit; background: white; border: 1px solid #a8bdb6; border-radius: 8px; padding: 9px 10px; }
.compose-row textarea:focus-visible { outline: 3px solid #18736b; outline-offset: 2px; }
#quick-replies-picker { max-height: 205px; overflow: auto; background: white; border: 1px solid #a8bdb6; border-radius: 8px; margin-bottom: 8px; padding: 4px; }
#quick-replies-picker button { display: flex; flex-direction: column; gap: 3px; text-align: left; width: 100%; border: 0; }
#quick-replies-picker button.active, #quick-replies-picker button:hover { background: #e0f1ec; }
#quick-replies-picker button span { width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#quick-replies-picker p { padding: 4px 8px; margin: 0; }

#quick-replies-list { max-height: 240px; overflow-y: auto; }
.saved-quick-reply { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid #d8e4df; }
.saved-quick-reply p { grid-column: 1 / -1; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
#quick-replies-body { font: inherit; resize: vertical; }

.saved-quick-reply-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

#statistics-panel { grid-column: 1 / -1; min-width: 0; overflow: auto; max-height: calc(100dvh - 75px); padding: 20px; }
#statistics-panel h1 { margin-top: 0; }
#statistics-filters { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; }
#statistics-filters label { display: grid; gap: 5px; }
.statistics-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }
.statistics-card { display: grid; gap: 8px; padding: 12px; background: #fff; border: 1px solid #c9dbd5; border-radius: 8px; }
.statistics-card strong { font-size: 1.6rem; }
.statistics-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 12px; margin: 16px 0; }
.statistics-chart { min-width: 0; padding: 14px; border: 1px solid #c9dbd5; border-radius: 8px; background: #fff; }
.statistics-chart h2 { margin: 0 0 10px; }
.statistics-chart select { max-width: 100%; margin-bottom: 8px; }
.statistics-trend { max-height: 260px; overflow: auto; }
.statistics-bar { display: grid; grid-template-columns: minmax(95px, 1fr) minmax(30px, 2fr) minmax(42px, auto); gap: 8px; align-items: center; padding: 5px 2px; }
.statistics-bar > span:first-child { overflow-wrap: anywhere; }
.statistics-bar strong { text-align: right; font-variant-numeric: tabular-nums; }
.statistics-track { height: 12px; border-radius: 5px; background: #eaf3f0; }
.statistics-track span { display: block; height: 100%; border-radius: inherit; background: #176b5d; }
.statistics-chart:nth-child(2) .statistics-bar + .statistics-bar .statistics-track span { background: #aa4057; }
.statistics-table { overflow: auto; max-height: 290px; }
.statistics-table table { border-collapse: collapse; width: 100%; background: #fff; }
.statistics-table th, .statistics-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #d7e4df; }
.statistics-table th { position: sticky; top: 0; background: #eaf3f0; }

/* Let the header and notice take their actual height before sizing the workspace. */
body { height: 100dvh; overflow: hidden; }
header { padding-top: max(12px, env(safe-area-inset-top)); }
.desk-layout { padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
.desk-layout > main { position: relative; grid-template-rows: minmax(0, 1fr); }
#main-menu, aside, #customers-panel, #statistics-panel { max-height: none; min-height: 0; overflow: auto; }
.thread { height: auto; min-height: 0; min-width: 0; grid-template-rows: auto minmax(0, 1fr) auto; }
.thread-head { min-width: 0; max-height: 39dvh; overflow-y: auto; }
#messages { min-height: 0; overscroll-behavior: contain; }
#messages > * { flex-shrink: 0; }
#composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.compose-row input[type=file] { max-width: 100%; }
.compact-chat-nav, #notes-close, #back-to-inbox, #chat-details-toggle { display: none; }
.conversation-heading h2, .chat-title, #members li, .statistics-card { overflow-wrap: anywhere; min-width: 0; }
dialog { max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow: auto; }
#staff-chat { margin: auto; }
.customer-row > *, .staff-layout > *, #members li > *, .saved-quick-reply > *, #statistics-filters > * { min-width: 0; }
#statistics-filters label { max-width: 100%; }
#statistics-filters input, #statistics-filters select { max-width: 100%; }
.statistics-table { overscroll-behavior-inline: contain; }

@media (max-width: 1140px) {
  #main-menu { position: absolute; z-index: 5; inset: 0 auto auto env(safe-area-inset-left); width: min(230px, 85vw); max-height: 100%; box-shadow: 0 6px 18px #123e3738; }
  main.has-notes { grid-template-columns: minmax(205px, 30%) minmax(0, 1fr); }
  main.customers-view.has-notes { grid-template-columns: minmax(0, 1fr); }
  .compact-chat-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
  #notes-close { display: inline-block; }
  #conversation-notes { display: none; }
  main.notes-open #conversation-notes { display: block; position: absolute; z-index: 3; inset: 0 0 0 auto; width: min(100%, 390px); box-shadow: -6px 0 20px #123e372a; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  #notes-title { margin: 0 0 8px; }
}

@media (max-width: 720px), (max-width: 960px) and (max-height: 560px) {
  header { flex-wrap: wrap; padding-inline: 12px; padding-bottom: 8px; gap: 8px; }
  header strong { font-size: 1rem; }
  .header-actions { justify-content: flex-start; gap: 6px 10px; }
  .header-actions #status, .header-actions #identity { display: none; }
  .sound-controls { justify-content: flex-start; gap: 6px; }
  .sound-controls input { width: 62px; }
  .desk-layout > main, main.has-notes { display: grid; grid-template-columns: minmax(0, 1fr); }
  main:not(.phone-chat) #conversation-panel, main.phone-chat #inbox-panel { display: none; }
  #back-to-inbox, #chat-details-toggle { display: inline-block; }
  main:not(.details-open) #chat-details { display: none; }
  .compact-chat-nav { justify-content: flex-start; }
  .thread-head, #composer, #messages, #customers-panel, #statistics-panel, #inbox-panel { padding: 10px; }
  .thread-head { max-height: 40dvh; }
  #composer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .compose-row textarea { flex-basis: 100%; max-height: 100px; }
  .compose-row button { flex: 1 1 auto; }
  .bubble { max-width: 92%; }
  #quick-replies-picker { max-height: 22dvh; }
  main.notes-open #conversation-notes { width: 100%; }
  .customer-row, #members li { flex-wrap: wrap; }
  .customer-row > button { flex-basis: 100%; }
  .member-actions { justify-content: flex-start; }
  #statistics-filters { padding: 10px; }
  #statistics-filters label { flex: 1 1 120px; }
  .statistics-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .statistics-card, .statistics-chart { padding: 10px; }
  dialog button, #main-menu button, .compact-chat-nav button, .compose-row button { min-height: 40px; }
  #staff-chat { width: min(96vw, 640px); }
  .staff-layout { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .staff-sidebar { max-height: 24dvh; border: 0; padding: 0; }
  #staff-messages { height: min(42dvh, 380px); }
}

#inbox-panel #filter { margin-bottom: 0; }
.chat-kind { justify-self: start; color: #135851; background: #d1f0e9; border-radius: 100px; padding: 2px 8px; font-size: .8rem; }
.group-sender { color: #145f52; font-size: .82rem; font-weight: 650; margin-bottom: 3px; }
.bubble a { color: #075680; text-decoration: underline; overflow-wrap: anywhere; }
#messages { overflow-anchor: none; }
#history-controls { align-self: center; display: grid; justify-items: center; gap: 4px; text-align: center; color: #4b655e; font-size: .875rem; }
#history-status:empty { display: none; }
