:root {
  --bg: #ededed;
  --card: #ffffff;
  --surface: #f7f7f7;
  --primary: #667eea;
  --primary-deep: #764ba2;
  --accent: #07c160;
  --text: #1f2937;
  --muted: #8a8f99;
  --border: #e5e7eb;
  --danger: #fa5151;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
  --bubble-agent: #95ec69;
}

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

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.agent-body {
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login-card {
  width: min(360px, 92vw);
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 16px;
  font-size: 20px;
}


.login-card label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.login-card input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.login-card button {
  width: 100%;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}

.agent-shell {
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  width: 100vw;
  max-width: 100vw;
  overflow: hidden;
}

.top-navbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(102, 126, 234, 0.3);
}

.top-navbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.6px;
}

.top-navbar-right {
  display: flex;
  gap: 12px;
}

.top-navbar-icon {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}


.chat-list-view {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.list-title {
  font-size: 14px;
  font-weight: 600;
}

.list-actions {
  display: flex;
  gap: 8px;
}

.ghost {
  border: 1px solid var(--border);
  background: #fff;
  color: #374151;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  contain: layout paint style;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
  content-visibility: auto;
  contain-intrinsic-size: 64px;
}

.session-item.active {
  background: #eef2ff;
}

.session-item:hover {
  background: #f5f7ff;
}

.session-avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  display: grid;
  place-items: center;
  position: relative;
  flex-shrink: 0;
}

.session-avatar.unread {
  background: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
}

.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 999px;
}

.session-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.session-title {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  gap: 6px;
  align-items: baseline;
  min-width: 0;
}

.source-tag {
  font-size: 10px;
  color: #1d4ed8;
  background: rgba(59, 130, 246, 0.12);
  padding: 2px 6px;
  border-radius: 999px;
  line-height: 1;
  white-space: nowrap;
}

.session-preview {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-right {
  display: grid;
  justify-items: end;
  gap: 4px;
  min-width: 60px;
}

.session-time {
  font-size: 10px;
  color: var(--muted);
}

.chat-detail-view {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
  background: #ededed;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-detail-header {
  background: #393a3e;
  color: #fff;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-detail-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-detail-name {
  font-size: 15px;
  font-weight: 600;
}

.back-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
}

.blocked-badge {
  background: var(--danger);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  margin-left: 8px;
}


.chat-detail-right {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#sound-indicator.pulse {
  animation: soundPulse 0.6s ease;
}

.sound-panel {
  position: absolute;
  right: 0;
  top: 40px;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  width: 200px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
  z-index: 20;
}

.sound-panel.hidden {
  display: none;
}

.sound-panel-title {
  font-size: 12px;
  color: var(--muted);
}

.sound-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sound-panel input[type="range"] {
  width: 100%;
}

.sound-value {
  font-size: 12px;
  color: var(--primary);
  min-width: 40px;
  text-align: right;
}

.sound-test-btn {
  border: none;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

@keyframes soundPulse {
  0% { transform: scale(1); opacity: 0.6; }
  40% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 0.6; }
}

.visitor-info-panel {
  background: #fff;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.visitor-info-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 6px 0;
  color: #4b5563;
}

.visitor-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.visitor-action-btn {
  flex: 1;
  border: none;
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  cursor: pointer;
  color: #fff;
}

.visitor-action-btn.note { background: var(--primary); }
.visitor-action-btn.block { background: var(--danger); }
.visitor-action-btn.unblock { background: var(--accent); }


.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  contain: layout paint style;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  content-visibility: auto;
  contain-intrinsic-size: 76px;
}

.group-card.collapsed .group-items {
  display: none;
}

.group-card.collapsed .group-actions {
  display: none;
}

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

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #e5e7eb;
  color: #1f2937;
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.avatar.agent {
  background: #d1fae5;
  color: #065f46;
}

.avatar.telegram {
  background: #cffafe;
  color: #0e7490;
}

.bubble {
  max-width: 72%;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
}

.bubble.agent {
  background: var(--bubble-agent);
  border-color: transparent;
}


.message-row.pending .bubble,
.message-row.queued .bubble {
  opacity: 0.7;
}

.message-row.failed .bubble {
  border-color: #ef4444;
  background: #fee2e2;
}

.message-row.failed .meta {
  color: #b91c1c;
}


.bubble.unread {
  border-color: rgba(248, 113, 113, 0.6);
}

.bubble img,
.bubble video {
  max-width: 100%;
  border-radius: 6px;
  margin-top: 6px;
}

.meta {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}

.meta .read-flag {
  color: #ef4444;
  font-weight: 600;
}


.meta .retry-btn {
  margin-left: 8px;
  border: none;
  background: transparent;
  color: #ef4444;
  font-size: 10px;
  cursor: pointer;
  padding: 0;
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.message-row.pending .retry-btn,
.message-row.queued .retry-btn {
  display: none;
}


.composer {
  background: #f7f7f7;
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  position: relative;
}

.composer-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-tools {
  display: flex;
  gap: 6px;
}

.tool-btn {
  min-width: 48px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: #374151;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  cursor: pointer;
}

.tool-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tool-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-label {
  line-height: 1;
}

.composer input {
  flex: 1;
  border: none;
  background: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
}

.tool-panel {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 10px;
  display: grid;
  gap: 10px;
}

.tool-panel.hidden {
  display: none;
}

.tool-tabs {
  display: flex;
  gap: 8px;
}

.tool-tab {
  border: 1px solid var(--border);
  background: #f9fafb;
  color: #374151;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.tool-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tool-section {
  display: grid;
  gap: 10px;
}

.tool-section.hidden {
  display: none;
}

.tool-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.group-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.group-nav.hidden {
  display: none;
}

.group-chip {
  border: 1px solid var(--border);
  background: #f3f4f6;
  color: #374151;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.group-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

#photo-groups {
  max-height: 40vh;
  overflow-y: auto;
  padding-right: 4px;
}

.group-list {
  display: grid;
  gap: 10px;
}

.group-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 8px;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.group-title {
  font-size: 13px;
  font-weight: 600;
}

.photo-group-toggle {
  border: none;
  background: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  cursor: pointer;
  padding: 0;
}

.photo-group-toggle .group-caret {
  font-size: 12px;
  color: var(--muted);
}

.photo-group-toggle .group-count {
  background: #eef2ff;
  color: #4338ca;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
}

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

.group-actions button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.group-actions .group-send {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.group-add {
  border: 1px dashed var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.group-items {
  display: grid;
  gap: 6px;
}

.reply-item,
.photo-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  background: #fff;
}

.reply-text {
  font-size: 12px;
  color: #374151;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.item-actions {
  display: flex;
  gap: 4px;
}

.item-actions button {
  border: none;
  background: #f3f4f6;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 11px;
  cursor: pointer;
}

.photo-thumb {
  width: 46px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #000;
}

.photo-label {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}

.more-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.more-panel {
  position: absolute;
  left: 12px;
  bottom: 60px;
  background: #fff;
  border-radius: 10px;
  padding: 8px;
  display: flex;
  gap: 8px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.more-panel button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.quick-replies .quick-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  position: relative;
}

.quick-replies .quick-btn.delete-mode::after {
  content: "\00D7";
  position: absolute;
  top: -6px;
  right: -2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  line-height: 16px;
  text-align: center;
}

.contact-actions {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: #fff;
}

.contact-actions button {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
}

.contact-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.contacts-view,
.profile-view {
  grid-column: 1 / -1;
  grid-row: 2 / 3;
  display: none;
  background: #ededed;
  padding: 16px;
  overflow-y: auto;
}

.contacts-header {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.contacts-list {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  contain: layout paint style;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: 60px;
}

.contact-item:last-child {
  border-bottom: none;
}

.contact-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #eef2ff;
  color: #4338ca;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.5px;
}

.contact-body {
  flex: 1;
  min-width: 0;
}

.contact-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

.contact-sub {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-right {
  text-align: right;
  font-size: 11px;
  color: #9ca3af;
}

.profile-header {
  background: #fff;
  padding: 16px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.profile-avatar {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.profile-name {
  font-size: 16px;
  font-weight: 600;
}

.profile-id {
  font-size: 12px;
  color: var(--muted);
}

.volume-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.volume-card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}

.volume-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.volume-slider {
  flex: 1;
}

.volume-value {
  font-size: 12px;
  color: var(--primary);
}

.volume-test-btn {
  border: none;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.share-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  display: grid;
  gap: 10px;
}
.update-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  display: grid;
  gap: 10px;
}

.update-card-title {
  font-size: 14px;
  font-weight: 600;
}

.update-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.update-status {
  font-size: 12px;
  color: var(--muted);
}

.update-status.ok {
  color: var(--accent);
}

.update-status.warn {
  color: #f59e0b;
}

.update-status.error {
  color: var(--danger);
}

.update-card-row .share-primary {
  white-space: nowrap;
}

.update-card button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


.share-card-title {
  font-size: 14px;
  font-weight: 600;
}

.share-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.share-link {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  background: #f9fafb;
}

.share-copy {
  flex-shrink: 0;
}

.share-primary {
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
}

.share-hint {
  font-size: 11px;
  color: var(--muted);
}

.announcement-preview {
  min-height: 48px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  color: var(--text);
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.announcement-preview.empty {
  color: var(--muted);
}

.share-card button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.logout-btn {
  width: 100%;
  border: none;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}

.bottom-tabbar {
  grid-column: 1 / -1;
  display: flex;
  border-top: 1px solid var(--border);
  background: #fff;
}

.bottom-tabbar .tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}

.bottom-tabbar .tab.active {
  color: var(--primary);
}

.tab-badge {
  position: absolute;
  top: 4px;
  right: 22px;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  padding: 1px 5px;
}

.uid {
  cursor: pointer;
}

.uid-menu {
  position: fixed;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  gap: 6px;
  box-shadow: var(--shadow);
  z-index: 50;
}

.uid-menu button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  z-index: 60;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(320px, 90vw);
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.modal-card h3 {
  margin: 0;
  font-size: 16px;
}

.modal-label {
  font-size: 12px;
  color: var(--muted);
}

.modal-card input,
.modal-card textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.modal-actions button {
  width: 100%;
  border-radius: 8px;
}

.hidden {
  display: none;
}

.agent-shell:has(#session-tabs .tab[data-view="contacts"].active) .chat-list-view,
.agent-shell:has(#session-tabs .tab[data-view="contacts"].active) .chat-detail-view,
.agent-shell:has(#session-tabs .tab[data-view="profile"].active) .chat-list-view,
.agent-shell:has(#session-tabs .tab[data-view="profile"].active) .chat-detail-view {
  display: none;
}

.agent-shell:has(#session-tabs .tab[data-view="contacts"].active) .contacts-view {
  display: block;
}

.agent-shell:has(#session-tabs .tab[data-view="profile"].active) .profile-view {
  display: block;
}

@media (max-width: 900px) {
  .agent-shell {
    grid-template-columns: 1fr;
  }
  .chat-list-view,
  .chat-detail-view,
  .contacts-view,
  .profile-view {
    grid-column: 1 / -1;
  }
  .chat-detail-view {
    display: none;
  }
  .agent-shell.show-chat .chat-detail-view {
    display: flex;
  }
  .agent-shell.show-chat .chat-list-view {
    display: none;
  }
  .top-navbar {
    padding: 8px 12px;
  }
  .chat-detail-header {
    padding: 8px 12px;
  }
  .messages {
    padding: 10px 12px;
    gap: 6px;
  }
  .bubble {
    max-width: 88%;
    font-size: 14px;
  }
  .composer {
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  }
  .tool-panel {
    max-height: 50vh;
    overflow-y: auto;
  }
  .tool-btn {
    min-width: 44px;
    height: 38px;
  }
  #photo-groups {
    max-height: 45vh;
  }
}


/* composer-grid-fix */
.composer-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.composer-tools {
  display: inline-flex;
  gap: 6px;
  flex: 0 0 auto;
}

.composer input {
  min-width: 0;
}

.send-btn {
  flex: 0 0 auto;
  min-width: 56px;
  white-space: nowrap;
}

.force-mobile .tool-label {
  display: none;
}

@media (pointer: coarse), (hover: none), (max-device-width: 900px) {
  .tool-label {
    display: none;
  }
}

html.force-mobile, html.force-mobile body {
  overflow-x: hidden;
}

.force-mobile .agent-shell {
  grid-template-columns: 1fr;
  width: 100vw;
  max-width: 100vw;
}

.force-mobile .chat-list-view,
.force-mobile .chat-detail-view,
.force-mobile .contacts-view,
.force-mobile .profile-view {
  grid-column: 1 / -1;
}

.force-mobile .chat-detail-view {
  display: none;
}

.force-mobile .agent-shell.show-chat .chat-detail-view {
  display: flex;
}

.force-mobile .agent-shell.show-chat .chat-list-view {
  display: none;
}

.force-mobile .top-navbar {
  padding: 8px 12px;
}

.force-mobile .chat-detail-header {
  padding: 8px 12px;
}

.force-mobile .messages {
  padding: 10px 12px;
  gap: 6px;
}

.force-mobile .bubble {
  max-width: 88%;
  font-size: 14px;
}

.force-mobile .composer {
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
}

.force-mobile .tool-panel {
  max-height: 50vh;
  overflow-y: auto;
}

.force-mobile .tool-btn {
  min-width: 44px;
  height: 38px;
}

.force-mobile #photo-groups {
  max-height: 45vh;
}

@media (pointer: coarse), (hover: none), (max-device-width: 900px) {
  html, body {
    overflow-x: hidden;
  }
  .agent-shell {
    grid-template-columns: 1fr;
    width: 100vw;
    max-width: 100vw;
  }
  .chat-list-view,
  .chat-detail-view,
  .contacts-view,
  .profile-view {
    grid-column: 1 / -1;
  }
  .chat-detail-view {
    display: none;
  }
  .agent-shell.show-chat .chat-detail-view {
    display: flex;
  }
  .agent-shell.show-chat .chat-list-view {
    display: none;
  }
  .top-navbar {
    padding: 8px 12px;
  }
  .chat-detail-header {
    padding: 8px 12px;
  }
  .messages {
    padding: 10px 12px;
    gap: 6px;
  }
  .bubble {
    max-width: 88%;
    font-size: 14px;
  }
  .composer {
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  }
  .tool-panel {
    max-height: 50vh;
    overflow-y: auto;
  }
  .tool-btn {
    min-width: 44px;
    height: 38px;
  }
  #photo-groups {
    max-height: 45vh;
  }
}


/* long-text clamp for tool panel */
.group-card,
.reply-item,
.photo-item,
.group-header {
  min-width: 0;
}

.group-title,
.reply-text,
.photo-group-toggle .group-name {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-actions {
  flex-shrink: 0;
}

.group-chip {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
