/* ===================================================================
   ARMAZÓN: la barra lateral, la cabecera con migas, las pestañas del área, la barra inferior del móvil y las capas globales
   (buscar, «Más», «＋ Nuevo», asistente). La lista de pantallas sale de app/navegacion.py.
   =================================================================== */

/* ===================================================================
   LA APLICACIÓN: barra lateral de áreas + columna con cabecera y contenido.
   La navegación sale de app/navegacion.py (una sola lista). Ver docs/ux-2.0.md.
   =================================================================== */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.side {
  width: var(--nav-w); flex: none; position: sticky; top: 0; align-self: flex-start;
  height: 100vh; height: 100dvh; overflow-y: auto; z-index: 20;
  display: flex; flex-direction: column; gap: 2px; padding: 14px 10px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 4px 8px 14px; font-weight: 800; letter-spacing: .02em; color: var(--accent-text); }
.brand:hover { text-decoration: none; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent-btn); color: var(--on-accent); display: grid; place-items: center; font-size: .8rem; flex: none; }
.nav-group-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; padding: 14px 10px 4px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: .7rem; width: 100%; min-height: 40px;
  border-left: 3px solid transparent; border-radius: var(--r-sm); padding: .4rem .6rem;
  color: var(--text-2); font-size: .92rem; transition: background .13s ease, color .13s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--text); border-left-color: var(--accent); font-weight: 650; }
.nav-item .lbl { flex: 1; }
.ico { width: 1.25em; height: 1.25em; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.rellena { fill: currentColor; stroke: none; }

/* Insignia de «lo que espera»: cifra gris; roja si hay algo urgente (una fuente rota, un post con error). */
.insignia {
  min-width: 22px; height: 20px; padding: 0 .4rem; border-radius: var(--r-pill);
  display: inline-grid; place-items: center; font-size: .72rem; font-weight: 700;
  background: var(--surface-3); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.insignia:empty { display: none; }
.insignia.urgente { background: var(--accent-btn); color: var(--on-accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 1px solid var(--border); }
.rail-toggle {
  display: flex; align-items: center; gap: .6rem; min-height: 36px; padding: .4rem .6rem;
  background: transparent; border: 0; border-radius: var(--r-sm); color: var(--muted); cursor: pointer; font-size: .82rem;
}
.rail-toggle:hover { background: var(--surface-2); color: var(--text); }
.git-commit { font-size: .7rem; color: var(--muted); text-align: center; padding: 2px 0; }

/* Carril: la barra lateral colapsada a iconos (la elige el usuario en escritorio; en tablet es siempre así) */
:root[data-rail="1"] .side { width: var(--rail-w); align-items: center; }
:root[data-rail="1"] .nav-item { justify-content: center; padding-inline: 0; width: 48px; border-left-width: 0; }
:root[data-rail="1"] .nav-item .lbl, :root[data-rail="1"] .brand .bt, :root[data-rail="1"] .rail-toggle .lbl { display: none; }
:root[data-rail="1"] .nav-item .insignia { position: absolute; top: 1px; right: 0; min-width: 18px; height: 18px; font-size: .64rem; }
:root[data-rail="1"] .nav-item[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); }
:root[data-rail="1"] .nav-group-label { font-size: 0; padding: 0; margin: 8px 0; width: 36px; border-top: 1px solid var(--border-strong); }
.app-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-top {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 10px;
  min-height: 60px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.crumb { display: flex; align-items: center; gap: .5rem; margin-right: auto; min-width: 0; font-weight: 700; font-size: 1rem; color: var(--text); }
.crumb a { color: var(--text-2); font-weight: 600; }
.crumb .sep { color: var(--muted); font-weight: 400; }
.crumb .actual { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb .logo-m { display: none; }
.buscar-btn {
  display: flex; align-items: center; gap: .6rem; min-height: 40px; width: min(380px, 38%);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 0 .8rem;
  color: var(--muted); cursor: pointer; font-size: .88rem; text-align: left;
}
.buscar-btn:hover { border-color: var(--border-strong); color: var(--text-2); }
.buscar-btn .lbl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: var(--tap); height: var(--tap); display: inline-grid; place-items: center; border-radius: var(--r); border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.usuario-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); color: var(--text); display: inline-grid; place-items: center; font-weight: 700; font-size: .82rem; flex: none; text-transform: uppercase; }
.menu-usuario { position: relative; }
.menu-usuario > summary { list-style: none; cursor: pointer; border-radius: 50%; }
.menu-usuario > summary::-webkit-details-marker { display: none; }
.menu-usuario .menu-caja {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: 250px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: var(--sh-3); padding: 12px;
}
.menu-caja .quien { font-size: .82rem; color: var(--text-2); word-break: break-all; margin-bottom: 10px; }
.menu-caja .quien b { display: block; color: var(--text); }
.menu-caja .grupo { display: flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; margin: 4px 0 12px; }
.menu-caja .grupo button { flex: 1; min-height: 34px; background: var(--surface-2); border: 0; color: var(--text-2); cursor: pointer; font-size: .8rem; }
.menu-caja .grupo button + button { border-left: 1px solid var(--border-strong); }
.menu-caja .grupo button[aria-pressed="true"] { background: var(--accent-btn); color: var(--on-accent); }
.menu-caja .etq { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.main { flex: 1; padding: 1.5rem 2rem 3rem; overflow-x: auto; min-width: 0; }
.main:focus { outline: none; }
.skip-link { position: absolute; left: 8px; top: -64px; z-index: 200; background: var(--accent-btn); color: var(--on-accent); padding: .6rem .9rem; border-radius: var(--r-sm); }
.skip-link:focus { top: 8px; text-decoration: none; }

/* Pestañas del área (la segunda fila, si la pestaña tiene subpestañas) */
.tabs-area { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-bottom: .9rem; }
.tabs-area::-webkit-scrollbar { display: none; }
.tabs-area .tab { white-space: nowrap; min-height: 42px; display: inline-flex; align-items: center; }
.tab-commit { margin-left: auto; padding-left: 1rem; align-self: center; font: .75rem ui-monospace, monospace; color: var(--muted); white-space: nowrap; }
.subtabs { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; margin: -.2rem 0 1rem; padding-bottom: 2px; }
.subtabs::-webkit-scrollbar { display: none; }

/* Barra inferior del móvil: cuatro áreas de trabajo y «Más» */
.bottom-nav { display: none; }

/* ===================================================================
   CAPAS GLOBALES: búsqueda, «Más», «＋ Nuevo» y el asistente. Son <dialog>
   nativos (foco y Escape gratis) que cubren la ventana; la caja de dentro es
   lo que se ve, y pulsar fuera de ella (sobre el propio <dialog>) cierra.
   `margin: 0` es la trampa #14: el reset universal anula el `margin: auto`.
   =================================================================== */
dialog.capa {
  position: fixed; inset: 0; margin: 0; padding: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  border: 0; background: transparent; color: var(--text); overflow: hidden;
}
dialog.capa::backdrop { background: var(--scrim); }
.capa-caja {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: var(--sh-3); display: flex; flex-direction: column; overflow: hidden;
}
.capa-cab { display: flex; align-items: center; gap: .6rem; padding: 12px 14px 12px 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.capa-cab .icon-btn { margin-left: auto; }
.capa-cuerpo { overflow-y: auto; padding: 8px; }
.capa-busqueda .capa-caja { margin: 9vh auto 0; width: min(620px, calc(100% - 24px)); max-height: 76vh; }
.capa-hoja .capa-caja { margin: 14vh auto 0; width: min(520px, calc(100% - 24px)); max-height: 76vh; }
.capa-asistente .capa-caja { margin: 0 0 0 auto; height: 100%; width: min(460px, 100%); border-radius: var(--r-lg) 0 0 var(--r-lg); border-right: 0; }
.capa-busqueda input[type=search] {
  flex: 1; min-width: 0; min-height: var(--tap); background: transparent; border: 0; color: var(--text); font-size: 1rem; padding: 0;
}
.capa-busqueda input[type=search]:focus-visible { box-shadow: none; }
.capa-busqueda .capa-cab { font-weight: 400; gap: .7rem; }
.res-grupo { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; padding: 10px 10px 4px; }
.res {
  display: flex; align-items: center; gap: .7rem; width: 100%; min-height: 48px; padding: .4rem .7rem; text-align: left;
  background: none; border: 0; border-radius: var(--r-sm); color: var(--text); cursor: pointer; font-size: .92rem;
}
.res:hover, .res:focus-visible { background: var(--surface-3); text-decoration: none; }
.res .rt { flex: 1; min-width: 0; }
.res .rt b { font-weight: 600; }
.res .rt small { display: block; color: var(--muted); font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res .antes { font-size: .72rem; color: var(--warn-fg); background: var(--warn-bg); border-radius: var(--r-pill); padding: 0 .55rem; white-space: nowrap; }
.res-vacio { padding: 26px 12px; text-align: center; color: var(--muted); font-size: .9rem; }
.mas-rejilla { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; }
.mas-rejilla a {
  position: relative; display: flex; flex-direction: column; gap: .4rem; min-height: 92px; padding: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); color: var(--text);
}
.mas-rejilla a:hover { text-decoration: none; border-color: var(--border-strong); }
.mas-rejilla a small { color: var(--muted); font-size: .76rem; }
.mas-rejilla .insignia { position: absolute; top: 10px; right: 10px; }
.mas-pie { display: flex; align-items: center; gap: .6rem; padding: 10px 14px 14px; font-size: .85rem; color: var(--text-2); }
.mas-pie .btn { margin-left: auto; }
.asistente-cuerpo { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 12px; gap: .6rem; }
.asistente-cuerpo .chat-box { flex: 1; max-height: none; }
.pildora-estado { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; font-weight: 600; padding: .25rem .65rem; border-radius: var(--r-pill); background: var(--ok-bg); color: var(--ok-fg); }
.pildora-estado::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pildora-estado.aviso { background: var(--warn-bg); color: var(--warn-fg); }
.capa-busqueda input[type=search]::-webkit-search-cancel-button { display: none; }

/* ===================================================================
   VOZ EN TODAS LAS PANTALLAS: el botón flotante del micro y su panel. El panel NO es un <dialog> modal a
   propósito: se puede seguir trabajando con la pantalla mientras se le habla al Reportero. Su contenido es
   el panel compartido de componentes.css y se carga al abrirlo la primera vez (static/voz-dock.js).
   =================================================================== */
.voz-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 45; width: 58px; height: 58px; border-radius: 50%;
  border: 0; background: var(--accent-btn); color: var(--on-accent); cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--sh-3); transition: transform .15s, background .15s;
}
.voz-fab:hover { background: var(--accent-hover); transform: scale(1.06); }
.voz-fab:focus-visible { box-shadow: var(--sh-3), var(--ring); }
.voz-fab .ico { width: 26px; height: 26px; stroke-width: 2; }
.voz-fab[aria-expanded="true"] { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); }
.voz-fab[data-fase="escuchando"] { background: var(--danger-btn); color: var(--on-accent); border: 0; animation: voz-latido 1.4s ease-in-out infinite; }
.voz-fab[data-fase="pensando"] { background: var(--info); color: var(--on-ok); border: 0; }
.voz-fab[data-fase="hablando"] { background: var(--ok); color: var(--on-ok); border: 0; }
.voz-fab[data-fase="pensando"]::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid transparent; border-top-color: var(--info);
  animation: voz-giro .9s linear infinite;
}
@keyframes voz-giro { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .voz-fab[data-fase="pensando"]::after { animation: none; border-color: var(--info); } }
.voz-dock {
  position: fixed; right: 22px; bottom: 92px; z-index: 46; width: min(410px, calc(100vw - 24px));
  height: min(620px, calc(100vh - 120px)); height: min(620px, calc(100dvh - 120px));
  display: flex; flex-direction: column; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--sh-3); overflow: hidden;
}
.voz-dock[hidden] { display: none; }
.voz-dock-cab { display: flex; align-items: center; gap: .5rem; padding: 6px 6px 6px 14px; border-bottom: 1px solid var(--border); font-weight: 700; }
.voz-dock-titulo { display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voz-dock-fase { font-size: .72rem; font-weight: 600; padding: .15rem .6rem; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); }
.voz-dock-fase:empty { display: none; }
.voz-dock-fase[data-fase="escuchando"] { background: var(--danger-bg); color: var(--danger-fg); }
.voz-dock-fase[data-fase="pensando"] { background: var(--info-bg); color: var(--info-fg); }
.voz-dock-fase[data-fase="hablando"] { background: var(--ok-bg); color: var(--ok-fg); }
.voz-dock-cuerpo { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 12px; overflow-y: auto; }
.voz-dock-pie { padding: 6px 12px 8px; border-top: 1px solid var(--border); font-size: .72rem; color: var(--muted); }
.voz-dock-pie kbd { font-family: inherit; font-size: .68rem; padding: 0 .35rem; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface-2); }
@media print { .voz-fab, .voz-dock { display: none; } }

/* ===== Adaptación a pantallas pequeñas y anchas de esta capa (de la más ancha a la más estrecha) ===== */

@media (max-width: 900px) {
/* ===== Tablet (≤ 900 px): la barra lateral queda siempre en carril de iconos ===== */
  .side { width: var(--rail-w); align-items: center; }
  .nav-item { justify-content: center; padding-inline: 0; width: 48px; border-left-width: 0; }
  .nav-item .lbl, .brand .bt, .rail-toggle, .git-commit { display: none; }
  .nav-item .insignia { position: absolute; top: 1px; right: 0; min-width: 18px; height: 18px; font-size: .64rem; }
  .nav-item[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); }
  .nav-group-label { font-size: 0; padding: 0; margin: 8px 0; width: 36px; border-top: 1px solid var(--border-strong); }
  .app-top { padding-inline: 16px; }
  .buscar-btn { width: 220px; }
  .buscar-btn kbd { display: none; }
  .main { padding: 1.25rem; }
}

@media (max-width: 600px) {
  .side { display: none; }
  .app-top { padding: 8px 8px 8px 14px; min-height: 56px; }
  .crumb .logo-m { display: grid; width: 28px; height: 28px; border-radius: 8px; background: var(--accent-btn); color: var(--on-accent); place-items: center; font-size: .72rem; font-weight: 800; flex: none; }
  .crumb .solo-escritorio { display: none; }
  .buscar-btn { width: var(--tap); height: var(--tap); padding: 0; justify-content: center; border-color: transparent; background: transparent; }
  .buscar-btn .lbl, .buscar-btn kbd { display: none; }
  .nuevo-btn .lbl { display: none; }
  .nuevo-btn { width: var(--tap); height: var(--tap); padding: 0; }
  .main { padding: 1rem .75rem calc(5.2rem + env(safe-area-inset-bottom, 0px)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav a, .bottom-nav button {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 52px; background: none; border: 0; border-radius: var(--r); color: var(--muted);
    font-size: .7rem; font-weight: 600; cursor: pointer;
  }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav [aria-current="page"] { color: var(--text); }
  .bottom-nav .pildora { width: 54px; height: 28px; border-radius: var(--r-pill); display: grid; place-items: center; }
  .bottom-nav [aria-current="page"] .pildora { background: var(--accent-soft); color: var(--accent); }
  .bottom-nav .ico { width: 1.4em; height: 1.4em; }
  .bottom-nav .insignia { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; font-size: .64rem; }
  .bottom-nav .insignia.urgente { min-width: 10px; width: 10px; height: 10px; padding: 0; font-size: 0; border: 2px solid var(--surface); box-sizing: content-box; left: calc(50% + 10px); top: 4px; }
  .capa-busqueda .capa-caja { margin: 0; width: 100%; height: 100%; max-height: none; border-radius: 0; border: 0; }
  .capa-hoja .capa-caja { margin: auto 0 0; width: 100%; max-height: 82%; border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0; }
  .capa-asistente .capa-caja { border-radius: 0; border: 0; }
  /* La voz en el móvil: el botón queda justo encima de la barra inferior, al alcance del pulgar, y el panel es una
     hoja que ocupa su sitio (con el panel abierto el botón sobra: el propio panel tiene su cabecera con «cerrar»). */
  .voz-fab { right: 14px; bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
  .voz-abierto .voz-fab { display: none; }
  .voz-dock { left: 8px; right: 8px; width: auto; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); height: min(78vh, 640px); height: min(78dvh, 640px); }
  .voz-dock-cab .icon-btn { width: var(--tap); height: var(--tap); }
  .voz-dock-pie { display: none; }
  .menu-usuario .menu-caja { position: fixed; right: 8px; top: 60px; }
/* Barra de acciones de una ficha: en móvil se queda al alcance del pulgar, encima de la barra inferior. */
  .main { overflow-x: clip; }
}
