/* ==========================================================================
   HOJA DE ESTILOS DE LA APLICACIÓN
   Sistema visual claro: azul institucional sobre blanco.

   Tres reglas que sostienen todo lo demás:
   1. Los colores se nombran por lo que significan (--primary, --ok, --danger),
      nunca por cómo se ven. Las vistas no escriben colores a mano.
   2. Primero el móvil. El menú lateral aparece a partir de 1024 px; por debajo
      hay barra inferior y el mismo menú como panel deslizante.
   3. Nada depende de una función que no esté en las dos últimas versiones de
      Chrome, Edge, Firefox y Safari (iOS incluido). Donde hay prefijo o valor de
      reserva, va escrito junto a la propiedad.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Marca */
  --primary: #1746A2;
  --primary-strong: #123A87;
  --primary-soft: #EAF1FE;
  --primary-border: #C9DAFB;
  --on-primary: #FFFFFF;

  /* Superficies y texto */
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F4F6FA;
  --surface-hover: #EAEFF6;
  --text: #0E1B33;
  --text-2: #33405A;
  --text-muted: #56627A;
  --border: #DCE2EC;
  --border-soft: #E8ECF3;
  --border-strong: #8593A6;

  /* Estados: texto oscuro sobre fondo tenue, siempre con contraste 4.5:1 o más */
  --ok: #17663A;
  --ok-soft: #E3F4E9;
  --ok-border: #A9D9BC;
  --ok-solid: #1B7A45;
  --warn: #7A4A00;
  --warn-soft: #FDF1DC;
  --warn-border: #EBCB8B;
  --warn-solid: #8A5300;
  --danger: #A4262C;
  --danger-soft: #FDECEC;
  --danger-border: #E5B4B6;
  --danger-solid: #B3261E;
  --info: #1746A2;
  --info-soft: #EAF1FE;
  --info-border: #C9DAFB;
  --neutral: #414C61;
  --neutral-soft: #EEF1F5;
  --neutral-border: #CBD3DF;
  --violet: #5B3FB8;
  --violet-soft: #EFEBFB;
  --violet-border: #CFC4F1;

  /* Un color por estado del contenido, el mismo en todas las pantallas */
  --status-queued: var(--neutral);
  --status-generating: var(--info);
  --status-captioning: var(--violet);
  --status-ready: #0B5F58;
  --status-scheduling: var(--warn);
  --status-scheduled: var(--warn);
  --status-failed: var(--danger);

  /* Fondo de un reproductor o de una vista previa: oscuro a propósito */
  --media-bg: #0E1B33;
  --media-text: #D5E2FB;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;

  --shadow-card: 0 1px 2px rgba(14, 27, 51, 0.04);
  --shadow-pop: 0 12px 32px rgba(14, 27, 51, 0.16), 0 2px 6px rgba(14, 27, 51, 0.08);
  --focus-ring: 0 0 0 3px rgba(23, 70, 162, 0.28);

  --sidebar-width: 264px;
  --topbar-height: 60px;
  --bottom-nav-height: 64px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

p { color: var(--text-2); }

a { color: var(--primary); }
a:hover { color: var(--primary-strong); }

img, video, canvas, svg { max-width: 100%; }
video { background: var(--media-bg); }

code, pre, kbd { font-family: var(--font-mono); font-size: 0.92em; }
code { background: var(--neutral-soft); border-radius: 4px; padding: 1px 5px; color: var(--text); }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* El foco se ve siempre que se llega con el teclado, en cualquier control. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--primary-border); color: var(--text); }

.text-muted { color: var(--text-muted); }
.text-red, .text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 400;
  background: var(--primary);
  color: var(--on-primary);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 12px; color: var(--on-primary); }

/* --------------------------------------------------------------------------
   Armazón: menú lateral, barra superior, contenido y barra inferior
   -------------------------------------------------------------------------- */
.shell, .app-wrapper {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.shell-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  /* Sitio para la barra inferior del móvil, más el borde seguro de iOS. */
  padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
}

/* Menú lateral. En el móvil es un panel que entra desde la izquierda. */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 300;
  width: min(86vw, 320px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}

/* Abierto con JavaScript (.open) o, sin él, por el ancla (#menu). */
.sidebar.open, .sidebar:target {
  transform: none;
  visibility: visible;
  transition: transform 0.22s ease, visibility 0s;
  box-shadow: var(--shadow-pop);
}

.sidebar-backdrop {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 290;
  background: rgba(14, 27, 51, 0.45);
  border: 0;
  width: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}
.sidebar.open ~ .sidebar-backdrop, .sidebar:target ~ .sidebar-backdrop {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0s;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  min-height: 44px;
}
.brand-badge:hover { color: var(--text); }

.brand-mark {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.2;
}

.sidebar-close {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 0;
  background: none;
  color: var(--text-2);
  text-decoration: none;
}
.sidebar-close:hover { background: var(--surface-hover); color: var(--text); }

.side-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-label {
  padding: 0 12px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  border: 0;
  background: none;
  width: 100%;
  text-align: left;
}
.side-link svg { flex: none; }
.side-link:hover { background: var(--surface-hover); color: var(--text); }
.side-link.active, .side-link[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.side-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 4px;
  min-width: 0;
}
.side-user-name { font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-role { font-size: 12px; color: var(--text-muted); line-height: 1.2; }

.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: var(--text);
  color: var(--on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
}

.version-note {
  padding: 8px 12px 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Subcuenta activa: el control que decide por dónde sale todo. */
.subaccount-switcher {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.subaccount-switcher-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.subaccount-switcher-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.subaccount-switcher form { flex: 1 1 auto; min-width: 0; margin: 0; }
.subaccount-initials {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
}
.subaccount-switcher .form-select {
  min-height: 44px;
  font-weight: 600;
  background-color: var(--surface);
}
.subaccount-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subaccount-warning {
  font-size: 13px;
  color: var(--warn);
}

/* Botón «Nueva publicación» y su menú de dos opciones. */
.new-post { position: relative; }
/* El <summary> queda como bloque y el diseño en fila va en un <span> interior: las versiones de
   Safari anteriores a la 16.4 no aplican display:flex a un <summary>. */
.new-post > summary, .user-menu > summary, .publish-sheet > summary {
  display: block;
  list-style: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  border-radius: var(--radius-sm);
}
.new-post > summary::-webkit-details-marker, .user-menu > summary::-webkit-details-marker, .publish-sheet > summary::-webkit-details-marker { display: none; }
.new-post > summary::marker, .user-menu > summary::marker, .publish-sheet > summary::marker { content: ''; }
.new-post-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}
.new-post > summary:hover .new-post-button { background: var(--primary-strong); }
.new-post-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}
.menu-option:hover { background: var(--surface-hover); color: var(--text); }
.menu-option-icon {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.menu-option-title { display: block; font-weight: 600; line-height: 1.3; }
.menu-option-text { display: block; font-size: 13px; color: var(--text-muted); line-height: 1.35; }

/* Barra superior */
.topbar, .top-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: var(--topbar-height);
  background-color: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-context { min-width: 0; display: flex; align-items: center; gap: 10px; }
.topbar-account { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-area { font-size: 13px; color: var(--text-muted); }

/* En el móvil, la barra superior dice con qué subcuenta se trabaja y abre el menú. */
.topbar-subaccount {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 10px 4px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  text-align: left;
}
.topbar-subaccount:hover { color: var(--text); background: var(--surface-hover); }
.topbar-subaccount-text { flex: 1 1 auto; min-width: 0; }
.topbar-subaccount-label { display: block; font-size: 11px; color: var(--text-muted); line-height: 1.2; }
.topbar-subaccount-name { display: block; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.header-actions { display: flex; align-items: center; gap: 10px; }

.user-menu { position: relative; display: none; }
.user-menu > summary { border-radius: var(--radius-full); }
.user-menu-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 12px 4px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-weight: 500;
}
.user-menu > summary:hover .user-menu-button { background: var(--surface-hover); }
.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 120;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 6px;
}
.user-menu-who { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }

.logout-btn { color: var(--text-2); }
.logout-btn:hover { color: var(--danger); }

/* Contenido */
.main-container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}
.main-container.page-narrow { max-width: 760px; }
.main-container.page-wide { max-width: 1200px; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 20px;
}
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; }
.page-lead { color: var(--text-muted); margin-top: 4px; font-size: 15px; }

/* Barra inferior del móvil */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  min-height: var(--bottom-nav-height);
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
  background-color: rgba(255, 255, 255, 0.97);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: stretch;
  gap: 2px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 54px;
  padding: 4px 2px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.2;
  border: 0;
  background: none;
  width: 100%;
}
.nav-item svg { width: 22px; height: 22px; flex: none; }
.nav-item:hover { color: var(--text); }
.nav-item.active, .nav-item[aria-current="page"] { color: var(--primary); font-weight: 600; }
.nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-item-publish { color: var(--primary); font-weight: 600; }
.nav-publish-mark {
  width: 46px;
  height: 30px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-publish-mark svg { width: 20px; height: 20px; }

/* En los teléfonos más estrechos (320 px) las cinco etiquetas caben enteras. */
@media (max-width: 359.98px) {
  .bottom-nav { padding-left: 2px; padding-right: 2px; gap: 0; }
  .nav-item { font-size: 10.5px; padding: 4px 0; }
  .nav-item span { overflow: visible; text-overflow: clip; }
}

/* Hoja inferior con las dos formas de publicar (solo móvil). */
.publish-sheet-panel {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(var(--bottom-nav-height) + 10px + env(safe-area-inset-bottom, 0px));
  z-index: 210;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.publish-sheet-title {
  padding: 8px 12px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Pestañas de las cuatro secciones de contenido (solo móvil y tableta). */
.section-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.section-tabs::-webkit-scrollbar { display: none; }
.section-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.section-tab:hover { background: var(--surface-hover); color: var(--text); }
.section-tab.active, .section-tab[aria-current="page"] {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
  font-weight: 600;
}

/* Configuración: índice por nivel a la izquierda, contenido a la derecha. */
.settings-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 0 16px 2px;
}
.settings-nav::-webkit-scrollbar { display: none; }
.settings-group { display: flex; gap: 6px; flex: none; align-items: center; }
.settings-group + .settings-group { padding-left: 12px; margin-left: 6px; border-left: 1px solid var(--border); }
.settings-group-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  padding-right: 4px;
}
.settings-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.settings-link:hover { background: var(--surface-hover); color: var(--text); }
.settings-link.active, .settings-link[aria-current="page"] {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
  font-weight: 600;
}
.settings-content { min-width: 0; }

.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--neutral-soft);
  color: var(--neutral);
  font-size: 13px;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   A partir de tableta ancha y escritorio: menú lateral fijo
   -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
  .shell-body { padding-bottom: 0; }

  .sidebar {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    bottom: auto;
    height: 100vh;
    height: 100dvh;
    width: var(--sidebar-width);
    flex: none;
    transform: none;
    visibility: visible;
    transition: none;
    box-shadow: none;
    padding: 20px 16px;
    z-index: 110;
  }
  .sidebar.open, .sidebar:target { box-shadow: none; }
  .sidebar-backdrop, .sidebar-close { display: none; }

  .bottom-nav, .section-tabs, .topbar-subaccount, .topbar-brand, .side-user-mobile { display: none; }
  .user-menu { display: block; }

  .topbar, .top-header { padding: 8px 32px; }

  .main-container { padding: 28px 32px 56px; }

  .settings-layout { flex-direction: row; align-items: flex-start; gap: 32px; }
  .settings-nav {
    position: -webkit-sticky;
    position: sticky;
    top: calc(var(--topbar-height) + 20px);
    flex: none;
    width: 220px;
    flex-direction: column;
    gap: 20px;
    overflow: visible;
    margin: 0;
    padding: 0;
  }
  .settings-group { flex-direction: column; align-items: stretch; gap: 2px; }
  .settings-group + .settings-group { padding-left: 0; margin-left: 0; border-left: 0; }
  .settings-group-label { padding: 0 12px 4px; }
  .settings-link {
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    white-space: normal;
  }
  .settings-content { flex: 1 1 auto; }
}

@media (max-width: 1023.98px) {
  .topbar-context { display: none; }
  .sidebar-wide-only { display: none; }
}

/* --------------------------------------------------------------------------
   Tarjetas y superficies
   -------------------------------------------------------------------------- */
.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.card-flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.card-head h2, .card-head h3 { font-size: 16px; font-weight: 600; }

.list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  text-decoration: none;
}
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); color: var(--text); }
.list-row-main { flex: 1 1 auto; min-width: 0; }
.list-row-title { font-weight: 600; overflow-wrap: anywhere; }
.list-row-meta { font-size: 13px; color: var(--text-muted); }

.date-chip { width: 48px; flex: none; text-align: center; }
.date-chip-day { font-size: 12px; color: var(--text-muted); text-transform: uppercase; }
.date-chip-num { font-size: 20px; font-weight: 700; line-height: 1.1; }

.icon-tile {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-tile.sm { width: 36px; height: 36px; border-radius: 8px; }
.icon-tile.danger { background: var(--danger-soft); color: var(--danger); }
.icon-tile.warn { background: var(--warn-soft); color: var(--warn); }
.icon-tile.ok { background: var(--ok-soft); color: var(--ok); }

.empty-state {
  padding: 28px 20px;
  text-align: center;
  color: var(--text-muted);
}

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 14px;
  color: var(--text-2);
}
.notice.warn { background: var(--warn-soft); border-color: var(--warn-border); color: var(--warn); }
.notice.danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.notice.info { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }
.notice a { color: inherit; text-decoration: underline; font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* Detalle de un contenido: el archivo a la izquierda, los pasos a la derecha. */
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.detail-main { min-width: 0; }
.detail-main > .card:last-child { margin-bottom: 0; }
.detail-player { display: block; max-width: 100%; max-height: 70vh; }

@media (min-width: 1200px) {
  .detail-layout { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 24px; align-items: start; }
  .detail-media {
    position: -webkit-sticky;
    position: sticky;
    top: calc(var(--topbar-height) + 20px);
  }
  .detail-player { max-height: min(62vh, 560px); }
}

/* --------------------------------------------------------------------------
   Botones
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  min-height: 46px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.btn:disabled, .btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover { background-color: var(--primary-strong); border-color: var(--primary-strong); color: var(--on-primary); }

.btn-secondary {
  background-color: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-2);
}
.btn-secondary:hover { background-color: var(--surface-hover); color: var(--text); }

.btn-outline {
  background-color: var(--surface);
  border-color: var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background-color: var(--primary-soft); color: var(--primary-strong); }

.btn-outline-danger {
  background-color: var(--surface);
  border-color: var(--danger-border);
  color: var(--danger);
}
.btn-outline-danger:hover { background-color: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-sm {
  min-height: 38px;
  padding: 6px 14px;
  font-size: 14px;
  width: auto;
}

/* En pantallas táctiles, nada que se toque baja de 44 px: ni los botones pequeños, ni los
   enlaces de una cabecera, ni el título de un bloque plegable. */
@media (pointer: coarse) {
  .btn-sm { min-height: 44px !important; min-width: 44px; }
  .card-head a, .page-header a:not(.btn) { display: inline-flex; align-items: center; min-height: 44px; }
  details:not([data-popover]) > summary { padding-top: 12px; padding-bottom: 12px; }
  .topbar-brand { min-width: 44px; justify-content: center; }
}

.admin-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background-color: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.admin-link-btn:hover { color: var(--primary); border-color: var(--primary-border); }

/* --------------------------------------------------------------------------
   Formularios
   -------------------------------------------------------------------------- */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-help { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.form-input, .form-textarea, .form-select {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-textarea, textarea.form-input { min-height: 96px; resize: vertical; }

.form-input::placeholder, .form-textarea::placeholder { color: #667085; opacity: 1; }

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.form-input:disabled, .form-textarea:disabled, .form-select:disabled,
.form-input[readonly] {
  background-color: var(--surface-2);
  color: var(--text-muted);
}

/* La flecha del desplegable se dibuja igual en los cuatro navegadores. */
.form-select, select.form-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2356627A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
  text-overflow: ellipsis;
}
.form-select::-ms-expand { display: none; }
.form-select[multiple], .form-select[size] { background-image: none; padding-right: 12px; }

/* Fecha y hora: Safari en iOS las encoge si no se le dice el ancho. */
input[type="date"].form-input, input[type="time"].form-input, input[type="datetime-local"].form-input {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value { text-align: left; }

input[type="checkbox"], input[type="radio"] {
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--primary);
  vertical-align: middle;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 44px;
  min-height: 44px;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 5px; }

input[type="range"] { accent-color: var(--primary); width: 100%; }

/* Selector de archivo: el botón dice «Elegir archivo» y se ve igual en todos los navegadores. */
input[type="file"].form-input, input[type="file"] {
  padding: 6px;
  min-height: 46px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  max-width: 100%;
}
input[type="file"]::file-selector-button {
  -webkit-appearance: none;
  appearance: none;
  margin-right: 12px;
  min-height: 32px;
  padding: 6px 14px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--surface);
  color: var(--primary);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
input[type="file"]::-webkit-file-upload-button {
  -webkit-appearance: none;
  margin-right: 12px;
  min-height: 32px;
  padding: 6px 14px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--surface);
  color: var(--primary);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* Con JavaScript, el selector de archivo se dibuja propio: el texto sale en español en cualquier
   navegador y con cualquier idioma del sistema. El campo real sigue ahí, transparente y encima,
   así que abrir el diálogo, arrastrar un archivo y la validación del navegador funcionan igual. */
.file-picker {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  min-width: 0;
  padding: 6px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.file-picker:hover { border-color: var(--primary); }
.file-picker:focus-within { border-color: var(--primary); box-shadow: var(--focus-ring); }
.file-picker-button {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 14px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
}
.file-picker-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 14px;
}
.file-picker.has-file .file-picker-name { color: var(--text); font-weight: 500; }
.file-picker input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

/* iOS amplía la página al enfocar un campo con letra menor de 16 px. */
@media (max-width: 767.98px) {
  input, select, textarea,
  .form-input, .form-textarea, .form-select { font-size: 16px !important; }
}

.input-icon-wrapper { position: relative; display: flex; align-items: center; }
.input-icon-left { position: absolute; left: 12px; color: var(--text-muted); pointer-events: none; }
.input-icon-right {
  position: absolute;
  right: 4px;
  min-width: 40px;
  min-height: 40px;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.input-with-left-icon { padding-left: 40px; }
.input-with-right-icon { padding-right: 46px; }

fieldset { border: 0; min-width: 0; }
legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 8px; }

/* --------------------------------------------------------------------------
   Estados
   -------------------------------------------------------------------------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  border: 1px solid transparent;
  background-color: var(--neutral-soft);
  color: var(--neutral);
}

.status-badge.queued, .status-badge.draft, .status-badge.pending, .status-badge.unknown {
  background-color: var(--neutral-soft); color: var(--neutral); border-color: var(--neutral-border);
}
.status-badge.generating, .status-badge.publishing, .status-badge.working {
  background-color: var(--info-soft); color: var(--info); border-color: var(--info-border);
}
.status-badge.captioning {
  background-color: var(--violet-soft); color: var(--violet); border-color: var(--violet-border);
}
.status-badge.ready, .status-badge.video_ready, .status-badge.approved {
  background-color: #E0F4F1; color: #0B5F58; border-color: #A8DAD3;
}
.status-badge.scheduling, .status-badge.scheduled, .status-badge.safety_rejected {
  background-color: var(--warn-soft); color: var(--warn); border-color: var(--warn-border);
}
.status-badge.published {
  background-color: var(--ok-soft); color: var(--ok); border-color: var(--ok-border);
}
.status-badge.failed, .status-badge.discarded {
  background-color: var(--danger-soft); color: var(--danger); border-color: var(--danger-border);
}

.badge-version, .version-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background-color: var(--neutral-soft);
  border: 1px solid var(--neutral-border);
  border-radius: var(--radius-full);
  line-height: 1.3;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
  display: inline-block;
  animation: pulse-animation 1.5s infinite;
}

@keyframes pulse-animation {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
}
.alert svg { flex: none; margin-top: 1px; }
.alert-success { background-color: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.alert-error { background-color: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.alert-warning { background-color: var(--warn-soft); border-color: var(--warn-border); color: var(--warn); }

/* --------------------------------------------------------------------------
   Dictado por voz (flujo de IA)
   -------------------------------------------------------------------------- */
.voice-hero-card {
  text-align: center;
  padding: 28px 20px;
  background: var(--surface);
}

.voice-record-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--primary);
  border: 4px solid var(--primary-border);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--on-primary);
  transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
.voice-record-btn:hover { background: var(--primary-strong); }

.voice-record-btn:active, .voice-record-btn.recording {
  background: var(--danger-solid);
  border-color: var(--danger-border);
  transform: scale(1.05);
  animation: recording-glow 1s infinite alternate;
}

.voice-record-btn.transcribing {
  opacity: 0.9;
  cursor: wait;
  background: var(--warn-solid);
  border-color: var(--warn-border);
  animation: transcribing-pulse 1.2s infinite ease-in-out;
}

.voice-record-btn.error { background: var(--danger-solid); border-color: var(--danger-border); }

@keyframes recording-glow {
  from { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.35); }
  to { box-shadow: 0 0 0 14px rgba(179, 38, 30, 0); }
}

@keyframes transcribing-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.spin-icon { animation: spin-kf 1s linear infinite; }
@keyframes spin-kf { 100% { transform: rotate(360deg); } }

.inline-transcribing-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--warn);
}
.inline-transcribing-state.success { color: var(--ok); }
.inline-transcribing-state.error { color: var(--danger); }

/* --------------------------------------------------------------------------
   Pestañas
   -------------------------------------------------------------------------- */
.tabs-header {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs-header::-webkit-scrollbar { display: none; }

.tab-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-2);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  cursor: pointer;
}
.tab-link:hover { color: var(--text); }
.tab-link.active, .tab-link[aria-selected="true"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-badge {
  background-color: var(--neutral-soft);
  color: var(--neutral);
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-full);
}
.tab-link.active .tab-badge { background-color: var(--primary); color: var(--on-primary); }

/* --------------------------------------------------------------------------
   Ventana modal
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(14, 27, 51, 0.5);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 24px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* --------------------------------------------------------------------------
   Detalles plegables y tablas
   -------------------------------------------------------------------------- */
details > summary { cursor: pointer; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; }

/* --------------------------------------------------------------------------
   Quien pide menos movimiento, lo tiene.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .sidebar, .sidebar-backdrop, .bottom-nav, .topbar, .top-header, .section-tabs { display: none !important; }
  .shell-body { padding-bottom: 0; }
  html, body { background: #FFFFFF; }
}
