/* ==========================================================================
   Nexos — Captura rápida (.cap-*)  ·  js/features/captura.js
   Modal no desktop, "bottom sheet" no celular (o .modal do base.css já vira
   sheet). Aqui: campo de texto, ferramentas (voz, foto, link), prévia do que
   o Nexos entendeu (chips editáveis), lote de vários itens, exemplos, ajuda,
   aviso de "solte para guardar" e detalhes do toast.
   ========================================================================== */

/* ---------- Estrutura do modal ---------- */
.modal.cap-modal { overflow: hidden; }
.cap-modal .modal-body {
  padding: 0; display: flex; flex-direction: column;
  flex: 1 1 auto; min-height: 0; overflow: hidden;
}
.cap { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

/* ---------- Cabeçalho ---------- */
.cap-head { display: flex; align-items: center; gap: 10px; padding: 16px 14px 4px 20px; flex-shrink: 0; }
.cap-badge {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  height: 26px; padding: 0 11px 0 9px; border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 12.5px; font-weight: 680; letter-spacing: -.005em;
}
.cap-badge svg.lucide { width: 14px; height: 14px; color: var(--accent); }
.cap-head-hint { flex: 1; min-width: 0; font-size: 12.8px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cap-close { margin-left: auto; color: var(--text-3); }
.cap-close:hover { color: var(--text); }

/* ---------- Campo ---------- */
.cap-field {
  position: relative; flex-shrink: 0;
  margin: 10px 18px 0; padding: 12px 12px 8px 14px;
  border: 1.5px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface);
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
}
.cap-field:hover { border-color: var(--border-2); }
.cap-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.cap-field.cap-shake { animation: capShake .42s var(--ease); }

.cap-text {
  display: block; width: 100%; min-height: 54px; max-height: 240px;
  border: 0; outline: none; background: transparent; resize: none; padding: 0;
  font-size: 17px; line-height: 1.5; font-weight: 450; letter-spacing: -.005em; color: var(--text);
  overflow-y: auto;
}
.cap-text::placeholder { color: var(--text-3); transition: color .3s; }
.cap-text:focus-visible { outline: none; }

/* Foto anexada */
.cap-attach {
  display: flex; align-items: center; gap: 11px;
  margin: 10px 0 2px; padding: 8px 8px 8px 8px;
  border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--border);
  animation: pop .22s var(--spring);
}
.cap-attach[hidden] { display: none; }
.cap-attach-img {
  width: 52px; height: 52px; border-radius: var(--r-sm); flex-shrink: 0;
  display: grid; place-items: center; color: var(--text-3);
  background: var(--surface-3) center / cover no-repeat;
  box-shadow: inset 0 0 0 1px var(--border);
}
.cap-attach-name { font-size: 13.5px; font-weight: 620; color: var(--text); }
.cap-attach-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin-top: 2px; font-size: 12px; color: var(--text-3); }
.cap-attach-sub svg.lucide { width: 12px; height: 12px; color: var(--accent); }

/* Selo "simulado" (voz, foto) */
.cap-sim {
  display: inline-flex; align-items: center;
  font-size: 10.5px; font-weight: 650; letter-spacing: .02em; line-height: 1.6;
  color: var(--text-3); background: var(--surface-3); border-radius: var(--r-full); padding: 0 7px;
}

/* Ferramentas */
.cap-tools { display: flex; align-items: center; gap: 2px; margin-top: 8px; margin-left: -6px; min-height: 34px; }
.cap-tool {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: inline-grid; place-items: center; color: var(--text-3);
  transition: background var(--dur), color var(--dur), transform .08s;
}
.cap-tool:hover { background: var(--hover); color: var(--text); }
.cap-tool:active { transform: scale(.94); }
.cap-tool svg.lucide { width: 18px; height: 18px; }
.cap-tool.on {
  background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger);
  animation: capRing 1.6s ease-out infinite;
}
.cap-voice {
  display: inline-flex; align-items: center; gap: 7px; min-width: 0;
  margin-left: 6px; font-size: 12.8px; font-weight: 560; color: var(--text-2);
  animation: fade .2s ease;
}
.cap-voice[hidden] { display: none; }
.cap-voice-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--danger); animation: pulse 1s ease-in-out infinite; }
.cap-voice-text { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cap-help-btn {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  height: 30px; padding: 0 11px; border-radius: var(--r-full);
  font-size: 12.5px; font-weight: 560; color: var(--text-3);
  transition: background var(--dur), color var(--dur);
}
.cap-help-btn:hover { background: var(--hover); color: var(--text-2); }
.cap-help-btn svg.lucide { width: 14px; height: 14px; color: var(--c-yellow-s); }

/* ---------- Área viva (prévia / lote / exemplos) ---------- */
.cap-live { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 18px 18px; overscroll-behavior: contain; }
.cap-live:empty { padding: 0; }
.cap-label {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin: 0 2px 9px; font-size: 12px; font-weight: 680; letter-spacing: .01em; color: var(--text-3);
}
.cap-label svg.lucide { width: 13px; height: 13px; color: var(--accent); }
.cap-sum { font-weight: 500; color: var(--text-2); margin-left: 2px; }
.cap-sum b { font-weight: 680; color: var(--text); }

/* Prévia de um item — sem animação de entrada: a prévia é refeita a cada tecla */
.cap-preview {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 14px 13px; border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--c-bg) 72%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c-s) 24%, var(--border));
}
.cap-pv-icon {
  width: 36px; height: 36px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--surface); color: var(--c-ink);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px color-mix(in srgb, var(--c-s) 20%, transparent);
}
.cap-pv-icon svg.lucide { width: 18px; height: 18px; }
.cap-pv-title { font-size: 15.5px; font-weight: 650; line-height: 1.35; color: var(--text); word-break: break-word; padding-top: 6px; }
.cap-pv-empty { color: var(--text-3); font-weight: 500; font-style: italic; }
.cap-pv-list { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 7px; font-size: 13px; color: var(--text-2); }
.cap-pv-list > span { display: inline-flex; align-items: center; gap: 6px; }
.cap-mini-check { display: inline-block; width: 12px; height: 12px; border-radius: 4px; border: 1.5px solid currentColor; opacity: .6; flex-shrink: 0; }
.cap-pv-url {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  margin-top: 7px; padding: 4px 10px; border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  font-size: 12.5px; color: var(--text-2);
}
.cap-pv-url svg.lucide { width: 13px; height: 13px; color: var(--text-3); }

/* Compras como pílulas */
.cap-pills { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 3px; }
.cap-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 31px; padding: 0 12px 0 9px; border-radius: var(--r-full);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  font-size: 13.5px; font-weight: 580; color: var(--text);
}
.cap-pill small { font-size: 11.5px; font-weight: 600; color: var(--text-3); }
.cap-emoji { font-size: 14px; line-height: 1; }

/* Chips editáveis */
.cap-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 11px; }
.cap-chip {
  position: relative; gap: 6px; max-width: 100%;
  border: 1px solid transparent; font-weight: 580;
  transition: background var(--dur), border-color var(--dur), box-shadow var(--dur), transform .08s;
}
.cap-chip svg.lucide { width: 14px; height: 14px; }
.cap-preview .cap-chip:not(.tint):not(.chip-late):not(.chip-today) { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.cap-chip.tint { border-color: color-mix(in srgb, var(--c-s) 30%, transparent); }
button.cap-chip:hover, .cap-chip-x:hover { box-shadow: var(--shadow-sm); border-color: var(--border-2); }
button.cap-chip.tint:hover { border-color: var(--c-s); }
.cap-chip-type { color: var(--text); }
.cap-chip-inbox svg.lucide:first-child { color: var(--accent); }
.cap-caret { opacity: .5; margin-left: -1px; margin-right: -3px; }
svg.lucide.cap-caret { width: 13px; height: 13px; }
.cap-chip-add {
  background: transparent !important; color: var(--text-3) !important;
  border: 1.5px dashed var(--border-2) !important;
}
.cap-chip-add:hover { color: var(--accent-ink) !important; border-color: var(--accent) !important; background: var(--accent-soft) !important; }
.cap-chip-x { padding-right: 3px; }
.cap-chip-main {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  height: 100%; color: inherit; font: inherit; white-space: nowrap;
}
.cap-chip-main .avatar { --size: 18px; }

/* Botão "x" (chips, anexo, linhas do lote) */
.cap-x {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: inline-grid; place-items: center; color: inherit; opacity: .55;
  transition: background var(--dur), opacity var(--dur), transform .08s;
}
.cap-x:hover { opacity: 1; background: var(--active); }
.cap-x:active { transform: scale(.9); }
.cap-x svg.lucide { width: 12px; height: 12px; }
.cap-attach .cap-x { width: 32px; height: 32px; color: var(--text-2); }
.cap-attach .cap-x svg.lucide { width: 15px; height: 15px; }

/* Sugestão do Claude (cartão-fantasma) */
.cap-ghost {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 10px;
  padding: 9px 9px 9px 13px; border-radius: var(--r-lg); text-align: left;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
  font-size: 13.4px; color: var(--text-2);
  transition: border-color var(--dur), background var(--dur), transform .08s;
}
.cap-ghost:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.cap-ghost:active { transform: scale(.99); }
.cap-ghost > svg.lucide { width: 15px; height: 15px; color: var(--accent); }
.cap-ghost > span:nth-of-type(1) { flex: 1; min-width: 0; }
.cap-ghost b { color: var(--text); font-weight: 650; }
.cap-ghost-ok {
  display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0;
  height: 28px; padding: 0 11px 0 9px; border-radius: var(--r-full);
  background: var(--accent); color: var(--on-accent); font-size: 12.5px; font-weight: 680;
}
.cap-ghost-ok svg.lucide { width: 13px; height: 13px; stroke-width: 2.4; }
.cap-note { display: flex; align-items: center; gap: 7px; margin: 10px 2px 0; font-size: 12.5px; color: var(--text-3); }
.cap-note svg.lucide { width: 13px; height: 13px; color: var(--accent); flex-shrink: 0; }
.cap-note.cap-warn {
  padding: 8px 8px 8px 11px; border-radius: var(--r); line-height: 1.4;
  background: var(--c-peach); color: var(--c-peach-ink);
}
.cap-note.cap-warn svg.lucide { color: currentColor; }
.cap-note.cap-warn > span { flex: 1; min-width: 0; }
.cap-note-btn {
  flex-shrink: 0; height: 28px; padding: 0 11px; border-radius: var(--r-full);
  background: var(--surface); color: var(--text); font-size: 12.5px; font-weight: 650; box-shadow: var(--shadow-sm);
}
.cap-note-btn:hover { background: var(--surface-2); }

/* Lote: várias coisas de uma vez */
.cap-batch { display: flex; flex-direction: column; gap: 6px; }
.cap-row {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 8px 8px 8px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--border);
  transition: opacity var(--dur), background var(--dur), border-color var(--dur);
}
.cap-row:hover { border-color: var(--border-2); }
.cap-row.off { opacity: .5; background: transparent; border-style: dashed; }
.cap-row.off .cap-row-title { text-decoration: line-through; text-decoration-color: var(--text-3); }
.cap-row-type {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; background: var(--c-bg); color: var(--c-ink);
  transition: box-shadow var(--dur), transform .08s;
}
.cap-row-type:hover { box-shadow: inset 0 0 0 1.5px var(--c-s); }
.cap-row-type:active { transform: scale(.94); }
.cap-row-type svg.lucide { width: 16px; height: 16px; }
.cap-row-title { font-size: 14px; font-weight: 600; line-height: 1.3; color: var(--text); word-break: break-word; }
.cap-row-title small { font-size: 12px; font-weight: 550; color: var(--text-3); margin-left: 2px; }
.cap-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 6px; margin-top: 3px; font-size: 12px; color: var(--text-3); }
.cap-row-meta > span:not(.chip):not(.avatar) { display: inline-flex; align-items: center; gap: 4px; }
.cap-row-meta svg.lucide { width: 12px; height: 12px; }
.cap-row-meta .chip { height: 20px; padding: 0 7px; font-size: 11.2px; }
.cap-row-meta .chip svg.lucide { width: 11px; height: 11px; }
.cap-row-x { width: 30px; height: 30px; color: var(--text-2); }
.cap-row-x svg.lucide { width: 14px; height: 14px; }
.cap-row.off .cap-row-x { opacity: 1; color: var(--accent); }
.cap-batch-dest {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-top: 12px; padding: 0 2px; font-size: 13px; color: var(--text-2);
}
.cap-batch-dest .cap-chip:not(.tint) { background: var(--surface); border-color: var(--border); color: var(--text-2); }

/* Exemplos (campo vazio) */
.cap-examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cap-ex {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 10px 12px; border-radius: var(--r); text-align: left;
  border: 1px dashed var(--border-2); color: var(--text-2); font-size: 13px;
  transition: background var(--dur), border-color var(--dur), color var(--dur), transform .1s var(--ease);
  animation: capIn .25s var(--ease) both;
}
.cap-ex:nth-child(2) { animation-delay: .04s; }
.cap-ex:nth-child(3) { animation-delay: .08s; }
.cap-ex:nth-child(4) { animation-delay: .12s; }
.cap-ex:hover { background: var(--surface-2); border-color: var(--accent); border-style: solid; color: var(--text); transform: translateY(-1px); }
.cap-ex .cap-emoji { font-size: 16px; }

/* ---------- Rodapé ---------- */
.cap-foot {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  padding: 12px 16px 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.cap-keys { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.cap-saved {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.8px; font-weight: 650; color: var(--success);
}
.cap-saved[hidden] { display: none; }
.cap-saved svg.lucide { width: 14px; height: 14px; stroke-width: 2.4; }
.cap-saved.cap-pop { animation: capPop .45s var(--spring); }
.cap-save { min-width: 104px; }
.cap-save svg.lucide { stroke-width: 2.3; }

/* ---------- Ajuda ("Como escrever") ---------- */
.popover.cap-help-pop { width: min(360px, calc(100vw - 24px)); padding: 14px; z-index: calc(var(--z-modal) + 10); }
.cap-help { display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.cap-help-title { display: flex; align-items: center; gap: 7px; font-weight: 680; color: var(--text); margin-bottom: 3px; }
.cap-help-title svg.lucide { width: 15px; height: 15px; color: var(--c-yellow-s); }
.cap-help-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.cap-help-row code {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
  padding: 1px 7px; border-radius: var(--r-xs);
  background: var(--surface-3); color: var(--text); white-space: nowrap;
}
.cap-help-row span { font-size: 12.5px; color: var(--text-3); text-align: right; }
.cap-help-foot { margin-top: 5px; padding-top: 9px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }

/* ---------- Detalhes do toast de confirmação ---------- */
.cap-toast-open {
  margin-left: 8px; padding: 2px 9px; border-radius: 7px;
  font-weight: 650; font-size: 12.8px; color: inherit;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bg) 35%, transparent);
  transition: background var(--dur);
}
.cap-toast-open:hover { background: rgba(127, 127, 127, .2); }
.cap-toast-sub { opacity: .7; font-size: 12.5px; }

/* ---------- "Solte para guardar no Nexos" ---------- */
.cap-drop {
  position: fixed; inset: 0; z-index: var(--z-drag);
  display: grid; place-items: center; padding: 24px; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 9%, var(--overlay));
  backdrop-filter: blur(4px);
  animation: fade .16s ease;
}
.cap-drop::before {
  content: ""; position: absolute; inset: 14px; border-radius: var(--r-xl);
  border: 2.5px dashed color-mix(in srgb, var(--accent) 75%, transparent);
  animation: capDash 1.6s ease-in-out infinite;
}
.cap-drop.out { animation: capFadeOut .16s ease forwards; }
.cap-drop-card {
  position: relative; text-align: center;
  padding: 28px 34px 26px; max-width: 400px;
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  animation: pop .25s var(--spring);
}
.cap-drop-icon {
  width: 66px; height: 66px; margin: 0 auto 14px; border-radius: 22px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
  animation: capBob 1.2s ease-in-out infinite;
}
.cap-drop-icon svg.lucide { width: 30px; height: 30px; }
.cap-drop-title { font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: -.015em; line-height: 1.2; color: var(--text); }
.cap-drop-sub { margin-top: 6px; font-size: 13.5px; color: var(--text-2); }
.cap-drop-sub b { color: var(--text); font-weight: 650; }

/* ---------- Animações ---------- */
@keyframes capIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes capShake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes capPop { 0% { transform: scale(.7); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes capRing { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 35%, transparent); } 100% { box-shadow: 0 0 0 9px transparent; } }
@keyframes capBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes capDash { 0%, 100% { opacity: .75; } 50% { opacity: 1; } }
@keyframes capFadeOut { to { opacity: 0; } }

/* ---------- Celular: bottom sheet ---------- */
@media (max-width: 760px) {
  .modal.cap-modal { max-height: 94vh; max-height: 94dvh; }
  .cap-head { padding: 8px 10px 2px 16px; }
  .cap-head-hint { display: none; }
  .cap-close { width: 40px; height: 40px; }
  .cap-field { margin: 8px 14px 0; padding: 10px 10px 6px 12px; }
  .cap-text { font-size: 16px; min-height: 48px; } /* 16px evita o zoom automático do iOS */
  .cap-tools { gap: 4px; }
  .cap-tool { width: 40px; height: 40px; border-radius: 12px; }
  .cap-help-btn { height: 36px; }
  .cap-help-btn span { display: none; }
  .cap-live { padding: 12px 14px 14px; }
  .cap-preview { padding: 12px; gap: 10px; }
  .cap-chip { height: 34px; }
  button.cap-chip::after { content: ""; position: absolute; inset: -3px -1px; }
  .cap-x { width: 26px; height: 26px; }
  .cap-row-x, .cap-attach .cap-x { width: 40px; height: 40px; }
  .cap-row-type { width: 40px; height: 40px; }
  .cap-ghost { padding: 8px 8px 8px 12px; }
  .cap-ghost-ok { height: 34px; padding: 0 12px 0 10px; }
  .cap-examples { grid-template-columns: minmax(0, 1fr); }
  .cap-ex { min-height: 44px; }
  .cap-foot { flex-wrap: wrap; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .cap-foot > .grow, .cap-keys { display: none; }
  .cap-saved { flex-basis: 100%; justify-content: center; }
  .cap-more, .cap-save { height: 46px; border-radius: 13px; font-size: 14.5px; }
  .cap-more { flex: 1 1 0; }
  .cap-save { flex: 1.3 1 0; }
  .modal.cap-modal { padding-bottom: 0; }
}
