:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8fafa;
  --surface-hover: #f2f5f4;
  --surface-selected: #eaf3f0;
  --text: #18201d;
  --text-soft: #5f6b66;
  --text-faint: #89938f;
  --border: #e1e6e4;
  --border-strong: #c9d1ce;
  --accent: #16735d;
  --accent-hover: #115e4c;
  --accent-soft: #e4f1ed;
  --warning: #a15c13;
  --warning-soft: #fff3e3;
  --danger: #b4232c;
  --danger-soft: #fdebec;
  --info: #356f92;
  --shadow: 0 18px 48px rgba(28, 39, 35, 0.16);
  --topbar-height: 50px;
  --mobile-nav-height: 58px;
  --account-width: 216px;
  --conversation-width: 340px;
  --radius: 5px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
}

button:not(:disabled),
select:not(:disabled),
label[for] {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

input,
textarea,
select {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 122, 100, 0.12);
}

button:focus-visible,
[role="option"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

textarea {
  resize: none;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

[hidden] {
  display: none !important;
}

.mobile-only,
.mobile-nav {
  display: none;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-soft);
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
}

.icon-button.mobile-only {
  display: none;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--border);
  background: var(--surface-hover);
  color: var(--text);
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.secondary-button {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover:not(:disabled) {
  background: var(--surface-hover);
}

.danger-button {
  border: 1px solid #e2b7ba;
  background: var(--surface);
  color: var(--danger);
}

.danger-button:hover:not(:disabled) {
  background: var(--danger-soft);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
}

.brand-mark svg {
  width: 23px;
  height: 23px;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  flex-basis: 30px;
  border-radius: 6px;
}

.brand-mark.small svg {
  width: 17px;
  height: 17px;
}

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--surface);
}

.boot-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.boot-copy strong {
  font-size: 17px;
}

.boot-copy span {
  color: var(--text-faint);
  font-size: 12px;
}

.spinner {
  width: 18px;
  height: 18px;
  margin-left: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 720ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.auth-view {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
  background: #eef2f0;
}

.login-panel {
  width: min(100%, 390px);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 36px rgba(31, 42, 38, 0.1);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 30px;
}

.login-brand h1 {
  margin: 0 0 4px;
  font-size: 21px;
  line-height: 1.25;
}

.login-brand p {
  margin: 0;
  color: var(--text-faint);
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
}

.login-form > label,
.account-form > label,
.account-form .form-grid-two label {
  margin: 0 0 7px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
}

.field-with-icon {
  position: relative;
  margin-bottom: 18px;
}

.field-with-icon > svg {
  position: absolute;
  top: 50%;
  left: 12px;
  z-index: 1;
  width: 17px;
  height: 17px;
  color: var(--text-faint);
  transform: translateY(-50%);
  pointer-events: none;
}

.field-with-icon input {
  width: 100%;
  height: 42px;
  padding: 9px 42px 9px 38px;
}

.field-action {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 34px;
  height: 34px;
}

.form-error {
  margin: 0 0 14px;
  padding: 9px 11px;
  border: 1px solid #edc5c7;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: #922f34;
  font-size: 13px;
  line-height: 1.5;
}

.login-button {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
}

.workspace {
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--surface);
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  width: 100%;
  height: var(--topbar-height);
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-brand,
.topbar-actions,
.user-summary {
  display: flex;
  align-items: center;
}

.topbar-brand {
  gap: 10px;
}

.topbar-brand strong {
  font-size: 15px;
}

.topbar-actions {
  gap: 12px;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.user-summary {
  gap: 8px;
}

.user-summary > span {
  max-width: 160px;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-status {
  display: inline-flex;
  min-width: 66px;
  align-items: center;
  gap: 7px;
  color: var(--text-soft);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

.event-status.is-live .status-dot {
  background: #2e9a63;
}

.event-status.is-connecting .status-dot {
  background: #d18a33;
}

.event-status.is-offline .status-dot {
  background: var(--danger);
}

.workspace-grid {
  display: grid;
  width: 100%;
  height: calc(100dvh - var(--topbar-height));
  grid-template-columns: var(--account-width) var(--conversation-width) minmax(0, 1fr);
  overflow: hidden;
}

.panel-region {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.account-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface-soft);
}

.panel-heading,
.conversation-title-row,
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-heading {
  min-height: 54px;
  padding: 8px 10px 8px 16px;
}

.heading-kicker,
.section-label {
  display: block;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}

.panel-heading h2,
.conversation-title-row h2,
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.account-nav,
.status-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 9px;
}

.account-nav {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
}

.account-nav-item,
.status-nav-item {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 40px;
  align-items: center;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-soft);
  text-align: left;
}

.account-nav-item {
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px;
  padding: 5px 8px;
}

.status-nav-item {
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  padding: 6px 9px;
}

.account-nav-item:hover,
.status-nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.account-nav-item.is-active,
.status-nav-item.is-active {
  background: var(--surface-selected);
  color: var(--accent-hover);
  font-weight: 600;
}

.account-nav-item.is-active::before,
.status-nav-item.is-active::before {
  display: none;
}

.account-glyph {
  position: relative;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 6px;
  background: #edf1ef;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
}

.account-glyph svg {
  width: 16px;
  height: 16px;
}

.account-glyph .enabled-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 8px;
  height: 8px;
  border: 2px solid var(--surface-soft);
  border-radius: 50%;
  background: #2e9a63;
}

.account-glyph .enabled-dot.is-disabled {
  background: var(--text-faint);
}

.account-copy {
  min-width: 0;
}

.account-name,
.account-secondary {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-name {
  color: inherit;
  font-size: 13px;
}

.account-secondary {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 400;
}

.account-unread,
.nav-count,
.unread-badge {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  padding: 0 6px;
  border-radius: 10px;
  background: #e7ece9;
  color: var(--text-soft);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.account-unread.has-unread,
.nav-count.attention.has-count,
.unread-badge {
  background: var(--danger);
  color: #ffffff;
}

.status-section {
  flex: 0 0 auto;
  margin-top: 8px;
  padding: 12px 0 14px;
  border-top: 1px solid var(--border);
}

.section-label {
  margin: 0 16px 8px;
}

.status-nav-item svg {
  width: 17px;
  height: 17px;
}

.conversation-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.conversation-toolbar {
  flex: 0 0 auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.conversation-title-row {
  min-height: 36px;
}

.conversation-heading {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
}

.conversation-scope {
  min-width: 0;
  max-width: 150px;
  overflow: hidden;
  color: var(--text-faint);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-field {
  position: relative;
  display: block;
  margin-top: 8px;
}

.search-field > svg {
  position: absolute;
  top: 50%;
  left: 10px;
  z-index: 1;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  transform: translateY(-50%);
  pointer-events: none;
}

.search-field input {
  width: 100%;
  height: 36px;
  padding: 7px 38px 7px 34px;
  border-color: transparent;
  background: #f0f3f2;
  font-size: 13px;
}

.search-field input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.search-clear {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 30px;
  height: 30px;
}

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

.conversation-item {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 70px;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #edf0ee;
  background: var(--surface);
  text-align: left;
}

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

.conversation-item.is-active {
  background: var(--surface-selected);
}

.avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: #e1e9e5;
  color: #456058;
  font-weight: 700;
  user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.conversation-avatar {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

.conversation-main {
  min-width: 0;
}

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

.conversation-line + .conversation-line {
  margin-top: 7px;
}

.conversation-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-time {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.conversation-preview {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item.has-unread .conversation-name,
.conversation-item.has-unread .conversation-preview {
  color: var(--text);
  font-weight: 600;
}

.conversation-summary {
  gap: 6px;
}

.conversation-account {
  display: inline-flex;
  max-width: 104px;
  min-width: 0;
  flex: 0 1 auto;
  align-items: center;
  gap: 5px;
  padding-right: 7px;
  border-right: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 11px;
}

.conversation-account span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-mark {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--account-color, var(--accent));
}

.unread-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 10px;
}

.list-state,
.message-state {
  flex: 0 0 auto;
}

.state-block {
  display: flex;
  min-height: 210px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  color: var(--text-faint);
  text-align: center;
}

.state-block svg {
  width: 28px;
  height: 28px;
  margin-bottom: 3px;
  color: #9ba7a2;
}

.state-block strong {
  color: var(--text-soft);
  font-size: 13px;
}

.state-block p {
  max-width: 260px;
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
}

.state-block .secondary-button {
  min-height: 34px;
  margin-top: 4px;
  padding: 6px 11px;
  font-size: 12px;
}

.skeleton-list {
  padding: 3px 0;
}

.skeleton-row {
  display: grid;
  min-height: 80px;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid #edf0ee;
}

.skeleton-avatar,
.skeleton-line {
  background: #e8edeb;
  animation: skeletonPulse 1.3s ease-in-out infinite;
}

.skeleton-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.skeleton-copy {
  display: flex;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
}

.skeleton-line {
  width: 82%;
  height: 10px;
  border-radius: 4px;
}

.skeleton-line.short {
  width: 48%;
}

@keyframes skeletonPulse {
  50% { opacity: 0.52; }
}

.is-spinning {
  animation: spin 720ms linear infinite;
}

.load-more-button {
  flex: 0 0 36px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-size: 12px;
}

.load-more-button:hover:not(:disabled) {
  background: var(--surface-soft);
}

.chat-panel {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.chat-empty {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--text-faint);
}

.empty-illustration {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  margin-bottom: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: #7f948d;
}

.empty-illustration svg {
  width: 25px;
  height: 25px;
}

.chat-empty h2 {
  margin: 0 0 7px;
  color: var(--text-soft);
  font-size: 15px;
}

.chat-empty p {
  margin: 0;
  font-size: 12px;
}

.chat-active {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
}

.chat-header {
  position: relative;
  z-index: 5;
  display: flex;
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
}

.chat-contact {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.avatar-large {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

.chat-contact-copy {
  min-width: 0;
}

.chat-name-row,
.chat-meta-row,
.chat-actions {
  display: flex;
  min-width: 0;
  align-items: center;
}

.chat-name-row {
  gap: 8px;
}

.chat-name-row h2 {
  min-width: 0;
  max-width: min(36vw, 360px);
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-meta-row {
  gap: 8px;
  margin-top: 4px;
}

.account-source,
.status-badge {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  border-radius: 5px;
  font-size: 10px;
  line-height: 20px;
  white-space: nowrap;
}

.account-source {
  max-width: 200px;
  gap: 6px;
  padding: 0;
  overflow: hidden;
  background: transparent;
  color: var(--text-soft);
  font-weight: 600;
  text-overflow: ellipsis;
}

.account-source::before {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--account-color, var(--accent));
  content: "";
}

.status-badge {
  padding: 0 6px;
  background: #edf0ef;
  color: var(--text-soft);
}

.status-badge[data-status="PENDING"] {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-badge[data-status="OPEN"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.external-id {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  color: var(--text-faint);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-actions {
  flex: 0 0 auto;
  gap: 8px;
}

.status-select-label {
  color: var(--text-faint);
  font-size: 11px;
}

.compact-select {
  width: 98px;
  height: 34px;
  padding: 5px 28px 5px 9px;
  background: var(--surface);
  font-size: 12px;
}

.message-list {
  min-height: 0;
  padding: 16px clamp(16px, 3.5vw, 46px) 20px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.message-date {
  width: max-content;
  max-width: 100%;
  margin: 8px auto 14px;
  padding: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 18px;
}

.message-row {
  display: flex;
  width: 100%;
  align-items: flex-end;
  max-width: 960px;
  gap: 8px;
  margin: 0 auto 12px;
}

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

.message-row.is-sync {
  opacity: 0.88;
}

.message-avatar {
  width: 30px;
  height: 30px;
  font-size: 10px;
}

.message-stack {
  display: flex;
  max-width: min(68%, 640px);
  min-width: 0;
  flex-direction: column;
}

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

.message-bubble {
  max-width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 7px 7px 7px 2px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.is-outbound .message-bubble {
  border-color: transparent;
  border-radius: 7px 7px 2px 7px;
  background: #e0f1eb;
}

.message-row.is-sync .message-bubble {
  border-style: dashed;
  background: #f5f7f6;
}

.message-image-link {
  display: block;
  max-width: min(320px, 54vw);
  overflow: hidden;
  border-radius: 6px;
  background: #e8ecea;
}

.message-image {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: contain;
}

.message-image-caption {
  display: block;
  padding: 8px 10px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  color: var(--text-faint);
  font-size: 11px;
}

.message-meta svg {
  width: 13px;
  height: 13px;
}

.message-meta .is-failed {
  color: var(--danger);
}

.retry-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  background: transparent;
  color: var(--danger);
  font-size: 10px;
}

.retry-button svg {
  width: 12px;
  height: 12px;
}

.message-system {
  display: flex;
  justify-content: center;
  margin: 12px 0;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.message-system span {
  max-width: 80%;
  padding: 0;
  background: transparent;
}

.new-messages-button {
  position: absolute;
  right: 22px;
  bottom: 162px;
  z-index: 8;
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border: 1px solid #b9dacf;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 5px 16px rgba(24, 54, 45, 0.13);
  color: var(--accent);
  font-size: 11px;
}

.new-messages-button svg {
  width: 14px;
  height: 14px;
}

.closed-notice {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  border-top: 1px solid #efd8c5;
  background: #fff6ee;
  color: #92501f;
  font-size: 11px;
  line-height: 1.4;
}

.closed-notice svg {
  width: 15px;
  height: 15px;
}

.attachment-tray {
  display: flex;
  min-height: 66px;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
}

.attachment-tray img {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 5px;
  background: #e8ecea;
  object-fit: cover;
}

.attachment-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}

.attachment-copy strong,
.attachment-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-copy strong {
  font-size: 12px;
}

.attachment-copy span {
  color: var(--text-faint);
  font-size: 10px;
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer-toolbar {
  display: flex;
  min-height: 34px;
  align-items: center;
  padding: 2px 12px;
}

.composer-hint,
.content-counter {
  color: var(--text-faint);
  font-size: 11px;
}

.composer-hint {
  margin-left: 4px;
}

.content-counter {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.content-counter.is-near-limit {
  color: var(--warning);
}

.composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 0 12px 12px;
}

.composer-input-row textarea {
  width: 100%;
  min-height: 62px;
  max-height: 160px;
  flex: 1;
  padding: 9px 11px;
  border-color: transparent;
  background: #f3f5f4;
  line-height: 1.55;
}

.composer-input-row textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.send-button {
  min-width: 84px;
  min-height: 38px;
  margin-bottom: 1px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(26, 33, 31, 0.42);
}

.account-modal {
  display: flex;
  width: min(880px, 100%);
  max-height: min(720px, calc(100dvh - 48px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header {
  flex: 0 0 67px;
  padding: 11px 16px 11px 20px;
  border-bottom: 1px solid var(--border);
}

.account-modal-body {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: 244px minmax(0, 1fr);
}

.account-settings-list {
  min-height: 0;
  padding: 14px 10px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface-soft);
}

.add-account-button {
  width: 100%;
  margin-bottom: 12px;
}

.settings-account-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-account-item {
  display: grid;
  width: 100%;
  min-height: 50px;
  grid-template-columns: 30px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
}

.settings-account-item:hover,
.settings-account-item.is-active {
  background: var(--surface-selected);
}

.settings-account-item .account-glyph {
  width: 30px;
  height: 30px;
}

.settings-account-item svg:last-child {
  width: 15px;
  height: 15px;
  color: var(--text-faint);
}

.account-form {
  min-width: 0;
  padding: 20px 24px;
  overflow-y: auto;
}

.form-heading {
  display: flex;
  min-height: 34px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.form-heading h3 {
  margin: 0;
  font-size: 15px;
}

.form-heading span {
  color: var(--text-faint);
  font-size: 11px;
}

.account-form > input,
.account-form .form-grid-two input,
.field-with-action input {
  width: 100%;
  height: 40px;
  padding: 8px 10px;
  margin-bottom: 16px;
}

.form-grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.field-with-action {
  position: relative;
}

.field-with-action input {
  padding-right: 45px;
}

.field-with-action .icon-button {
  position: absolute;
  top: 3px;
  right: 3px;
}

.toggle-row {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 2px 0 18px !important;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.toggle-row > span:first-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.toggle-row strong {
  color: var(--text);
  font-size: 13px;
}

.toggle-row small {
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
}

.switch-control {
  position: relative;
  display: block;
  width: 38px;
  height: 22px;
  flex: 0 0 38px;
}

.switch-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-control span {
  position: absolute;
  inset: 0;
  border-radius: 11px;
  background: #b9c2be;
  transition: background 140ms ease;
}

.switch-control span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  content: "";
  transition: transform 140ms ease;
}

.switch-control input:checked + span {
  background: var(--accent);
}

.switch-control input:checked + span::after {
  transform: translateX(16px);
}

.switch-control input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(20, 122, 100, 0.18);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 4px;
}

.form-actions-spacer {
  flex: 1;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2000;
  display: flex;
  width: min(360px, calc(100vw - 32px));
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: grid;
  min-height: 46px;
  grid-template-columns: 20px minmax(0, 1fr) 26px;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(27, 39, 34, 0.16);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: auto;
  animation: toastIn 160ms ease-out;
}

.toast.is-error {
  border-left-color: var(--danger);
}

.toast.is-warning {
  border-left-color: var(--warning);
}

.toast > svg {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.toast.is-error > svg {
  color: var(--danger);
}

.toast.is-warning > svg {
  color: var(--warning);
}

.toast .icon-button {
  width: 26px;
  height: 26px;
  flex-basis: 26px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
}

@media (max-width: 1120px) {
  :root {
    --account-width: 204px;
    --conversation-width: 324px;
  }

  .account-nav-item {
    padding-right: 6px;
  }

  .chat-header {
    padding-right: 12px;
    padding-left: 14px;
  }

  .message-list {
    padding-right: 22px;
    padding-left: 22px;
  }
}

@media (max-width: 920px) {
  :root {
    --topbar-height: 52px;
  }

  .mobile-only,
  .mobile-nav {
    display: flex;
  }

  .icon-button.mobile-only {
    display: inline-grid;
  }

  .workspace-grid {
    height: calc(100dvh - var(--topbar-height) - var(--mobile-nav-height) - env(safe-area-inset-bottom));
    grid-template-columns: 1fr;
  }

  .account-panel,
  .conversation-panel,
  .chat-panel {
    display: none;
    width: 100%;
    height: 100%;
    border-right: 0;
  }

  .workspace[data-mobile-view="accounts"] .account-panel,
  .workspace[data-mobile-view="conversations"] .conversation-panel,
  .workspace[data-mobile-view="chat"] .chat-panel {
    display: flex;
  }

  .workspace[data-mobile-view="chat"] .chat-panel {
    display: block;
  }

  .topbar {
    padding: 0 10px;
  }

  .topbar .icon-button,
  .panel-heading .icon-button,
  .chat-header .icon-button,
  .composer .icon-button,
  .modal-header .icon-button {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .topbar-brand {
    gap: 8px;
  }

  .topbar-brand .brand-mark {
    display: none;
  }

  .topbar-brand strong {
    max-width: 48vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-divider,
  .user-summary > span {
    display: none;
  }

  .mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    align-items: flex-start;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    background: var(--surface);
  }

  .mobile-nav button {
    display: flex;
    height: var(--mobile-nav-height);
    flex: 1;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    background: transparent;
    color: var(--text-faint);
    font-size: 10px;
  }

  .mobile-nav button.is-active {
    color: var(--accent);
  }

  .mobile-nav svg {
    width: 19px;
    height: 19px;
  }

  .account-nav {
    max-height: none;
  }

  .workspace[data-mobile-view="chat"] .topbar,
  .workspace[data-mobile-view="chat"] .mobile-nav {
    display: none;
  }

  .workspace[data-mobile-view="chat"] .workspace-grid {
    height: 100dvh;
  }

  .conversation-toolbar {
    padding-top: 11px;
  }

  .chat-header {
    min-height: 60px;
    padding: 6px 10px;
  }

  .chat-contact {
    gap: 8px;
  }

  .avatar-large {
    width: 38px;
    height: 38px;
  }

  .chat-name-row h2 {
    max-width: 34vw;
    font-size: 14px;
  }

  .external-id,
  .status-select-label {
    display: none;
  }

  .account-source {
    max-width: 38vw;
  }

  .compact-select {
    width: 86px;
  }

  .message-list {
    padding: 15px 12px 20px;
  }

  .message-stack {
    max-width: 80%;
  }

  .message-image-link {
    max-width: 66vw;
  }

  .composer-input-row {
    gap: 8px;
    padding: 0 10px 10px;
  }

  .composer-input-row textarea {
    min-height: 58px;
  }

  .send-button {
    min-width: 72px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .new-messages-button {
    right: 12px;
    bottom: 150px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .account-modal {
    width: 100%;
    max-height: calc(100dvh - 24px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }

  .account-modal-body {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .account-form {
    padding: 18px;
  }

  .toast-region {
    right: 12px;
    bottom: calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom));
    left: 12px;
    width: auto;
  }

  .workspace[data-mobile-view="chat"] ~ .toast-region {
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 620px) {
  .login-panel {
    padding: 26px 22px;
  }

  .account-modal-body {
    display: block;
    overflow-y: auto;
  }

  .account-settings-list {
    max-height: 180px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .settings-account-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .account-form {
    overflow: visible;
  }

  .form-grid-two {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .form-actions {
    flex-wrap: wrap;
  }

  .form-actions-spacer {
    display: none;
  }

  .form-actions .danger-button {
    margin-right: auto;
  }
}

@media (max-width: 420px) {
  .event-status-text {
    display: none;
  }

  .event-status {
    min-width: 12px;
  }

  .chat-name-row h2 {
    max-width: 30vw;
  }

  .chat-name-row .status-badge {
    display: none;
  }

  .compact-select {
    width: 80px;
    padding-left: 7px;
  }

  .message-avatar {
    display: none;
  }

  .message-stack {
    max-width: 86%;
  }

  .send-button span {
    display: none;
  }

  .send-button {
    min-width: 44px;
    width: 44px;
    padding: 0;
  }

  .settings-account-list {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
