/* Responsive workspace and durable process feedback */
body.auth-locked {
  overflow: hidden;
}

/* Quiet live UI updates: keep scroll usable, but remove visual bars and flicker. */
html,
body {
  overflow: hidden;
}

* {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

*::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
}

.app-shell {
  height: calc(100dvh - 56px);
}

.main,
.modulo,
.dialogue-layout,
.chat-area,
.chat-thread,
.docs-content,
.conversation-list,
.chat-messages,
.kanban-board,
.card-list,
.modal-body {
  min-height: 0;
}

.chat-thread {
  flex: 1;
  overflow: hidden;
  background: var(--page);
}

.chat-messages {
  background: var(--page);
  padding-bottom: 28px;
}

.chat-footer {
  align-items: flex-end;
}

textarea.message-input {
  min-height: 44px;
  max-height: 180px;
  height: 44px;
  line-height: 20px;
  resize: vertical;
  overflow-y: hidden;
  padding-top: 11px;
  padding-bottom: 11px;
}

.chat-footer > .btn-icon,
.chat-footer > .btn-primary,
.chat-footer > .btn-secondary {
  min-height: 44px;
  flex-shrink: 0;
}

.chat-messages::after,
.docs-content::after,
.conversation-list::after {
  content: "";
  display: block;
  height: 18px;
  flex-shrink: 0;
}

.kanban-board {
  scrollbar-width: none !important;
  padding-bottom: 28px;
}

.dialogue-head {
  overflow: hidden;
}

.dialogue-counters {
  justify-content: flex-start;
  padding-right: 4px;
}

.dialogue-settings-button {
  width: 30px;
  height: 30px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}

.dialogue-settings-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.kanban-column {
  min-height: min(620px, calc(100dvh - 148px));
  padding: 10px;
  transition: background-color .16s, outline-color .16s;
}

.kanban-column.drag-target {
  outline: 2px solid rgba(34, 197, 94, .28);
  outline-offset: 2px;
  background: #ecfdf5;
}

.card-list {
  min-height: 120px;
  padding: 8px 2px 18px;
}

.card-list.drag-over {
  background: rgba(34, 197, 94, .08);
}

.kanban-drop-placeholder {
  min-height: 46px;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--primary);
  border-radius: 4px;
  background: rgba(34, 197, 94, .1);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  transition: min-height .14s ease, opacity .14s ease;
}

.is-dragging-card .kanban-card:not(.dragging) {
  transition: transform .14s ease, margin .14s ease, background-color .14s ease;
}

.kanban-card.dragging {
  opacity: .42;
}

.kanban-card,
.doc-cell,
.suggested-card,
.conversation-item,
.message,
.settings-card,
.connection-card,
.monitor-metric,
.settings-nav button {
  animation: none !important;
}

.is-live-refreshing .topbar-logo::after {
  content: none !important;
}

body.auth-locked .topbar,
body.auth-locked .app-shell,
body.auth-locked #card-modal,
body.auth-locked #modal-root,
body.auth-locked #job-progress-root,
body.auth-locked #job-tools-button,
body.auth-locked #job-tools-panel,
body.auth-locked #global-results,
body.auth-locked #toast-root {
  display: none !important;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
  background: #f7f7f5;
}

.auth-card {
  width: min(520px, 100%);
  overflow: hidden;
  padding: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 18px 50px rgba(26, 26, 26, .08);
}

.auth-panel-head {
  padding: 26px 28px 20px;
  border-bottom: 1px solid var(--border);
}

.auth-panel-head p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.auth-brand span {
  color: var(--primary);
  font-size: 22px;
  font-weight: 800;
}

.auth-brand strong {
  color: var(--text);
  font-size: 17px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  padding: 12px 28px 0;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--border);
}

.auth-tabs button {
  height: 46px;
  padding: 0 14px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}

.auth-tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.auth-feedback {
  margin: 0 28px 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  background: var(--page);
}

.auth-feedback.ok {
  border-color: #bbf7d0;
  color: #166534;
  background: #f0fdf4;
}

.auth-feedback.warn {
  border-color: #fde68a;
  color: #92400e;
  background: #fffbeb;
}

.auth-feedback.error {
  border-color: #fecaca;
  color: #991b1b;
  background: #fef2f2;
}

.auth-key-status {
  position: relative;
  display: grid;
  justify-items: start;
  gap: 8px;
  margin: 0 28px 14px;
  padding: 9px 12px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--page);
}

.auth-key-status.ok {
  border-color: rgba(34, 197, 94, .34);
  background: transparent;
}

.auth-key-status.missing,
.auth-key-status.local,
.auth-key-status.invalid {
  border-color: var(--border);
  background: transparent;
}

.auth-key-status strong {
  color: var(--text);
  font-size: 12px;
  line-height: 1;
}

.auth-key-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  background: #fff;
}

.auth-key-tag.found {
  border-color: #86efac;
  color: #166534;
  background: #dcfce7;
}

.auth-key-tag.missing {
  border-color: #d1d5db;
  color: #6b7280;
  background: #f9fafb;
}

.auth-key-icon {
  position: relative;
  width: 12px;
  height: 12px;
  display: inline-block;
  color: currentColor;
}

.auth-key-icon::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  width: 5px;
  height: 5px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  background: transparent;
}

.auth-key-icon::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 5px;
  width: 7px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 3px 3px 0 -1px currentColor;
}

.auth-key-tag.found .auth-key-icon::before {
  background: currentColor;
  box-shadow: inset 0 0 0 2px #dcfce7;
}

.auth-key-tag.missing .auth-key-icon::after {
  background: transparent;
  border-top: 1.6px solid currentColor;
  box-shadow: none;
}

.auth-note {
  color: var(--muted);
  font-size: 12px;
}

.auth-form {
  display: grid;
  gap: 12px;
  padding: 0 28px 28px;
}

.auth-card .auth-form + .auth-key-tools {
  margin-top: -12px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.auth-field {
  position: relative;
  display: block;
}

.auth-form input {
  height: 44px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  background: #fff;
  text-transform: none;
  font-weight: 400;
}

.auth-form input:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 1px 6px rgba(34, 197, 94, .16);
}

.auth-password-field input {
  padding-right: 52px;
}

.auth-password-toggle {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 44px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0 4px 4px 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.auth-password-toggle:hover,
.auth-password-toggle:focus-visible {
  color: var(--primary);
  outline: 0;
}

.auth-eye-icon {
  position: relative;
  width: 18px;
  height: 12px;
  display: block;
  border: 1.6px solid currentColor;
  border-radius: 999px / 720px;
}

.auth-eye-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.auth-eye-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -4px;
  width: 1.5px;
  height: 20px;
  border-radius: 999px;
  background: currentColor;
  transform: translateX(-50%) rotate(-45deg);
}

.auth-password-toggle.is-visible .auth-eye-icon::after {
  opacity: 0;
}

.auth-password-rules {
  display: grid;
  gap: 7px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--page);
  color: var(--muted);
}

.auth-password-rules[hidden] {
  display: none !important;
}

.auth-password-rules strong {
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
}

.auth-password-rule {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.auth-password-rule::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: .72;
}

.auth-password-rule.ok {
  color: #16a34a;
}

.auth-password-rule.ok::before {
  background: currentColor;
  box-shadow: inset 0 0 0 2px #fff;
  opacity: 1;
}

.auth-actions,
.auth-key-tools {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.auth-key-tools {
  margin-top: 16px;
  padding: 0 28px 28px;
}

.auth-key-tools .btn-secondary {
  flex: 1 1 0;
  min-width: 0;
  white-space: normal;
}

.auth-note {
  display: block;
  margin: 16px 28px 26px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.auth-user-list {
  display: grid;
  gap: 8px;
}

.auth-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.auth-user-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.session-counter {
  order: 1;
  min-width: 74px;
  justify-content: center;
  gap: 6px;
}

.session-counter strong {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.session-counter.is-ending {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.session-counter.is-ending strong {
  color: #b45309;
}

.session-date-time-label {
  order: 2;
  display: grid;
  gap: 1px;
  min-width: 174px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
}

.session-date-time-label strong {
  color: var(--primary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.session-date-time-label span {
  white-space: nowrap;
}

.activities-bell-button {
  order: 3;
  width: 36px;
  min-width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  background: #fff;
}

.profile-menu-button {
  order: 4;
  width: 38px;
  min-width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.profile-menu-button:focus-visible,
.activities-bell-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.profile-avatar-mini {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
}

.profile-avatar-mini.has-photo img,
.profile-avatar-mini img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-menu-panel,
.notifications-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 120;
  width: min(340px, calc(100vw - 24px));
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(15, 23, 42, .14);
}

.notifications-panel {
  right: 44px;
  width: min(360px, calc(100vw - 24px));
}

.profile-menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 10px;
  border-bottom: 1px solid var(--border);
}

.profile-menu-head strong,
.notifications-head strong,
.profile-menu-item strong,
.notification-row strong {
  display: block;
}

.profile-menu-head small,
.profile-menu-item small,
.notification-row span,
.notifications-head span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.profile-menu-item {
  width: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.profile-menu-item:not(:disabled):hover,
.notification-row:hover {
  background: var(--primary-soft);
}

.profile-menu-item:disabled {
  opacity: .45;
  cursor: default;
}

.profile-menu-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--page);
  color: var(--primary);
}

.notifications-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 10px;
  border-bottom: 1px solid var(--border);
}

.notifications-list {
  display: grid;
  gap: 4px;
  max-height: min(360px, 62vh);
  overflow: auto;
  padding-top: 6px;
}

.notification-row,
.notification-empty {
  padding: 9px 8px;
  border-radius: 6px;
}

.notification-row.is-process {
  border-left: 3px solid var(--primary);
}

.notification-empty {
  color: var(--muted);
  text-align: center;
}

.session-settings-field {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(90px, .6fr);
  gap: 8px;
}

.session-settings-field select,
.session-settings-field input {
  width: 100%;
}

.dialogue-tabs[hidden] {
  display: none !important;
}

.dialogue-counters button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.dialogue-counters button.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.dialogue-counters button strong {
  font-size: 11px;
}

.topbar {
  gap: clamp(6px, 1.4vw, 16px);
  padding-inline: clamp(10px, 2vw, 24px);
}

.topbar-logo {
  flex-shrink: 0;
}

.global-search {
  min-width: 140px;
  max-width: min(620px, 48vw);
  margin-inline: clamp(6px, 1.8vw, 24px);
}

.topbar-actions {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
}

.topbar-actions .btn-secondary {
  white-space: nowrap;
}

.app-shell,
.main,
.modulo,
.dialogue-layout,
.chat-area,
.docs-content,
.kanban-board {
  min-width: 0;
}

.sidebar {
  width: clamp(156px, 13vw, 200px);
}

.nav-item {
  padding-inline: clamp(12px, 1.4vw, 20px);
}

.kanban-board {
  height: calc(100dvh - 120px);
  padding: clamp(10px, 1.6vw, 16px);
  scrollbar-width: thin;
}

.kanban-column {
  width: clamp(236px, 24vw, 272px);
}

.docs-content {
  padding: clamp(12px, 2vw, 24px);
}

.docs-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}

.doc-thumb {
  position: relative;
  overflow: hidden;
}

.pdf-thumb-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 10px;
  text-align: center;
  background: #f7f7f5;
  color: var(--muted);
  transition: opacity .18s ease;
}

.pdf-thumb-fallback strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 30px;
  padding: 0 8px;
  border-radius: 4px;
  background: #ea4335;
  color: #fff;
  font-size: 12px;
}

.pdf-thumb-fallback small {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-thumb.has-native-preview:not(.is-thumb-loading) .pdf-thumb-fallback {
  opacity: 0;
  pointer-events: none;
}

.pdf-thumb iframe {
  position: relative;
  z-index: 1;
}

.pdf-thumb.is-thumb-loading iframe {
  opacity: .01;
}

.icon-thumb {
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  text-align: center;
}

.icon-thumb small {
  width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-card-with-thumb .doc-thumb,
.attachment-card .doc-thumb {
  width: 72px;
  height: 48px;
  flex-shrink: 0;
  margin: 0;
}

.attachment-card .doc-thumb small {
  display: none;
}

.docs-list .doc-thumb {
  display: flex;
  width: 52px;
  height: 40px;
  flex-shrink: 0;
  margin: 0;
}

.suggested-card {
  width: clamp(190px, 22vw, 240px);
}

.dialogue-sidebar {
  width: clamp(300px, 27vw, 380px);
}

.chat-header,
.chat-footer {
  padding-inline: clamp(10px, 1.6vw, 16px);
}

.chat-messages {
  padding: clamp(10px, 1.8vw, 16px);
}

.message {
  max-width: min(760px, 74%);
}

.modal-overlay {
  padding: clamp(8px, 4vw, 42px) clamp(8px, 2vw, 16px);
}

.modal-wide,
.email-viewer-modal {
  width: min(1120px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px);
}

.email-viewer-modal {
  min-height: min(720px, calc(100dvh - 16px));
}

.modal-body {
  padding: clamp(12px, 2vw, 18px);
}

.form-grid.three {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.settings-layout {
  grid-template-columns: minmax(170px, 220px) minmax(0, 1fr);
}

.monitor-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}

.job-tools-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.job-tools-button[hidden] {
  display: none;
}

.job-tools-button strong {
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
}

.job-tools-button.has-hidden-jobs {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.job-tools-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 160;
  width: min(380px, calc(100vw - 24px));
  max-height: min(520px, calc(100dvh - 82px));
  overflow: auto;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, .18);
}

.job-tools-panel[hidden] {
  display: none;
}

.job-tools-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.job-tools-head span {
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.job-tools-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.job-tools-item:first-of-type {
  border-top: 0;
}

.job-tools-item strong,
.job-tools-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-tools-item small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.job-tools-item > span {
  font-weight: 700;
  color: var(--primary);
}

.job-tools-track {
  grid-column: 1 / -1;
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.job-tools-track i {
  display: block;
  height: 100%;
  background: var(--primary);
  transition: width .25s;
}

.job-tools-item button {
  justify-self: start;
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
}

.job-tools-item button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.job-progress-subtitle {
  margin-top: 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.job-progress-eta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.job-progress-actions {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}

.job-progress-hide,
.job-progress-cancel {
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
}

.job-progress-hide:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.job-progress-cancel:hover {
  border-color: var(--danger);
  color: var(--danger);
}

@media (max-width: 1060px) {
  .global-search {
    max-width: min(520px, 42vw);
  }

  .docs-list .doc-cell {
    gap: 10px;
    padding-inline: 12px;
  }

  .email-viewer-content {
    padding-inline: clamp(18px, 5vw, 48px);
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    padding-block: 8px;
  }

  .topbar-logo {
    order: 1;
  }

  .topbar-actions {
    order: 2;
    margin-left: auto;
  }

  .global-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    margin: 0;
  }

  .app-shell {
    height: calc(100dvh - 96px);
    margin-top: 96px;
  }

  .sidebar {
    width: 112px;
  }

  .nav-item {
    gap: 7px;
    padding: 10px 8px;
    font-size: 12px;
  }

  .nav-icon {
    width: 16px;
  }

  .docs-toolbar {
    padding: 10px 12px;
  }

  .docs-actions {
    width: 100%;
    justify-content: space-between;
  }

  .dialogue-layout {
    flex-direction: column;
  }

  .dialogue-sidebar {
    width: 100%;
    height: min(44%, 340px);
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .chat-area {
    min-height: 0;
  }

  .message {
    max-width: 92%;
  }

  .preview-modal .modal-body {
    grid-template-columns: 1fr;
  }

  .preview-side {
    order: 2;
  }

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

  .settings-nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
  }

  .job-tools-panel {
    left: auto;
    right: 0;
  }
}

@media (max-width: 560px) {
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .topbar-actions .btn-secondary {
    padding: 7px 9px;
    font-size: 12px;
  }

  .app-shell {
    height: calc(100dvh - 134px);
    margin-top: 134px;
  }

  .sidebar {
    height: auto;
    width: 100%;
    display: flex;
    overflow-x: auto;
    padding: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav-item {
    width: auto;
    flex-shrink: 0;
    border-left: 0;
    border-bottom: 3px solid transparent;
  }

  .nav-item.active {
    border-bottom-color: var(--primary);
  }

  .kanban-board {
    height: calc(100dvh - 198px);
  }

  .kanban-column {
    width: min(82vw, 272px);
  }

  .docs-grid {
    grid-template-columns: 1fr;
  }

  .docs-list .doc-cell {
    align-items: flex-start;
    flex-direction: column;
  }

  .docs-list .doc-meta {
    margin-left: 0;
  }

  .dialogue-sidebar {
    height: 48%;
  }

  .chat-header {
    height: auto;
    min-height: 58px;
    flex-wrap: wrap;
    padding-block: 8px;
  }

  .chat-tools {
    margin-left: 52px;
  }

  .message {
    max-width: 100%;
  }

  .email-meta-grid,
  .monitor-metrics {
    grid-template-columns: 1fr;
  }

  .email-viewer-content {
    padding: 16px;
  }

  .email-action-row {
    flex-wrap: wrap;
  }

  .job-progress-root {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
  }

  .job-tools-panel {
    left: 0;
    right: auto;
    width: calc(100vw - 20px);
  }
}

/* Theme switcher and dark mode */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}

.theme-choice {
  min-height: 88px;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.theme-choice span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.theme-choice.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

body.theme-dark {
  --bg: #1e1e1e;
  --page: #1e1e1e;
  --surface: #181818;
  --soft: #252526;
  --primary-soft: #2a2d2e;
  --text: #cccccc;
  --muted: #8f8f8f;
  --border: #2d2d30;
  color-scheme: dark;
  background: var(--page);
}

body.theme-dark .topbar,
body.theme-dark .sidebar,
body.theme-dark .module-toolbar,
body.theme-dark .board-header,
body.theme-dark .filter-shell,
body.theme-dark .dialogue-sidebar,
body.theme-dark .dialogue-head,
body.theme-dark .dialogue-tabs,
body.theme-dark .conversation-search-wrap,
body.theme-dark .chat-header,
body.theme-dark .chat-footer,
body.theme-dark .modal-header,
body.theme-dark .modal-side,
body.theme-dark .modal-wide,
body.theme-dark .settings-card,
body.theme-dark .connection-card,
body.theme-dark .context-menu,
body.theme-dark .global-results,
body.theme-dark .filter-panel,
body.theme-dark .drive-search-panel,
body.theme-dark .reaction-popover,
body.theme-dark .dialogue-settings-menu,
body.theme-dark .job-progress-card,
body.theme-dark .job-tools-panel,
body.theme-dark .auth-card,
body.theme-dark .call-modal,
body.theme-dark .email-viewer-modal,
body.theme-dark .contact-panel,
body.theme-dark .contact-cover,
body.theme-dark .contact-section,
body.theme-dark .docs-list,
body.theme-dark .compact-list {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

body.theme-dark .auth-screen,
body.theme-dark .chat-area,
body.theme-dark .chat-thread,
body.theme-dark .chat-messages,
body.theme-dark .docs-content,
body.theme-dark .card-modal {
  background: var(--page);
}

body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea,
body.theme-dark .docs-search,
body.theme-dark .conversation-search,
body.theme-dark .message-input,
body.theme-dark .modal-textarea,
body.theme-dark .date-input,
body.theme-dark .inline-add input,
body.theme-dark .form-field input,
body.theme-dark .form-field select,
body.theme-dark .form-field textarea,
body.theme-dark .preview-toolbar input,
body.theme-dark .drive-advanced select,
body.theme-dark .drive-advanced input,
body.theme-dark .kanban-controls select,
body.theme-dark .kanban-controls input {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--text);
}

body.theme-dark input::placeholder,
body.theme-dark textarea::placeholder {
  color: #7a7a7a;
}

body.theme-dark .btn-secondary,
body.theme-dark .btn-primary,
body.theme-dark .btn-filter,
body.theme-dark .view-btn,
body.theme-dark .btn-icon,
body.theme-dark .board-chip,
body.theme-dark .settings-nav button,
body.theme-dark .settings-tab,
body.theme-dark .column-menu,
body.theme-dark .column-add,
body.theme-dark .job-progress-hide,
body.theme-dark .job-progress-cancel,
body.theme-dark .job-tools-item button {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--text);
}

body.theme-dark .btn-secondary:hover,
body.theme-dark .btn-primary:hover,
body.theme-dark .btn-filter:hover,
body.theme-dark .view-btn:hover,
body.theme-dark .btn-icon:hover,
body.theme-dark .settings-nav button:hover,
body.theme-dark .context-menu button:hover,
body.theme-dark .dialogue-settings-menu button:hover,
body.theme-dark .global-result:hover,
body.theme-dark .drive-result:hover,
body.theme-dark .compact-list button.compact-item:hover,
body.theme-dark .conversation-item:hover,
body.theme-dark .conversation-item.active,
body.theme-dark .nav-item:hover,
body.theme-dark .nav-item.active,
body.theme-dark .settings-nav button.active,
body.theme-dark .settings-tab.active,
body.theme-dark .view-btn.active,
body.theme-dark .board-chip.active {
  background: var(--primary-soft);
  border-color: #3c3c3c;
  color: var(--text);
}

body.theme-dark .nav-item.active,
body.theme-dark .settings-nav button.active,
body.theme-dark .settings-tab.active,
body.theme-dark .view-btn.active,
body.theme-dark .board-chip.active,
body.theme-dark .theme-choice.active {
  border-color: var(--primary);
  color: var(--primary);
}

body.theme-dark .kanban-column {
  background: var(--soft);
}

body.theme-dark .kanban-card,
body.theme-dark .gmail-suggestion-card,
body.theme-dark .doc-cell,
body.theme-dark .suggested-card,
body.theme-dark .folder-card,
body.theme-dark .conversation-item,
body.theme-dark .message.received,
body.theme-dark .email-message,
body.theme-dark .history-item,
body.theme-dark .attachment-card,
body.theme-dark .compact-item,
body.theme-dark .monitor-metric,
body.theme-dark .monitor-channel,
body.theme-dark .email-thread-item,
body.theme-dark .chooser-card,
body.theme-dark .skeleton-doc,
body.theme-dark .skeleton-card,
body.theme-dark .skeleton-row,
body.theme-dark .auth-user-row {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

body.theme-dark .message.sent {
  background: #2a2d2e;
  color: var(--text);
}

body.theme-dark .doc-thumb,
body.theme-dark .docs-grid,
body.theme-dark .docs-list-header,
body.theme-dark .card-badge,
body.theme-dark .dialogue-settings-menu span,
body.theme-dark .tab-count,
body.theme-dark .email-meta-grid,
body.theme-dark .email-thread-history,
body.theme-dark .monitor-details code,
body.theme-dark .card-composer,
body.theme-dark .board-empty,
body.theme-dark .column-empty,
body.theme-dark .progress-bar,
body.theme-dark .job-progress-track,
body.theme-dark .job-tools-track {
  background: var(--soft);
  border-color: var(--border);
  color: var(--muted);
}

body.theme-dark .chat-meta-panel,
body.theme-dark .chat-meta-panel .chip,
body.theme-dark .dialogue-counters span,
body.theme-dark .dialogue-counters button,
body.theme-dark .contact-trigger,
body.theme-dark .message-actions button,
body.theme-dark .reply-box,
body.theme-dark .reaction,
body.theme-dark .email-message-head,
body.theme-dark .email-expanded-content,
body.theme-dark .email-thread-history,
body.theme-dark .email-thread-item,
body.theme-dark .email-meta-grid > div,
body.theme-dark .attachment-card,
body.theme-dark .deleted-retention {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--text);
}

body.theme-dark .chat-meta-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

body.theme-dark .chat-meta-panel .chip:not(.active),
body.theme-dark .dialogue-counters span:not(.active),
body.theme-dark .dialogue-counters button:not(.active) {
  color: var(--muted);
}

body.theme-dark .chat-meta-panel .chip.active,
body.theme-dark .dialogue-counters span.active,
body.theme-dark .dialogue-counters button.active {
  background: rgba(34, 197, 94, .18);
  border-color: var(--primary);
  color: #86efac;
}

body.theme-dark .email-kicker,
body.theme-dark .message-status,
body.theme-dark .message-time,
body.theme-dark .email-message-head p,
body.theme-dark .doc-meta {
  color: var(--muted);
}

body.theme-dark .preview-stage,
body.theme-dark .preview-page,
body.theme-dark .email-viewer-content {
  background: #fff;
  color: #1a1a1a;
}

body.theme-dark .email-viewer-content .doc-meta,
body.theme-dark .preview-page .doc-meta {
  color: #666;
}

body.theme-dark .modal-overlay {
  background: rgba(0, 0, 0, .62);
}

body.theme-dark .global-result,
body.theme-dark .context-menu button,
body.theme-dark .dialogue-settings-menu button,
body.theme-dark .drive-result,
body.theme-dark .reaction-popover button,
body.theme-dark .emoji-strip button {
  background: transparent;
  color: var(--text);
}

body.theme-dark .auth-feedback {
  background: var(--soft);
  border-color: var(--border);
  color: var(--muted);
}

body.theme-dark .auth-feedback.ok,
body.theme-dark .status-connected,
body.theme-dark .card-badge.ok {
  background: #0d2c1a;
  color: #86efac;
}

body.theme-dark .auth-feedback.warn,
body.theme-dark .deleted-retention,
body.theme-dark .call-status,
body.theme-dark .status-connecting,
body.theme-dark .status-syncing {
  background: #31250d;
  border-color: #6b4f13;
  color: #facc15;
}

body.theme-dark .auth-feedback.error,
body.theme-dark .connection-error,
body.theme-dark .status-error,
body.theme-dark .card-badge.danger {
  background: #3a1212;
  border-color: #7f1d1d;
  color: #fecaca;
}

body.theme-dark .auth-key-status,
body.theme-dark .auth-key-status.local,
body.theme-dark .auth-key-status.invalid,
body.theme-dark .auth-key-status.missing {
  background: transparent;
  border-color: var(--border);
}

body.theme-dark .auth-key-status.ok {
  background: transparent;
  border-color: rgba(34, 197, 94, .34);
}

body.theme-dark .auth-key-tag.found {
  background: rgba(34, 197, 94, .16);
  border-color: rgba(34, 197, 94, .52);
  color: #86efac;
}

body.theme-dark .auth-key-tag.found .auth-key-icon::before {
  box-shadow: inset 0 0 0 2px #1e1e1e;
}

body.theme-dark .auth-key-tag.missing {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--muted);
}

body.theme-dark .auth-password-rules {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--muted);
}

body.theme-dark .auth-password-rule.ok {
  color: #86efac;
}

body.theme-dark .auth-password-rule.ok::before {
  box-shadow: inset 0 0 0 2px #1f1f1f;
}

body.theme-dark .doc-thumb.is-thumb-loading::before,
body.theme-dark .skeleton-doc::after,
body.theme-dark .skeleton-card::after,
body.theme-dark .skeleton-row::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .08), transparent);
}

@media (max-width: 720px) {
  .theme-picker {
    grid-template-columns: 1fr;
  }

  .auth-key-tools {
    flex-direction: column;
  }
}

/* Dialogue composer: WhatsApp-like tools, attachments, emojis and audio states */
.message-composer-footer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.message-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.message-tools-root {
  position: relative;
  flex-shrink: 0;
}

.message-tools-trigger {
  font-size: 16px;
}

.message-tools-menu,
.emoji-picker {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  z-index: 95;
  width: 236px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .18);
}

.message-tools-menu button,
.message-tool-submenu button {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.message-tools-menu button:hover,
.message-tool-submenu button:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.message-tool-submenu-wrap {
  position: relative;
}

.message-tool-submenu-wrap > button::after {
  content: "›";
  color: var(--muted);
}

.message-tool-submenu {
  position: absolute;
  left: calc(100% + 7px);
  bottom: 0;
  display: none;
  width: 214px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .18);
}

.message-tool-submenu-wrap:hover .message-tool-submenu,
.message-tool-submenu-wrap:focus-within .message-tool-submenu,
.message-tool-submenu-wrap.open .message-tool-submenu {
  display: block;
}

.composer-input-shell {
  position: relative;
  flex: 1;
  min-width: 0;
}

.composer-input-shell .message-input {
  width: 100%;
  padding-right: 48px;
}

.message-transcribe-button {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.message-transcribe-button:hover,
.message-transcribe-button.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.message-attachment-preview {
  position: relative;
  width: min(420px, 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 38px 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.message-attachment-thumb {
  width: 52px;
  height: 38px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.message-attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-attachment-thumb .doc-icon {
  width: 30px;
  height: 26px;
  margin: 0;
  font-size: 9px;
}

.message-attachment-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

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

.message-attachment-main span {
  color: var(--muted);
  font-size: 12px;
}

.message-attachment-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  opacity: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  transition: opacity .14s, color .14s, border-color .14s;
}

.message-attachment-preview:hover .message-attachment-remove {
  opacity: 1;
}

.message-attachment-remove:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.emoji-picker {
  width: min(340px, calc(100vw - 32px));
  padding: 10px;
}

.emoji-search {
  width: 100%;
  height: 36px;
  margin-bottom: 8px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--page);
  color: var(--text);
}

.emoji-grid {
  max-height: 220px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  overflow: auto;
}

.emoji-grid button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 20px;
}

.emoji-grid button:hover {
  background: var(--primary-soft);
}

.emoji-empty {
  grid-column: 1 / -1;
  padding: 12px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.composer-audio-state {
  width: min(360px, 100%);
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.composer-audio-state strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.audio-wave {
  width: 46px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--primary);
}

.audio-wave i {
  width: 3px;
  height: 8px;
  display: block;
  border-radius: 999px;
  background: currentColor;
  animation: composer-wave .82s ease-in-out infinite;
}

.audio-wave i:nth-child(2) {
  animation-delay: .08s;
}

.audio-wave i:nth-child(3) {
  animation-delay: .16s;
}

.audio-wave i:nth-child(4) {
  animation-delay: .24s;
}

.audio-wave i:nth-child(5) {
  animation-delay: .32s;
}

@keyframes composer-wave {
  0%, 100% {
    height: 7px;
    opacity: .52;
  }

  50% {
    height: 19px;
    opacity: 1;
  }
}

.audio-button {
  font-size: 17px;
}

.audio-button.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

body.theme-dark .message-tools-menu,
body.theme-dark .message-tool-submenu,
body.theme-dark .emoji-picker,
body.theme-dark .message-attachment-preview,
body.theme-dark .message-attachment-thumb,
body.theme-dark .message-attachment-remove,
body.theme-dark .composer-audio-state {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

body.theme-dark .message-tools-menu button,
body.theme-dark .message-tool-submenu button {
  color: var(--text);
}

body.theme-dark .message-tools-menu button:hover,
body.theme-dark .message-tool-submenu button:hover,
body.theme-dark .emoji-grid button:hover,
body.theme-dark .message-transcribe-button:hover,
body.theme-dark .message-transcribe-button.active {
  background: var(--primary-soft);
  color: var(--primary);
}

body.theme-dark .emoji-search {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--text);
}

@media (max-width: 560px) {
  .message-composer-row {
    align-items: stretch;
  }

  .message-tools-menu {
    width: min(236px, calc(100vw - 24px));
  }

  .message-tool-submenu {
    left: 0;
    bottom: calc(100% + 7px);
  }

  .emoji-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* Dialogue refinements: search, channel tags and WhatsApp-like layering */
.dialogue-sidebar {
  overflow: visible;
}

.conversation-list {
  overflow-y: auto;
}

.dialogue-head {
  overflow: visible;
  z-index: 240;
}

.dialogue-settings-wrap {
  z-index: 340;
}

.dialogue-settings-menu {
  z-index: 360;
}

.conversation-search-box {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.conversation-search-box .conversation-search {
  min-width: 0;
  flex: 1;
}

.conversation-search-clear {
  position: absolute;
  right: 8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.conversation-search-clear:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.conversation-search-clear[hidden] {
  display: none;
}

.conversation-name-wrap {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.conversation-channel-tags {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}

.channel-tag {
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  opacity: .38;
  filter: saturate(.45);
}

.channel-tag.is-on {
  opacity: 1;
  filter: none;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, .12);
}

.channel-whatsapp {
  background: #25d366;
  border-color: #25d366;
  color: #fff;
}

.channel-email {
  background: #ea4335;
  border-color: #ea4335;
  color: #fff;
}

.channel-sms {
  background: #64748b;
  border-color: #64748b;
  color: #fff;
}

.channel-messenger,
.channel-facebook {
  background: #1877f2;
  border-color: #1877f2;
  color: #fff;
}

.channel-instagram {
  background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
  border-color: #c13584;
  color: #fff;
}

.channel-manual {
  background: #6b7280;
  border-color: #6b7280;
  color: #fff;
}

.channel-tag.is-off {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.conversation-preview.has-draft {
  color: var(--primary);
}

.conversation-preview.has-draft strong {
  font-weight: 800;
}

.chat-channel {
  text-transform: none;
}

.chat-header .contact-trigger {
  background: transparent;
}

.chat-header .contact-trigger:hover {
  background: transparent;
}

.message-tools-menu,
.emoji-picker {
  z-index: 370;
}

.message-composer-footer {
  z-index: 220;
  overflow: visible;
}

.message-composer-row {
  align-items: center;
}

.message-tools-trigger,
.audio-button {
  border-color: transparent;
  background: transparent;
}

.composer-input-shell .message-input {
  border-radius: 24px;
  resize: vertical;
}

body.theme-dark .chat-header,
body.theme-dark .chat-footer,
body.theme-dark .message-composer-footer {
  background: var(--page);
}

body.theme-dark .contact-trigger,
body.theme-dark .chat-header .contact-trigger,
body.theme-dark .message-tools-trigger,
body.theme-dark .audio-button {
  background: transparent;
  border-color: transparent;
}

body.theme-dark .composer-input-shell .message-input,
body.theme-dark .conversation-search {
  background: #252526;
  border-color: #333333;
}

body.theme-dark .chat-header {
  border-bottom-color: var(--border);
}

body.theme-dark .channel-tag.is-off {
  background: transparent;
  color: #6f6f6f;
}

@media (max-width: 900px) {
  .conversation-channel-tags {
    max-width: 118px;
  }
}

@media (max-width: 560px) {
  .conversation-name-wrap {
    max-width: 100%;
  }

  .channel-tag {
    width: 16px;
    padding: 0;
    overflow: hidden;
    text-indent: -999px;
  }

  .channel-tag::first-letter {
    text-indent: 0;
  }
}

/* Dialogue execution fixes: search order, modal layers and inline chat search */
.dialogue-sidebar .conversation-search-wrap {
  order: -2;
  padding: 12px 12px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.dialogue-sidebar .dialogue-head {
  order: -1;
}

.conversation-search-box .conversation-search {
  padding-right: 12px;
}

.dialogue-search-settings-slot {
  position: relative;
  flex-shrink: 0;
}

.dialogue-search-settings-slot .dialogue-settings-wrap {
  position: relative;
  z-index: 340;
}

.conversation-search-clear {
  display: none !important;
}

#modal-root {
  position: relative;
  z-index: 420;
}

#modal-root .modal-overlay {
  z-index: 420;
}

.document-chooser-overlay {
  align-items: center;
  padding: 24px;
}

.document-chooser-modal {
  width: min(920px, calc(100vw - 40px));
  max-height: min(760px, calc(100dvh - 48px));
}

.document-chooser-header {
  flex-shrink: 0;
}

.document-chooser-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(120px, 180px));
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.document-chooser-tools input,
.document-chooser-tools select {
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.document-chooser-tools input:focus,
.document-chooser-tools select:focus {
  outline: 0;
  border-color: var(--primary);
}

.document-chooser-body {
  flex: 1;
  min-height: 0;
  max-height: calc(100dvh - 190px);
  overflow: auto;
}

.document-chooser-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.document-chooser-list .chooser-card {
  min-width: 0;
}

.chat-search-inline {
  min-width: min(420px, 42vw);
  max-width: min(520px, 46vw);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.chat-search-inline input {
  min-width: 0;
  flex: 1;
  height: 34px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.chat-search-inline input:focus {
  outline: 0;
  border-color: var(--primary);
}

.chat-search-count {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.message.chat-search-hit {
  outline: 1px solid rgba(34, 197, 94, .4);
  outline-offset: 2px;
}

.message.chat-search-current {
  outline-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .14);
}

.chat-tools .btn-icon.is-disabled {
  opacity: .42;
}

body.theme-dark .document-chooser-tools,
body.theme-dark .document-chooser-tools input,
body.theme-dark .document-chooser-tools select,
body.theme-dark .chat-search-inline input {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--text);
}

@media (max-width: 900px) {
  .document-chooser-tools {
    grid-template-columns: 1fr 1fr;
  }

  .document-chooser-list {
    grid-template-columns: 1fr;
  }

  .chat-search-inline {
    min-width: 0;
    max-width: none;
    flex: 1 1 100%;
    order: 4;
  }

  .chat-header {
    flex-wrap: wrap;
    height: auto;
    min-height: 64px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
}

/* Update-safe controls, integration switches and visual monitoring */
.icon-only {
  width: 38px;
  min-width: 38px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  font-size: 17px;
  line-height: 1;
}

.docs-actions .icon-only {
  border-radius: 4px;
}

.docs-actions .btn-primary.icon-only {
  font-size: 18px;
  font-weight: 800;
}

.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.view-btn.icon-only[aria-pressed="true"],
.view-btn.icon-only.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.apply-update-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  white-space: nowrap;
}

.apply-update-button span {
  font-size: 15px;
  line-height: 1;
}

.apply-update-button strong {
  font-size: 13px;
}

.is-page-reloading .apply-update-button .update-download-icon {
  animation: update-spin .6s linear infinite;
}

.is-page-reloading .apply-update-button .update-tooltip,
.is-page-reloading .apply-update-button .update-tooltip * {
  animation: none !important;
  transform: none !important;
}

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

.connection-card.integration-card {
  display: flex;
  min-height: 224px;
}

.connection-card-main {
  width: 100%;
  display: grid;
  align-content: start;
  gap: 12px;
}

.connection-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.connection-card-head h3 {
  margin: 0 0 7px;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.status-connected,
.status-completed {
  background: #dcfce7;
  color: #166534;
}

.status-syncing,
.status-connecting,
.status-running,
.status-queued,
.status-paused {
  background: #fef3c7;
  color: #92400e;
}

.status-disconnected,
.status-cancelled {
  background: #f3f4f6;
  color: #6b7280;
}

.status-error {
  background: #fee2e2;
  color: #991b1b;
}

.connection-switch {
  width: 46px;
  height: 26px;
  flex: 0 0 auto;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #e5e7eb;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease;
}

.connection-switch span {
  width: 18px;
  height: 18px;
  display: block;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .16);
  transition: transform .16s ease;
}

.connection-switch.is-on {
  border-color: var(--primary);
  background: var(--primary);
}

.connection-switch.is-on span {
  transform: translateX(20px);
}

.connection-vitals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.connection-vitals span {
  min-width: 0;
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--page);
}

.connection-vitals strong,
.connection-vitals small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-vitals small {
  color: var(--muted);
  font-size: 11px;
}

.connection-details {
  padding-top: 2px;
}

.connection-details summary,
.monitor-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.connection-details[open],
.monitor-details[open] {
  display: grid;
  gap: 9px;
}

.monitor-empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  text-align: center;
}

.monitor-toolbar-visual {
  align-items: center;
  margin-bottom: 12px;
}

.monitor-toolbar-visual h3 {
  margin: 0 0 4px;
}

.monitor-pulse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.monitor-pulse-card {
  position: relative;
  min-height: 112px;
  overflow: hidden;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.monitor-pulse-card > span {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.monitor-pulse-card strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 22px;
  line-height: 1.1;
}

.monitor-pulse-card small {
  display: block;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 10px;
}

.monitor-pulse-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.monitor-ok > span {
  background: #22c55e;
}

.monitor-warn > span {
  background: #f59e0b;
}

.monitor-danger > span {
  background: #ef4444;
}

.monitor-visual-grid {
  align-items: stretch;
}

.monitor-card-visual {
  display: grid;
  align-content: start;
  gap: 14px;
}

.monitor-wide {
  grid-column: span 2;
}

.monitor-card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.monitor-card-title h3 {
  margin: 0;
}

.monitor-card-title span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.monitor-progress-grid {
  display: grid;
  gap: 10px;
}

.monitor-progress {
  display: grid;
  gap: 7px;
}

.monitor-progress > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

.monitor-progress span {
  color: var(--muted);
  font-size: 12px;
}

.monitor-progress i {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.monitor-progress b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #86efac);
  transition: width .25s ease;
}

.monitor-metrics-compact {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.monitor-metrics-compact .monitor-metric {
  min-height: 72px;
}

.monitor-metric small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.monitor-detail-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.monitor-label-row,
.monitor-job {
  display: grid;
  gap: 4px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}

.monitor-label-row:first-child,
.monitor-job:first-child {
  border-top: 0;
}

.monitor-label-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.monitor-label-row span,
.monitor-job span,
.monitor-job small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.monitor-job strong {
  color: var(--primary);
  font-size: 12px;
}

.storage-dial {
  --pct: 0;
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  margin: 4px auto;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--pct) * 1%), var(--border) 0);
}

.storage-dial strong {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
}

.monitor-channel-list {
  display: grid;
  gap: 8px;
}

.monitor-channel {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--page);
}

.monitor-channel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

body.theme-dark .icon-only,
body.theme-dark .connection-vitals span,
body.theme-dark .monitor-pulse-card,
body.theme-dark .monitor-card-visual,
body.theme-dark .monitor-channel,
body.theme-dark .storage-dial strong {
  background: #1f1f1f;
  border-color: var(--border);
  color: var(--text);
}

body.theme-dark .connection-switch {
  background: #333333;
  border-color: #3c3c3c;
}

body.theme-dark .connection-switch span {
  background: #cccccc;
}

body.theme-dark .connection-switch.is-on {
  background: var(--primary);
  border-color: var(--primary);
}

body.theme-dark .status-connected,
body.theme-dark .status-completed {
  background: rgba(34, 197, 94, .16);
  color: #86efac;
}

body.theme-dark .status-syncing,
body.theme-dark .status-connecting,
body.theme-dark .status-running,
body.theme-dark .status-queued,
body.theme-dark .status-paused {
  background: rgba(245, 158, 11, .16);
  color: #fbbf24;
}

body.theme-dark .status-disconnected,
body.theme-dark .status-cancelled {
  background: #252526;
  color: var(--muted);
}

body.theme-dark .status-error {
  background: rgba(239, 68, 68, .18);
  color: #fca5a5;
}

body.theme-dark .monitor-progress i {
  background: #333333;
}

body.theme-dark .monitor-progress b {
  background: linear-gradient(90deg, var(--primary), #4ade80);
}

@media (max-width: 820px) {
  .monitor-wide {
    grid-column: auto;
  }

  .apply-update-button strong {
    display: none;
  }
}

/* Dialogue timeline and explicit send target */
.dialogue-timeline {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 980px;
  margin: 0 auto;
  padding: 4px 0 24px;
}

.timeline-day {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  position: relative;
}

.timeline-day::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 24px;
  bottom: -18px;
  width: 1px;
  background: var(--border);
}

.timeline-date-marker {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: start;
  color: var(--text);
  font-weight: 700;
}

.timeline-date-marker span {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border: 2px solid var(--primary);
  border-radius: 50%;
  background: var(--surface);
  z-index: 1;
}

.timeline-day-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.timeline-channel-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: visible;
}

.timeline-channel-group > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.timeline-channel-group > header small {
  color: var(--muted);
}

.timeline-channel-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}

.timeline-channel-pill.channel-whatsapp {
  background: rgba(37, 211, 102, .14);
  color: #128c4a;
}

.timeline-channel-pill.channel-email {
  background: rgba(0, 133, 111, .12);
  color: #00856f;
}

.timeline-channel-pill.channel-sms,
.timeline-channel-pill.channel-manual {
  background: rgba(100, 116, 139, .14);
  color: #475569;
}

.timeline-channel-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.timeline-message-wrap {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.timeline-message-time {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  padding-top: 8px;
  text-align: right;
}

.timeline-message-wrap .message {
  max-width: min(760px, 100%);
  width: fit-content;
  margin-bottom: 0;
}

.timeline-message-wrap .message.sent {
  justify-self: end;
}

.timeline-message-wrap .message.email-message {
  width: min(760px, 100%);
  max-width: min(760px, 100%);
}

.composer-target-panel {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.composer-target-panel.needs-choice {
  border-color: rgba(0, 133, 111, .35);
  background: rgba(0, 133, 111, .05);
}

.composer-target-panel.selected {
  border-color: rgba(34, 197, 94, .38);
  background: rgba(34, 197, 94, .08);
}

.composer-target-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}

.composer-target-head span {
  flex: 1;
  color: var(--muted);
  font-size: 12px;
}

.composer-target-head button,
.composer-target-actions button {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}

.composer-target-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.composer-target-actions button:hover,
.composer-target-head button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.interaction-mention-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

body.theme-dark .timeline-date-marker span,
body.theme-dark .timeline-channel-group,
body.theme-dark .composer-target-panel,
body.theme-dark .composer-target-head button,
body.theme-dark .composer-target-actions button {
  background: var(--surface);
  border-color: var(--border);
}

body.theme-dark .composer-target-panel.needs-choice {
  background: rgba(0, 133, 111, .08);
}

body.theme-dark .composer-target-panel.selected {
  background: rgba(34, 197, 94, .1);
}

@media (max-width: 760px) {
  .timeline-day {
    grid-template-columns: 1fr;
  }

  .timeline-day::before {
    display: none;
  }

  .timeline-message-wrap {
    grid-template-columns: 1fr;
  }

  .timeline-message-time {
    text-align: left;
    padding: 0;
  }
}
