/* ============================================================================
   APP CSS — cascada por capas (MANIFIESTO §3): base → layout → components → utils
   Solo consume tokens de tokens.css. Cero literales de color/espacio.
   ========================================================================== */
@layer base, layout, components, utilities;

/* ---------------------------------------------------------------- BASE ---- */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: var(--leading-normal);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3, p { margin: 0; }
  a { color: inherit; text-decoration: none; }
  button, input, textarea, select { font: inherit; color: inherit; }
  /* Selects y sus opciones en tema oscuro/claro (no más fondo blanco). */
  select { color-scheme: inherit; }
  option { background: var(--color-surface); color: var(--color-text); }

  /* Estilo unificado de TODOS los controles (adiós inputs planos "Win98"). */
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
  textarea, select {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    color: var(--color-text);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):focus,
  textarea:focus, select:focus {
    outline: none;
    border-color: var(--color-focus-ring);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-focus-ring) 22%, transparent);
    background: var(--color-bg);
  }
  ::placeholder { color: var(--color-text-muted); opacity: .7; }

  :focus-visible {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }

  ::-webkit-scrollbar { width: 11px; height: 11px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
    border: 3px solid transparent; background-clip: padding-box;
  }
  ::-webkit-scrollbar-thumb:hover { background: var(--color-surface-hover); background-clip: padding-box; }

  /* Aparición suave de elementos creados (que "se sienta rico"). */
  @keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(.985); } to { opacity: 1; transform: none; } }

  /* Accesibilidad: respetar a quien prefiere menos movimiento. */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  }

  /* Transición de lujo entre temas — FALLBACK (Firefox/Safari): crossfade. */
  html.theme-transition,
  html.theme-transition *,
  html.theme-transition *::before,
  html.theme-transition *::after {
    transition: background-color var(--dur-base) var(--ease),
                color var(--dur-base) var(--ease),
                border-color var(--dur-base) var(--ease),
                fill var(--dur-base) var(--ease) !important;
  }

  /* View Transitions API: iris circular del tema nuevo sobre el viejo.
     Sin crossfade default + z-index, animado por @keyframes con --x/--y/--r. */
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
  ::view-transition-old(root) { z-index: 0; }
  ::view-transition-new(root) { z-index: 1; animation: iris 0.55s cubic-bezier(0.4, 0, 0.2, 1) both; }
  @keyframes iris {
    from { clip-path: circle(0px at var(--x) var(--y)); }
    to   { clip-path: circle(var(--r) at var(--x) var(--y)); }
  }

  /* Radial bloom de marca (efecto en ambos caminos). */
  .theme-bloom {
    position: fixed; transform: translate(-50%, -50%); border-radius: var(--radius-full);
    pointer-events: none; z-index: var(--z-toast);
    background: radial-gradient(circle, color-mix(in srgb, var(--color-primary) 45%, transparent), transparent 70%);
    animation: theme-bloom 520ms ease-out forwards;
  }
  @keyframes theme-bloom { from { width: 0; height: 0; opacity: .85; } to { width: 220vmax; height: 220vmax; opacity: 0; } }
}

/* -------------------------------------------------------------- LAYOUT ---- */
@layer layout {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-4);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border-soft);
  }
  .sidebar-foot { margin-top: auto; display: grid; gap: var(--space-3); }
  .sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }

  /* ---- Menú plegable (rail de iconos) — pulido ---- */
  .app-shell { transition: grid-template-columns var(--dur-base) var(--ease); }
  .app-shell.collapsed { grid-template-columns: 68px 1fr; }

  .app-shell.collapsed .sidebar { align-items: center; padding-left: var(--space-2); padding-right: var(--space-2); }
  .app-shell.collapsed .sidebar-top { flex-direction: column; gap: var(--space-2); }

  .app-shell.collapsed .brand-name,
  .app-shell.collapsed .nav-item > span,
  .app-shell.collapsed #btn-add > span,
  .app-shell.collapsed .user-name,
  .app-shell.collapsed .user-row .link { display: none; }

  .app-shell.collapsed .nav { width: 100%; gap: var(--space-2); }
  .app-shell.collapsed .nav-item {
    width: 44px; height: 44px; padding: 0; margin: 0 auto;
    justify-content: center; font-size: var(--text-lg); border-radius: var(--radius-md);
  }
  .app-shell.collapsed #btn-add {
    width: 44px; height: 44px; padding: 0; margin: 0 auto; font-size: var(--text-lg);
  }
  .app-shell.collapsed .user-row { justify-content: center; }
  .app-shell.collapsed .user-row .muted { font-size: var(--text-lg); }
  /* Modo enfoque: al plegar el menú, el topbar también se adelgaza (más espacio útil) */
  .app-shell.collapsed .topbar { min-height: 0; padding-top: var(--space-1); padding-bottom: var(--space-1); }
  .app-shell.collapsed .topbar-title { display: none; }

  /* El item activo no salta de tamaño al cambiar de vista */
  .nav-item { transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }

  .main {
    overflow: hidden; display: flex; flex-direction: column;
    background: radial-gradient(900px 360px at 65% -6%, color-mix(in srgb, var(--color-primary) 7%, transparent), transparent 60%);
  }
  .view { flex: 1; overflow: auto; padding: var(--space-6); }

  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-3); padding: var(--space-3) var(--space-5); min-height: 64px;
    border-bottom: 1px solid var(--color-border-soft);
    background: color-mix(in srgb, var(--color-surface) 85%, transparent);
    backdrop-filter: blur(10px);
    position: sticky; top: 0; z-index: var(--z-sticky);
    box-shadow: 0 1px 0 var(--color-border-soft);
    transition: min-height var(--dur-base) var(--ease), padding var(--dur-base) var(--ease);
  }
  .topbar-title { font-weight: var(--font-bold); font-size: var(--text-lg); color: var(--color-text); letter-spacing: -.01em; }
  .topbar-right { display: flex; align-items: center; gap: var(--space-3); }
  .role-pill {
    display: inline-flex; align-items: center; gap: var(--space-1);
    padding: var(--space-1) var(--space-3); border-radius: var(--radius-full);
    border: 1px solid var(--color-border); background: var(--color-surface-2);
    color: var(--color-text); font-size: var(--text-xs); font-weight: var(--font-semibold);
    cursor: pointer; white-space: nowrap; transition: background var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease);
  }
  .role-pill:hover { filter: brightness(1.08); }
  @media (max-width: 600px) { .role-pill { display: none; } }
  .topbar-user { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3); border-radius: var(--radius-full); color: var(--color-text); border: 1px solid var(--color-border-soft); }
  .topbar-user:hover { background: var(--color-surface-2); }
  .topbar-user-name { font-weight: var(--font-semibold); font-size: var(--text-sm); }
  .topbar-user img, .topbar-user .avatar-ph {
    width: 34px; height: 34px; border-radius: var(--radius-full); object-fit: cover;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 55%, transparent);
  }
  @media (max-width: 700px) { #btn-event span, .topbar-user-name { display: none; } }
  @media (max-width: 600px) { .topbar-user-name { display: none; } }

  /* ---- Notificaciones (campana del topbar) ---- */
  .topbar-notifs { position: relative; }
  .notif-btn { position: relative; }
  .notif-badge {
    position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px;
    padding: 0 5px; border-radius: var(--radius-full);
    background: var(--color-danger); color: #fff;
    font-size: 11px; font-weight: var(--font-bold); line-height: 18px; text-align: center;
    box-shadow: 0 0 0 2px var(--color-bg);
  }
  .notif-panel {
    position: absolute; top: calc(100% + var(--space-2)); right: 0;
    width: min(360px, 92vw); max-height: 70vh; overflow-y: auto;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg, 0 12px 40px rgba(0,0,0,.35));
    z-index: var(--z-modal); padding: var(--space-2);
  }
  .notif-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-2) var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border-soft); }
  .notif-empty { text-align: center; padding: var(--space-5) var(--space-3); }
  .notif-list { display: flex; flex-direction: column; gap: 2px; padding-top: var(--space-2); }
  .notif-item {
    display: flex; align-items: center; gap: var(--space-3); width: 100%; text-align: left;
    padding: var(--space-2) var(--space-3); border: 0; background: transparent;
    border-radius: var(--radius-md); cursor: pointer; color: var(--color-text);
  }
  .notif-item:hover { background: var(--color-surface-2); }
  .notif-new { background: color-mix(in srgb, var(--color-primary) 8%, transparent); }
  .notif-ic { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: var(--radius-full); background: color-mix(in srgb, var(--c) 22%, transparent); font-size: var(--text-sm); }
  .notif-body { flex: 1; min-width: 0; }
  .notif-title { font-weight: var(--font-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .notif-dot { width: 8px; height: 8px; flex: none; border-radius: var(--radius-full); background: var(--color-primary); }

  /* ---- Inicio: panel fusionado (inbox colapsado + lanzador) ---- */
  .home-panel { display: grid; grid-template-columns: 1fr 1.25fr; gap: var(--space-4); margin-top: var(--space-4); align-items: start; }
  @media (max-width: 780px) { .home-panel { grid-template-columns: 1fr; } }
  .home-inbox { padding: 0; overflow: hidden; }
  .home-inbox-head { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: var(--space-4); border: 0; background: transparent; cursor: pointer; color: var(--color-text); }
  .home-inbox-head:hover { background: var(--color-surface-2); }
  .home-inbox-ic { font-size: var(--text-xl); }
  .badge-pending { display: inline-block; margin-left: var(--space-2); padding: 1px 8px; border-radius: var(--radius-full); background: var(--color-primary); color: var(--color-on-primary); font-size: var(--text-xs); font-weight: var(--font-bold); }
  .home-inbox-list { border-top: 1px solid var(--color-border-soft); padding: var(--space-2); display: flex; flex-direction: column; gap: 2px; }
  .action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: var(--space-2); }
  .action-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: var(--space-3) var(--space-2); border: 1px solid var(--color-border-soft); border-radius: var(--radius-md); background: var(--color-surface); cursor: pointer; color: var(--color-text); transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
  .action-tile:hover { background: var(--color-surface-2); transform: translateY(-2px); border-color: var(--color-border); }
  .action-tile-ico { font-size: 1.5rem; line-height: 1; }
  .action-tile span:last-child { font-size: var(--text-xs); font-weight: var(--font-medium); }

  /* ---- Inicio: WORKSPACE de 3 paneles ---- */
  .workspace { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: var(--space-4); height: calc(100vh - 150px); margin-top: var(--space-3); }
  .ws-col { display: flex; flex-direction: column; min-height: 0; background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); overflow: hidden; }
  .ws-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-soft); }
  .ws-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-2); display: flex; flex-direction: column; gap: 2px; }
  .ws-fill { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: var(--space-3); gap: var(--space-2); }
  .ws-fill .keep-composer { flex: none; }
  .ws-sep { text-align: center; color: var(--color-text-muted); font-size: var(--text-xs); padding: 2px 0; }
  .assistant-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .ws-link { display: flex; align-items: center; gap: var(--space-3); width: 100%; text-align: left; padding: var(--space-3); border: 0; background: transparent; border-radius: var(--radius-md); cursor: pointer; color: var(--color-text); }
  .ws-link:hover { background: var(--color-surface-2); }
  .ws-link-ic { font-size: var(--text-lg); }
  @media (max-width: 920px) {
    .workspace { grid-template-columns: 1fr; height: auto; }
    .ws-body { max-height: 48vh; }
    .ws-fill { min-height: 60vh; }
  }

  /* ---- Inicio: asistente SIEMPRE al centro + panel izq (mensajes) y der (resumen) ---- */
  .cg-shell { display: flex; gap: var(--space-4); justify-content: center; align-items: stretch; height: calc(100vh - 120px); }
  .cg-main { flex: 0 1 800px; min-width: 0; display: flex; flex-direction: column; gap: var(--space-3); }
  .cg-title { text-align: center; }
  .cg-title h1 { font-size: var(--text-2xl); margin: 0; }
  .cg-hint { text-align: center; font-style: italic; color: var(--color-text-muted); min-height: 1.3em; opacity: 0; transition: opacity .25s var(--ease); }
  .cg-hint.show { opacity: 1; }
  .cg-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); overflow: hidden; }

  .cg-aside { flex: 0 0 300px; display: flex; flex-direction: column; min-height: 0; background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); overflow: hidden; }
  .cg-side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-soft); }
  .presence { display: flex; align-items: center; gap: 5px; font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 3px; }
  .presence-dot { width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--color-text-muted); opacity: .5; }
  .cg-side-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-2); display: flex; flex-direction: column; gap: 2px; }
  .cg-side-empty { text-align: center; padding: var(--space-6) var(--space-3); display: grid; place-items: center; gap: var(--space-2); }
  .cg-side-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-top: 1px solid var(--color-border-soft); font-size: var(--text-xs); color: var(--color-text-muted); }
  .cg-side-foot .link { cursor: pointer; }
  /* Modo notificación discreto (solo cuántos, sin contenido) */
  .notif-only { flex: 1; display: grid; place-content: center; place-items: center; gap: 6px; text-align: center; padding: var(--space-5); }
  .notif-num { font-size: 2.6rem; font-weight: var(--font-bold); color: var(--color-primary); line-height: 1; }
  /* Resumen derecho */
  .cg-sub { font-size: var(--text-xs); font-weight: var(--font-semibold); text-transform: uppercase; letter-spacing: .05em; padding: var(--space-2); color: var(--color-text-muted); }
  .sum-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2); border-radius: var(--radius-md); }

  @media (max-width: 1080px) {
    .cg-shell { flex-direction: column; height: auto; }
    .cg-main { flex: none; order: -1; }   /* el asistente primero en móvil */
    .cg-chat { height: 60vh; }
    .cg-aside { flex: none; }
    .cg-side-body { max-height: 42vh; }
  }

  /* ---- Pestañas de chat plegadas (Messenger), abajo-izquierda ---- */
  .chat-tabs { position: fixed; left: var(--space-5); bottom: var(--space-5); z-index: var(--z-sticky); display: flex; gap: var(--space-2); flex-wrap: wrap; max-width: 56vw; }
  .chat-tab { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 6px; border-radius: var(--radius-full); border: 1px solid var(--color-border); background: var(--color-surface); box-shadow: var(--shadow-md); cursor: pointer; color: var(--color-text); font-size: var(--text-sm); font-weight: var(--font-medium); }
  .chat-tab:hover { background: var(--color-surface-2); }
  .chat-tab .avatar-xs { width: 24px; height: 24px; }
  .chat-tab-name { max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .chat-tab-dot { width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--color-primary); }
  body.on-home .chat-tabs { display: none; } /* en Inicio ya está el panel de mensajes */
  @media (max-width: 560px) { .chat-tab-name { display: none; } .chat-tabs { left: var(--space-3); bottom: var(--space-3); } }

  /* ---- Demo cel: marco de teléfono + mockup móvil del Inicio ---- */
  .demo-stage { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-4); }
  .demo-caption { font-size: var(--text-sm); }
  .phone { width: 390px; height: 800px; max-height: calc(100vh - 170px); border-radius: 46px; background: #05070b; border: 1px solid var(--color-border); box-shadow: 0 30px 80px rgba(0,0,0,.5); padding: 12px; }
  .phone-screen { position: relative; width: 100%; height: 100%; border-radius: 36px; overflow: hidden; background: var(--color-bg); display: flex; flex-direction: column; }
  .phone-notch { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 130px; height: 24px; background: #05070b; border-radius: 0 0 16px 16px; z-index: 5; }
  .m-status { display: flex; justify-content: space-between; padding: 8px 20px 2px; font-size: 11px; color: var(--color-text-muted); }
  .m-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 14px 8px; border-bottom: 1px solid var(--color-border-soft); }
  .m-brand { font-weight: var(--font-bold); }
  .m-bell { position: relative; font-size: var(--text-lg); background: transparent; border: 0; cursor: pointer; color: var(--color-text); }
  .m-bell-badge { position: absolute; top: -4px; right: -6px; background: var(--color-danger); color: #fff; font-size: 9px; font-weight: var(--font-bold); border-radius: var(--radius-full); padding: 0 4px; }
  .m-chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .m-chat-wrap .assistant-chat { flex: 1; min-height: 0; }
  .m-pending { cursor: pointer; }
  /* Marco Galaxy S25 Ultra (más grande, 19.5:9) */
  .phone-s25 { width: 412px; height: 900px; max-height: calc(100vh - 130px); border-radius: 50px; }
  /* INBOX como tira de avatares (estilo historias) + lista expandible */
  .m-strip-wrap { position: relative; border-bottom: 1px solid var(--color-border-soft); }
  .m-strip-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px 0; }
  .m-strip-head strong { font-size: var(--text-sm); }
  .m-strip-tog { background: transparent; border: 0; cursor: pointer; color: var(--color-text-muted); font-size: var(--text-md, var(--text-sm)); padding: 2px 6px; }
  .m-strip { display: flex; gap: 10px; overflow-x: auto; padding: 6px 12px 10px; scrollbar-width: none; }
  .m-strip::-webkit-scrollbar { display: none; }
  .m-strip-item { flex: 0 0 auto; width: 64px; background: transparent; border: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--color-text); }
  /* Círculo dividido: el FONDO del wrapper es el anillo (top historia / abajo mensaje) */
  .m-strip-avawrap { position: relative; width: 58px; height: 58px; border-radius: var(--radius-full); padding: 3px; }
  .m-strip-ava { width: 100%; height: 100%; border-radius: var(--radius-full); object-fit: cover; background: var(--color-surface-2); display: grid; place-items: center; border: 2px solid var(--color-bg); }
  .m-tap { position: absolute; left: 0; width: 100%; height: 50%; background: transparent; border: 0; padding: 0; cursor: pointer; z-index: 2; }
  .m-tap-top { top: 0; }
  .m-tap-bot { bottom: 0; }
  /* Pulso verde cuando hay mensaje nuevo (medio anillo inferior) */
  .m-strip-avawrap.pulse { animation: msgpulse 1.6s ease-out infinite; }
  @keyframes msgpulse {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-success) 60%, transparent); }
    70%  { box-shadow: 0 0 0 7px color-mix(in srgb, var(--color-success) 0%, transparent); }
    100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-success) 0%, transparent); }
  }
  @media (prefers-reduced-motion: reduce) { .m-strip-avawrap.pulse { animation: none; } }
  .m-strip-new { border: 1.5px dashed var(--color-border); color: var(--color-text-muted); font-size: var(--text-lg); }
  .m-strip-dot { position: absolute; top: 0; right: 0; width: 13px; height: 13px; border-radius: var(--radius-full); background: var(--color-danger); border: 2px solid var(--color-surface); }
  .m-strip-name { font-size: 10px; max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-inbox-drop { position: absolute; top: 100%; left: 0; right: 0; z-index: 6; max-height: 340px; overflow-y: auto; background: var(--color-surface); border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow-lg); padding: var(--space-2); }
  .m-drop-row { display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left; padding: var(--space-2); border: 0; background: transparent; border-radius: var(--radius-md); cursor: pointer; color: var(--color-text); }
  .m-drop-row:hover { background: var(--color-surface-2); }
  .m-drop-name { font-weight: var(--font-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-drop-last { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-dot { width: 10px; height: 10px; border-radius: var(--radius-full); background: var(--color-danger); flex: none; }

  /* ---- Demo cel: FEED (red social esencial) ---- */
  .m-feed { flex: 1; overflow-y: auto; padding: 0 0 86px; display: flex; flex-direction: column; gap: var(--space-3); }
  .m-cards { display: flex; flex-direction: column; gap: var(--space-3); }
  /* Dashboard de widgets (móvil) */
  .m-dash-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-2) var(--space-3) 0; }
  .m-dash { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-2); }
  .m-w { background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); overflow: hidden; }
  .m-w-head { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border-soft); font-size: var(--text-sm); }
  .m-w-body { display: flex; flex-direction: column; }
  .m-w-row { display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left; padding: var(--space-2) var(--space-3); border: 0; background: transparent; color: var(--color-text); font-size: 13px; }
  button.m-w-row { cursor: pointer; }
  button.m-w-row:hover { background: var(--color-surface-2); }
  .m-acc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px; }
  .m-acc-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 1px solid var(--color-border-soft); border-radius: var(--radius-md); background: transparent; cursor: pointer; color: var(--color-text); font-size: 11px; }
  .m-acc-tile:hover { background: var(--color-surface-2); }
  .m-acc-ic { font-size: 20px; }
  .m-feed-empty { text-align: center; padding: var(--space-7) var(--space-4); display: grid; place-items: center; gap: var(--space-2); }
  .feed-card { background: var(--color-surface); border-top: 1px solid var(--color-border-soft); border-bottom: 1px solid var(--color-border-soft); }
  .feed-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
  .feed-img { width: 100%; display: block; max-height: 420px; object-fit: cover; background: var(--color-surface-2); cursor: zoom-in; }
  .feed-actions { display: flex; gap: 8px; padding: 8px 12px 4px; }
  .feed-act { background: transparent; border: 1px solid var(--color-border-soft); border-radius: var(--radius-full); padding: 5px 12px; cursor: pointer; color: var(--color-text); font-size: 13px; }
  .feed-act.on { border-color: var(--color-primary); }
  .feed-reactbar { display: flex; gap: 6px; padding: 4px 12px 8px; }
  .feed-emoji { background: var(--color-surface-2); border: 0; border-radius: var(--radius-full); width: 34px; height: 34px; font-size: 18px; cursor: pointer; transition: transform var(--dur-fast) var(--ease); }
  .feed-emoji:hover { transform: scale(1.15); }
  .feed-caption { padding: 2px 12px 8px; font-size: 13px; line-height: 1.4; }
  .feed-comments { padding: 0 12px 10px; display: flex; flex-direction: column; gap: 6px; }
  .feed-cmt { display: flex; align-items: center; gap: 6px; font-size: 13px; background: var(--color-surface-2); border-radius: var(--radius-md); padding: 6px 10px; }
  .feed-cmt-x { background: transparent; border: 0; cursor: pointer; color: var(--color-text-muted); }
  .feed-cmt-add { display: flex; gap: 6px; }
  .feed-cmt-input { flex: 1; border: 1px solid var(--color-border); border-radius: var(--radius-full); padding: 6px 12px; background: var(--color-bg); color: var(--color-text); font-size: 13px; }

  /* 3 botones flotantes dentro del teléfono */
  .m-fabs { position: absolute; right: 14px; bottom: 18px; z-index: 7; display: flex; flex-direction: column; gap: 10px; align-items: center; }
  .m-fab2 { width: 46px; height: 46px; border-radius: var(--radius-full); border: 1px solid var(--color-border); background: var(--color-surface); box-shadow: var(--shadow-md); cursor: pointer; font-size: 20px; color: var(--color-text); }
  .m-fab2-main { width: 56px; height: 56px; background: var(--color-primary); color: #fff; border: 0; font-size: 24px; }

  /* Bottom sheets dentro del teléfono */
  .m-backdrop { position: absolute; inset: 0; z-index: 8; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; }
  .m-sheet { width: 100%; max-height: 80%; background: var(--color-surface); border-radius: 22px 22px 0 0; display: flex; flex-direction: column; min-height: 0; animation: sheet-up .2s var(--ease); }
  .m-sheet.tall { height: 80%; }
  .m-sheet-bar { width: 40px; height: 4px; border-radius: 2px; background: var(--color-border); margin: 8px auto 4px; }
  .m-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 14px 8px; border-bottom: 1px solid var(--color-border-soft); }
  .m-sheet-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; padding: var(--space-2); }
  .m-sheet-body .assistant-chat { flex: 1; min-height: 0; }
  @keyframes sheet-up { from { transform: translateY(24px); opacity: .5; } to { transform: none; opacity: 1; } }
  .m-ava { width: 30px; height: 30px; border-radius: var(--radius-full); background: var(--color-surface-2); display: inline-grid; place-items: center; }
  .m-pending { display: flex; align-items: center; gap: 8px; margin: 10px 14px 0; padding: 8px 12px; background: var(--color-surface-2); border-radius: var(--radius-md); font-size: 12px; }
  .m-pending .m-link { color: var(--color-primary); font-weight: var(--font-semibold); }
  .m-chat { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
  .m-bubble { max-width: 82%; padding: 9px 12px; border-radius: 16px; font-size: 13px; line-height: 1.4; }
  .m-in { align-self: flex-start; background: var(--color-surface-2); border-bottom-left-radius: 5px; }
  .m-out { align-self: flex-end; background: var(--color-primary); color: var(--color-on-primary); border-bottom-right-radius: 5px; }
  .m-inputbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--color-border-soft); }
  .m-inputbar .box { flex: 1; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 20px; padding: 8px 14px; color: var(--color-text-muted); font-size: 13px; }
  .m-plus { font-size: var(--text-xl); color: var(--color-text-muted); }
  .m-send { width: 34px; height: 34px; border-radius: var(--radius-full); background: var(--color-primary); color: #fff; display: grid; place-items: center; }
  .m-nav { display: flex; justify-content: space-around; align-items: center; padding: 6px 6px 16px; border-top: 1px solid var(--color-border-soft); }
  .m-navitem { background: transparent; border: 0; color: var(--color-text-muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: var(--text-lg); }
  .m-navlbl { font-size: 9px; }
  .m-fab { width: 48px; height: 48px; border-radius: var(--radius-full); background: var(--color-primary); color: #fff; font-size: var(--text-2xl); border: 0; margin-top: -16px; box-shadow: var(--shadow-md); }

  /* ---- Mensajes: lista de chats ---- */
  .chat-list { display: flex; flex-direction: column; gap: 2px; margin-top: var(--space-3); }
  .chat-row {
    display: flex; align-items: center; gap: var(--space-3); width: 100%; text-align: left;
    padding: var(--space-3); border: 0; background: transparent; border-radius: var(--radius-md);
    cursor: pointer; color: var(--color-text);
  }
  .chat-row:hover { background: var(--color-surface-2); }
  .chat-row-body { flex: 1; min-width: 0; }
  .chat-row-top { display: flex; justify-content: space-between; gap: var(--space-2); align-items: baseline; }
  .chat-row-last { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* ---- Burbujas de mensaje (compartidas por las ventanitas) ---- */
  .msg-row { display: flex; }
  .msg-out { justify-content: flex-end; }
  .msg-in  { justify-content: flex-start; }
  .msg-bubble {
    max-width: 80%; padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-lg); position: relative; word-wrap: break-word; overflow-wrap: anywhere;
  }
  .msg-out .msg-bubble { background: var(--color-primary); color: var(--color-on-primary); border-bottom-right-radius: var(--radius-sm); }
  .msg-in  .msg-bubble { background: var(--color-surface-2); border-bottom-left-radius: var(--radius-sm); }
  .msg-text { white-space: pre-wrap; line-height: var(--leading-normal); font-size: var(--text-sm); }
  /* Mensaje que mandó tu agente (en TU hilo, con su foto+nombre) */
  .msg-by-assistant { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--node-message) 60%, transparent); }
  .msg-sender { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: var(--font-semibold); opacity: .85; margin-bottom: 3px; }
  .msg-sender .avatar-xs { width: 16px; height: 16px; }
  .msg-sender-ic { font-size: 12px; }
  .msg-meta { display: flex; align-items: center; gap: var(--space-2); justify-content: flex-end; margin-top: 2px; }
  .msg-time { font-size: 10px; opacity: .7; }
  .msg-save { border: 0; background: transparent; cursor: pointer; font-size: var(--text-xs); opacity: .55; padding: 0; }
  .msg-save:hover { opacity: 1; }

  /* ---- Inbox emergente (desde el FAB 💬) ---- */
  .inbox-panel {
    position: fixed; right: var(--space-5); bottom: calc(var(--space-5) + 210px);
    z-index: var(--z-modal); width: min(340px, 92vw); max-height: min(460px, 70vh);
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop-in var(--dur-base) var(--ease);
  }
  .inbox-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-soft); }
  .inbox-list { overflow-y: auto; padding: var(--space-2); }

  /* ---- Ventanitas de chat flotantes (estilo Messenger) ---- */
  .chat-dock { position: fixed; right: 0; bottom: 0; z-index: var(--z-sticky); pointer-events: none; }
  .chat-window {
    position: fixed; bottom: var(--space-5); width: 320px; height: 420px;
    display: flex; flex-direction: column; overflow: hidden; pointer-events: auto;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-lg);
    animation: pop-in var(--dur-base) var(--ease);
  }
  /* Plegado = pill compacto: solo avatar+nombre+cerrar; se empacan más (caben más). */
  .chat-window.min { height: auto; width: auto; max-width: 220px; border-radius: var(--radius-full); }
  .chat-window.min .cw-head { border-radius: var(--radius-full); padding: var(--space-1) var(--space-2) var(--space-1) var(--space-2); }
  .chat-window.min .cw-thread, .chat-window.min .cw-composer, .chat-window.min .cw-actions { display: none; }
  .chat-window.min .cw-name { max-width: 120px; }
  .cw-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3); background: var(--node-message); color: #fff; }
  .cw-title { display: flex; align-items: center; gap: var(--space-2); background: transparent; border: 0; color: #fff; cursor: pointer; min-width: 0; flex: 1; }
  .cw-name { font-weight: var(--font-semibold); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cw-btn { color: #fff; width: 26px; height: 26px; }
  .cw-btn:hover { background: rgba(255,255,255,.18); }
  .cw-thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3) var(--space-2); min-height: 0; }
  .cw-composer { display: flex; align-items: flex-end; gap: var(--space-1); padding: var(--space-2); border-top: 1px solid var(--color-border-soft); }
  .cw-input { flex: 1; resize: none; border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-2) var(--space-3); background: var(--color-bg); color: var(--color-text); max-height: 96px; font: inherit; font-size: var(--text-sm); }
  .cw-dir, .cw-send { flex: none; }
  .avatar-xs { width: 26px; height: 26px; border-radius: var(--radius-full); object-fit: cover; }
  .avatar-xs.avatar-ph { display: grid; place-items: center; background: var(--color-surface-2); }
  @media (max-width: 620px) {
    .chat-window { width: calc(100vw - var(--space-4) * 2); right: var(--space-4) !important; height: 70vh; }
    .chat-window ~ .chat-window { display: none; } /* en móvil, una a la vez */
  }

  /* ---- Pestañas (Configuración y otras vistas) ---- */
  .tabs { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-4) 0 var(--space-2); border-bottom: 1px solid var(--color-border-soft); }
  .tab {
    padding: var(--space-2) var(--space-3); border: 0; background: transparent; cursor: pointer;
    color: var(--color-text-muted); font-weight: var(--font-medium); font-size: var(--text-sm);
    border-bottom: 2px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  }
  .tab:hover { color: var(--color-text); background: var(--color-surface-2); }
  .tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
  .tab-panel.hidden { display: none; }

  /* ---- Tablero de WIDGETS componible (web + móvil, §8-quater) ---- */
  .home-bar { display: flex; justify-content: flex-end; margin-bottom: var(--space-3); }
  .home-grid { display: grid; grid-template-columns: repeat(var(--cols, 12), 1fr); grid-auto-rows: var(--row, 36px); gap: var(--gap, 8px); align-items: stretch; }
  .w-card { background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
  .w-head { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-soft); }
  .w-head strong { font-size: var(--text-sm); }
  .w-body { display: flex; flex-direction: column; }
  .w-row { display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left; padding: var(--space-2) var(--space-3); border: 0; background: transparent; color: var(--color-text); font-size: var(--text-sm); }
  button.w-row { cursor: pointer; }
  button.w-row:hover { background: var(--color-surface-2); }
  .w-chat { display: flex; flex-direction: column; flex: 1; min-height: 340px; }
  .w-chat .assistant-chat { flex: 1; min-height: 0; }
  .w-acc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px; }
  .w-acc-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 1px solid var(--color-border-soft); border-radius: var(--radius-md); background: transparent; cursor: pointer; color: var(--color-text); font-size: 11px; }
  .w-acc-tile:hover { background: var(--color-surface-2); }
  .w-acc-ic { font-size: 20px; }
  /* En el tablero, cada widget ocupa su rejilla (cols × rows) y su contenido scrollea. */
  .home-grid .w-card { position: relative; min-height: 0; }
  .home-grid .w-chat { min-height: 0; }
  .home-grid .w-card .w-body, .home-grid .w-card .m-cards { overflow-y: auto; flex: 1; min-height: 0; }

  /* Zoom SOLO del área de inicio (no toca topbar/menú) */
  .home-zoom { width: 100%; }
  /* Banda FIJA (Estados): fuera del zoom y del grid → siempre a tamaño real y usable */
  .home-status { margin-bottom: var(--space-4); }
  .home-status:empty { display: none; }
  .home-status .w-pinned { width: 100%; }

  /* Modo edición: cuadrícula VISIBLE (celdas finas) como guía de encaje */
  .home-grid.editing {
    min-height: 70vh;
    padding: 2px;
    border-radius: var(--radius-lg);
    background-color: var(--color-surface-2);
    background-image:
      linear-gradient(to right, var(--color-border) 1px, transparent 1px),
      linear-gradient(to bottom, var(--color-border) 1px, transparent 1px);
    background-size: var(--cell-w, 80px) var(--cell-h, 44px);
    background-position: 0 0;
    outline: 1px dashed var(--color-border-soft);
  }
  .home-grid.editing .w-card { cursor: grab; user-select: none; box-shadow: var(--shadow-sm); }
  .home-grid.editing .w-card:active { cursor: grabbing; }
  .home-grid.editing .w-card > :not(.w-rm):not(.w-rz) { pointer-events: none; }
  .home-grid .w-card.dragging { opacity: .55; outline: 2px solid var(--color-primary); z-index: 5; }

  /* Fantasma: marca el hueco destino */
  .w-ghost { display: none; border: 2px dashed var(--color-primary); border-radius: var(--radius-md); background: var(--color-surface); opacity: .35; pointer-events: none; z-index: 1; }

  .w-rm { position: absolute; top: 6px; right: 6px; z-index: 6; width: 24px; height: 24px; display: none; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: var(--color-surface-2); color: var(--color-danger); cursor: pointer; font-size: var(--text-sm); box-shadow: var(--shadow-sm); }
  .home-grid.editing .w-rm { display: flex; }

  /* 8 manijas de redimensión (lados + esquinas) — estiras hacia cualquier dirección */
  .w-rz { position: absolute; z-index: 6; display: none; touch-action: none; }
  .home-grid.editing .w-rz { display: block; }
  .w-rz-n { top: -4px; left: 10px; right: 10px; height: 9px; cursor: ns-resize; }
  .w-rz-s { bottom: -4px; left: 10px; right: 10px; height: 9px; cursor: ns-resize; }
  .w-rz-e { right: -4px; top: 10px; bottom: 10px; width: 9px; cursor: ew-resize; }
  .w-rz-w { left: -4px; top: 10px; bottom: 10px; width: 9px; cursor: ew-resize; }
  .w-rz-ne { top: -5px; right: -5px; width: 14px; height: 14px; cursor: nesw-resize; }
  .w-rz-nw { top: -5px; left: -5px; width: 14px; height: 14px; cursor: nwse-resize; }
  .w-rz-se { bottom: -5px; right: -5px; width: 14px; height: 14px; cursor: nwse-resize; }
  .w-rz-sw { bottom: -5px; left: -5px; width: 14px; height: 14px; cursor: nesw-resize; }
  .home-grid.editing .w-rz-ne, .home-grid.editing .w-rz-nw, .home-grid.editing .w-rz-se, .home-grid.editing .w-rz-sw {
    background: var(--color-primary); border: 2px solid var(--color-surface); border-radius: 3px;
  }

  @media (max-width: 760px) {
    .home-grid { grid-template-columns: 1fr !important; grid-auto-rows: auto !important; }
    .home-grid .w-card { grid-column: 1 / -1 !important; grid-row: auto !important; }
    .home-grid.editing { min-height: 0; }
  }

  /* Botón expandir del widget asistente (abre el módulo completo) */
  .w-chat { position: relative; }
  .w-expand { position: absolute; top: 6px; right: 6px; z-index: 2; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--color-border-soft); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); cursor: pointer; opacity: .65; }
  .w-expand:hover { opacity: 1; background: var(--color-surface-2); }

  /* ---- Módulo ASISTENTE IA (chat completo, estilo ChatGPT) ---- */
  .ai-app { display: flex; gap: var(--space-4); height: calc(100dvh - 150px); min-height: 440px; }
  .ai-side { width: 280px; flex: none; display: flex; flex-direction: column; gap: var(--space-3); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); padding: var(--space-3); background: var(--color-surface); overflow: hidden; }
  .ai-side-sec { display: flex; flex-direction: column; gap: 4px; min-height: 0; }
  .ai-side-grow { flex: 1; min-height: 0; }
  .ai-side-h { display: flex; align-items: center; justify-content: space-between; font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .04em; padding: 0 4px; }
  .ai-projects { display: flex; flex-direction: column; gap: 2px; }
  .ai-proj { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; padding: 6px 8px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text); cursor: pointer; font-size: var(--text-sm); }
  .ai-proj .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ai-proj:hover { background: var(--color-surface-2); }
  .ai-proj.on { background: var(--color-surface-2); font-weight: 600; }
  .ai-proj-x { opacity: 0; color: var(--color-danger); font-size: 11px; }
  .ai-proj:hover .ai-proj-x { opacity: .7; }
  .ai-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
  .ai-row { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: var(--radius-md); cursor: pointer; }
  .ai-row:hover { background: var(--color-surface-2); }
  .ai-row.on { background: var(--color-surface-2); box-shadow: inset 2px 0 0 var(--color-primary); }
  .ai-row-t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); }
  .ai-badge { font-size: 10px; color: var(--color-text-muted); white-space: nowrap; }
  .ai-row-acts { display: none; }
  .ai-row:hover .ai-row-acts { display: flex; }
  .ai-mini { width: 24px; height: 24px; border: 0; background: transparent; cursor: pointer; font-size: 12px; border-radius: var(--radius-sm); }
  .ai-mini:hover { background: var(--color-bg); }
  .ai-main { flex: 1; min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); overflow: hidden; background: var(--color-surface); }
  .ai-main-head { display: flex; flex-direction: column; gap: 6px; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-soft); }
  .ai-head-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
  .ai-main-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ai-main-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .ai-input { width: 100%; box-sizing: border-box; padding: var(--space-2) var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg); color: var(--color-text); font-size: var(--text-sm); }
  .ai-side-config { margin-top: 4px; padding: 8px 10px; border: 1px solid var(--color-border-soft); border-radius: var(--radius-md); background: transparent; color: var(--color-text); cursor: pointer; font-size: var(--text-sm); text-align: left; }
  .ai-side-config:hover { background: var(--color-surface-2); }
  .ai-config-wrap { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-4); }

  /* Conversación centrada en columna (no pegada a la izquierda) — estilo asistentes actuales */
  .ai-main-body .assistant-log,
  .ai-main-body .assistant-foot { padding-left: max(var(--space-3), calc((100% - 820px) / 2)); padding-right: max(var(--space-3), calc((100% - 820px) / 2)); }

  /* Etiquetas: nube lateral (grafo) */
  .ai-tags-cloud { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 2px; }
  .ai-tagf { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border: 1px solid var(--color-border-soft); border-radius: var(--radius-full); background: transparent; color: var(--color-text); cursor: pointer; font-size: var(--text-xs); }
  .ai-tagf:hover { background: var(--color-surface-2); }
  .ai-tagf.on { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }
  .ai-tagf-n { opacity: .6; font-size: 10px; }

  /* Etiquetas: chips mini en la lista de conversaciones */
  .ai-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .ai-row-tags { display: flex; gap: 4px; overflow: hidden; }
  .ai-tag-mini { font-size: 10px; color: var(--color-text-muted); white-space: nowrap; }

  /* Etiquetas: editor en la cabecera del chat */
  .ai-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
  .ai-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border-radius: var(--radius-full); background: var(--color-surface-2); font-size: var(--text-xs); }
  .ai-tag-x { border: 0; background: transparent; cursor: pointer; color: var(--color-text-muted); font-size: 10px; padding: 0 2px; }
  .ai-tag-x:hover { color: var(--color-danger); }
  .ai-tag-add, .ai-tag-auto { border: 1px dashed var(--color-border); background: transparent; color: var(--color-text-muted); cursor: pointer; font-size: var(--text-xs); padding: 2px 8px; border-radius: var(--radius-full); }
  .ai-tag-add:hover, .ai-tag-auto:hover { background: var(--color-surface-2); color: var(--color-text); }

  @media (max-width: 760px) {
    .ai-app { flex-direction: column; height: auto; }
    .ai-side { width: auto; max-height: 40vh; }
    .ai-main { min-height: 60vh; }
  }

  .view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border-soft);
    gap: var(--space-4);
  }
  .view-header h1 { font-size: var(--text-xl); }
  .graph-metrics { margin-top: var(--space-1); }

  .stack { display: grid; gap: var(--space-4); }
  .row   { display: flex; gap: var(--space-3); align-items: center; }
  .grid-cards {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  @media (max-width: 760px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
      flex-direction: row; flex-wrap: wrap; align-items: center;
      border-right: 0; border-bottom: 1px solid var(--color-border-soft);
    }
    .sidebar-foot { margin: 0; }
    .nav { display: flex; gap: var(--space-2); }
  }
}

/* ----------------------------------------------------------- COMPONENTS --- */
@layer components {

  /* Marca / nav */
  .brand { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--font-bold); font-size: var(--text-lg); letter-spacing: -.02em; }
  .brand-logo {
    font-size: var(--text-md); width: 34px; height: 34px; display: grid; place-items: center;
    border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
    background: linear-gradient(135deg, color-mix(in srgb, var(--color-primary) 30%, var(--color-surface-2)), var(--color-surface-2));
  }
  .nav { display: grid; gap: var(--space-1); }
  .nav-item {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-weight: var(--font-medium);
    position: relative;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }
  .nav-item:hover { background: var(--color-surface-2); color: var(--color-text); }
  .nav-item.active {
    background: color-mix(in srgb, var(--color-primary) 16%, transparent);
    color: var(--color-text); font-weight: var(--font-semibold);
  }
  .nav-item.active::before {
    content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 60%; border-radius: var(--radius-full); background: var(--color-primary);
  }

  .nav-toggle { font-size: var(--text-lg); line-height: 1; padding: var(--space-1) var(--space-2); border-radius: var(--radius-md); }
  .nav-toggle:hover { background: var(--color-surface-2); }

  .user-row { display: flex; align-items: center; justify-content: space-between; font-size: var(--text-sm); }
  .link { color: var(--color-primary-hover); }
  .muted { color: var(--color-text-muted); }

  /* Botones */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    color: var(--color-text);
    cursor: pointer; white-space: nowrap;
    font-weight: var(--font-semibold); font-size: var(--text-sm); letter-spacing: .01em;
    transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  }
  .btn:hover { background: var(--color-surface-hover); transform: translateY(-1px); }
  .btn:active { transform: translateY(0); }
  .btn-primary { background: var(--color-primary); color: var(--color-on-primary); box-shadow: 0 4px 14px color-mix(in srgb, var(--color-primary) 38%, transparent); }
  .btn-primary:hover { background: var(--color-primary-hover); box-shadow: 0 6px 18px color-mix(in srgb, var(--color-primary) 45%, transparent); }
  .btn-danger { background: var(--color-danger); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--color-danger) 32%, transparent); }
  .btn-danger:hover { background: var(--color-danger-hover); }
  .btn-ghost { background: transparent; border-color: var(--color-border); box-shadow: none; }
  .btn-ghost:hover { background: var(--color-surface-2); }
  .btn-block { width: 100%; }
  .btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }

  /* Selector visual de tipo (capturar) */
  .field-label { display: block; color: var(--color-text-muted); font-size: var(--text-sm); margin-bottom: var(--space-2); }
  .type-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: var(--space-2); }
  .type-tile {
    display: flex; flex-direction: column; align-items: center; gap: var(--space-1);
    padding: var(--space-2); border: 1px solid var(--color-border); border-radius: var(--radius-md);
    background: var(--color-surface-2); cursor: pointer; font-size: var(--text-xs); color: var(--color-text);
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  }
  .type-tile:hover { background: var(--color-surface-hover); transform: translateY(-1px); }
  .type-tile.active { border-color: var(--color-primary); background: color-mix(in srgb, var(--color-primary) 16%, var(--color-surface-2)); }
  .type-tile-ico { font-size: var(--text-lg); }
  .type-guide { font-size: var(--text-sm); padding: var(--space-2) var(--space-3); background: var(--color-surface-2); border-radius: var(--radius-md); line-height: var(--leading-normal); }

  /* Campos de formulario */
  .field { display: grid; gap: var(--space-2); font-size: var(--text-sm); }
  .field > span { color: var(--color-text-muted); }
  .field input, .field textarea, .field select {
    width: 100%;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
  }
  .field textarea { resize: vertical; min-height: 90px; }
  .field-check { display: flex; align-items: center; gap: var(--space-2); }
  .field-check input { width: auto; }

  /* Tarjetas */
  .card {
    background: var(--color-surface);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
  }
  .card-title { font-weight: var(--font-bold); margin-bottom: var(--space-1); letter-spacing: -.01em; }
  .stat-num { font-size: var(--text-2xl); font-weight: var(--font-bold); letter-spacing: -.02em; }
  h1, h2 { letter-spacing: -.02em; }
  h2 { font-size: var(--text-lg); }

  /* Chips de tipo de nodo */
  .chip {
    display: inline-flex; align-items: center; gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--color-on-primary);
  }

  /* Cabecera hero (ficha / perfil) */
  .detail-back { margin-bottom: var(--space-3); }
  .hero-card {
    display: flex; gap: var(--space-5); align-items: flex-start;
    background: var(--color-surface); border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-sm);
  }
  .hero-card h1 { font-size: var(--text-2xl); }
  @media (max-width: 560px) { .hero-card { flex-direction: column; align-items: center; text-align: center; } }

  /* Perfil con PORTADA (estilo Facebook) */
  .profile-card { background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
  .profile-cover {
    position: relative; height: 200px; background-size: cover; background-position: center;
    background-color: var(--color-surface-2);
    background-image: linear-gradient(120deg, color-mix(in srgb, var(--color-primary) 35%, transparent), color-mix(in srgb, var(--node-topic) 35%, transparent));
  }
  .cover-change { position: absolute; right: var(--space-3); bottom: var(--space-3); background: rgba(0,0,0,.55); color: #fff; border: 0; }
  .cover-change:hover { background: rgba(0,0,0,.72); }
  .profile-main { display: flex; gap: var(--space-4); align-items: flex-start; padding: 0 var(--space-5) var(--space-5); }
  .profile-main .avatar-lg { width: 120px; height: 120px; margin-top: -52px; }
  .profile-main .grow { padding-top: var(--space-3); }
  .profile-card h1 { font-size: var(--text-2xl); }
  @media (max-width: 560px) { .profile-main { flex-direction: column; align-items: center; text-align: center; } }

  /* Avatar grande (ficha de amigo / perfil) */
  .avatar-lg {
    width: 96px; height: 96px; border-radius: var(--radius-full); object-fit: cover;
    box-shadow: 0 0 0 3px var(--color-surface), 0 0 0 5px color-mix(in srgb, var(--color-primary) 45%, transparent), var(--shadow-md);
  }
  /* Avatar pequeño (agenda, chips) */
  .avatar-sm { width: 26px; height: 26px; border-radius: var(--radius-full); object-fit: cover; flex: 0 0 auto; }
  .avatar-ph { display: inline-grid; place-items: center; background: var(--color-surface-2); font-size: var(--text-sm); }

  /* Buscador global directo (en topbar) */
  .topbar-search { position: relative; }
  .topbar-search-input {
    width: 240px; max-width: 40vw; padding: var(--space-1) var(--space-3);
    background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-full);
    color: var(--color-text); outline: none;
  }
  .topbar-search-input:focus { border-color: var(--color-focus-ring); }
  .topbar-search-results {
    position: absolute; top: calc(100% + var(--space-2)); left: 0;
    width: min(420px, 80vw); max-height: 60vh; overflow-y: auto; z-index: var(--z-modal);
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--space-2);
    animation: pop-in var(--dur-fast) var(--ease);
  }
  @media (max-width: 640px) { .topbar-search-input { width: 130px; } .topbar-search-results { width: 80vw; } }

  /* (Antiguo command palette — reutiliza estilos de fila) */
  .palette-bg { position: fixed; inset: 0; z-index: var(--z-modal); background: rgba(0,0,0,.5); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
  .palette { width: min(560px, 92vw); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; animation: pop-in var(--dur-base) var(--ease); }
  .palette-top { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-soft); }
  .palette-input { flex: 1; border: 0; background: transparent; outline: none; font-size: var(--text-lg); }
  .palette-kbd { font-size: var(--text-xs); color: var(--color-text-muted); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 0 var(--space-1); }
  .palette-results { max-height: 56vh; overflow-y: auto; padding: var(--space-2); }
  .palette-empty { padding: var(--space-5); text-align: center; color: var(--color-text-muted); }
  .palette-row { display: flex; align-items: center; gap: var(--space-3); width: 100%; text-align: left; padding: var(--space-2) var(--space-3); border: 0; background: transparent; border-radius: var(--radius-md); cursor: pointer; }
  .palette-row:hover { background: var(--color-surface-2); }
  .palette-ico { width: 26px; text-align: center; font-size: var(--text-lg); }

  /* Lightbox de fotos/videos */
  .lightbox {
    position: fixed; inset: 0; z-index: var(--z-toast);
    background: rgba(0,0,0,.88); display: grid; place-items: center; padding: var(--space-5);
    animation: pop-in var(--dur-base) var(--ease);
  }
  .lightbox-stage { display: grid; place-items: center; }
  .lightbox-media { max-width: 90vw; max-height: 86vh; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); }
  .lightbox-x { position: fixed; top: var(--space-4); right: var(--space-5); background: rgba(0,0,0,.5); color: #fff; border: 0; border-radius: var(--radius-full); width: 40px; height: 40px; font-size: var(--text-lg); cursor: pointer; }
  .lightbox-nav { position: fixed; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.5); color: #fff; border: 0; border-radius: var(--radius-full); width: 48px; height: 48px; font-size: var(--text-lg); cursor: pointer; }
  .lightbox-prev { left: var(--space-4); } .lightbox-next { right: var(--space-4); }
  .lightbox-nav:hover, .lightbox-x:hover { background: rgba(0,0,0,.75); }
  .lightbox-counter { position: fixed; bottom: var(--space-5); left: 50%; transform: translateX(-50%); color: #fff; font-size: var(--text-sm); opacity: .85; }

  /* Galería de recuerdos (media) */
  .media-thumb img, .media-thumb video { cursor: zoom-in; }
  .media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: var(--space-3); }
  .media-thumb { position: relative; aspect-ratio: 1; border-radius: var(--radius-md); overflow: hidden; background: var(--color-surface-2); }
  .media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
  .media-del {
    position: absolute; top: var(--space-1); right: var(--space-1); display: none;
    width: 24px; height: 24px; border-radius: var(--radius-full); border: 0; cursor: pointer;
    background: rgba(0,0,0,.6); color: #fff; font-size: var(--text-xs);
  }
  .media-thumb:hover .media-del { display: block; }
  .media-share {
    position: absolute; top: var(--space-1); left: var(--space-1); display: none;
    width: 24px; height: 24px; border-radius: var(--radius-full); border: 0; cursor: pointer;
    background: rgba(0,0,0,.6); color: #fff; font-size: var(--text-xs);
  }
  .media-thumb:hover .media-share { display: block; }
  .share-link { flex: 1; min-width: 200px; font-size: var(--text-sm); padding: var(--space-2) var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg); color: var(--color-text); }

  /* Nudges "Para ti" */
  .nudge {
    display: flex; align-items: center; gap: var(--space-3); width: 100%; text-align: left;
    padding: var(--space-3); border: 1px solid var(--color-border-soft); border-radius: var(--radius-md);
    background: var(--color-surface-2); cursor: pointer;
    transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  }
  .nudge:hover { background: var(--color-surface-hover); transform: translateX(2px); }

  /* Tarjeta de evento con portada */
  .event-cover { width: 100%; height: 130px; object-fit: cover; display: block; }
  .event-cover-ph { display: grid; place-items: center; font-size: var(--text-2xl); background: color-mix(in srgb, var(--node-event) 16%, var(--color-surface-2)); }
  .event-card { transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
  .event-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

  /* Inicio: lienzo cálido */
  .home-hero { margin-bottom: var(--space-4); }
  .home-hero h1 { font-size: var(--text-2xl); }
  .friend-chip {
    display: inline-flex; align-items: center; gap: var(--space-1);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    background: var(--color-surface); border: 1px solid var(--color-border);
    cursor: pointer; font-size: var(--text-sm); font-weight: var(--font-medium);
    transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  }
  .friend-chip:hover { background: var(--color-surface-2); transform: translateY(-1px); }
  .friend-chip:active { transform: translateY(0); }
  .friend-chip-add { border-style: dashed; color: var(--color-text-muted); }
  .friend-chip-on { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }

  /* Respuesta del asistente IA */
  .ai-answer {
    margin-top: var(--space-2); padding: var(--space-3) var(--space-4);
    background: color-mix(in srgb, var(--color-primary) 8%, var(--color-surface-2));
    border: 1px solid color-mix(in srgb, var(--color-primary) 25%, var(--color-border-soft));
    border-radius: var(--radius-md); white-space: pre-wrap; line-height: var(--leading-normal);
  }

  /* Grid de configuración */
  .settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4); }

  /* Notas estilo Keep */
  .keep-composer { max-width: 620px; margin: 0 auto var(--space-5); padding: var(--space-3) var(--space-4); }
  .keep-input {
    width: 100%; border: 0; background: transparent; resize: none; outline: none;
    font-size: var(--text-md); line-height: var(--leading-normal); overflow: hidden;
  }
  .keep-tools { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-2); flex-wrap: wrap; }
  .keep-who {
    padding: var(--space-2) var(--space-3); background: var(--color-bg);
    border: 1px solid var(--color-border); border-radius: var(--radius-md);
    color: var(--color-text); max-width: 220px;
  }
  .type-pick {
    border: 1px solid var(--color-border); background: transparent; cursor: pointer;
    padding: var(--space-1) var(--space-2); border-radius: var(--radius-full);
    font-size: var(--text-xs); color: var(--color-text-muted);
    transition: all var(--dur-fast) var(--ease);
  }
  .type-pick:hover { background: var(--color-surface-2); }
  .type-pick.active { color: var(--color-on-primary); background: var(--c); border-color: var(--c); }

  .keep-board { columns: 250px; column-gap: var(--space-4); }
  .keep-card {
    break-inside: avoid; margin: 0 0 var(--space-4); cursor: pointer;
    background: color-mix(in srgb, var(--c) 10%, var(--color-surface));
    border: 1px solid color-mix(in srgb, var(--c) 30%, var(--color-border-soft));
    border-radius: var(--radius-lg); padding: var(--space-4);
    transition: box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
    position: relative;
  }
  .keep-card { animation: pop-in var(--dur-base) var(--ease) both; }
  .keep-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
  .keep-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); }
  .keep-card-head strong { font-weight: var(--font-semibold); }
  .keep-dot { width: 10px; height: 10px; border-radius: var(--radius-full); background: var(--c); flex: 0 0 auto; margin-top: 4px; }
  .keep-card-body { margin-top: var(--space-2); white-space: pre-wrap; color: var(--color-text); font-size: var(--text-sm); }
  .keep-card-foot { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }
  .keep-card-actions { position: absolute; top: var(--space-2); right: var(--space-2); display: none; gap: var(--space-1); }
  .keep-card:hover .keep-card-actions { display: flex; }

  /* Barras del panel de actividad */
  .bars { display: grid; gap: var(--space-2); }
  .bar-row { display: grid; grid-template-columns: 96px 1fr 40px; gap: var(--space-3); align-items: center; }
  .bars-compact .bar-row { grid-template-columns: 44px 1fr 34px; }
  .bar-label { color: var(--color-text-muted); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bar-track { background: var(--color-surface-2); border-radius: var(--radius-full); height: 14px; overflow: hidden; }
  .bar-fill { display: block; height: 100%; background: var(--color-primary); border-radius: var(--radius-full); min-width: 2px; }
  .bar-val { text-align: right; color: var(--color-text-muted); font-size: var(--text-sm); }

  /* Calendario más vivo (FullCalendar v6) */
  .cal-card { padding: var(--space-4); }
  .cal-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-3); font-size: var(--text-xs); color: var(--color-text-muted); }
  .cal-legend-item { display: inline-flex; align-items: center; gap: var(--space-1); }
  .cal-dot { width: 10px; height: 10px; border-radius: var(--radius-full); display: inline-block; }

  .fc {
    --fc-border-color: var(--color-border-soft);
    --fc-page-bg-color: transparent;
    --fc-neutral-bg-color: var(--color-surface-2);
    --fc-today-bg-color: color-mix(in srgb, var(--color-primary) 14%, transparent);
    --fc-button-bg-color: var(--color-surface-2);
    --fc-button-border-color: var(--color-border);
    --fc-button-hover-bg-color: var(--color-surface-hover);
    --fc-button-active-bg-color: var(--color-primary);
    --fc-button-text-color: var(--color-text);
    font-size: var(--text-sm);
  }
  .fc .fc-toolbar-title { font-size: var(--text-lg); font-weight: var(--font-bold); text-transform: capitalize; }
  .fc .fc-button { border-radius: var(--radius-md); font-weight: var(--font-medium); padding: var(--space-1) var(--space-3); text-transform: capitalize; box-shadow: none; }
  .fc .fc-daygrid-day-frame { border-radius: var(--radius-md); }
  .fc .fc-daygrid-day.fc-day-today { border-radius: var(--radius-md); }
  .fc .fc-daygrid-day-number { font-weight: var(--font-medium); padding: var(--space-1) var(--space-2); }
  .fc .fc-daygrid-event {
    border: 0; border-radius: var(--radius-full); padding: 1px var(--space-2);
    font-size: var(--text-xs); font-weight: var(--font-medium);
    box-shadow: var(--shadow-sm);
    transition: transform var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease);
  }
  .fc .fc-daygrid-event:hover { transform: translateY(-1px) scale(1.02); filter: brightness(1.08); cursor: pointer; }
  .fc .fc-col-header-cell-cushion { color: var(--color-text-muted); text-transform: uppercase; font-size: var(--text-xs); letter-spacing: .04em; }
  .fc .fc-list-event:hover td { background: var(--color-surface-2); }
  .fc-theme-standard .fc-list-day-cushion { background: var(--color-surface-2); }

  /* Badge de estado (consume color del token --badge inyectado en línea) */
  .badge {
    display: inline-flex; align-items: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs); font-weight: var(--font-medium);
    color: var(--badge, var(--color-text-muted));
    border: 1px solid var(--badge, var(--color-border));
    background: color-mix(in srgb, var(--badge, var(--color-surface-2)) 14%, transparent);
  }

  /* Pills (participantes, relacionados) */
  .pill {
    display: inline-flex; align-items: center; gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border-soft);
    font-size: var(--text-sm); font-weight: var(--font-medium);
    transition: background var(--dur-fast) var(--ease);
  }
  .pill:hover { background: var(--color-surface-hover); }
  .pill-sm { padding: 2px var(--space-2); font-size: var(--text-xs); font-weight: var(--font-normal); }
  .gap-1 { gap: var(--space-1); }
  .pill-x {
    border: 0; background: transparent; cursor: pointer;
    color: var(--color-text-muted); font-size: var(--text-xs); padding: 0;
  }
  .pill-x:hover { color: var(--color-danger); }

  /* Timeline / bitácora de avances */
  .timeline { display: grid; gap: var(--space-4); padding-left: var(--space-3); }
  .timeline-item {
    position: relative; display: grid; grid-template-columns: auto 1fr; gap: var(--space-3);
    padding-left: var(--space-4);
    border-left: 2px solid var(--color-border);
    animation: pop-in var(--dur-base) var(--ease) both;
  }
  .timeline-item:last-child { border-left-color: transparent; }
  .timeline-dot {
    position: absolute; left: calc(var(--space-1) * -1); top: var(--space-1);
    width: 12px; height: 12px; border-radius: var(--radius-full);
    background: var(--node-update, var(--color-success));
    border: 2px solid var(--color-surface);
  }
  .timeline-body {
    grid-column: 2;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
    padding: var(--space-3);
  }

  /* Tabla agenda */
  .table { width: 100%; border-collapse: collapse; }
  .table th, .table td {
    text-align: left; padding: var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--color-border-soft);
  }
  .table th { color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--font-semibold); text-transform: uppercase; letter-spacing: .06em; }
  .table tbody tr { transition: background var(--dur-fast) var(--ease); }
  .table tbody tr:hover td { background: var(--color-surface-2); }
  .table tbody tr:last-child td { border-bottom: 0; }

  /* Alertas */
  .alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); }
  .alert-error { background: color-mix(in srgb, var(--color-danger) 18%, transparent); color: var(--color-danger-hover); }

  /* Empty states */
  .empty {
    display: grid; place-items: center; gap: var(--space-3);
    padding: var(--space-8); text-align: center; color: var(--color-text-muted);
  }
  .empty-emoji { font-size: var(--text-2xl); }

  /* Grafo */
  #graph-canvas { width: 100%; height: 100%; min-height: 420px; }
  .graph-wrap { display: flex; gap: var(--space-4); height: calc(100vh - 190px); }
  .graph-canvas-box {
    flex: 1; min-width: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }
  /* Tercera columna: info + acciones del nodo */
  .graph-inspector {
    width: 320px; flex: 0 0 320px; overflow-y: auto;
    background: var(--color-surface); border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-lg); padding: var(--space-4);
    display: flex; flex-direction: column; gap: var(--space-3);
    animation: pop-in var(--dur-base) var(--ease);
  }
  .insp-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
  .insp-head strong { font-size: var(--text-lg); }
  .insp-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  @media (max-width: 820px) {
    .graph-wrap { flex-direction: column; height: auto; }
    .graph-inspector { width: 100%; flex: none; }
    #graph-canvas { height: 60vh; }
  }

  /* Modal */
  .modal-backdrop {
    position: fixed; inset: 0; z-index: var(--z-modal);
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(4px);
    display: grid; place-items: center; padding: var(--space-4);
  }
  .modal {
    width: min(560px, 100%);
    max-height: 90vh; overflow: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-5);
    animation: modal-in var(--dur-base) var(--ease);
  }
  @keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
  .modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
  .modal-title { font-size: var(--text-lg); font-weight: var(--font-semibold); }
  .modal-actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-5); }
  .icon-btn { background: transparent; border: 0; cursor: pointer; font-size: var(--text-lg); color: var(--color-text-muted); }

  /* Toast */
  .toast-root {
    position: fixed; right: var(--space-5); bottom: calc(var(--space-5) + 72px);
    z-index: var(--z-toast); display: grid; gap: var(--space-2);
  }

  /* Asistente flotante: justo encima de la footbar de FABs (ahora horizontales) */
  .assistant-panel {
    position: fixed; right: var(--space-5); bottom: calc(var(--space-5) + 72px);
    z-index: var(--z-modal); width: min(370px, 92vw); height: min(500px, 72vh);
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    animation: pop-in var(--dur-base) var(--ease);
  }
  .assistant-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-soft); }
  .assistant-log { flex: 1; overflow-y: auto; padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
  .assistant-msg { padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); max-width: 85%; white-space: pre-wrap; font-size: var(--text-sm); line-height: var(--leading-normal); }
  .assistant-msg.typing::after { content: '▋'; margin-left: 1px; opacity: .45; animation: blink 1s steps(1) infinite; }
  @keyframes blink { 50% { opacity: 0; } }
  @media (prefers-reduced-motion: reduce) { .assistant-msg.typing::after { animation: none; } }
  .assistant-user { align-self: flex-end; background: var(--color-primary); color: var(--color-on-primary); border-bottom-right-radius: var(--radius-sm); }
  .assistant-ai { align-self: flex-start; background: var(--color-surface-2); border-bottom-left-radius: var(--radius-sm); }
  /* Markdown dentro de las respuestas de la IA */
  .assistant-msg .md-pre { background: var(--color-bg); border: 1px solid var(--color-border-soft); border-radius: var(--radius-sm); padding: var(--space-2); overflow-x: auto; margin: 4px 0; font-size: 12px; white-space: pre; }
  .assistant-msg .md-code { background: var(--color-bg); border: 1px solid var(--color-border-soft); border-radius: 4px; padding: 0 4px; font-size: .92em; }
  .assistant-msg .md-ul, .assistant-msg .md-ol { margin: 4px 0; padding-left: 20px; }
  .assistant-msg .md-ul li, .assistant-msg .md-ol li { margin: 2px 0; }
  .assistant-msg .md-h { font-weight: var(--font-bold); margin: 6px 0 2px; }
  .assistant-msg .md-h1 { font-size: 1.12em; } .assistant-msg .md-h2 { font-size: 1.06em; } .assistant-msg .md-h3 { font-size: 1em; }
  .assistant-msg a { color: inherit; text-decoration: underline; }
  .assistant-foot { display: flex; gap: var(--space-2); padding: var(--space-3); border-top: 1px solid var(--color-border-soft); }
  .assistant-input { flex: 1; resize: none; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); background: var(--color-bg); max-height: 120px; }
  .assistant-head-actions { display: flex; align-items: center; gap: var(--space-1); }
  /* Botón de voz: rojo + pulso cuando está activo */
  .voice-btn.voice-on { color: var(--color-danger); }
  .voice-btn.voice-on { animation: voicepulse 1.4s ease-in-out infinite; }
  .voice-btn.voice-connecting { opacity: .55; }
  @keyframes voicepulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.14); } }
  @media (prefers-reduced-motion: reduce) { .voice-btn.voice-on { animation: none; } }

  /* Sistema de iconos (emoji a color ↔ línea SVG) */
  .ico { display: inline-flex; align-items: center; justify-content: center; line-height: 1; vertical-align: -0.12em; }
  .ico-svg { width: 1.15em; height: 1.15em; }
  .ico-svg svg { width: 100%; height: 100%; display: block; }
  /* Sobre fondos de color (FAB, botones, cabeceras) el icono sigue el color del contenedor */
  .fab, .cw-head, .btn-primary, .btn-danger, .friend-chip-on, .assistant-user,
  .w-segbtn.on, .ai-tagf.on, .ai-row.on { --ico-color: currentColor; }

  /* Área de Apariencia */
  .appr-row { display: flex; gap: var(--space-3); flex-wrap: wrap; }
  .appr-opt { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); border: 2px solid var(--color-border-soft); border-radius: var(--radius-lg); background: var(--color-surface); cursor: pointer; font-size: var(--text-sm); }
  .appr-opt:hover { background: var(--color-surface-2); }
  .appr-opt.on { border-color: var(--color-primary); }
  .appr-opt .ico { font-size: 22px; }
  .appr-swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  .appr-swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--color-border); cursor: pointer; padding: 0; }
  .appr-swatch.on { outline: 2px solid var(--color-text); outline-offset: 2px; }
  .appr-preview { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: 30px; padding: var(--space-4); border: 1px solid var(--color-border-soft); border-radius: var(--radius-lg); background: var(--color-surface); }
  /* Tarjeta de confirmación para acciones destructivas propuestas por la IA */
  .assistant-pending {
    align-self: flex-start; max-width: 85%;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-danger, #dc2626);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    display: flex; flex-direction: column; gap: var(--space-2);
    font-size: var(--text-sm);
  }
  .assistant-pending-text { line-height: var(--leading-normal); }
  .assistant-pending-actions { display: flex; gap: var(--space-2); }

  /* Clúster de botones flotantes (capturar · asistente · mensajes) */
  .fab-stack {
    position: fixed; right: var(--space-5); bottom: var(--space-5);
    z-index: var(--z-sticky);
    display: flex; flex-direction: row; align-items: center; gap: var(--space-3);
  }
  .fab {
    width: 56px; height: 56px; border-radius: var(--radius-full);
    border: 0; cursor: pointer;
    background: var(--color-primary); color: var(--color-on-primary);
    font-size: var(--text-2xl); line-height: 1;
    box-shadow: var(--shadow-lg);
    display: grid; place-items: center;
    transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease);
  }
  .fab:hover { background: var(--color-primary-hover); transform: translateY(-2px) scale(1.04); }
  .fab:active { transform: translateY(0) scale(0.98); }
  /* Secundarios del clúster: más pequeños y con su color de marca */
  /* Las 3 burbujas del clúster, del MISMO tamaño */
  .fab-sm { width: 56px; height: 56px; font-size: var(--text-2xl); }
  .fab-assistant { background: var(--node-topic); color: #fff; }
  .fab-assistant:hover { background: var(--node-topic); filter: brightness(1.12); }
  .fab-chat { background: var(--node-message); color: #fff; }
  .fab-chat:hover { background: var(--node-message); filter: brightness(1.12); }
  .toast {
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    animation: toast-in var(--dur-base) var(--ease);
  }
  .toast-success { border-left: 3px solid var(--color-success); }
  .toast-error   { border-left: 3px solid var(--color-danger); }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

  /* Auth */
  .auth-body {
    display: grid; place-items: center; min-height: 100vh; padding: var(--space-4);
    background:
      radial-gradient(900px 500px at 50% -8%, color-mix(in srgb, var(--color-primary) 22%, transparent), transparent 60%),
      radial-gradient(700px 400px at 90% 110%, color-mix(in srgb, var(--node-topic) 16%, transparent), transparent 60%),
      var(--color-bg);
  }
  .auth-card {
    width: min(400px, 100%);
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-8) var(--space-6);
    display: grid; gap: var(--space-5);
    backdrop-filter: blur(8px);
  }
  .auth-brand { text-align: center; display: grid; gap: var(--space-2); justify-items: center; }
  .auth-logo {
    font-size: var(--text-2xl); width: 64px; height: 64px; display: grid; place-items: center;
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, color-mix(in srgb, var(--color-primary) 30%, var(--color-surface-2)), var(--color-surface-2));
  }
  .auth-brand h1 { font-size: var(--text-2xl); }
}

/* --------------------------------------------------- ETIQUETAS (#tags) --- */
@layer components {
  /* Preview de las #etiquetas detectadas bajo la caja de captura. */
  .tag-preview { display: flex; flex-wrap: wrap; gap: var(--space-1); }
  .tag-preview:empty { display: none; }
  .tag-chip {
    background: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface-2));
    color: var(--color-primary); border: none;
  }
  /* Typeahead de etiquetas existentes (reusar > crear). */
  .tag-suggest {
    position: absolute; left: var(--space-3); right: var(--space-3); z-index: 30;
    margin-top: var(--space-1); padding: var(--space-1);
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    max-height: 240px; overflow: auto;
  }
  .tag-suggest-hint { font-size: var(--text-xs); color: var(--color-text-muted); padding: var(--space-1) var(--space-2); }
  .tag-suggest-item {
    display: flex; justify-content: space-between; align-items: center; gap: var(--space-2);
    width: 100%; text-align: left; padding: var(--space-2);
    background: none; border: none; border-radius: var(--radius-sm);
    color: var(--color-text); font-size: var(--text-sm); cursor: pointer;
  }
  .tag-suggest-item:hover { background: var(--color-surface-hover); }
  /* Nube de etiquetas (filtro en Notas). */
  .tag-cloud { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
  .tag-cloud-chip {
    display: inline-flex; align-items: center; gap: var(--space-1);
    padding: 2px var(--space-2); font-size: var(--text-sm);
    background: var(--color-surface-2); color: var(--color-text);
    border: 1px solid var(--color-border); border-radius: var(--radius-full); cursor: pointer;
  }
  .tag-cloud-chip:hover { background: var(--color-surface-hover); }
  .tag-cloud-chip.on { background: var(--color-primary); color: var(--color-on-primary); border-color: transparent; }
  .tag-cloud-chip .tag-cloud-n { font-size: var(--text-xs); opacity: .7; }
}

/* ----------------------------------------------------------- UTILITIES --- */
@layer utilities {
  .hidden { display: none !important; }
  .text-sm { font-size: var(--text-sm); }
  .text-muted { color: var(--color-text-muted); }
  .mt-2 { margin-top: var(--space-2); }
  .mt-4 { margin-top: var(--space-4); }
  .gap-2 { gap: var(--space-2); }
  .grow { flex: 1; }
  .right { margin-left: auto; }
}
