/* =================================================================
   Life Base Tasks Mobile — folha de estilo consolidada
   Um único layout: 2x2 no desktop, panes + bottom nav no mobile.
   Sem dependência de fontes externas (system font stack + SVG inline).
   ================================================================= */

:root {
  color-scheme: dark;
  --bg: #0b0d18;
  --bg-2: #0f1020;
  --surface: rgba(20, 22, 36, 0.86);
  --surface-2: rgba(255, 255, 255, 0.05);
  --surface-3: rgba(255, 255, 255, 0.08);
  --text: #f5f7fb;
  --text-strong: #ffffff;
  --muted: #aab3c6;
  --muted-strong: #cdd5e3;
  --accent: #b9a5ff;
  --accent-strong: #7f5af0;
  --accent-soft: rgba(127, 90, 240, 0.18);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(198, 209, 255, 0.20);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.14);
  --success: #34d399;
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --shadow: 0 20px 60px rgba(4, 6, 16, 0.42);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; background: var(--bg-2); }

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 14% 12%, rgba(127, 90, 240, 0.16), transparent 24%),
    radial-gradient(circle at 88% 8%, rgba(56, 189, 248, 0.08), transparent 22%),
    linear-gradient(180deg, #070915 0%, var(--bg) 46%, #080b16 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open { overflow: hidden; }

h1, h2, h3, p { margin-top: 0; }
h2 { font-size: clamp(1.25rem, 2.2vw, 1.7rem); letter-spacing: -0.02em; line-height: 1.1; margin-bottom: 0; }
h3 { font-size: 1.05rem; letter-spacing: -0.01em; margin-bottom: 0; }
p { line-height: 1.6; }
a { color: var(--accent); }

button,
input:not([type='checkbox']):not([type='radio']),
select,
textarea { font: inherit; }

button {
  border: 1px solid transparent;
  background: var(--accent-strong);
  color: #fff;
  font-weight: 650;
  cursor: pointer;
  border-radius: 999px;
  padding: 12px 18px;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0) scale(0.98); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid rgba(160, 145, 255, 0.9);
  outline-offset: 2px;
}

.ghost-button {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.ghost-button:hover { background: var(--surface-3); border-color: var(--border-strong); }

.hidden { display: none !important; }

/* ---------- Shell ---------- */
.app-shell {
  position: relative;
  z-index: 1;
  width: min(1600px, calc(100vw - 20px));
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 24px max(10px, env(safe-area-inset-left));
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* ---------- Topbar ---------- */
.app-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 16px;
  border-radius: 22px;
  background: rgba(16, 18, 30, 0.72);
  border: 1px solid var(--border);
  box-shadow: 0 16px 44px rgba(3, 5, 14, 0.3);
  backdrop-filter: blur(20px) saturate(160%);
}
.app-topbar-brand { display: grid; gap: 2px; min-width: 0; }
.app-topbar-title { margin: 0; font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em; }
.app-topbar-subtitle { margin: 0; font-size: 0.7rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.app-topbar-actions { display: flex; gap: 10px; margin-left: auto; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover { background: var(--surface-3); border-color: var(--border-strong); }

/* ---------- PWA hint ---------- */
.pwa-hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  border-color: rgba(155, 134, 255, 0.24);
  background: linear-gradient(180deg, rgba(127, 90, 240, 0.14), var(--surface));
}
.pwa-hint p { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.pwa-hint-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.pwa-hint-close { width: 38px; height: 38px; color: var(--muted); }
.pwa-hint-close svg { width: 16px; height: 16px; }
.pwa-hint-close:hover { color: var(--text); }

/* ---------- Login ---------- */
.login-card { max-width: 520px; margin: 8vh auto 16px; }
.login-card form { display: grid; gap: 14px; margin-top: 12px; }
.login-card p { color: var(--muted); }

label { display: grid; gap: 7px; font-size: 0.9rem; color: var(--muted-strong); }

input:not([type='checkbox']):not([type='radio']),
select,
textarea {
  width: 100%;
  background: rgba(8, 12, 20, 0.7);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  border-color: rgba(160, 145, 255, 0.6);
  box-shadow: 0 0 0 4px var(--accent-soft);
  background: rgba(8, 12, 20, 0.9);
}
input::placeholder, textarea::placeholder { color: rgba(170, 179, 198, 0.7); }

.password-field { position: relative; }
.password-field input { padding-right: 3.2rem; }
.password-toggle {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.password-toggle:hover, .password-toggle[aria-pressed='true'] {
  background: var(--accent-soft);
  color: var(--text);
  transform: translateY(-50%);
}
.password-toggle svg { width: 1.1rem; height: 1.1rem; }

.error-message { color: var(--danger); margin: 8px 0 0; word-break: break-word; min-height: 1.2em; }

/* ---------- Common bits ---------- */
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted-strong);
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
}
.badge-soft { background: var(--accent-soft); border-color: rgba(155, 134, 255, 0.22); color: #ded6ff; }

.empty-state { text-align: center; padding: 24px 16px; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 8px; font-size: 1.02rem; }
.empty-state p { margin: 0; }

/* ---------- Workspace (base = mobile: painéis empilhados, um por vez) ---------- */
.workspace-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}
/* minmax(0,1fr) impede que a track implícita cresça pelo max-content do
   conteúdo (palavra/linha longa) e estoure a largura da tela no mobile. */
.workspace-pane { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0; align-content: start; }
.app-panel { overflow: clip; max-width: 100%; }
/* No mobile o wrapper de arquivos é transparente ao layout (os painéis viram
   filhos diretos do shell e a bottom nav controla qual aparece). */
.files-workspace { display: contents; }

/* Alternador de área (desktop) — escondido por padrão/mobile */
.desktop-view-switch {
  display: none;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.desktop-view-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted-strong);
  border: 1px solid transparent;
  font-weight: 600;
}
.desktop-view-button svg { width: 18px; height: 18px; }
.desktop-view-button:hover { color: var(--text); }
.desktop-view-button.active {
  background: var(--accent-soft);
  color: #fff;
  border-color: rgba(155, 134, 255, 0.28);
}

/* Botões de colapso do explorer — só fazem sentido no desktop */
.sidebar-toggle, .sidebar-expand { display: none; }
.explorer-header-titles { min-width: 0; }
.explorer-header-actions { display: flex; align-items: center; gap: 8px; }
.chat-header-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Toolbar / tabs ---------- */
.filter-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.toolbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tab-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  scrollbar-width: thin;
}
.tab-button {
  flex: 0 0 auto;
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 16px;
  background: transparent;
  color: var(--muted-strong);
  border: 1px solid transparent;
  font-weight: 600;
  white-space: nowrap;
}
.tab-button:hover { background: var(--surface-2); color: var(--text); }
.tab-button.active {
  background: var(--accent-soft);
  color: #fff;
  border-color: rgba(155, 134, 255, 0.28);
}

.toolbar-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(200px, 0.9fr);
  gap: 12px;
  align-items: end;
}
.search-box input { min-height: 50px; }

/* ---------- Filtro de pasta (popover com árvore) ---------- */
.folder-filter { position: relative; display: grid; gap: 7px; min-width: 0; }
.folder-filter-label { font-size: 0.82rem; color: var(--muted-strong); font-weight: 600; }
.folder-filter-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 10px 12px;
  background: rgba(8, 12, 20, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-weight: 500;
  text-align: left;
}
.folder-filter-button:hover { border-color: var(--border-strong); transform: none; }
.folder-filter-button.has-filter { border-color: rgba(155, 134, 255, 0.45); }
.folder-filter-icon { width: 18px; height: 18px; color: var(--accent); flex: 0 0 auto; }
.folder-filter-current { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-filter-caret { width: 18px; height: 18px; color: var(--muted); flex: 0 0 auto; }

.folder-filter-panel {
  /* position/top/left/width definidos via JS (fixed) para não ser cortado
     pelo overflow:clip do card de filtros. */
  position: fixed;
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(160%);
}
.folder-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 10px 6px 8px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.88rem;
}
.folder-row:hover { background: var(--surface-2); }
.folder-row.selected { background: var(--accent-soft); color: #fff; }
.folder-row-all { border-bottom: 1px solid var(--border); border-radius: 10px 10px 0 0; margin-bottom: 4px; }
.folder-twisty {
  width: 20px; height: 20px; padding: 0; flex: 0 0 auto;
  background: transparent; border: 0; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.folder-twisty svg { width: 16px; height: 16px; transition: transform 120ms ease; }
.folder-twisty.open svg { transform: rotate(90deg); }
.folder-twisty:hover { color: var(--text); background: var(--surface-3); border-radius: 6px; transform: none; }
.folder-twisty-spacer { width: 20px; flex: 0 0 auto; }
.folder-row-icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--accent); }
.folder-row-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-row-count { flex: 0 0 auto; font-size: 0.76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.folder-empty { margin: 8px; color: var(--muted); font-size: 0.85rem; }

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.status-bar strong { font-size: 1rem; color: var(--text); }

.undo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(155, 134, 255, 0.24);
  background: var(--accent-soft);
}
.undo-banner span { min-width: 0; color: var(--text); font-size: 0.9rem; }
.undo-banner button { flex: 0 0 auto; }

/* ---------- Task list ---------- */
.tasks-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.task-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  transition: background-color 160ms ease, border-color 160ms ease, opacity 220ms ease, transform 220ms ease;
}
.task-card:hover { background: var(--surface-3); }
.task-card[data-urgency='overdue'] { border-left-color: var(--danger); }
.task-card[data-urgency='today']   { border-left-color: var(--warning); }
.task-card[data-urgency='upcoming']{ border-left-color: var(--accent); }

.task-card-leaving { opacity: 0; transform: translateX(10px) scale(0.98); }

.task-toggle { display: flex; gap: 12px; align-items: flex-start; }

/* Área de toque >= 44px em volta do checkbox */
.task-checkbox-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -11px 0 -11px -11px;
  flex: 0 0 auto;
  cursor: pointer;
}
.task-checkbox { width: 24px; height: 24px; accent-color: var(--accent-strong); cursor: pointer; }

.task-title-button {
  appearance: none;
  width: 100%;
  padding: 4px 0 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 650;
  font-size: 1rem;
  line-height: 1.4;
  cursor: pointer;
}
.task-title-button:hover { color: var(--accent); transform: none; }

.task-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.badge.due-date[data-urgency='overdue'] { color: #fecdd3; background: var(--danger-soft); border-color: rgba(251, 113, 133, 0.3); }
.badge.due-date[data-urgency='today']   { color: #fde68a; background: var(--warning-soft); border-color: rgba(251, 191, 36, 0.3); }
.badge.priority[data-priority='high']   { color: #fda4af; }
.badge.priority[data-priority='medium'] { color: #fcd34d; }
.badge.priority[data-priority='low'],
.badge.priority[data-priority='lowest'] { color: #86efac; }

.task-path { margin: 0; color: var(--muted); font-size: 0.82rem; word-break: break-word; }

/* ---------- Explorer (árvore compacta estilo VS Code) ---------- */
.explorer-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.explorer-header .eyebrow { margin-bottom: 0; }
.explorer-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.explorer-search-box input { min-height: 42px; }
.explorer-tree { display: block; min-height: 160px; max-height: 60vh; overflow: auto; padding-right: 2px; }

.tree-folder { display: block; }
.tree-children { display: block; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 30px;
  padding: 5px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.3;
  cursor: pointer;
  list-style: none;
}
.tree-row::-webkit-details-marker { display: none; }
.tree-row:hover { background: var(--surface-2); transform: none; }
.tree-twisty {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: var(--muted);
  transition: transform 120ms ease;
}
.tree-folder[open] > .tree-row .tree-twisty { transform: rotate(90deg); }
.tree-spacer { width: 16px; flex: 0 0 16px; }
.tree-icon { width: 16px; height: 16px; flex: 0 0 16px; }
.tree-icon.folder-icon { color: var(--accent); }
.tree-icon.file-icon { color: var(--muted-strong); }
.tree-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tree-file.active { background: var(--accent-soft); color: #fff; }
.tree-file.active .tree-icon { color: var(--accent); }
/* Guia de indentação sutil */
.tree-children { border-left: 1px solid var(--border); margin-left: 15px; }

/* ---------- File viewer ---------- */
.file-viewer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  min-width: 0;
}
.file-viewer-title { flex: 1 1 auto; min-width: 0; word-break: break-word; font-size: 1.02rem; }
.file-viewer-title.hidden { display: none; }
.file-viewer-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.markdown-viewer {
  line-height: 1.66;
  overflow-wrap: anywhere;
  overflow: auto;
  max-height: 62vh;
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(9, 12, 22, 0.7);
  border: 1px solid var(--border);
  color: var(--muted-strong);
}
.markdown-viewer.empty-viewer { display: grid; align-items: center; }
.markdown-viewer h1, .markdown-viewer h2, .markdown-viewer h3,
.markdown-viewer h4, .markdown-viewer h5, .markdown-viewer h6 {
  margin: 1.2em 0 0.5em;
  color: var(--text);
  letter-spacing: -0.01em;
}
.markdown-viewer h1 { font-size: 1.5rem; }
.markdown-viewer h2 { font-size: 1.3rem; }
.markdown-viewer h3 { font-size: 1.12rem; }
.markdown-viewer p { color: var(--muted-strong); }
.markdown-viewer strong { color: var(--text); }
.markdown-viewer code, .markdown-viewer pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown-viewer code {
  background: rgba(255, 255, 255, 0.07);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.9em;
}
.markdown-viewer pre {
  background: rgba(3, 8, 16, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
}
.markdown-viewer pre code { background: none; padding: 0; }
.markdown-viewer blockquote { margin: 0.6em 0; padding-left: 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.markdown-viewer img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.markdown-viewer ul, .markdown-viewer ol { margin: 0.4em 0; padding-left: 1.3rem; }
.markdown-viewer li + li { margin-top: 0.4rem; }
.markdown-viewer hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }
.markdown-viewer .markdown-task { list-style: none; margin-left: -1.3rem; display: flex; align-items: flex-start; gap: 10px; }
.markdown-viewer .markdown-task-label { display: inline-flex; cursor: pointer; flex: 0 0 auto; }
.markdown-viewer input[type='checkbox'] { width: 20px; height: 20px; margin: 3px 0 0; flex: 0 0 20px; accent-color: var(--accent-strong); cursor: pointer; }
.viewer-task-checkbox:disabled { cursor: progress; }
.markdown-viewer .markdown-task-text { min-width: 0; }

.wikilink {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed rgba(185, 165, 255, 0.5);
  cursor: pointer;
}
.wikilink:hover { border-bottom-style: solid; }

.viewer-line-highlight {
  background: rgba(127, 90, 240, 0.18);
  border-radius: 8px;
  box-shadow: 0 0 0 6px rgba(127, 90, 240, 0.1);
  transition: background-color 400ms ease, box-shadow 400ms ease;
}

/* ---------- Abas de arquivos abertos (inline no cabeçalho) ---------- */
.viewer-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.viewer-tabs::-webkit-scrollbar { height: 6px; }
.viewer-tabs::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
.viewer-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  max-width: 190px;
  padding: 6px 6px 6px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--muted-strong);
  cursor: pointer;
  font-size: 0.84rem;
}
.viewer-tab:hover { background: var(--surface-3); }
.viewer-tab.active {
  background: var(--accent-soft);
  border-color: rgba(155, 134, 255, 0.28);
  color: #fff;
}
.viewer-tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.viewer-tab-action {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  border: 0;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}
.viewer-tab-action svg { width: 13px; height: 13px; }
.viewer-tab-action:hover { background: var(--surface-3); color: var(--text); opacity: 1; transform: none; }
.viewer-tab-action[data-unpin] { color: var(--accent); opacity: 1; }

/* Botão de fixar no cabeçalho do viewer */
.pin-file-button { color: var(--muted); }
.pin-file-button.active { color: var(--accent); background: var(--accent-soft); border-color: rgba(155, 134, 255, 0.28); }
.pin-file-button svg { width: 18px; height: 18px; }

/* ---------- Editor estilo Obsidian ---------- */

/* Alternador Editor | Fonte */
.viewer-mode-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.viewer-mode-toggle button {
  padding: 6px 14px;
  min-height: 32px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted-strong);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.82rem;
}
.viewer-mode-toggle button:hover { color: var(--text); transform: none; }
.viewer-mode-toggle button.active {
  background: var(--accent-soft);
  color: #fff;
  border-color: rgba(155, 134, 255, 0.28);
}

/* Indicador de save */
#viewerContextBadge[data-save='pending'],
#viewerContextBadge[data-save='saving'] { color: #fde68a; }
#viewerContextBadge[data-save='error'],
#viewerContextBadge[data-save='conflict'] {
  color: #fecdd3;
  background: var(--danger-soft);
  border-color: rgba(251, 113, 133, 0.3);
}

/* Live preview: blocos clicáveis para editar */
.live-editor [data-line] { cursor: text; border-radius: 6px; }
.live-editor [data-line]:hover { background: rgba(255, 255, 255, 0.03); }
.live-empty-hint { color: var(--muted); font-style: italic; }

.block-editor {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  line-height: 1.66;
  color: var(--text);
  background: rgba(127, 90, 240, 0.08);
  border: 1px solid rgba(155, 134, 255, 0.3);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 0.3em 0;
  resize: none;
  overflow: hidden;
}
.block-editor:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
  /* Mantém o fundo sutil; o textarea:focus global escureceria o bloco. */
  background: rgba(127, 90, 240, 0.08);
}

/* Modo fonte: overlay de textarea transparente sobre espelho destacado */
.markdown-viewer.source-host {
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
  display: block;
}
.source-editor { position: relative; height: 100%; min-height: 320px; }
.source-highlight,
.source-input {
  position: absolute;
  inset: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.65;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  padding: 16px;
  border-radius: var(--radius-md);
}
.source-highlight {
  background: rgba(9, 12, 22, 0.7);
  border: 1px solid var(--border);
  overflow: hidden;
  pointer-events: none;
  color: var(--muted-strong);
}
.source-highlight code {
  display: block;
  font: inherit;
  background: none;
  padding: 0;
  white-space: inherit;
  word-break: inherit;
  overflow-wrap: inherit;
}
.source-input {
  background: transparent;
  border: 1px solid transparent;
  color: transparent;
  caret-color: #e8ecff;
  resize: none;
  overflow: auto;
}
.source-input:focus {
  outline: none;
  border-color: rgba(160, 145, 255, 0.4);
  box-shadow: 0 0 0 4px var(--accent-soft);
  /* O textarea:focus global escurece o fundo e cobriria o espelho destacado. */
  background: transparent;
}
.source-input::selection { background: rgba(127, 90, 240, 0.4); color: transparent; }

/* Tokens do markdown em texto puro (cores apenas — métricas iguais ao textarea) */
.md-heading { color: #d7c7ff; font-weight: 700; }
.md-quote { color: #93a2b8; font-style: italic; }
.md-hr, .md-fence { color: #7dd3fc; }
.md-codeblock, .md-inlinecode { color: #a5f3fc; }
.md-task { color: #34d399; font-weight: 700; }
.md-listmark { color: #b9a5ff; font-weight: 700; }
.md-wikilink { color: #b9a5ff; text-decoration: underline dashed; }
.md-link { color: #7dd3fc; text-decoration: underline; }
.md-bold { color: #fff; font-weight: 700; }
.md-em { color: #fde68a; font-style: italic; }
.md-tag { color: #f0abfc; }
.md-meta { color: #fbbf24; }

/* ---------- Chat (sessões + conversa) ---------- */
.chat-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0; }
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; }

/* Coluna de conversas (histórico) */
.chat-sessions {
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: rgba(9, 12, 22, 0.35);
  min-height: 0;
}
.chat-sessions.mobile-open { display: flex; }
.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
}
.new-chat-button svg { width: 16px; height: 16px; }
.chat-session-list { display: grid; gap: 6px; overflow-y: auto; min-height: 0; align-content: start; }
.chat-session-empty { margin: 8px 4px; color: var(--muted); font-size: 0.85rem; }
.chat-session-item {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-weight: 500;
}
.chat-session-item:hover { background: var(--surface-2); transform: none; }
.chat-session-item.active { background: var(--accent-soft); border-color: rgba(155, 134, 255, 0.24); }
.chat-session-item strong {
  font-size: 0.86rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-session-item small { color: var(--muted); font-size: 0.72rem; }

/* Conversa — flex column: filhos escondidos (contexto/anexos) não deslocam
   o layout, as mensagens ocupam a sobra e o composer fica compacto embaixo. */
.chat-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  min-height: 0;
  min-width: 0;
}
.chat-main > * { flex: 0 0 auto; }
.chat-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chat-header-title { min-width: 0; }
.chat-title-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-header-title h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-rename {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}
.chat-rename svg { width: 14px; height: 14px; }
.chat-rename:hover { background: var(--surface-2); color: var(--text); transform: none; }

/* Indicador discreto do arquivo em contexto (linha some quando vazio) */
.chat-context { display: flex; justify-content: flex-end; min-height: 0; }
.chat-context:has(.hidden) { display: none; }
.chat-context-badge {
  color: var(--muted);
  font-size: 0.74rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-messages {
  display: grid;
  gap: 10px;
  align-content: start;
  overflow-y: auto;
  min-height: 160px;
  padding-right: 2px;
  /* Ocupa toda a sobra do flex column e encolhe com scroll interno */
  flex: 1 1 auto;
}
.chat-messages.chat-empty { align-content: center; }
.chat-message { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 14px; background: var(--surface-2); max-width: 92%; }
.chat-message header { margin-bottom: 6px; color: var(--muted); font-size: 0.8rem; }
.chat-message strong { color: var(--text); }
.chat-message-body { color: var(--text); line-height: 1.55; overflow-wrap: anywhere; }
.chat-message-user { background: var(--accent-soft); border-color: rgba(155, 134, 255, 0.2); justify-self: end; }
.chat-message-assistant { background: var(--surface-2); justify-self: start; }
.chat-message-attachments { margin-top: 8px; color: var(--muted); font-size: 0.78rem; overflow-wrap: anywhere; }

/* Bolha "digitando..." estilo mensageiro */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  min-width: 0;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Anexos pendentes */
.chat-attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted-strong);
  font-size: 0.8rem;
}
.chip-remove {
  padding: 0;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
}
.chip-remove:hover { color: var(--danger); transform: none; }

/* Composer estilo mensageiro: anexo + campo + enviar na mesma barra */
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px;
  border-radius: 26px;
  background: rgba(8, 12, 20, 0.7);
  border: 1px solid var(--border);
}
.chat-composer:focus-within { border-color: rgba(160, 145, 255, 0.5); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  resize: none;
  border: 0;
  background: transparent;
  padding: 9px 6px;
  line-height: 1.45;
  overflow-y: auto;
}
.chat-composer textarea:focus { border: 0; box-shadow: none; background: transparent; outline: none; }
.composer-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}
.composer-icon svg { width: 20px; height: 20px; }
.composer-icon:hover { background: var(--surface-2); color: var(--text); transform: none; }
.composer-send { background: var(--accent-strong); color: #fff; }
.composer-send:hover { background: #8f6bff; color: #fff; }

/* Microfone: pulsa em vermelho enquanto grava */
.composer-mic.recording {
  background: var(--danger-soft);
  border-color: rgba(251, 113, 133, 0.45);
  color: var(--danger);
  animation: mic-pulse 1.6s infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.35); }
  50% { box-shadow: 0 0 0 9px rgba(251, 113, 133, 0); }
}
.chat-status { margin: 0; color: var(--muted); font-size: 0.8rem; }

/* ---------- Constelação do Conhecimento ---------- */
.constellation-card { padding: 0; overflow: clip; }
.cg-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 480px;
  background:
    radial-gradient(1150px 860px at 58% 44%, rgba(96, 74, 156, 0.16), transparent 60%),
    radial-gradient(820px 680px at 66% 52%, rgba(40, 122, 140, 0.11), transparent 58%),
    #07060c;
}
#cgCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#cgCanvas.dragging { cursor: grabbing; }

.cg-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: #949cab; font-size: 0.95rem; z-index: 5; pointer-events: none;
}
.cg-loading-star { animation: cg-twinkle 1.6s infinite ease-in-out; font-size: 1.2rem; color: #d7c7ff; }
@keyframes cg-twinkle { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

.cg-mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.cg-panel {
  position: absolute;
  background: rgba(14, 16, 24, 0.78);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  box-shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.75);
  z-index: 10;
}

.cg-hint {
  position: absolute; right: 16px; top: 14px; z-index: 6;
  font-size: 11px; color: #5b6270; font-family: ui-monospace, monospace;
  text-align: right; line-height: 1.7; pointer-events: none;
}
.cg-hint b { color: #949cab; font-weight: 500; }

/* HUD esquerdo */
.cg-hud {
  top: 14px; left: 14px; width: 300px;
  max-height: calc(100% - 28px);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.28s ease;
}
.cg-hud.collapsed { transform: translateX(calc(-100% - 22px)); opacity: 0; pointer-events: none; }
.cg-hud-btn {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  color: #5b6270; background: none; border: none; padding: 5px; line-height: 0; border-radius: 7px;
}
.cg-hud-btn:hover { color: #e7eaf0; background: rgba(127, 90, 240, 0.16); transform: none; }
.cg-hud-open {
  top: 14px; left: 14px; width: 40px; height: 40px; padding: 0;
  display: none; align-items: center; justify-content: center; color: #949cab;
}
.cg-hud-open.show { display: inline-flex; }
.cg-hud-open:hover { color: #fff; transform: none; }
.cg-scroll { overflow-y: auto; padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 16px; }
.cg-scroll::-webkit-scrollbar { width: 8px; }
.cg-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 8px; }

.cg-brand { display: flex; flex-direction: column; gap: 5px; padding-right: 26px; }
.cg-eyebrow { font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: #5b6270; font-family: ui-monospace, monospace; }
.cg-brand h1 { font-size: 19px; line-height: 1.15; margin: 0; font-weight: 650; letter-spacing: -0.015em; color: #e7eaf0; }
.cg-brand p { margin: 2px 0 0; font-size: 12px; color: #949cab; line-height: 1.45; }

.cg-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.cg-stat { border: 1px solid rgba(255, 255, 255, 0.09); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.cg-stat .n { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; color: #e7eaf0; }
.cg-stat .l { font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: #5b6270; font-family: ui-monospace, monospace; }

.cg-block-label { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: #5b6270; font-family: ui-monospace, monospace; margin-bottom: 8px; }

.segmented { display: flex; gap: 3px; padding: 3px; border: 1px solid rgba(255, 255, 255, 0.09); border-radius: 10px; }
.segbtn { flex: 1; background: transparent; color: #949cab; border: none; border-radius: 7px; padding: 7px 8px; font-size: 12px; font-weight: 500; }
.segbtn:hover { color: #e7eaf0; transform: none; }
.segbtn.active { background: rgba(127, 90, 240, 0.2); color: #d7c7ff; }

.cg-search { position: relative; }
.cg-search input {
  width: 100%; padding: 8px 11px 8px 32px; min-height: 0;
  background: transparent; color: #e7eaf0;
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 9px; font-size: 13px;
}
.cg-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: #5b6270; }
.cg-search .count { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 11px; color: #d7c7ff; font-family: ui-monospace, monospace; }

.cg-legend { display: flex; flex-direction: column; gap: 3px; }
.leg { display: flex; align-items: center; gap: 9px; padding: 5px 7px; border-radius: 8px; cursor: pointer; user-select: none; }
.leg:hover { background: rgba(127, 90, 240, 0.14); }
.leg.off { opacity: 0.35; }
.leg .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 8px -1px currentColor; }
.leg .name { font-size: 12.5px; flex: 1; color: #e7eaf0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leg .c { font-size: 11px; color: #5b6270; font-family: ui-monospace, monospace; }

.cg-navlist { display: flex; flex-direction: column; gap: 2px; max-height: 200px; overflow-y: auto; }
#cgResults:empty { display: none; }
.navitem { display: flex; align-items: center; gap: 9px; padding: 5px 7px; border-radius: 8px; cursor: pointer; user-select: none; }
.navitem:hover { background: rgba(127, 90, 240, 0.14); }
.navitem .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.navitem .name { font-size: 12.5px; flex: 1; color: #e7eaf0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navitem .c { font-size: 11px; color: #5b6270; font-family: ui-monospace, monospace; }

.cg-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cg-toggle-row > span { font-size: 12.5px; color: #949cab; }
.cg-switch { position: relative; width: 38px; height: 21px; flex: none; cursor: pointer; }
.cg-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.cg-switch .track { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.16); border-radius: 999px; transition: background 0.16s; }
.cg-switch .knob { position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #e7eaf0; transition: transform 0.16s; }
.cg-switch input:checked + .track { background: var(--accent-strong); }
.cg-switch input:checked + .track + .knob { transform: translateX(17px); background: #fff; }

/* Detalhe do nó */
.cg-detail { right: 14px; bottom: 66px; width: 280px; padding: 15px 16px; display: none; }
.cg-detail.show { display: block; }
.cg-dcat { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cg-dcat .dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 8px -1px currentColor; }
.cg-dcat .t { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: #949cab; font-family: ui-monospace, monospace; }
.cg-detail h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; line-height: 1.25; color: #e7eaf0; word-break: break-word; }
.cg-dpath { font-size: 10.5px; color: #5b6270; word-break: break-all; line-height: 1.4; margin-bottom: 11px; }
.cg-drow { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid rgba(255, 255, 255, 0.09); padding-top: 10px; }
.cg-drow .k { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: #5b6270; font-family: ui-monospace, monospace; }
.cg-drow .v { font-size: 16px; font-weight: 600; color: #e7eaf0; }
.cg-open-note { padding: 7px 14px; font-size: 0.8rem; }
.cg-links { margin-top: 10px; max-height: 160px; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.cg-links a { min-height: 25px; font-size: 12px; color: #949cab; cursor: pointer; padding: 3px 6px; border-radius: 6px; display: flex; align-items: center; gap: 7px; }
.cg-links a:hover { color: #e7eaf0; background: rgba(127, 90, 240, 0.14); }
.cg-links a .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.cg-links a .lnm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-close { position: absolute; top: 11px; right: 11px; color: #5b6270; background: none; border: none; padding: 4px; line-height: 0; border-radius: 6px; }
.cg-close:hover { color: #e7eaf0; background: rgba(127, 90, 240, 0.16); transform: none; }

/* Dock inferior */
.cg-dock { left: 50%; transform: translateX(-50%); bottom: 14px; display: flex; align-items: center; gap: 4px; padding: 5px; }
.pbtn { background: transparent; color: #949cab; border: 1px solid transparent; border-radius: 9px; font-size: 12px; font-family: ui-monospace, monospace; padding: 7px 12px; white-space: nowrap; }
.pbtn:hover { color: #e7eaf0; background: rgba(127, 90, 240, 0.14); transform: none; }
.pbtn.active { color: #d7c7ff; background: rgba(127, 90, 240, 0.2); }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 45;
  width: 60px;
  height: 60px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-strong);
  box-shadow: 0 16px 40px rgba(127, 90, 240, 0.44);
}
.fab svg { width: 26px; height: 26px; }
.fab:hover { background: #8f6bff; }

/* ---------- Create modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  background: rgba(2, 6, 14, 0.78);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}
.modal-card { width: min(520px, 100%); margin: 8vh 0 24px; }
.create-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.create-card form { display: grid; gap: 14px; }
.create-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.create-actions { display: flex; justify-content: flex-end; }
.create-actions button { min-width: 160px; }

/* ---------- Bottom nav (mobile) ---------- */
.workspace-nav {
  display: none;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 40;
  width: min(560px, calc(100vw - 16px));
  padding: 8px;
  border-radius: 26px;
  border: 1px solid var(--border);
  background: rgba(15, 17, 28, 0.82);
  backdrop-filter: blur(22px) saturate(160%);
  box-shadow: 0 18px 42px rgba(4, 6, 14, 0.4);
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.workspace-nav-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 18px;
  padding: 8px 6px;
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
}
.workspace-nav-button strong { font-size: 0.74rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.workspace-nav-button small { font-size: 0.66rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
.workspace-nav-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}
.workspace-nav-icon svg { width: 18px; height: 18px; }
.workspace-nav-button.active { background: var(--accent-soft); color: #fff; border-color: rgba(155, 134, 255, 0.28); }
.workspace-nav-button.active .workspace-nav-icon { background: rgba(185, 165, 255, 0.22); color: #fff; }

.is-hidden-pane { display: none !important; }
.is-active-pane { display: grid !important; }

/* ---------- Desktop workspace (≥981px): abas de tela cheia + chat popup ---------- */
@media (min-width: 981px) {
  .desktop-view-switch { display: inline-flex; }
  .workspace-nav { display: none !important; }
  .sidebar-toggle { display: inline-flex; }

  /* O shell vira um contêiner simples; a aba ativa controla o que aparece. */
  .workspace-shell { display: block; }

  /* Aba Tarefas: ocupa tudo */
  .workspace-tasks { display: none; }
  .workspace-shell[data-desktop-view='tasks'] .workspace-tasks { display: grid; }
  .workspace-shell[data-desktop-view='tasks'] .tasks-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Aba Arquivos: explorer (sidebar) + viewer (área principal), altura cheia */
  .files-workspace { display: none; }
  .workspace-shell[data-desktop-view='files'] .files-workspace {
    display: grid;
    grid-template-columns: var(--sidebar-w, 300px) minmax(0, 1fr);
    gap: 16px;
    height: calc(100dvh - 118px);
  }
  .workspace-shell[data-desktop-view='files'] .workspace-explorer,
  .workspace-shell[data-desktop-view='files'] .workspace-viewer {
    height: 100%;
    min-height: 0;
    /* Sem isso o align-content:start do .workspace-pane colapsa o card
       para a altura do conteúdo e o editor não preenche a página. */
    align-content: stretch;
    grid-template-rows: minmax(0, 1fr);
  }
  .workspace-shell[data-desktop-view='files'] .explorer-card {
    height: 100%;
    min-height: 0;
    grid-template-rows: auto auto 1fr;
  }
  .workspace-shell[data-desktop-view='files'] .explorer-tree {
    max-height: none;
    min-height: 0;
  }
  .workspace-shell[data-desktop-view='files'] .file-viewer-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }
  .workspace-shell[data-desktop-view='files'] .file-viewer-header { flex: 0 0 auto; }
  .workspace-shell[data-desktop-view='files'] .markdown-viewer {
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
  }

  /* Sidebar colapsada: some o explorer, viewer ocupa tudo, botão ▶ reexpande */
  .workspace-shell.sidebar-collapsed[data-desktop-view='files'] .files-workspace {
    grid-template-columns: minmax(0, 1fr);
  }
  .workspace-shell.sidebar-collapsed[data-desktop-view='files'] .workspace-explorer {
    display: none;
  }
  .workspace-shell.sidebar-collapsed[data-desktop-view='files'] .sidebar-expand {
    display: inline-flex;
  }

  /* Aba Chat: tela cheia com coluna de conversas à esquerda */
  .workspace-chat { display: none; }
  .workspace-shell[data-desktop-view='chat'] .workspace-chat {
    display: grid;
    /* Trava a track na altura do pane; sem isso o align-content:start
       do pane encolhe o card para a altura natural do conteúdo. */
    grid-template-rows: minmax(0, 1fr);
    align-content: stretch;
    height: calc(100dvh - 118px);
    min-height: 0;
  }
  .workspace-shell[data-desktop-view='chat'] .chat-card {
    height: 100%;
    min-height: 0;
  }
  .workspace-shell[data-desktop-view='chat'] .chat-layout {
    grid-template-columns: 280px minmax(0, 1fr);
    height: 100%;
  }
  .workspace-shell[data-desktop-view='chat'] .chat-sessions { display: flex; }
  .workspace-shell[data-desktop-view='chat'] .chat-messages { min-height: 0; }
  /* O FAB de nova tarefa cobria o botão de enviar do composer */
  .workspace-shell[data-desktop-view='chat'] .fab { display: none; }
  /* No desktop a coluna de conversas é fixa; o toggle é só do mobile */
  .chat-sessions-toggle { display: none; }

  /* Aba Constelação: palco em tela cheia */
  .workspace-constellation { display: none; }
  .workspace-shell[data-desktop-view='constellation'] .workspace-constellation {
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    height: calc(100dvh - 118px);
    min-height: 0;
  }
  .workspace-shell[data-desktop-view='constellation'] .constellation-card {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
  }
  .workspace-shell[data-desktop-view='constellation'] .fab { display: none; }
}

/* ---------- Responsive (mobile) ---------- */
@media (max-width: 980px) {
  .app-shell { padding-bottom: calc(24px + 84px); }
  .workspace-nav { display: grid; }
  .markdown-viewer, .explorer-tree { max-height: none; }
  .fab { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .source-editor { min-height: 62vh; }

  /* Chat no pane mobile: conversa em altura de tela, sessões colapsáveis */
  .chat-messages { max-height: none; min-height: 40vh; }
  /* FAB não pode cobrir o enviar quando o chat é o pane ativo */
  .workspace-shell:has(.workspace-chat.is-active-pane) .fab { display: none; }
  /* Constelação no mobile: palco alto, FAB fora do caminho */
  .cg-stage { height: calc(100dvh - 210px); min-height: 420px; }
  .cg-hint { display: none; }
  .cg-hud { width: min(300px, calc(100vw - 60px)); }
  .workspace-shell:has(.workspace-constellation.is-active-pane) .fab { display: none; }
  .chat-sessions {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    max-height: 46vh;
    overflow-y: auto;
  }
}

@media (max-width: 620px) {
  .app-shell { width: min(100vw - 12px, 100vw); padding-left: 8px; padding-right: 8px; }
  .toolbar-grid, .tasks-list, .create-grid { grid-template-columns: 1fr; }
  .app-topbar-title { font-size: 0.94rem; }
  .toolbar-row { align-items: stretch; }
  .undo-banner { flex-direction: column; align-items: stretch; }
  .workspace-nav-button small { display: none; }
  .login-card { margin-top: 4vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  button:hover, .task-card, .viewer-line-highlight { transition: none !important; transform: none !important; }
  .typing-dot { animation: none; opacity: 0.7; }
  .composer-mic.recording { animation: none; }
  html { scroll-behavior: auto; }
}
