/* Bandeja: árbol de filtros | lista | conversación (al estilo Chatwoot). Solo tokens de styles.css.
   Anchos: árbol 190-230 px, lista 280-360 px, conversación el resto; la vista ocupa la altura de la
   ventana y cada columna se desplaza por dentro, así el buscador y el compositor no se pierden de vista. */

.inbox { --inbox-h: calc(100dvh - 128px); height: max(var(--inbox-h), 460px); grid-template-columns: clamp(290px, 30%, 380px) minmax(0, 1fr); align-items: stretch; gap: 10px; }
.inbox.has-tree { grid-template-columns: clamp(210px, 17%, 240px) clamp(280px, 26%, 350px) minmax(0, 1fr); }
.inbox-list, .inbox-thread, .inbox-tree { min-height: 0; overflow: hidden; }

/* --- Árbol --- */
.inbox-tree { display: flex; flex-direction: column; gap: 2px; padding: 8px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); scrollbar-width: thin; }
.inbox-tree-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; }
.inbox-tree-head .icon-button { width: 30px; height: 30px; }
.tree-group { display: grid; gap: 1px; }
.tree-top { padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.tree-section { display: grid; gap: 2px; padding-top: 6px; }
.tree-section + .tree-section { margin-top: 2px; border-top: 1px solid var(--line); }
.tree-section-title { display: flex; align-items: center; gap: 4px; width: 100%; min-height: 26px; padding: 0 6px; border: 0; background: transparent; color: var(--subtle); font: inherit; font-size: .68rem; font-weight: 750; letter-spacing: .08em; text-align: left; text-transform: uppercase; cursor: pointer; }
.tree-section-title:hover { color: var(--ink); }
.tree-section-title .tree-item-chevron { margin: 0; }

.tree-item { --tone: var(--accent); --tone-soft: var(--accent-soft); display: flex; align-items: center; gap: 8px; width: 100%; min-width: 0; min-height: 31px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--ink); font: inherit; font-size: var(--text-sm); font-weight: 550; text-align: left; cursor: pointer; }
.tree-item:hover { background: var(--surface-2); }
.tree-item:focus-visible, .tree-section-title:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -2px; }
.tree-item.tone-danger { --tone: var(--danger); --tone-soft: var(--danger-soft); }
.tree-item.tone-warning { --tone: var(--warning); --tone-soft: var(--warning-soft); }
.tree-item.tone-info { --tone: var(--accent-strong); --tone-soft: var(--accent-soft); }
.tree-item.tone-neutral { --tone: var(--muted); --tone-soft: var(--surface-2); }
.tree-item.active { border-color: color-mix(in srgb, var(--tone) 32%, transparent); background: var(--tone-soft); color: var(--tone); font-weight: 700; }
.tree-item.tone-danger:not(.is-empty) { color: var(--danger); }
.tree-item.is-empty { color: var(--subtle); }
.tree-item.is-empty .tree-item-count { opacity: .6; }
.tree-item.nested { min-height: 28px; font-size: var(--text-xs); }
.tree-nested { display: grid; gap: 1px; margin: 0 0 4px 17px; padding-left: 8px; border-left: 1px solid var(--line); }
.tree-item-icon { display: grid; flex: 0 0 18px; width: 18px; height: 18px; place-items: center; }
.tree-item-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item-count { flex: 0 0 auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .68rem; font-variant-numeric: tabular-nums; font-weight: 700; line-height: 18px; text-align: center; }
.tree-item.active .tree-item-count { background: color-mix(in srgb, var(--tone) 18%, transparent); color: var(--tone); }
.tree-item.tone-danger:not(.is-empty) .tree-item-count { background: var(--danger); color: #fff; }
.tree-item-chevron { display: inline-grid; flex: 0 0 auto; place-items: center; color: var(--subtle); transition: transform var(--dur-1) var(--ease-out); }
.tree-item-chevron.open { transform: rotate(90deg); }
.tree-item .ch-badge { flex: 0 0 auto; }
.tree-dot { flex: 0 0 auto; width: 10px; height: 10px; margin: 0 4px; border-radius: 50%; background: var(--muted); }
.tree-dot.c-accent { background: var(--accent); }
.tree-dot.c-coral { background: var(--coral); }
.tree-dot.c-success { background: var(--success); }
.tree-dot.c-warning { background: var(--warning); }
.tree-dot.c-danger { background: var(--danger); }
.tree-hints { margin: auto 0 0; padding: 10px 6px 2px; color: var(--subtle); font-size: .68rem; line-height: 1.8; }
.tree-hints kbd { padding: 0 5px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface-2); color: var(--muted); font: inherit; font-weight: 700; }

/* --- Lista --- */
.inbox-list { display: flex; flex-direction: column; gap: 0; padding: 0; border-radius: var(--radius-md); box-shadow: none; }
.inbox-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 2px; }
.inbox-list-head > div { min-width: 0; }
.inbox-list-head small { display: block; overflow: hidden; color: var(--muted); font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.inbox-list-head h2 { margin: 0; overflow: hidden; font-family: var(--font); font-size: var(--text-md); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.inbox-list-head .button { flex: 0 0 auto; min-height: 28px; padding: 0 10px; font-size: var(--text-xs); }
.inbox-total { flex: 0 0 auto; padding: 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: var(--text-xs); font-weight: 700; line-height: 22px; }
.inbox-search { display: flex; align-items: center; gap: 6px; padding: 8px 12px; }
.inbox-search .tree-toggle { position: relative; margin: 0; flex: 0 0 auto; width: 34px; height: 34px; }
.inbox-search .tree-toggle.active { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); color: var(--accent-strong); }
.inbox-search .tree-toggle.has-active::after { position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--coral); content: ""; }
.inbox-search { margin: 0; }
.inbox-search-field { margin: 0; display: flex; flex: 1 1 auto; align-items: center; gap: 6px; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); }
.inbox-search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.inbox-search-field input { flex: 1 1 auto; font-weight: 500; min-width: 0; min-height: 0; padding: 0; border: 0; background: transparent; box-shadow: none; font-size: var(--text-sm); }
.inbox-search-field input:focus { outline: 0; box-shadow: none; }
.inbox-list > .alert, .inbox-list > .label-manager { margin: 0 12px 8px; }
.inbox-list > .skeleton-list { margin: 8px 12px; }
.inbox-list > .empty-state { margin: auto; padding: 16px; }
.inbox-list > .empty-state p { margin-bottom: 14px; }
.inbox-rows { flex: 1 1 auto; align-content: start; max-height: none; min-height: 0; padding: 0 6px 6px; gap: 1px; overflow-y: auto; scrollbar-width: thin; }
.inbox-list > .inbox-more { flex: 0 0 auto; width: auto; margin: 0 12px 10px; }

/* Filas densas: 3 líneas, avatar de 36 px, nombre y hora arriba, mensaje y marcas debajo. */
.inbox-row { gap: 9px; padding: 8px 8px 8px 10px; border-radius: var(--radius-sm); }
.inbox-row .patient-avatar { width: 36px; height: 36px; font-size: var(--text-sm); }
.inbox-row-top strong { font-size: var(--text-sm); font-weight: 650; }
.inbox-row.unread .inbox-row-top strong { font-weight: 800; }
.inbox-row.active { border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.inbox-row-meta { gap: 4px; }
.inbox-row-meta .status-pill { min-height: 18px; padding: 0 7px; font-size: .64rem; }
.inbox-row-meta .label-chip { padding: 0 7px; font-size: .64rem; }

/* --- Conversación: ocupa el alto; solo los mensajes se desplazan --- */
.inbox-thread { padding: 14px 16px; border-radius: var(--radius-md); box-shadow: none; }
.inbox-messages { flex: 1 1 auto; min-height: 0; max-height: none; padding-block: 12px 6px; overflow-y: auto; scrollbar-width: thin; }
.inbox-composer { flex: 0 0 auto; }
.inbox-placeholder { align-items: center; }
.inbox-thread-head h2 { font-size: var(--text-md); }

/* --- Pantallas medianas: sin el árbol se gana la conversación --- */
@media (max-width: 1100px) {
  .inbox.has-tree { grid-template-columns: 190px minmax(240px, 300px) minmax(0, 1fr); }
  .tree-hints { display: none; }
}

/* --- Celular: una sola columna. El árbol es un panel sobre la lista; al abrir un chat solo se ve el chat --- */
@media (max-width: 900px) {
  .inbox, .inbox.has-tree { --inbox-h: calc(100dvh - 190px); grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .inbox.has-tree { grid-template-rows: auto minmax(0, 1fr); }
  .inbox.has-tree .inbox-tree { max-height: 46dvh; }
  .inbox.has-open .inbox-tree { display: none; }
  .inbox-list-head { padding-top: 8px; }
  .tree-item { min-height: 40px; }
  .tree-item.nested { min-height: 36px; }
  .inbox-search .tree-toggle { width: 40px; height: 40px; }
  .inbox-search-field { height: 40px; }
  .inbox-row { padding-block: 10px; }
  .inbox-thread { padding: 12px; }
}

/* Bandeja pausada o archivada: se ve apagada y lo dice con palabra, no sólo con color. */
.tree-item.is-out .tree-item-label { color: var(--muted); }
.tree-item.is-out .ch-badge { opacity: .55; }
.tree-nested.is-out { opacity: .72; }
.tree-item.is-out { min-height: 40px; padding-block: 3px; }
.tree-item-body { display: flex; flex: 1 1 auto; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; }
.tree-item-body .tree-item-label { max-width: 100%; }
.tree-item-mark { padding: 0 6px; border-radius: 999px; background: var(--warning-soft); color: var(--warning); font-size: .64rem; font-style: normal; font-weight: 750; line-height: 15px; }
.tree-item-mark.mark-archived { background: var(--surface-2); color: var(--muted); }
.tree-archived-toggle { display: flex; align-items: center; gap: 6px; width: 100%; min-height: 28px; margin-top: 4px; padding: 0 8px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: transparent; color: var(--muted); font: inherit; font-size: var(--text-xs); font-weight: 600; text-align: left; cursor: pointer; }
.tree-archived-toggle:hover, .tree-archived-toggle.active { background: var(--surface-2); color: var(--ink); }
.tree-archived-toggle:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -2px; }
@media (max-width: 900px) { .tree-archived-toggle { min-height: 40px; } }
