/* ============================================================================
   NextLayer — Chat (M1 + M2 + M5)
   ========================================================================== */

/* ---- Painel de busca de conversas (switcher) --------------------------- */
.conv-switcher {
  position: fixed; z-index: 60; width: 384px; max-width: calc(100vw - 24px);
  max-height: min(72vh, 560px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
  overflow: hidden; animation: modal-in var(--dur-fast) var(--ease);
}
.switcher-search { padding: var(--space-3); border-bottom: 1px solid var(--border); }
.switcher-folders { display: flex; flex-direction: column; gap: 6px; padding: var(--space-3) var(--space-3) 0; }
.switcher-list { flex: 1; overflow-y: auto; padding: var(--space-2); }

/* Pastas (chips) */
.fold-chip {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 9px;
  font-size: var(--text-xs); font-weight: var(--fw-medium); border-radius: var(--radius-full);
  background: var(--surface-2); color: var(--text-muted); border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.fold-chip:hover { background: var(--surface-3); color: var(--text); }
.fold-chip.active { background: var(--brand-soft); color: var(--brand); }
.fold-chip .caret { opacity: 0.8; }
.fc-count { font-variant-numeric: tabular-nums; opacity: 0.6; margin-left: 2px; }
.conv-folder { display: inline-flex; align-items: center; gap: 3px; }
.conv-folder .caret { width: 11px; height: 11px; opacity: 0.7; }
/* Cabeçalho "Pastas" no painel de busca */
.sf-header { display: flex; align-items: center; justify-content: space-between; }
.sf-title { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; font-weight: var(--fw-medium); color: var(--text-faint); }
.sf-manage { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: var(--radius-md); color: var(--text-muted); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.sf-manage:hover { background: var(--surface-3); color: var(--text); }
.sf-manage .icon { width: 15px; height: 15px; }
.sf-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sf-empty { font-size: var(--text-xs); padding: 1px 0 3px; }

/* Gerenciar pastas (modal CRUD) */
.fold-list { display: flex; flex-direction: column; margin-top: var(--space-3); border-top: 1px solid var(--border); }
.fold-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.fold-row-name { display: inline-flex; align-items: center; gap: 6px; flex: 1; font-size: var(--text-sm); font-weight: var(--fw-medium); min-width: 0; }
.fold-row-name span[data-name] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold-row-name .caret { width: 13px; height: 13px; opacity: 0.7; flex-shrink: 0; }
.fold-row-count { font-size: var(--text-xs); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fold-row-actions { display: inline-flex; gap: 2px; }
.conv-group-label { padding: var(--space-3) var(--space-2) var(--space-1); font-size: var(--text-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; font-weight: var(--fw-medium); }

.conv-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  padding: var(--space-3); border-radius: var(--radius-md); text-align: left;
  transition: background var(--dur-fast) var(--ease);
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--brand-soft); }
.conv-item .col { min-width: 0; flex: 1; }
.conv-item .ctitle { font-size: var(--text-sm); font-weight: var(--fw-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item.active .ctitle { color: var(--brand); }
.conv-item .cmeta { font-size: var(--text-xs); color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.conv-item .cmenu { opacity: 0; flex: none; }
.conv-item:hover .cmenu { opacity: 1; }

/* ---- Thread (coluna única) --------------------------------------------- */
.thread { display: flex; flex-direction: column; height: 100%; overflow: hidden; min-width: 0; background: var(--bg); }
.thread-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border);
  background: var(--surface); flex: none;
}
.th-left  { flex: 1; min-width: 0; display: flex; justify-content: flex-start; }
.th-right { flex: 1; min-width: 0; display: flex; justify-content: flex-end; }
.th-center { flex: 0 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; gap: var(--space-2); }
.thread-title { min-width: 0; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-rename { color: var(--text-faint); flex-shrink: 0; }
.thread-rename:hover { color: var(--brand); }
.thread-rename .icon { width: 15px; height: 15px; }
.hide-sm { display: inline; }
/* a pílula de pasta é badge (inline-flex); hide-sm não pode rebaixá-la para inline */
.folder-pill.hide-sm { display: inline-flex; flex: none; white-space: nowrap; }
@media (max-width: 560px) { .hide-sm { display: none; } .folder-pill.hide-sm { display: none; } .thread-head { padding: var(--space-3) var(--space-4); gap: var(--space-2); } }

.messages { flex: 1; overflow-y: auto; }
.messages-inner { max-width: 760px; margin: 0 auto; padding: var(--space-6) var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-6); }

.msg { display: flex; gap: var(--space-3); animation: msg-in 0.3s var(--ease); }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg .who { flex: none; }
.msg-body { min-width: 0; flex: 1; }
.msg .name { font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-muted); margin-bottom: var(--space-1); display: flex; align-items: center; flex-wrap: wrap; gap: 4px var(--space-2); }
.msg .model-tag { font-weight: var(--fw-regular); color: var(--text-faint); font-family: var(--font-mono); font-size: 11px; }
.msg .msg-meta { font-weight: var(--fw-regular); color: var(--text-faint); font-size: var(--text-xs); }

.ai-avatar { background: var(--brand); color: var(--brand-contrast); }

/* Destaque dos avatares no chat (box-shadow como anel não altera o tamanho do círculo) */
.msg .avatar:not(.ai-avatar) { background: var(--surface-2); color: var(--text); box-shadow: 0 0 0 2px var(--brand), var(--shadow-2); }
.msg .ai-avatar { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand), var(--shadow-2); }

/* Markdown render */
.md { font-size: var(--text-base); line-height: var(--leading-normal); color: var(--text); }
.md > * + * { margin-top: var(--space-3); }
.md h1, .md h2, .md h3 { margin-top: var(--space-4); }
.md ul, .md ol { padding-left: 1.3em; display: flex; flex-direction: column; gap: 4px; }
.md code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 0.85em; border: 1px solid var(--border); }
.md pre { background: var(--surface-3); padding: var(--space-4); border-radius: var(--radius-md); overflow-x: auto; border: 1px solid var(--border); }
.md pre code { background: none; border: none; padding: 0; font-size: var(--text-sm); }
.md table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.md th, .md td { padding: var(--space-2) var(--space-3); border: 1px solid var(--border); text-align: left; }
.md th { background: var(--surface-2); font-weight: var(--fw-semibold); }
.md strong { font-weight: var(--fw-semibold); }
.md a { color: var(--info); text-decoration: underline; text-underline-offset: 2px; }
.md blockquote { border-left: 3px solid var(--border-strong); padding: 2px 0 2px var(--space-4); color: var(--text-muted); }

/* Cursor de streaming */
.stream-cursor { display: inline-block; width: 7px; height: 1.1em; vertical-align: text-bottom; background: var(--brand); border-radius: 1px; animation: blink 1s steps(2) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

.msg-actions { display: flex; gap: var(--space-1); margin-top: var(--space-2); opacity: 0; transition: opacity var(--dur-fast); }
.msg:hover .msg-actions, .msg-actions.has-fb { opacity: 1; }
.msg-action { width: 28px; height: 28px; display: grid; place-items: center; border-radius: var(--radius-sm); color: var(--text-faint); }
.msg-action:hover { background: var(--surface-2); color: var(--text); }
.msg-action.on { color: var(--brand); }

/* ---- Composer ----------------------------------------------------------- */
.composer-wrap { flex: none; padding: var(--space-3) var(--space-5) var(--space-5); background: var(--bg); }
.composer {
  max-width: 760px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft), var(--shadow-2); }
.composer textarea {
  width: 100%; border: none; background: none; resize: none; outline: none;
  padding: var(--space-4) var(--space-4) var(--space-2); font-size: var(--text-base);
  line-height: 1.5; max-height: 200px; color: var(--text);
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer-bar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3) var(--space-3); }
.composer-bar .spacer { flex: 1; }
.composer .send {
  width: 34px; height: 34px; border-radius: var(--radius-md);
  background: var(--brand); color: var(--brand-contrast);
  display: grid; place-items: center; transition: background var(--dur-fast), opacity var(--dur-fast);
}
.composer .send:disabled { opacity: 0.4; }
.composer .send:not(:disabled):hover { background: var(--brand-hover); }
.composer-hint { max-width: 760px; margin: var(--space-2) auto 0; font-size: var(--text-xs); color: var(--text-faint); text-align: center; }

/* Pílula de skill ativa / seletor de modelo na barra */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px;
  border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--fw-medium);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-muted);
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.pill:hover { background: var(--surface-2); color: var(--text); }
.pill .icon { width: 14px; height: 14px; }
.pill .caret { width: 12px; height: 12px; opacity: 0.6; }
.pill .pill-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: var(--radius-full);
  background: var(--brand); color: var(--brand-contrast);
  font-size: 10px; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; line-height: 1;
}

/* Popover "Configurar conversa" */
.cfg-pop {
  position: absolute; z-index: 60; width: 300px; max-width: calc(100vw - 24px);
  display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-3);
  padding: var(--space-4); animation: modal-in var(--dur-fast) var(--ease);
}
.cfg-pop .field { gap: var(--space-1); }
.cfg-head { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); font-weight: var(--fw-medium); }
.cfg-sep { height: 1px; background: var(--border); margin: 0 calc(-1 * var(--space-4)); }
.cfg-ctx-list { display: flex; flex-direction: column; gap: 2px; max-height: 132px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-1); }
.cfg-check { display: flex; align-items: center; gap: var(--space-2); padding: 5px var(--space-2); border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; }
.cfg-check:hover { background: var(--surface-2); }
.cfg-check input { width: 15px; height: 15px; flex: none; accent-color: var(--brand); cursor: pointer; }
.cfg-check span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cfg-none { font-size: var(--text-xs); color: var(--text-faint); padding: 5px var(--space-2); }

/* ---- Welcome / empty thread -------------------------------------------- */
.chat-welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-5); padding: var(--space-6); text-align: center; }
.welcome-orb { width: 64px; height: 64px; border-radius: 18px; background: var(--brand); color: var(--brand-contrast); display: grid; place-items: center; box-shadow: var(--shadow-2); }
.welcome-orb .icon { width: 30px; height: 30px; }
.suggestion-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 240px)); gap: var(--space-3); }
.suggestion {
  text-align: left; padding: var(--space-4); border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface); transition: border-color var(--dur-fast), transform var(--dur-fast);
}
.suggestion:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow-1); }
.suggestion .stitle { font-size: var(--text-sm); font-weight: var(--fw-medium); }
.suggestion .sdesc { font-size: var(--text-xs); color: var(--text-faint); margin-top: 2px; }

@media (max-width: 560px) {
  .suggestion-grid { grid-template-columns: 1fr; }
}
