/* Conversations workspace */
.module-conversations .topbar {
  display: none;
}

#conversations.view.active {
  display: grid;
  height: calc(100dvh - 56px);
  min-height: 680px;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

.conversation-compact-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
}

.conversation-compact-header h2 {
  margin: 2px 0 0;
  font-size: 25px;
  line-height: 1.05;
}

.conversation-compact-header .primary-button,
.conversation-compact-header .primary-button svg {
  display: inline-flex;
  align-items: center;
}

.conversation-compact-header .primary-button {
  gap: 7px;
}

.conversation-compact-header .primary-button svg {
  width: 16px;
  height: 16px;
}

.conversation-summary-badges {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.conversation-summary-badge,
.source-badge,
.provider-status-badge,
.consent-badge,
.conversation-status-badge,
.conversation-priority {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: max-content;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.conversation-summary-badge {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
}

.conversation-summary-badge:hover,
.conversation-summary-badge.active {
  color: var(--brand);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  background: #f7f1ef;
}

.conversation-summary-badge svg,
.source-badge svg,
.conversation-priority svg {
  width: 13px;
  height: 13px;
}

.conversation-summary-badge strong {
  color: var(--ink);
  font-size: 13px;
}

.source-badge,
.provider-status-badge {
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #f7f7f6;
}

.source-badge.is-simulated,
.provider-status-badge.is-simulated {
  color: #8a5314;
  border-color: #e7cfaa;
  background: #fff7e8;
}

.source-badge.is-manual {
  color: #315c6b;
  border-color: #bfd5dc;
  background: #eef7f9;
}

.conversation-area-tabs {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0 0 3px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.conversation-area-tab {
  display: flex;
  align-items: center;
  min-width: max-content;
  min-height: 42px;
  gap: 9px;
  padding: 6px 10px;
  border-radius: 7px;
}

.conversation-area-tab::before {
  width: 3px;
}

.conversation-area-tab span {
  gap: 5px;
}

.conversation-area-tab span strong {
  font-size: 12px;
  white-space: nowrap;
}

.conversation-area-tab small {
  display: inline-flex;
  gap: 3px;
  font-size: 9px;
  white-space: nowrap;
}

.conversation-area-tab small b,
.conversation-area-tab small i {
  position: static;
  display: inline;
  min-width: 0;
  height: auto;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-size: inherit;
  font-style: normal;
}

.conversation-layout {
  position: relative;
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-columns: minmax(330px, 25%) minmax(450px, 1fr) minmax(285px, 22%);
  gap: 0;
  align-items: stretch;
  overflow: hidden;
}

.conversation-layout.context-hidden {
  grid-template-columns: minmax(330px, 25%) minmax(450px, 1fr);
}

.conversation-layout.context-hidden .conversation-context-panel {
  display: none;
}

.conversation-sidebar,
.conversation-thread-panel,
.conversation-context-panel {
  height: 100%;
  min-height: 0;
  max-height: none;
}

.conversation-sidebar {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 9px;
  padding: 12px 10px;
  overflow: hidden;
}

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

.conversation-sidebar-head h2 {
  margin: 2px 0 0;
  font-size: 16px;
}

.conversation-result-count {
  display: grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: #fff;
  font-size: 11px;
  font-weight: 900;
}

.conversation-search {
  min-height: 38px;
  margin: 0;
}

.conversation-search svg {
  width: 15px;
  color: var(--muted);
}

.conversation-list-controls {
  display: grid;
  gap: 7px;
}

.conversation-filters {
  flex-wrap: nowrap;
  margin: 0;
  padding-bottom: 2px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.conversation-filters button {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 9px;
  font-size: 10px;
}

.conversation-sort-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.conversation-sort-label select {
  min-width: 128px;
  height: 30px;
  padding: 0 26px 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-size: 11px;
  text-transform: none;
}

.conversation-list {
  align-content: start;
  gap: 4px;
  max-height: none;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conversation-item {
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: start;
  min-height: 116px;
  gap: 7px 9px;
  padding: 9px;
}

.conversation-preview {
  gap: 4px;
}

.conversation-preview-head strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-origin {
  color: var(--area-color) !important;
  font-weight: 800;
}

.source-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #d18a2f;
}

.conversation-item .conversation-preview em {
  display: -webkit-box;
  min-height: 31px;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.4;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.conversation-row-meta {
  display: flex !important;
  align-items: center;
  gap: 5px !important;
  min-width: 0;
}

.conversation-row-meta > small {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-status-badge,
.conversation-priority,
.consent-badge {
  min-height: 20px;
  padding: 0 7px;
  border: 1px solid var(--line);
}

.conversation-status-badge[data-status-tone="da-leggere"],
.conversation-status-badge[data-status-tone="da-rispondere"] {
  color: #8d2d1e;
  border-color: #edc5bd;
  background: #fff1ee;
}

.conversation-status-badge[data-status-tone="in-attesa-cliente"] {
  color: #48604e;
  border-color: #c6d8ca;
  background: #edf5ef;
}

.conversation-status-badge[data-status-tone="in-attesa-operatore"],
.conversation-status-badge[data-status-tone="da-approvare"] {
  color: #7b5515;
  border-color: #e2cfaa;
  background: #fff8e8;
}

.conversation-status-badge[data-status-tone="archiviata"],
.conversation-status-badge[data-status-tone="risolta"] {
  color: #5d6268;
  background: #f0f1f2;
}

.conversation-status-badge[data-status-tone="bloccata"] {
  color: #8b1818;
  border-color: #e4b6b6;
  background: #fff0f0;
}

.conversation-priority {
  min-height: 18px;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 9px;
}

.conversation-priority[data-priority="alta"] {
  color: #a02f1c;
}

.conversation-item > b {
  min-width: 20px;
  min-height: 20px;
  font-size: 10px;
}

.conversation-thread-panel {
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

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

.conversation-thread-head {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.conversation-contact-heading {
  min-width: 0;
}

.conversation-contact-heading > div {
  min-width: 0;
}

.conversation-contact-heading h2,
.conversation-contact-heading p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-head-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.thread-action-button,
.thread-status-control {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #fff;
  font-size: 10px;
  font-weight: 800;
}

.thread-action-button svg,
.thread-status-control svg {
  width: 14px;
  height: 14px;
}

.thread-status-control select {
  max-width: 118px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 10px;
  outline: 0;
}

.thread-more-menu {
  position: relative;
}

.thread-more-menu summary {
  display: grid;
  list-style: none;
  place-items: center;
}

.thread-more-menu summary::-webkit-details-marker {
  display: none;
}

.thread-more-menu > div {
  position: absolute;
  z-index: 8;
  top: 40px;
  right: 0;
  display: grid;
  width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: var(--shadow);
}

.thread-more-menu > div button {
  min-height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
}

.thread-more-menu > div button:hover {
  background: #f4f2ef;
}

.conversation-mobile-back {
  display: none;
}

.thread-meta-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  padding: 4px 12px;
  border-bottom: 1px solid #ddd8cf;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font-size: 10px;
}

.thread-meta-strip > span:first-child {
  display: flex;
  align-items: center;
  gap: 6px;
}

.message-list {
  align-content: start;
  min-height: 0;
  max-height: none;
  padding: 18px clamp(16px, 4vw, 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.message-bubble {
  position: relative;
  gap: 7px;
  max-width: min(72%, 560px);
  padding: 10px 12px 8px;
}

.message-bubble header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  font-size: 11px;
}

.message-bubble header button {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 0;
  color: var(--muted);
  background: transparent;
}

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

.message-bubble p {
  line-height: 1.45;
}

.message-bubble.internal {
  justify-self: center;
  width: min(82%, 640px);
  max-width: none;
  border: 1px dashed #d7bd79;
  border-radius: 7px;
  background: #fff9e9;
}

.message-bubble.system {
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 7px;
  max-width: 78%;
  padding: 6px 10px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: none;
  font-size: 11px;
}

.message-bubble.system > svg {
  width: 13px;
  height: 13px;
}

.message-bubble.system small {
  display: none;
}

.message-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

.message-attachment svg {
  width: 14px;
  height: 14px;
}

.conversation-composer {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  padding: 9px 11px 10px;
}

.composer-status-row,
.composer-footer,
.composer-tools,
.composer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.composer-status-row {
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}

.composer-status-row > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.composer-status-row svg {
  width: 13px;
  height: 13px;
}

.conversation-composer textarea {
  min-height: 66px;
  max-height: 130px;
  line-height: 1.45;
}

.composer-footer {
  justify-content: space-between;
}

.composer-tools {
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.composer-tool {
  display: inline-flex;
  min-width: max-content;
  min-height: 30px;
  align-items: center;
  gap: 5px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
  font-weight: 800;
}

.composer-tool:hover {
  border-color: var(--line);
  color: var(--ink);
  background: #f7f7f6;
}

.composer-tool svg {
  width: 14px;
  height: 14px;
}

.composer-attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.composer-attachment-list span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 5px;
  color: #315c6b;
  background: #eef7f9;
  font-size: 10px;
  font-weight: 700;
}

.composer-attachment-list svg,
.composer-attachment-list button {
  width: 13px;
  height: 13px;
}

.composer-attachment-list button {
  display: grid;
  padding: 0;
  place-items: center;
  border: 0;
  color: inherit;
  background: transparent;
}

.conversation-context-panel {
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conversation-profile-head {
  margin-bottom: 8px;
  padding-bottom: 10px;
}

.conversation-avatar.profile {
  width: 48px;
  height: 48px;
  font-size: 15px;
}

.context-accordion {
  border-bottom: 1px solid var(--line);
}

.context-accordion > summary {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.context-accordion > summary::-webkit-details-marker {
  display: none;
}

.context-accordion > summary span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.context-accordion > summary svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
  transition: transform 160ms ease;
}

.context-accordion[open] > summary > svg:last-child {
  transform: rotate(180deg);
}

.context-accordion-body {
  display: grid;
  gap: 8px;
  padding: 0 0 12px;
}

.context-grid.compact {
  gap: 5px;
  margin: 0;
}

.context-grid.compact span {
  grid-template-columns: minmax(90px, 0.8fr) minmax(0, 1.2fr);
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 0;
  border-radius: 5px;
  background: #f7f7f6;
}

.context-grid.compact strong {
  overflow-wrap: anywhere;
  font-size: 11px;
}

.context-grid.compact small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 9px;
}

.context-accordion-body p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.consent-badge[data-consent-tone="valid"] {
  color: #3d6748;
  border-color: #bed4c4;
  background: #edf7f0;
}

.consent-badge[data-consent-tone="pending"] {
  color: #895f16;
  border-color: #e1c996;
  background: #fff7e6;
}

.consent-badge[data-consent-tone="revoked"],
.consent-badge[data-consent-tone="blocked"] {
  color: #941d1d;
  border-color: #e2b5b5;
  background: #fff0f0;
}

.consent-badge[data-consent-tone="neutral"] {
  color: #5d6268;
  background: #f0f1f2;
}

.context-warning {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 8px;
  border: 1px solid #e7cfaa;
  border-radius: 6px;
  color: #76501b !important;
  background: #fff8e9;
}

.context-warning svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

.context-reopen-button,
.context-mobile-close {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 11px;
  font-weight: 800;
}

.context-reopen-button {
  position: absolute;
  z-index: 6;
  top: 10px;
  right: 10px;
  padding: 0 10px;
}

.context-reopen-button[hidden] {
  display: none !important;
}

.context-reopen-button svg,
.context-mobile-close svg {
  width: 15px;
  height: 15px;
}

.context-mobile-close {
  display: none;
}

#newConversationDialog .dialog-card {
  min-width: min(440px, calc(100vw - 52px));
}

@media (max-width: 1180px) {
  #conversations.view.active {
    height: auto;
    min-height: calc(100dvh - 36px);
    overflow: visible;
  }

  .conversation-layout,
  .conversation-layout.context-hidden {
    height: min(760px, calc(100dvh - 175px));
    min-height: 590px;
    grid-template-columns: minmax(300px, 36%) minmax(0, 1fr);
    overflow: hidden;
  }

  .conversation-context-panel {
    position: fixed;
    z-index: 40;
    top: 16px;
    right: 16px;
    bottom: 16px;
    display: none;
    width: min(360px, calc(100vw - 32px));
    height: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 20px 70px rgba(24, 28, 35, 0.25);
  }

  .conversation-layout.context-visible .conversation-context-panel {
    display: block;
  }

  .context-reopen-button,
  .context-reopen-button[hidden] {
    display: inline-flex !important;
  }

  .conversation-layout.context-visible .context-reopen-button {
    display: none !important;
  }

  .context-mobile-close {
    display: inline-flex;
    margin-bottom: 10px;
    padding: 0 10px;
    box-shadow: none;
  }

  .thread-action-button span,
  .thread-status-control > svg {
    display: none;
  }

  .thread-action-button {
    width: 32px;
    justify-content: center;
    padding: 0;
  }
}

@media (max-width: 760px) {
  .module-conversations .main {
    padding: 12px;
  }

  #conversations.view.active {
    min-height: calc(100dvh - 24px);
    grid-template-rows: auto auto auto minmax(0, 1fr);
  }

  .conversation-compact-header h2 {
    font-size: 21px;
  }

  .conversation-compact-header .primary-button {
    min-height: 36px;
    padding: 0 10px;
    font-size: 11px;
  }

  .conversation-area-tab {
    min-height: 38px;
  }

  .conversation-area-tab small {
    display: none;
  }

  .conversation-layout,
  .conversation-layout.context-hidden {
    display: block;
    height: calc(100dvh - 175px);
    min-height: 520px;
  }

  .conversation-sidebar {
    display: grid;
    height: 100%;
    border-right: 0;
  }

  .conversation-thread-panel,
  .conversation-context-panel {
    display: none;
  }

  .conversation-layout.mobile-thread-open .conversation-sidebar {
    display: none;
  }

  .conversation-layout.mobile-thread-open .conversation-thread-panel {
    display: grid;
    height: 100%;
  }

  .conversation-layout.context-visible .conversation-sidebar,
  .conversation-layout.context-visible .conversation-thread-panel {
    display: none;
  }

  .conversation-layout.context-visible .conversation-context-panel {
    position: static;
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .conversation-mobile-back {
    display: grid;
    flex: 0 0 auto;
  }

  .conversation-avatar.large {
    display: none !important;
  }

  .conversation-thread-head {
    grid-template-columns: minmax(0, 1fr);
  }

  .conversation-contact-heading {
    width: 100%;
  }

  .conversation-head-actions {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .thread-meta-strip {
    overflow-x: auto;
  }

  .message-list {
    padding: 14px 10px;
  }

  .message-bubble {
    max-width: 88%;
  }

  .composer-status-row {
    overflow-x: auto;
  }

  .composer-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .composer-actions {
    justify-content: flex-end;
  }

  .composer-tool span {
    display: none;
  }

  .composer-tool {
    width: 32px;
    min-width: 32px;
    justify-content: center;
    padding: 0;
  }

  .context-reopen-button,
  .context-reopen-button[hidden] {
    top: 8px;
    right: 8px;
  }
}
