/* MELQ WebUI Debug — styles */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d1117;
  --bg2:      #161b22;
  --bg3:      #21262d;
  --border:   #30363d;
  --text:     #c9d1d9;
  --text-dim: #8b949e;
  --text-muted: #6e7681;
  --accent:   #58a6ff;
  --green:    #56d364;
  --yellow:   #e3b341;
  --red:      #f85149;
  --purple:   #bc8cff;
  --font:     'Cascadia Code', 'Fira Code', Consolas, monospace;
  --font-ui:  system-ui, -apple-system, sans-serif;
  --radius:   4px;
  --pad:      16px;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 13px; line-height: 1.5; }

/* ── layout ── */
#root { display: flex; flex-direction: column; height: 100vh; }

/* ── splash ── */
.splash { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 16px; color: var(--text-dim); }
.splash-title { font-size: 20px; font-weight: bold; color: var(--accent); font-family: var(--font); }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── header ── */
.header { display: flex; align-items: center; gap: 12px; padding: 6px var(--pad); background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.header-brand { font-weight: bold; color: var(--accent); font-size: 13px; font-family: var(--font); }
.header-session { color: var(--text-muted); font-size: 11px; font-family: var(--font); }
.header-actions { margin-left: auto; display: flex; gap: 6px; }
.badge { padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: bold; background: var(--bg3); border: 1px solid var(--border); color: var(--text-dim); }
.badge.ready  { border-color: var(--green);  color: var(--green); }
.badge.busy   { border-color: var(--yellow); color: var(--yellow); }
.badge.error  { border-color: var(--red);    color: var(--red); }

/* ── buttons ── */
.btn { padding: 4px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-family: var(--font-ui); font-size: 12px; cursor: pointer; transition: border-color 0.15s; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: bold; }
.btn.primary:hover { background: #79c0ff; border-color: #79c0ff; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: rgba(248,81,73,0.12); }

/* ── scroll-to-bottom button ── */
.scroll-bottom-btn {
  position: absolute; bottom: 8px; right: 8px; z-index: 5;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 50%;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-dim); font-size: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  transition: border-color 0.15s, color 0.15s, opacity 0.2s;
  opacity: 0; pointer-events: none;
}
.scroll-bottom-btn.visible { opacity: 1; pointer-events: auto; }
.scroll-bottom-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── feed container — relative for scroll button positioning ── */
.feed { flex: 1; overflow-y: auto; padding: 8px 0; position: relative; }
.feed::-webkit-scrollbar { width: 5px; }
.feed::-webkit-scrollbar-track { background: var(--bg); }
.feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── turn separator — gradient, mais visível que border simples ── */
.turn-sep {
  border: none; margin: 12px var(--pad) 8px;
  height: 1px; background: linear-gradient(to right, transparent, var(--border), transparent);
}

/* ── user message ── */
.user-msg { padding: 2px var(--pad); display: flex; gap: 8px; align-items: baseline; }
.user-msg .prefix { color: var(--accent); font-weight: bold; flex-shrink: 0; font-family: var(--font); font-size: 12px; opacity: 0.8; }
.user-msg .text { color: var(--text); white-space: pre-wrap; }

/* ── system message ── */
.sys-msg { padding: 2px var(--pad); color: var(--text-muted); font-size: 11px; font-family: var(--font); font-style: italic; }
.sys-msg.error { color: var(--red); font-style: normal; }

/* ── turn card ────────────────────────────────────────────────────────────
   Cada turno (sequência de thinking/tool/resposta entre um user_msg e o
   turn_meta seguinte) vira um card — fundo levemente destacado sobre o `--bg`
   geral do feed, cantos arredondados, e o rodapé de métricas com borda
   superior. Agrupamento acontece na camada de render (`Feed`), não no reducer. */
.turn-card {
  margin: 8px var(--pad);
  padding: 6px 10px 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.turn-card-meta {
  display: flex; gap: 12px; margin-top: 4px; padding: 6px 2px 4px;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 11px; font-family: var(--font);
}

/* ── timeline row: gutter fixo com trilho em segmentos ───────────────────
   Substitui a antiga linha contínua por trás de cada nó: o gutter (~20px)
   desenha um segmento ACIMA do dot (se não é o primeiro nó do turno) e um
   ABAIXO (se não é o último) — o dot fica centralizado e "corta" a linha,
   em vez de ficar sobreposto a uma linha ininterrupta. */
.tl-row { display: flex; align-items: stretch; }
.tl-gutter { position: relative; width: 20px; flex-shrink: 0; }
.tl-line {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 1px; background: var(--border);
}
.tl-line--up   { top: 0; height: 10px; }
.tl-line--down { top: 10px; bottom: 0; }
.tl-dot-wrap {
  position: absolute; left: 50%; top: 10px; transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; background: var(--bg2); border-radius: 50%;
}
.tl-row-content { flex: 1; min-width: 0; padding: 1px 0 5px; }

/* wrapper de cada ícone Lucide (svg inline) — inline-flex evita gap de baseline */
.lc-icon { display: inline-flex; align-items: center; }

/* dot: reflete STATUS (tool) ou é neutro (thinking/resposta) */
.tl-dot--icon { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.tl-dot--icon.spin svg { animation: spin 1s linear infinite; }
.tl-dot--icon.done  { color: var(--green); }
.tl-dot--icon.error { color: var(--red); }
.tl-dot--plain { display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
.tl-dot--plain.pulse { background: var(--yellow); animation: thinking-pulse 1.2s ease-in-out infinite; }
@keyframes thinking-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ── subagent depth nesting ──
   Indenta só o CONTEÚDO da subtool, nunca a row inteira — assim o gutter
   (linha principal + dot) fica na mesma coluna pra todos os nós e a linha
   vertical do turno não "quebra" quando aparece uma tool de subagente. */
.tl-row[data-depth="2"] .tl-row-content { padding-left: 16px; }
.tl-row[data-depth="3"] .tl-row-content { padding-left: 32px; }

/* ── NodeHeader: chevron + ícone de tipo + rótulo + trailing ── */
.node-header {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 6px; border-radius: var(--radius);
  cursor: pointer; user-select: none;
  font-family: var(--font); font-size: 11px; color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.node-header:hover { background: rgba(255,255,255,0.05); }
.node-header--static { cursor: default; }
.node-chevron {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px; flex-shrink: 0;
  color: var(--text-muted); transition: transform 0.15s;
}
.node-chevron.open { transform: rotate(90deg); }
.node-chevron.invisible { visibility: hidden; }
.node-label { flex: 1; min-width: 0; }
.node-body { padding: 3px 4px 2px 20px; }

.thinking-text { color: var(--text-muted); font-size: 11px; font-family: var(--font); white-space: pre-wrap; line-height: 1.5; }

/* live thinking (streaming) */
.thinking-live-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--yellow); opacity: 0.7; animation: thinking-pulse 1.2s ease-in-out infinite; display: inline-block; flex-shrink: 0; }

/* ── tool blocks ── */
.tool-block { margin-bottom: 6px; }
.tool-block:last-child { margin-bottom: 0; }
.tool-block-label {
  font-size: 9px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--accent); font-weight: 700; margin-bottom: 5px;
  padding-bottom: 3px; border-bottom: 1px solid var(--border);
}
.tool-body { padding: 0; color: var(--text); font-size: 12px; font-family: var(--font-ui); word-break: break-word; max-height: 220px; overflow-y: auto; }
.tool-body .assistant-response { padding: 0; margin: 0; border-left: none; font-size: 12px; }
.tool-copy-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 11px; padding: 1px 4px; opacity: 0; transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}
.node-header:hover .tool-copy-btn { opacity: 1; }
.tool-copy-btn:hover { color: var(--accent); }

/* ── JSON key/value viewer (para leigo — sem chaves, sem colchetes) ──
   Hierarquia: a CHAVE é um rótulo discreto (coluna fixa, minúscula→caixa alta,
   `_`→espaço vindo do JS); o VALOR é o destaque, com cor por TIPO (texto neutro,
   número em azul, booleano em roxo) — pra parar de ser um blob monocromático. */
.json-view { font-size: 12px; font-family: var(--font-ui); color: var(--text); }
.jv-obj { display: flex; flex-direction: column; }
.jv-row { display: flex; gap: 10px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid rgba(48,54,61,0.45); }
.jv-row:last-child { border-bottom: none; }
.jv-key {
  flex-shrink: 0; min-width: 96px; word-break: break-word;
  color: var(--text-muted); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px; line-height: 1.7;
}
.jv-val { flex: 1; min-width: 0; line-height: 1.5; }
.jv-str  { color: var(--text); }
.jv-num  { color: var(--accent); font-weight: 600; }
.jv-bool { color: var(--purple); font-weight: 600; }
.jv-null, .jv-empty { color: var(--text-muted); font-style: italic; }
.jv-list { list-style: none; display: flex; flex-direction: column; gap: 3px; padding-left: 2px; }
.jv-list-item { position: relative; padding-left: 14px; }
.jv-list-item::before { content: "•"; position: absolute; left: 0; color: var(--accent); }
/* aninhamento: bloco recuado com filete à esquerda */
.jv-val > .jv-obj, .jv-val > .jv-list,
.jv-list-item > .jv-obj, .jv-list-item > .jv-list { margin-top: 3px; padding-left: 10px; border-left: 1px solid var(--border); }

/* ── assistant response — borda esquerda sutil para hierarquia ── */
.assistant-response {
  padding: 4px var(--pad) 6px calc(var(--pad) + 12px);
  border-left: 2px solid rgba(88, 166, 255, 0.2);
  margin-left: var(--pad);
  margin-right: var(--pad);
  line-height: 1.65;
}
.assistant-response p { margin-bottom: 8px; }
.assistant-response p:last-child { margin-bottom: 0; }
.assistant-response h1, .assistant-response h2, .assistant-response h3 { margin: 10px 0 5px; color: #e6edf3; }
.assistant-response ul, .assistant-response ol { margin: 5px 0 5px 18px; }
.assistant-response li { margin: 2px 0; }
.assistant-response code { background: var(--bg3); border-radius: 3px; padding: 1px 4px; font-family: var(--font); font-size: 12px; }
.assistant-response pre { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin: 6px 0; overflow-x: auto; }
.assistant-response pre code { background: none; padding: 0; }
.assistant-response table { border-collapse: collapse; margin: 6px 0; width: 100%; }
.assistant-response th, .assistant-response td { border: 1px solid var(--border); padding: 4px 8px; }
.assistant-response th { background: var(--bg3); }
.assistant-response strong { color: #e6edf3; }
.assistant-response a { color: var(--accent); }
.assistant-response blockquote { border-left: 3px solid var(--border); padding-left: 8px; color: var(--text-dim); margin: 4px 0; }

/* ── input area ── */
.input-area { flex-shrink: 0; padding: 8px var(--pad); background: var(--bg2); border-top: 1px solid var(--border); }
.input-wrapper { position: relative; }
.input-box {
  width: 100%; padding: 8px 40px 8px 40px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-family: var(--font-ui); font-size: 13px;
  resize: none; outline: none; line-height: 1.5; min-height: 38px; max-height: 160px; overflow-y: auto;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-box:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,0.12); }
.input-box:disabled { opacity: 0.5; cursor: not-allowed; }
.input-send-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--accent); cursor: pointer;
  padding: 4px; font-size: 16px; line-height: 1; transition: color 0.15s;
}
.input-send-btn:hover:not(:disabled) { color: var(--text); }
.input-send-btn:disabled { color: var(--text-muted); cursor: not-allowed; }
.cancel-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: 1px solid var(--red); color: var(--red);
  padding: 2px 8px; border-radius: var(--radius); cursor: pointer; font-size: 12px;
}
.cancel-btn:hover { background: rgba(248,81,73,0.1); }

/* ── modo voz (experimental) ── */
.voice-toggle-btn {
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 4px 6px; font-size: 15px; line-height: 1; border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}
.voice-toggle-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.voice-toggle-btn.active { color: var(--accent); }
@keyframes voice-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.voice-toggle-btn.active { animation: voice-pulse 1.6s ease-in-out infinite; }
.voice-status-pill {
  display: inline-block; margin: 0 0 6px; padding: 3px 10px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-muted); font-size: 11px; font-family: var(--font-ui);
}

/* ── anexos ── */
.attach-btn {
  position: absolute; left: 32px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 4px 6px; font-size: 15px; line-height: 1; border-radius: var(--radius);
  transition: color 0.15s, background 0.15s; z-index: 1;
}
.attach-btn:hover:not(:disabled) { color: var(--text); background: rgba(255,255,255,0.06); }
.attach-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* segundo botão à esquerda (voz + clipe) → mais espaço interno no textarea */
.input-box--attach { padding-left: 64px; }

.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 240px;
  padding: 3px 6px 3px 4px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 11px; color: var(--text-dim);
}
.attach-chip-thumb { width: 22px; height: 22px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
.attach-chip-icon { font-size: 14px; line-height: 1; flex-shrink: 0; }
.attach-chip-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip-size { color: var(--text-muted); flex-shrink: 0; }
.attach-chip-remove {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 0 2px; font-size: 12px; line-height: 1; flex-shrink: 0; transition: color 0.15s;
}
.attach-chip-remove:hover { color: var(--red); }

.input-area.drag-over { background: rgba(88,166,255,0.06); outline: 1px dashed var(--accent); outline-offset: -3px; }
.attach-drop-hint {
  margin-bottom: 8px; padding: 6px 10px; text-align: center;
  border: 1px dashed var(--accent); border-radius: var(--radius);
  color: var(--accent); font-size: 12px;
}

/* ── session picker sheet ── */
@keyframes sheet-up   { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheet-fade { from { opacity: 0; }               to { opacity: 1; } }
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 10; animation: sheet-fade 0.2s ease; }
.sheet {
  position: fixed; bottom: 0; left: 0; right: 0; max-height: 78vh;
  background: var(--bg2); border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0; z-index: 11; display: flex; flex-direction: column;
  animation: sheet-up 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -6px 24px rgba(0,0,0,0.5);
}
.sheet-handle-wrap { display: flex; justify-content: center; padding: 10px; cursor: grab; flex-shrink: 0; }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; transition: background 0.15s; }
.sheet-handle-wrap:hover .sheet-handle { background: var(--text-muted); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--pad) 10px; flex-shrink: 0; }
.sheet-title { font-weight: bold; color: var(--text); font-size: 14px; }
.sheet-count { color: var(--text-muted); font-size: 11px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 var(--pad); display: flex; flex-direction: column; gap: 8px; }
.sheet-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 10px var(--pad) 14px; border-top: 1px solid var(--border); flex-shrink: 0; }

/* session cards */
.picker-controls { display: flex; gap: 8px; flex-shrink: 0; }
.picker-search { flex: 1; padding: 7px 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-family: var(--font-ui); font-size: 13px; outline: none; transition: border-color 0.15s; }
.picker-search:focus { border-color: var(--accent); }
.session-cards { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; overflow-y: auto; }
.session-cards::-webkit-scrollbar { width: 5px; }
.session-cards::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.session-card { padding: 10px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.session-card:hover  { border-color: var(--accent); }
.session-card.selected { border-color: var(--accent); background: rgba(88,166,255,0.06); }
.card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.card-name { flex: 1; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font); font-size: 12px; }
.card-date { color: var(--text-muted); font-size: 11px; }
.card-turns { color: var(--text-muted); font-size: 11px; }
.card-preview { color: var(--text-muted); font-size: 11px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-delete-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; padding: 0 2px; flex-shrink: 0; opacity: 0; transition: opacity 0.15s, color 0.15s; }
.session-card:hover .card-delete-btn { opacity: 1; }
.card-delete-btn:hover { color: var(--red); }
.card-empty { color: var(--text-muted); font-size: 12px; padding: 24px 0; text-align: center; }
.card-name-edit {
  flex: 1; background: var(--bg); border: 1px solid var(--accent); border-radius: 3px;
  color: var(--text); font-family: var(--font); font-size: 12px; padding: 1px 4px;
  outline: none;
}

/* ── loading overlay for session load ── */
.session-loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 15;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: var(--text-dim); font-size: 13px;
}

/* delete confirm */
@keyframes dialog-pop { from { opacity: 0; transform: translate(-50%, -48%) scale(0.95); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.delete-confirm-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 20; }
.delete-confirm-dialog {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--bg2); border: 1px solid var(--red); border-radius: 8px;
  padding: 18px; width: min(280px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  animation: dialog-pop 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.delete-confirm-title { font-weight: bold; color: var(--red); font-size: 13px; }
.delete-confirm-name { color: var(--text-dim); font-size: 12px; font-family: var(--font); word-break: break-word; }
.delete-confirm-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 2px; }
