/* ===========================================================================
   SISTEMA DE DISEÑO — content.sendahealth.es
   Hoja de estilo común a TODAS las páginas. Basada en la marca de Senda
   (ww3.sendahealth.com): fondo claro cálido, texto oscuro, azul #334DCF en los
   detalles. Un único conjunto de tokens y componentes reutilizables.
   =========================================================================== */

/* ------------------------------- TOKENS ---------------------------------- */
:root {
  /* Marca */
  --primary: #334dcf; /* primary-100 */
  --primary-hover: #2a3fb0;
  --primary-dark: #0e0e90; /* primary-150 */
  --primary-soft: #f2f5fc; /* primary-30 (fondos suaves) */
  --primary-100: #dbe1f5; /* primary-60 (bordes/realces) */
  --accent: #9b51e0; /* vivid-purple (agente Research) */

  /* Neutros cálidos (Senda) */
  --bg: #e9e5dd; /* fondo general (más oscuro que las tarjetas para que destaquen) */
  --surface: #ffffff; /* tarjetas y cabeceras */
  --surface-2: #faf9f7; /* filas alternas / zonas sutiles */
  --border: #e6e2d9; /* neutral-200 aprox */
  --text: #1d1b16; /* neutral-900 */
  --muted: #7f786c; /* neutral-600 */

  /* Feedback */
  --danger: #cf2e2e;
  --danger-soft: #fbecec;
  --success: #1f9d55;

  /* Forma */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(29, 27, 22, 0.05);
  --shadow: 0 1px 3px rgba(29, 27, 22, 0.06), 0 8px 24px rgba(29, 27, 22, 0.05);
  --ring: 0 0 0 3px rgba(51, 77, 207, 0.15);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Tokens del tema oscuro. Se aplican cuando el usuario lo fija (data-theme="dark")
   o, si no ha fijado ninguno, cuando el sistema está en oscuro. */
:root[data-theme="dark"] {
  --primary: #7e93f5;
  --primary-hover: #94a6f8;
  --primary-dark: #5071e7;
  --primary-soft: #23283a;
  --primary-100: #2a3358;
  --accent: #c08ae6;
  --bg: #100e08; /* fondo general (más oscuro para que las tarjetas destaquen) */
  --surface: #24211a;
  --surface-2: #1c1a14;
  --border: #38342b;
  --text: #f4f3f0;
  --muted: #b8b5ae;
  --danger: #f28b82;
  --danger-soft: #3a1c1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 8px 24px rgba(0, 0, 0, 0.4);
  --ring: 0 0 0 3px rgba(126, 147, 245, 0.25);
}
/* Nota: NO se aplica modo oscuro automático por preferencia del SO. La marca de
   Senda es clara; el modo oscuro es opcional y solo se activa si el usuario lo
   elige en su perfil (data-theme="dark"). */

/* -------------------------------- BASE ----------------------------------- */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}
a {
  color: var(--primary);
}
button {
  font-family: inherit;
}
h1,
h2,
h3 {
  color: var(--text);
}
.muted {
  color: var(--muted);
}

/* ------------------------------ LAYOUT ----------------------------------- */
/* Contenedor centrado (vistas de una columna) */
.zen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Shell con cabecera de marca fija + contenido debajo */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.app-shell .zen {
  flex: 1;
  min-height: 0;
  align-items: flex-start;
  padding-top: 40px;
}

/* Cabecera de marca común */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.app-header-logo {
  height: 32px;
  width: auto;
  display: block;
}
.app-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.app-header-user {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Logo bicolor: variante clara para fondos claros, blanca para fondos oscuros.
   (El logo lleva color de marca, por eso no se puede invertir por CSS.) */
.logo-on-dark {
  display: none;
}
:root[data-theme="dark"] .logo-on-light {
  display: none;
}
:root[data-theme="dark"] .logo-on-dark {
  display: block;
}
@media (max-width: 640px) {
  .app-header-user {
    display: none;
  }
}

/* ---------------------------- COMPONENTES -------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Botones */
.btn {
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover {
  background: var(--surface-2);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-soft);
  filter: brightness(0.97);
}
/* Botón blanco con icono (p.ej. Google) */
.btn-oauth {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s;
}
.btn-oauth:hover {
  background: var(--surface-2);
}

/* Campos de formulario */
.input,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder,
.textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

/* Chip / etiqueta */
.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  margin: 0 6px 6px 0;
}

/* Separador con texto */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 12px;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.form-error {
  color: var(--danger);
  font-size: 14px;
  margin: 0 0 16px;
}

/* Menú de usuario (desplegable en la cabecera) */
.usermenu {
  position: relative;
}
.usermenu-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
}
.usermenu-trigger:hover {
  background: var(--surface-2);
}
.usermenu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 300px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 40;
}
.usermenu-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 12px;
}
.usermenu-karma {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.usermenu-sep {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}
.usermenu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
}
.usermenu-item:hover {
  background: var(--surface-2);
}
/* Etiqueta de grupo (p. ej. "Administración") */
.usermenu-grouplabel {
  padding: 4px 10px 2px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #7b61ff;
}
/* Botones de la ZONA ADMIN: color propio (violeta) para distinguirlos de los
   ítems de usuario (que van en el color de texto por defecto). */
.usermenu-item--admin {
  color: #7b61ff;
  font-weight: 600;
}
.usermenu-item--admin:hover {
  background: rgba(123, 97, 255, 0.1);
}
:root[data-theme="dark"] .usermenu-grouplabel,
:root[data-theme="dark"] .usermenu-item--admin {
  color: #a998ff;
}
.usermenu-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* -------------------------- ADMIN: layout + menú lateral ---------------- */
.admin-layout {
  display: flex;
  align-items: stretch;
  width: 100%;
}
.admin-sidebar {
  width: 224px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 57px;
  max-height: calc((100dvh / var(--zoom, 1)) - 57px);
  overflow-y: auto;
}
.admin-sidebar.collapsed { width: 58px; }
.admin-collapse {
  align-self: flex-end;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 8px;
  width: 28px;
  height: 26px;
  cursor: pointer;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1;
}
.admin-navitem {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.admin-navitem:hover { background: var(--surface-2); }
.admin-navitem.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.admin-navicon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.admin-sidebar.collapsed .admin-navlabel,
.admin-sidebar.collapsed .admin-collapse { display: none; }
.admin-sidebar.collapsed .admin-navitem { justify-content: center; gap: 0; padding: 9px 0; }
.admin-main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
  width: 100%;
}
@media (max-width: 820px) {
  .admin-sidebar { width: 58px; }
  .admin-sidebar .admin-navlabel, .admin-sidebar .admin-collapse { display: none; }
  .admin-sidebar .admin-navitem { justify-content: center; gap: 0; padding: 9px 0; }
  .admin-main { padding: 16px 14px; }
}

/* -------------------------- PÁGINA: LOGIN -------------------------------- */
/* Split-screen estilo producto.sendahealth.es: panel de marca (izq) + form (der).
   El panel de marca es siempre oscuro (identidad); el formulario usa los
   componentes comunes (.input/.btn-primary/.btn-oauth). */
.login-split {
  display: flex;
  min-height: 100dvh;
}
.login-aside {
  display: none;
  position: relative;
  width: 50%;
  flex-direction: column;
  justify-content: space-between;
  padding: 48px;
  overflow: hidden;
  background: linear-gradient(135deg, #0e0e90 0%, #1e1b4b 100%);
  color: #fff;
}
.login-aside .blob {
  position: absolute;
  width: 320px;
  height: 320px;
  border-radius: 999px;
  background: #8ed1fc;
  opacity: 0.14;
  filter: blur(64px);
  pointer-events: none;
}
.login-logo-light {
  width: 200px;
  height: auto;
}
.login-title {
  font-size: clamp(34px, 4vw, 46px);
  font-weight: 800;
  line-height: 1.05;
  margin: 0;
  letter-spacing: -0.02em;
  color: #fff !important; /* panel azul: forzar blanco por encima de la regla global de h1 */
}
.login-title .accent {
  color: #8ed1fc;
}
.login-features {
  list-style: none;
  padding: 0;
  margin: 28px 0 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-features li {
  display: flex;
  align-items: center;
  gap: 12px;
}
.login-features .ico {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8ed1fc;
}
.login-features span {
  color: #fff;
  font-size: 14px;
}
.login-foot {
  position: relative;
  z-index: 10;
  color: rgba(219, 225, 245, 0.65);
  font-size: 12px;
}
.login-foot a {
  color: inherit;
  text-decoration: none;
}
.login-foot a:hover {
  color: #fff;
}
.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--surface);
  padding: 48px 32px;
}
.login-card {
  width: 100%;
  max-width: 384px;
}
.login-logo-dark {
  width: 170px;
  height: auto;
  margin-bottom: 32px;
}
.login-card h1 {
  font-size: 24px;
  font-weight: 800;
  margin: 0 0 4px;
}
.login-card .login-sub {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 28px;
}
@media (min-width: 1024px) {
  .login-aside {
    display: flex;
  }
  .login-logo-dark {
    display: none !important; /* en desktop el logo va en el panel de marca */
  }
}

/* ------------------- PÁGINA: REFINAMIENTO (responsive) ------------------- */
.refine-root {
  /* Se divide entre --zoom para que, con el zoom global del sitio, la altura
     renderizada siga cabiendo en la ventana y el input del chat no se corte. */
  height: calc(100dvh / var(--zoom, 1));
  display: flex;
  flex-direction: column;
}
.refine-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
  min-height: 0;
}
.refine-article {
  overflow-y: auto;
  padding: 28px 32px;
  min-height: 0;
}
.refine-chat {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.refine-mobile-tabs {
  display: none;
}
@media (max-width: 900px) {
  .refine-grid {
    grid-template-columns: 1fr;
  }
  .refine-article {
    padding: 20px 16px;
  }
  .refine-mobile-tabs {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .refine-mobile-tabs .btn {
    flex: 1;
  }
  .refine-grid[data-tab="article"] .refine-chat {
    display: none;
  }
  .refine-grid[data-tab="chat"] .refine-article {
    display: none;
  }
}

/* Barra inferior separada del chat: acción de publicar */
.refine-bottom {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Barra de herramientas del editor HTML */
.editor-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.editor-toolbar .btn {
  padding: 5px 10px;
  font-size: 13px;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg button {
  border: none;
  background: var(--surface);
  color: var(--muted);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.seg button.active {
  background: var(--surface-2);
  color: var(--text);
}
.seg-sm button {
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 500;
}

/* ---------------------------------------------------------------------------
   Contenido del post renderizado con el estilo del blog de Senda
   (tipografía y colores de marca: cuerpo oscuro, enlaces/acentos en azul)
--------------------------------------------------------------------------- */
.post-content {
  color: var(--text);
  font-size: 16px;
  line-height: 1.72;
  word-break: break-word;
}
.post-content > *:first-child {
  margin-top: 0;
}
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4 {
  color: var(--text);
  font-weight: 800;
  line-height: 1.25;
  margin: 1.6em 0 0.5em;
  letter-spacing: -0.01em;
}
.post-content h1 { font-size: 30px; }
.post-content h2 {
  font-size: 24px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-100);
}
.post-content h3 { font-size: 20px; }
.post-content h4 { font-size: 17px; }
.post-content p { margin: 0 0 1.1em; }
.post-content a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.post-content a:hover { color: var(--primary-dark); }
.post-content ul,
.post-content ol { margin: 0 0 1.1em; padding-left: 1.4em; }
.post-content li { margin: 0.3em 0; }
.post-content blockquote {
  margin: 1.2em 0;
  padding: 8px 16px;
  border-left: 4px solid var(--primary);
  background: var(--primary-soft);
  color: var(--text);
  border-radius: 0 8px 8px 0;
}
.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  margin: 1em 0;
}
.post-content strong { font-weight: 700; }
.post-content code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.post-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}
.post-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.2em 0;
}
.post-content th,
.post-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

/* Resaltado de texto añadido en una edición (diff en la vista previa) */
mark.diff-added {
  background: #cfe3ff;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
:root[data-theme="dark"] mark.diff-added {
  background: #24406e;
  color: #eaf2ff;
}

/* Alertas bloqueantes de publicación */
.publish-alert {
  width: 100%;
  max-width: 720px;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
}

/* Modal de previsualización */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 12, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 780px;
  max-height: calc(100dvh / var(--zoom, 1) - 48px);
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
}
