/* ── obsi ─────────────────────────────────────────────────────
   Tokens de color: claro por defecto, oscuro por sistema o forzado
   con data-theme. --accent lo fija el usuario en ajustes. */
:root {
  --accent: #8b6cf6;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --accent-text: color-mix(in srgb, var(--accent) 80%, var(--text));

  --bg: #ffffff;
  --bg-side: #f7f7f8;
  --bg-ribbon: #f0f0f2;
  --bg-hover: #ebebee;
  --bg-active: #e3e3e8;
  --bg-elev: #ffffff;
  --border: #e4e4e8;
  --border-strong: #d2d2d8;
  --text: #1f1f24;
  --text-2: #4a4a55;
  --muted: #7a7a86;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgb(15 15 25 / .12), 0 2px 6px rgb(15 15 25 / .06);
  --scrim: rgb(10 10 15 / .35);
  /* Grafo: el canvas no entiende color-mix, van en hex */
  --grafo-nodo: #8a8a96;
  --grafo-linea: #c9c9d1;
  --grafo-texto: #3a3a44;
  --grafo-etiqueta: #10a37f;
  --grafo-adjunto: #d4a017;
  --grafo-rota: #a8a8b3;

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --editor-font-size: 16px;
  --radius: 8px;
  --radius-sm: 5px;
  --left-w: 260px;
  --right-w: 280px;
  --ribbon-w: 44px;
  --tabbar-h: 40px;
  --status-h: 26px;
  --ease: cubic-bezier(.2, .7, .2, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1e22;
    --bg-side: #18181b;
    --bg-ribbon: #141417;
    --bg-hover: #2a2a30;
    --bg-active: #33333a;
    --bg-elev: #25252b;
    --border: #2c2c32;
    --border-strong: #3a3a42;
    --text: #e4e4e9;
    --text-2: #b9b9c2;
    --muted: #8a8a95;
    --danger: #f87171;
    --shadow: 0 12px 34px rgb(0 0 0 / .45), 0 2px 6px rgb(0 0 0 / .3);
    --scrim: rgb(0 0 0 / .5);
    --grafo-nodo: #9a9aa6;
    --grafo-linea: #45454f;
    --grafo-texto: #d0d0d8;
    --grafo-etiqueta: #34c79b;
    --grafo-adjunto: #e0b43a;
    --grafo-rota: #62626d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1e1e22;
  --bg-side: #18181b;
  --bg-ribbon: #141417;
  --bg-hover: #2a2a30;
  --bg-active: #33333a;
  --bg-elev: #25252b;
  --border: #2c2c32;
  --border-strong: #3a3a42;
  --text: #e4e4e9;
  --text-2: #b9b9c2;
  --muted: #8a8a95;
  --danger: #f87171;
  --shadow: 0 12px 34px rgb(0 0 0 / .45), 0 2px 6px rgb(0 0 0 / .3);
  --scrim: rgb(0 0 0 / .5);
  --grafo-nodo: #9a9aa6;
  --grafo-linea: #45454f;
  --grafo-texto: #d0d0d8;
  --grafo-etiqueta: #34c79b;
  --grafo-adjunto: #e0b43a;
  --grafo-rota: #62626d;
  color-scheme: dark;
}

/* Variantes: sepia (sobre el claro) y negro puro para OLED (sobre el oscuro) */
:root[data-variante="sepia"] {
  --bg: #f8f1e3;
  --bg-side: #f1e8d6;
  --bg-ribbon: #eadfca;
  --bg-hover: #e8dcc5;
  --bg-active: #dfd1b6;
  --bg-elev: #fbf6ec;
  --border: #e2d5bd;
  --border-strong: #d2c2a4;
  --text: #3b3226;
  --text-2: #5a4d3c;
  --muted: #8a7a63;
  --grafo-linea: #d6c6a8;
  --grafo-texto: #4a3f30;
}
:root[data-variante="negro"] {
  --bg: #000000;
  --bg-side: #0a0a0b;
  --bg-ribbon: #000000;
  --bg-hover: #1a1a1d;
  --bg-active: #242428;
  --bg-elev: #111113;
  --border: #1f1f23;
  --border-strong: #2e2e34;
  --grafo-linea: #33333a;
}

:root {
  --font-texto: var(--font-ui);
  --ancho-lectura: 46em;
  --scroll: color-mix(in srgb, var(--text) 18%, transparent);
  --scroll-hover: color-mix(in srgb, var(--text) 32%, transparent);
}

/* ── Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
kbd {
  font: 500 11px var(--font-mono);
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-side);
  color: var(--text-2);
}
svg.icon { width: 18px; height: 18px; flex: none; }
.sm svg.icon { width: 16px; height: 16px; }

/* ── Botones ─────────────────────────────────────────────── */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  transition: background .12s, color .12s;
}
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.is-active { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-elev); font-weight: 500;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: translateY(1px); }
.btn svg.icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent-text); font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

/* ── Shell de la app ─────────────────────────────────────── */
body.app { overflow: hidden; }
.shell {
  display: grid;
  grid-template-columns: var(--ribbon-w) var(--left-w) 0 1fr 0 var(--right-w);
  grid-template-rows: 1fr var(--status-h);
  height: 100vh; height: 100dvh;
}
.shell.left-closed { grid-template-columns: var(--ribbon-w) 0 0 1fr 0 var(--right-w); }
.shell.right-closed { grid-template-columns: var(--ribbon-w) var(--left-w) 0 1fr 0 0; }
.shell.left-closed.right-closed { grid-template-columns: var(--ribbon-w) 0 0 1fr 0 0; }
.shell.left-closed .side-left, .shell.right-closed .side-right { visibility: hidden; }
.shell.left-closed [data-resize="left"], .shell.right-closed [data-resize="right"] { pointer-events: none; }

.ribbon {
  grid-row: 1 / 3;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0;
  background: var(--bg-ribbon);
  border-right: 1px solid var(--border);
}
.ribbon-sep { width: 20px; height: 1px; background: var(--border); margin: 6px 0; }
.ribbon-spacer { flex: 1; }

.side {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
  background: var(--bg-side);
}
.side-left { border-right: 1px solid var(--border); }
.side-right { border-left: 1px solid var(--border); }
.side-tabs {
  display: flex; gap: 2px; align-items: center;
  height: var(--tabbar-h); padding: 0 8px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.side-tab {
  display: grid; place-items: center;
  width: 32px; height: 28px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--muted);
}
.side-tab:hover { background: var(--bg-hover); color: var(--text); }
.side-tab.is-active { background: var(--bg-active); color: var(--text); }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px 4px 14px; flex: none;
}
.side-title { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.side-tools { display: flex; gap: 2px; }
.side-body { flex: 1; overflow: auto; padding: 4px 6px 12px; }
.side-foot {
  flex: none; padding: 8px 14px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted);
}
.vault-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.vault-name svg.icon { width: 15px; height: 15px; }

.empty-mini {
  display: grid; justify-items: center; gap: 6px;
  padding: 32px 12px; text-align: center; color: var(--muted); font-size: 13px;
}
.empty-mini svg.icon { width: 28px; height: 28px; opacity: .6; }
.empty-mini p { margin: 0; }

.resizer {
  position: relative; z-index: 5; width: 0; cursor: col-resize;
}
.resizer::after {
  content: ""; position: absolute; inset: 0 -3px;
  transition: background .15s;
}
.resizer:hover::after, .resizer.is-dragging::after { background: color-mix(in srgb, var(--accent) 55%, transparent); }
body.resizing { cursor: col-resize; user-select: none; }

/* Columna explícita: en móvil los paneles salen de la grilla (fixed) y la auto-ubicación la correría a la columna 2 */
.workspace { grid-column: 4; grid-row: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
#btn-toggle-right { flex: none; }
.statusbar {
  grid-column: 2 / -1;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 12px; font-size: 12px; color: var(--muted);
  background: var(--bg-side); border-top: 1px solid var(--border);
}
.status-right { display: flex; gap: 14px; }

/* ── Tooltip y avisos ─────────────────────────────────────── */
.tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  padding: 4px 8px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg);
  font-size: 12px; font-weight: 500; white-space: nowrap;
  box-shadow: var(--shadow);
}
.toasts { position: fixed; right: 16px; bottom: 40px; z-index: 90; display: grid; gap: 8px; }
.toast {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 13px; animation: toast-in .2s var(--ease);
}
.toast.is-error { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ── Modal de ajustes ─────────────────────────────────────── */
.modal {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow);
}
.modal[open] { animation: modal-in .18s var(--ease); }
.modal::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-card { padding: 0 0 8px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px 22px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-elev); z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.settings-group { padding: 14px 22px 4px; }
.settings-group h3 { margin: 0 0 4px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: 0; }
.setting p { margin: 2px 0 0; font-size: 12.5px; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius); background: var(--bg-hover); flex: none; }
.segmented button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-2); font-size: 13px; font-weight: 500;
}
.segmented button svg.icon { width: 15px; height: 15px; }
.segmented button[aria-checked="true"] { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .1);
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px var(--sw); }

.range-wrap { display: flex; align-items: center; gap: 10px; flex: none; }
.range-wrap input { accent-color: var(--accent); width: 140px; }
.range-wrap output { width: 40px; font: 500 12px var(--font-mono); color: var(--text-2); }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong);
  transition: background .15s; pointer-events: none;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .25);
  transition: transform .18s var(--ease);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Login ───────────────────────────────────────────────── */
body.auth {
  display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(400px, 100%); padding: 32px 28px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.auth-logo svg { width: 32px; height: 32px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.auth-card > p { margin: 0 0 20px; }
.auth-card form { display: grid; gap: 14px; }
.auth-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.auth-card input {
  height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
.auth-card input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-card .btn { height: 40px; margin-top: 6px; }
.auth-sep { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; font-size: 12px; color: var(--muted); }
.auth-sep::before, .auth-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-card .btn-google { width: 100%; justify-content: center; margin-top: 0; text-decoration: none; color: var(--text); }
.btn-google svg { width: 18px; height: 18px; }
.auth-error {
  margin-bottom: 14px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px;
  color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}

.auth-legal { margin: 18px 0 0; font-size: 12px; text-align: center; }
.auth-legal a { color: var(--muted); }

/* ── Privacidad y condiciones ─────────────────────────────── */
body.legal { min-height: 100dvh; background: var(--bg); color: var(--text); overflow: auto; }
.legal-doc { max-width: 720px; margin: 0 auto; padding: 32px 16px 48px; line-height: 1.65; font-size: 15px; }
.legal-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 28px; }
.legal-cab .auth-logo { margin: 0; color: var(--text); text-decoration: none; }
.legal-cab nav { display: flex; gap: 16px; font-size: 14px; }
.legal-cab nav a { color: var(--text-2); text-decoration: none; }
.legal-cab nav a[aria-current] { color: var(--accent-text); font-weight: 600; }
.legal-doc h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -.02em; line-height: 1.2; }
.legal-doc h1 + p { margin-top: 0; }
.legal-doc h2 { margin: 32px 0 8px; font-size: 19px; letter-spacing: -.01em; }
.legal-doc h3 { margin: 18px 0 4px; font-size: 15px; }
.legal-doc ul { padding-left: 22px; }
.legal-doc li { margin: 4px 0; }
.legal-doc a { color: var(--accent-text); }
.legal-doc code { font-family: var(--font-mono); font-size: .88em; padding: 1px 5px; border-radius: 4px; background: var(--bg-hover); overflow-wrap: anywhere; }
.legal-pie { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 13px; }
.legal-pie a { color: var(--muted); }

/* ── Móvil: los paneles laterales flotan sobre el área de trabajo ── */
.scrim { position: fixed; inset: 0; z-index: 30; background: var(--scrim); }
@media (max-width: 768px) {
  .shell, .shell.left-closed, .shell.right-closed, .shell.left-closed.right-closed {
    grid-template-columns: var(--ribbon-w) 0 0 1fr 0 0;
  }
  .resizer { display: none; }
  .side {
    position: fixed; top: 0; bottom: 0; z-index: 40;
    width: min(300px, 85vw);
    box-shadow: var(--shadow);
  }
  /* Hasta que app.js aplica el estado, ocultos y sin animar el cierre inicial */
  .shell:not(.animar) .side { visibility: hidden; }
  .shell.animar .side { transition: transform .22s var(--ease), visibility .22s; }
  .side-left { left: var(--ribbon-w); }
  .side-right { right: 0; }
  .shell.left-closed .side-left { transform: translateX(calc(-100% - var(--ribbon-w))); }
  .shell.right-closed .side-right { transform: translateX(100%); }
  .statusbar { grid-column: 2 / -1; }
  .setting { flex-direction: column; align-items: flex-start; }
  .swatches { justify-content: flex-start; }
}

/* ── Barras de desplazamiento finas, con los colores del tema ── */
* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
*:hover { scrollbar-color: var(--scroll-hover) transparent; }

.segmented-envuelve { display: inline-grid; grid-template-columns: repeat(3, auto); }

/* ── Movimiento reducido: sin animaciones ni transiciones ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Grabadora de audio: el botón de la barra y el contador de la barra de estado */
.icon-btn.is-grabando { color: #fff; background: var(--danger); }
.icon-btn.is-grabando:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.estado-grabando { display: inline-flex; align-items: center; gap: 5px; margin-right: 12px; color: var(--danger); font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.estado-grabando svg.icon { width: 13px; height: 13px; animation: latido 1.2s ease-in-out infinite; }
@keyframes latido { 50% { opacity: .3; } }
