/* Estilos de la app, sacados de la página a su archivo para que el navegador los guarde en caché
   (auditoría ARQSEO 1205, R042/R043). Origen: templates/tools/letterhead.php. */
  /* ── Fit-to-screen FHD: la raíz llena el __body del app-shell. Aprovecha
     todo el ancho (~1840) en 3 zonas + barra superior. El scroll vive DENTRO
     del formulario, del lienzo y del panel derecho; la página solo baja a la
     guía/FAQ (planning/diseno-fhd/letterhead.md + fit-to-screen-convencion.md). ── */
  .sw-tool-shell__body > .tool-letterhead-root {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  /* Override del ancho útil del workspace para esta tool (FHD ~1840). */
  .tool-letterhead-root > .container {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 1840px;
    padding: 0 32px;
  }
  @media (max-width: 1280px) { .tool-letterhead-root > .container { padding: 0 24px; } }
  @media (max-width: 640px)  { .tool-letterhead-root > .container { padding: 0 16px; } }

  /* ── Barra superior full-width (selector · medidor · cómo usar) ── */
  .lh-topbar {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 18px;
    padding: 8px 14px; margin-bottom: 14px;
    background: var(--sw-bg-subtle); border: 1px solid var(--sw-border);
    border-radius: var(--sw-radius-lg);
  }
  .lh-topbar__sel { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; min-width: 0; }
  .lh-topbar__lbl {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--sw-text-subtle); white-space: nowrap;
  }
  .lh-topbar__lbl svg { color: var(--sw-brand-500); }
  .lh-topbar .lh-select { min-width: 200px; max-width: 280px; }
  .lh-topbar .lh-help-btn { flex: 0 0 auto; margin-left: auto; }

  /* Medidor de completitud (centro de la barra superior, siempre visible) */
  .lh-meter { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
  .lh-meter__bar { height: 6px; border-radius: 999px; background: var(--sw-bg-strong); overflow: hidden; }
  .lh-meter__fill { display: block; height: 100%; width: 0;
    background: linear-gradient(90deg, var(--sw-brand-500), var(--sw-spot-500));
    border-radius: 999px; transition: width var(--sw-dur-base) var(--sw-ease-out); }
  .lh-meter__txt { display: block; font-size: 12.5px; color: var(--sw-text-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* ── Conmutador móvil "Editar | Vista previa" (oculto en desktop/tablet) ── */
  .lh-mtabs { display: none; }

  /* ── Rejilla: formulario (760) · lienzo (fluido) · panel hoja+acciones (320) ── */
  .lh-grid {
    display: grid;
    grid-template-columns: 760px minmax(0, 1fr) 320px;
    gap: 20px;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
  }
  @media (max-width: 1500px) {
    /* Algo menos de ancho: formulario un poco más estrecho, panel igual. */
    .lh-grid { grid-template-columns: 620px minmax(0, 1fr) 300px; gap: 16px; }
  }
  @media (min-width: 881px) and (max-width: 1180px) {
    /* Tablet landscape (~1024×768): 2 columnas (form | previa). El panel
       "Hoja A4 + Acciones" se pliega a una franja full-width ABAJO (slim, 1
       fila) para no robar el escaso alto vertical de 768px (ver .lh-aside).
       La tool sigue fit-to-screen: scroll interno en form y lienzo. */
    .lh-grid {
      grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
      grid-template-rows: minmax(0, 1fr) auto;
      column-gap: 16px; row-gap: 12px;
    }
  }
  @media (max-width: 880px) {
    /* Tablet portrait (~768) y móvil: 1 columna, la página scrollea con
       normalidad y cada zona es autocontenida. Form arriba, panel "Hoja y
       acciones" en medio (compacto) y vista previa debajo con max-height
       para que el A4 quede a un scroll corto, no empujando la página. */
    .sw-tool-shell__body > .tool-letterhead-root,
    .tool-letterhead-root > .container { overflow: visible; height: auto; }
    .lh-grid { grid-template-columns: 1fr; min-height: 0; }
    .lh-form, .lh-output, .lh-aside { min-height: 0; }
    .lh-form__scroll, .lh-aside__scroll { overflow: visible; }
    .lh-stage { max-height: 70vh; }
  }
  @media (min-width: 641px) and (max-width: 880px) {
    /* Portrait de tablet (~768 ancho): el formulario aún respira en 2
       sub-columnas para los pares; la previa conserva alto cómodo. */
    .lh-stage { max-height: 64vh; }
  }

  /* Formulario: columna flex con zona scrollable interna. */
  .lh-form {
    background: var(--sw-bg-subtle); border: 1px solid var(--sw-border);
    border-radius: var(--sw-radius-lg); padding: 18px;
    display: flex; flex-direction: column;
    min-height: 0; overflow: hidden;
  }
  .lh-form__scroll {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0 -18px; padding: 0 18px;
  }

  /* Tag de plantilla activa dentro de Identificación */
  .lh-field--tplactive { justify-content: flex-start; }
  .lh-field--tplactive .lh-tag { align-self: flex-start; margin-top: 2px; }

  .lh-block {
    border: 1px solid var(--sw-border);
    border-radius: var(--sw-radius-md);
    padding: 12px 14px 6px;
    margin-bottom: 14px;
    background: var(--sw-bg);
  }
  .lh-block legend {
    font-size: 12.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--sw-text-muted);
    padding: 0 6px;
  }
  .lh-req { color: var(--sw-brand-500); font-weight: 800; }
  .lh-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
  .lh-row--2 { grid-template-columns: 1fr 1fr; }
  @media (max-width: 600px) { .lh-row--2 { grid-template-columns: 1fr; } }
  .lh-field { margin-bottom: 10px; display: flex; flex-direction: column; gap: 5px; }
  .lh-field label { font-size: 13px; font-weight: 600; color: var(--sw-text-muted); }
  .lh-field input, .lh-field textarea, .lh-select, .lh-field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--sw-border);
    border-radius: var(--sw-radius-md);
    background: var(--sw-bg);
    font: 14.5px var(--sw-font-sans);
    color: var(--sw-text);
  }
  .lh-field input[type="color"] { height: 38px; width: 48px; padding: 4px; cursor: pointer; flex: 0 0 auto; }
  .lh-field textarea { font-family: var(--sw-font-mono); font-size: 13.5px; line-height: 1.55; resize: vertical; }
  .lh-field input:focus, .lh-field textarea:focus, .lh-field select:focus, .lh-select:focus {
    outline: none; border-color: var(--sw-brand-500); box-shadow: var(--sw-shadow-focus);
  }
  .lh-field small { font-size: 12.5px; color: var(--sw-text-subtle); }
  .lh-field small code { font-family: var(--sw-font-mono); font-size: 12px; background: var(--sw-bg-muted); padding: 1px 4px; border-radius: 4px; }
  .lh-hint { font-size: 13px; color: var(--sw-text-subtle); margin: 0 0 8px; }
  .lh-inline { display: flex; gap: 8px; align-items: stretch; }
  .lh-inline input { flex: 1; }

  /* Selector visual de plantillas */
  .lh-tpls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  @media (max-width: 600px) { .lh-tpls { grid-template-columns: repeat(2, 1fr); } }
  .lh-tpl {
    display: flex; flex-direction: column; gap: 6px; align-items: stretch;
    padding: 6px; border: 1.5px solid var(--sw-border); border-radius: var(--sw-radius-md);
    background: var(--sw-bg); cursor: pointer; text-align: center;
    transition: border-color var(--sw-dur-fast) var(--sw-ease-out), box-shadow var(--sw-dur-fast) var(--sw-ease-out);
  }
  .lh-tpl:hover { border-color: var(--sw-border-strong); }
  .lh-tpl.is-active { border-color: var(--sw-brand-500); box-shadow: var(--sw-shadow-glow); background: var(--sw-brand-50); }
  .lh-tpl:focus-visible { outline: none; border-color: var(--sw-brand-500); box-shadow: var(--sw-shadow-focus); }
  .lh-tpl__name { font-size: 12px; font-weight: 600; color: var(--sw-text-muted); }
  .lh-tpl.is-active .lh-tpl__name { color: var(--sw-brand-600); }
  .lh-tpl__thumb {
    position: relative; display: block; height: 46px; border-radius: var(--sw-radius-xs);
    background: #fff; border: 1px solid var(--sw-border); overflow: hidden; padding: 6px;
  }
  .lh-tpl__thumb i { display: block; background: #d4d4d4; border-radius: 1px; }
  /* Miniaturas por plantilla (líneas/bloques que evocan cada layout) */
  .lh-thumb--classic i:nth-child(1) { height: 5px; width: 60%; margin: 0 auto 4px; background: #1a1a1a; }
  .lh-thumb--classic i:nth-child(2) { height: 1px; width: 100%; margin: 0 0 5px; background: #1a1a1a; }
  .lh-thumb--classic i:nth-child(3) { height: 3px; width: 90%; }
  .lh-thumb--modern { padding-left: 10px; }
  .lh-thumb--modern::before { content:""; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--sw-brand-500); }
  .lh-thumb--modern i:nth-child(1) { height: 6px; width: 70%; background: #1a1a1a; margin-bottom: 5px; }
  .lh-thumb--modern i:nth-child(2) { height: 3px; width: 50%; margin-bottom: 4px; }
  .lh-thumb--modern i:nth-child(3) { height: 3px; width: 80%; }
  .lh-thumb--minimal i:nth-child(1) { height: 3px; width: 45%; background: #1a1a1a; margin-bottom: 3px; }
  .lh-thumb--minimal i:nth-child(2) { height: 1px; width: 100%; background: #d4d4d4; margin-bottom: 8px; }
  .lh-thumb--minimal i:nth-child(3) { height: 3px; width: 70%; }
  .lh-thumb--executive { padding: 0; }
  .lh-thumb--executive i:nth-child(1) { height: 16px; width: 100%; background: #1a1a1a; margin-bottom: 6px; }
  .lh-thumb--executive i:nth-child(2) { height: 3px; width: 70%; margin: 0 8px 4px; }
  .lh-thumb--executive i:nth-child(3) { height: 3px; width: 50%; margin: 0 8px; }
  .lh-thumb--agency i:nth-child(1) { height: 8px; width: 55%; background: var(--sw-brand-500); margin-bottom: 4px; }
  .lh-thumb--agency i:nth-child(2) { height: 2px; width: 100%; background: var(--sw-brand-500); margin-bottom: 6px; }
  .lh-thumb--agency i:nth-child(3) { height: 3px; width: 75%; }
  .lh-thumb--legal i:nth-child(1) { height: 4px; width: 50%; margin: 0 auto 3px; background: #1a1a1a; }
  .lh-thumb--legal i:nth-child(2) { height: 3px; width: 100%; border-top: 1px solid #1a1a1a; border-bottom: 1px solid #1a1a1a; background: transparent; margin-bottom: 5px; }
  .lh-thumb--legal i:nth-child(3) { height: 3px; width: 85%; }
  .lh-thumb--medical i:nth-child(1) { height: 5px; width: 55%; background: #0e7490; margin-bottom: 4px; }
  .lh-thumb--medical i:nth-child(2) { height: 2px; width: 100%; background: #0ea5e9; margin-bottom: 6px; }
  .lh-thumb--medical i:nth-child(3) { height: 3px; width: 70%; }
  .lh-thumb--academic i:nth-child(1) { height: 4px; width: 65%; margin: 0 auto 4px; background: #1e3a8a; }
  .lh-thumb--academic i:nth-child(2) { height: 1px; width: 100%; background: #1e3a8a; margin-bottom: 6px; }
  .lh-thumb--academic i:nth-child(3) { height: 3px; width: 80%; margin: 0 auto; }

  /* Dropzone logo */
  .lh-drop {
    position: relative; border: 1.5px dashed var(--sw-border-strong);
    border-radius: var(--sw-radius-md); background: var(--sw-bg);
    padding: 16px; cursor: pointer; text-align: center;
    transition: border-color var(--sw-dur-fast) var(--sw-ease-out), background var(--sw-dur-fast) var(--sw-ease-out);
  }
  .lh-drop:hover, .lh-drop:focus-visible { border-color: var(--sw-brand-500); background: var(--sw-brand-50); outline: none; }
  .lh-drop.is-drag { border-color: var(--sw-brand-500); background: var(--sw-brand-50); }
  .lh-drop.has-logo { padding: 10px; }
  .lh-drop__inner { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--sw-text-muted); }
  .lh-drop__ico { color: var(--sw-text-subtle); }
  .lh-drop__txt { font-size: 13.5px; }
  .lh-drop__sub { font-size: 12px; color: var(--sw-text-subtle); }
  .lh-drop__preview { max-height: 64px; max-width: 80%; display: block; margin: 0 auto; }
  .lh-drop.has-logo .lh-drop__inner { display: none; }
  .lh-drop__clear {
    position: absolute; top: 6px; right: 6px;
    width: 24px; height: 24px; border-radius: 999px;
    border: 1px solid var(--sw-border); background: var(--sw-bg);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--sw-text-muted);
  }
  .lh-drop__clear:hover { border-color: var(--sw-error-500); color: var(--sw-error-500); }
  .lh-logo-url summary { font-size: 12.5px; color: var(--sw-text-subtle); cursor: pointer; padding: 6px 0 2px; }

  /* Color + swatches */
  .lh-color-row { display: flex; align-items: center; gap: 10px; }
  .lh-swatches { display: flex; gap: 6px; }
  .lh-sw { width: 22px; height: 22px; border-radius: 999px; border: 2px solid var(--sw-border); background: var(--c); cursor: pointer; padding: 0; }
  .lh-sw:hover { transform: scale(1.1); }
  .lh-sw:focus-visible { outline: none; box-shadow: var(--sw-shadow-focus); }

  /* ── Panel derecho: Hoja A4 + Acciones (scroll-y interno) ── */
  .lh-aside {
    display: flex; flex-direction: column;
    min-height: 0; min-width: 0;
  }
  .lh-aside__scroll {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column; gap: 14px;
  }
  .lh-aside__h {
    font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--sw-text-muted); margin: 0 0 10px;
    display: flex; align-items: center; gap: 7px;
  }
  .lh-aside__h svg { color: var(--sw-brand-500); }
  .lh-aside__sheet, .lh-aside__actions { margin-bottom: 0; }
  .lh-aside__actions { display: flex; flex-direction: column; gap: 8px; }
  .lh-aside__actions .lh-aside__h { margin-bottom: 2px; }
  .lh-aside__actrow { display: flex; gap: 8px; }
  .lh-aside__actrow .sw-btn { flex: 1 1 auto; }
  .lh-status { font-size: 13.5px; color: var(--sw-text-subtle); min-height: 16px; }
  .lh-status.is-ok { color: var(--sw-success-500); }
  .lh-status.is-error { color: var(--sw-brand-600); }

  /* Columna de salida (centro): mini-barra de zoom + lienzo scrollable + pista. */
  .lh-output {
    display: flex; flex-direction: column;
    min-height: 0; min-width: 0;
  }
  /* Cabecera de output: solo zoom + copiar texto. */
  .lh-output__head {
    display: flex; align-items: center; justify-content: flex-end;
    margin-bottom: 12px; gap: 12px; flex-wrap: wrap;
    flex: 0 0 auto;
  }
  .lh-tag {
    font-size: 12px; padding: 2px 8px; border-radius: 999px;
    background: var(--sw-bg-muted); color: var(--sw-text-muted);
    text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
  }
  .lh-zoom { display: flex; align-items: center; gap: 6px; }
  .lh-zoom__btn {
    width: 30px; height: 30px; border-radius: var(--sw-radius-sm);
    border: 1px solid var(--sw-border); background: var(--sw-bg);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--sw-text-muted);
  }
  .lh-zoom__btn:hover { border-color: var(--sw-brand-500); color: var(--sw-brand-600); }
  .lh-zoom__btn:focus-visible { outline: none; box-shadow: var(--sw-shadow-focus); }
  .lh-zoom__fit { width: auto; padding: 0 10px; font-size: 13px; font-weight: 600; }
  .lh-zoom__val { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--sw-text-muted); min-width: 38px; text-align: center; }

  /* Stage / paper — ocupa el alto libre de la columna y scrollea por dentro
     (el lienzo A4 es más alto que la pantalla). */
  .lh-stage {
    background: var(--sw-bg-muted);
    border: 1px solid var(--sw-border);
    border-radius: var(--sw-radius-lg);
    padding: 24px;
    overflow: auto;
    display: flex; justify-content: center; align-items: flex-start;
    flex: 1 1 auto;
    min-height: 0;
  }
  .lh-paper {
    background: #fff;
    border: 1px solid var(--sw-border);
    padding: 36px 44px;
    color: #1a1a1a;
    width: 700px;
    min-height: 980px;
    flex: 0 0 auto; /* 06-11-2026: que no se estreche dentro del lienzo */
    box-shadow: var(--sw-shadow-lg);
    display: flex;
    flex-direction: column;
    transform-origin: top center;
    transition: transform var(--sw-dur-fast) var(--sw-ease-out);
  }
  .lh-paper__body { flex: 1; }
  .lh-print-hint { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--sw-text-subtle); margin: 10px 0 0; flex: 0 0 auto; }

  /* Plantilla classic */
  .lh-paper--classic { font: 13.5px / 1.6 'Georgia', 'Times New Roman', serif; }
  .lh-paper--classic .lh-paper__head {
    text-align: center;
    border-bottom: 1px solid #1a1a1a;
    padding-bottom: 14px;
    margin-bottom: 22px;
  }
  .lh-paper--classic .lh-paper__head .lh-empresa { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
  .lh-paper--classic .lh-paper__head .lh-eslogan { font-style: italic; color: #525252; font-size: 13px; margin-top: 3px; }
  .lh-paper--classic .lh-paper__foot {
    border-top: 1px solid #1a1a1a;
    margin-top: 22px;
    padding-top: 10px;
    text-align: center;
    color: #525252;
    font-size: 11.5px;
  }

  /* Plantilla modern */
  .lh-paper--modern { font: 13.5px / 1.6 'Inter', sans-serif; }
  .lh-paper--modern .lh-paper__head {
    display: flex; align-items: center; gap: 18px;
    border-left: 6px solid var(--lh-color, #f43f5e);
    padding: 8px 0 8px 16px;
    margin-bottom: 22px;
  }
  .lh-paper--modern .lh-paper__head .lh-empresa { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
  .lh-paper--modern .lh-paper__head .lh-eslogan { color: #525252; font-size: 13px; margin-top: 2px; }
  .lh-paper--modern .lh-paper__foot {
    color: #525252; font-size: 11.5px;
    margin-top: 22px;
    padding-top: 10px;
    border-top: 2px solid var(--lh-color, #f43f5e);
    display: flex; flex-wrap: wrap; gap: 14px;
  }

  /* Plantilla minimal */
  .lh-paper--minimal { font: 13.5px / 1.65 'Inter', sans-serif; }
  .lh-paper--minimal .lh-paper__head {
    margin-bottom: 28px;
    padding-bottom: 6px;
    border-bottom: 1px solid #d4d4d4;
  }
  .lh-paper--minimal .lh-paper__head .lh-empresa { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; }
  .lh-paper--minimal .lh-paper__head .lh-eslogan { color: #71716f; font-size: 12.5px; margin-top: 1px; }
  .lh-paper--minimal .lh-paper__foot {
    color: #71716f; font-size: 11px;
    margin-top: 26px; padding-top: 10px;
    border-top: 1px solid #d4d4d4;
    text-align: center;
  }

  .lh-empresa { display: block; }
  .lh-paper__head img.lh-logo { max-height: 72px; max-width: 200px; display: block; }
  .lh-paper--classic .lh-paper__head img.lh-logo { margin: 0 auto 8px; }
  .lh-paper--minimal .lh-paper__head img.lh-logo { margin: 0 auto 12px; max-height: 60px; }

  .lh-doc { display: flex; flex-direction: column; gap: 14px; }
  .lh-doc .lh-dest { color: #1a1a1a; font-weight: 600; }
  .lh-doc .lh-fecha { color: #525252; font-size: 12.5px; }
  .lh-doc .lh-asunto { font-weight: 700; }
  .lh-doc .lh-cuerpo { white-space: pre-wrap; }
  .lh-doc .lh-firma { margin-top: 30px; font-style: italic; }
  .lh-empty {
    color: #a1a1aa; font-style: italic; text-align: center;
    padding: 60px 20px;
  }

  /* Body font variants para preview */
  .lh-paper.body-sans  .lh-paper__body, .lh-paper.body-sans .lh-doc { font-family: 'Inter', sans-serif; }
  .lh-paper.body-mono  .lh-paper__body, .lh-paper.body-mono .lh-doc { font-family: var(--sw-font-mono); }
  .lh-paper.body-serif .lh-paper__body, .lh-paper.body-serif .lh-doc { font-family: 'Georgia', serif; }

  /* ── Plantilla executive ── */
  .lh-paper--executive { font: 13.5px / 1.6 'Georgia', serif; padding: 0 44px 36px; }
  .lh-paper--executive .lh-paper__head {
    background: #1a1a1a; color: #fff;
    margin: 0 -44px 22px;
    padding: 22px 44px;
    display: flex; align-items: center; gap: 18px;
  }
  .lh-paper--executive .lh-paper__head .lh-empresa {
    font-size: 22px; letter-spacing: 1px; font-weight: 400; color: #fff;
  }
  .lh-paper--executive .lh-paper__head .lh-eslogan { color: #c9c9c0; font-style: italic; }
  .lh-paper--executive .lh-paper__head img.lh-logo { filter: brightness(0) invert(1); max-height: 56px; }
  .lh-paper--executive .lh-paper__foot {
    border-top: 1px solid #1a1a1a;
    margin-top: 22px; padding-top: 10px;
    color: #525252; font-size: 11.5px;
    display: flex; flex-wrap: wrap; gap: 14px;
  }

  /* ── Plantilla agency ── */
  .lh-paper--agency { font: 13.5px / 1.6 'Inter', sans-serif; }
  .lh-paper--agency .lh-paper__head {
    display: grid; grid-template-columns: 1fr auto;
    align-items: end; gap: 18px;
    margin-bottom: 22px; padding-bottom: 12px;
    border-bottom: 4px solid var(--lh-color, #f43f5e);
  }
  .lh-paper--agency .lh-paper__head .lh-empresa {
    font-size: 28px; font-weight: 800; color: var(--lh-color, #f43f5e);
    letter-spacing: -0.5px;
  }
  .lh-paper--agency .lh-paper__head .lh-eslogan { color: #525252; font-size: 13px; margin-top: 2px; }
  .lh-paper--agency .lh-paper__foot {
    margin-top: 22px; padding-top: 10px;
    border-top: 1px solid #d4d4d4;
    color: #71716f; font-size: 11.5px;
  }

  /* ── Plantilla legal ── */
  .lh-paper--legal { font: 13px / 1.6 'Times New Roman', serif; }
  .lh-paper--legal .lh-paper__head {
    text-align: center;
    margin-bottom: 28px; padding-bottom: 12px;
    border-bottom: 3px double #1a1a1a;
  }
  .lh-paper--legal .lh-paper__head .lh-empresa {
    font-size: 19px; font-weight: 700; letter-spacing: 0.5px;
    text-transform: uppercase;
  }
  .lh-paper--legal .lh-paper__head .lh-eslogan {
    color: #525252; font-size: 11.5px; font-style: italic; margin-top: 2px;
  }
  .lh-paper--legal .lh-paper__foot {
    margin-top: 22px; padding-top: 10px;
    border-top: 3px double #1a1a1a;
    text-align: center;
    color: #525252; font-size: 10.5px;
    line-height: 1.55;
  }

  /* ── Plantilla medical ── */
  .lh-paper--medical { font: 13px / 1.65 'Inter', sans-serif; }
  .lh-paper--medical .lh-paper__head {
    display: flex; gap: 16px; align-items: center;
    border-bottom: 2px solid #0ea5e9;
    padding-bottom: 14px; margin-bottom: 22px;
  }
  .lh-paper--medical .lh-paper__head .lh-empresa {
    font-size: 18px; font-weight: 700; color: #0e7490;
  }
  .lh-paper--medical .lh-paper__head .lh-eslogan { color: #525252; font-size: 12px; }
  .lh-paper--medical .lh-paper__foot {
    margin-top: 22px; padding-top: 10px;
    border-top: 1px solid #d4d4d4;
    color: #525252; font-size: 11px;
    text-align: right;
  }

  /* ── Plantilla academic ── */
  .lh-paper--academic { font: 13px / 1.6 'Georgia', serif; }
  .lh-paper--academic .lh-paper__head {
    display: flex; align-items: center; gap: 18px;
    border-bottom: 1px solid #1e3a8a;
    padding-bottom: 14px; margin-bottom: 22px;
  }
  .lh-paper--academic .lh-paper__head .lh-empresa {
    font-size: 18px; font-weight: 700; color: #1e3a8a;
    text-transform: uppercase; letter-spacing: 1.5px;
  }
  .lh-paper--academic .lh-paper__head .lh-eslogan {
    color: #525252; font-size: 11.5px; font-style: italic; margin-top: 2px;
  }
  .lh-paper--academic .lh-paper__foot {
    margin-top: 22px; padding-top: 10px;
    border-top: 1px solid #1e3a8a;
    color: #525252; font-size: 10.5px; text-align: center;
  }

  /* ── Logo SVG inline ── */
  .lh-paper__head .lh-logo-svg {
    max-height: 72px; max-width: 200px; display: block;
    overflow: hidden;
  }
  .lh-paper__head .lh-logo-svg svg { max-height: 72px; max-width: 200px; display: block; }

  /* ── 2 columnas en body ── */
  .lh-paper.cols-2 .lh-doc .lh-cuerpo {
    column-count: 2; column-gap: 24px;
  }

  /* ── Marca de agua ── */
  .lh-paper { position: relative; }
  .lh-paper__watermark {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 96px; font-weight: 900;
    color: rgba(0,0,0,0.06);
    pointer-events: none;
    letter-spacing: 6px;
    user-select: none;
    z-index: 0;
    white-space: nowrap;
  }
  .lh-paper__head, .lh-paper__body, .lh-paper__foot { position: relative; z-index: 1; }

  /* Modal extras */
  .lh-steps { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; color: var(--sw-text); }
  .lh-steps kbd {
    font-family: var(--sw-font-mono); font-size: 12px;
    background: var(--sw-bg-muted); border: 1px solid var(--sw-border);
    border-radius: 4px; padding: 1px 5px;
  }

  /* ── Botón + panel "Cómo usar" ── */
  .lh-help-btn { flex: 0 0 auto; }
  .lh-help-card { max-width: 620px; }
  .lh-help__lead { font-size: 14.5px; color: var(--sw-text-muted); line-height: 1.6; margin: 0 0 18px; }
  .lh-help__lead strong { color: var(--sw-text); }
  .lh-help__h {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--sw-text-muted); margin: 18px 0 10px;
  }
  .lh-help__h:first-of-type { margin-top: 0; }
  .lh-help__h svg { color: var(--sw-brand-500); }
  .lh-help__steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
  .lh-help__steps li { font-size: 14px; line-height: 1.55; color: var(--sw-text); }
  .lh-help__steps strong { color: var(--sw-brand-700); }
  .lh-help__steps code, .lh-help__tips code {
    font-family: var(--sw-font-mono); font-size: 12.5px;
    background: var(--sw-bg-muted); border: 1px solid var(--sw-border);
    border-radius: 4px; padding: 1px 5px;
  }
  .lh-help__tips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
  .lh-help__tips li {
    position: relative; padding-left: 18px;
    font-size: 14px; line-height: 1.55; color: var(--sw-text-muted);
  }
  .lh-help__tips li::before {
    content: ""; position: absolute; left: 2px; top: 7px;
    width: 6px; height: 6px; border-radius: 999px; background: var(--sw-spot-500);
  }
  .lh-help__tips strong { color: var(--sw-text); }
  .lh-help__keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
  .lh-help__keys li { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--sw-text-muted); }
  .lh-help__keys span { color: var(--sw-text-muted); }
  .lh-help__keys kbd {
    font-family: var(--sw-font-mono); font-size: 12px;
    background: var(--sw-bg-muted); border: 1px solid var(--sw-border);
    border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; color: var(--sw-text);
  }

  /* ── Responsive del panel derecho (Hoja A4 + Acciones) ── */
  @media (min-width: 881px) and (max-width: 1180px) {
    /* Tablet landscape: el panel se pliega a una franja full-width DEBAJO del
       grid de 2 columnas, en una sola fila compacta (Hoja A4 + Acciones lado a
       lado). Va abajo —no encima— para no comprimir form+previa en los ~640px
       de alto útil de un 1024×768. Sus paneles internos no scrollean: la franja
       es de alto fijo y queda siempre visible al pie del workspace. */
    .lh-aside {
      grid-column: 1 / -1; grid-row: 2;
      order: 0;
    }
    .lh-aside__scroll {
      flex-direction: row; flex-wrap: wrap; align-items: stretch;
      gap: 12px; overflow: visible;
    }
    .lh-aside__sheet, .lh-aside__actions {
      flex: 1 1 320px; min-width: 0;
      border: 1px solid var(--sw-border); border-radius: var(--sw-radius-md);
      padding: 10px 12px; background: var(--sw-bg);
    }
    /* Hoja A4: los 4 controles en rejilla horizontal para ocupar poco alto. */
    .lh-aside__sheet { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; align-items: end; }
    .lh-aside__sheet .lh-aside__h { grid-column: 1 / -1; margin-bottom: 2px; }
    .lh-aside__sheet .lh-field { margin-bottom: 0; }
    /* Acciones: Guardar/Exportar arriba en fila, Vaciar/Borrar debajo. */
    .lh-aside__actions { gap: 8px; }
    .lh-aside__actions .lh-aside__h { margin-bottom: 0; }
  }
  @media (max-width: 880px) {
    /* Tablet portrait / móvil — 1 columna en orden: formulario → Hoja y
       acciones → vista previa. Así rellenas datos, ajustas la hoja y al final
       ves el A4 con su zoom (un scroll corto, sin empujar la página). */
    .lh-grid { display: flex; flex-direction: column; }
    .lh-form  { order: 1; }
    .lh-aside { grid-column: auto; grid-row: auto; order: 2; }
    .lh-output { order: 3; }
    .lh-aside__scroll { flex-direction: column; gap: 12px; }
    .lh-aside__sheet, .lh-aside__actions {
      flex: 1 1 auto; margin-bottom: 0;
      border: 1px solid var(--sw-border); border-radius: var(--sw-radius-md);
      padding: 10px 12px; background: var(--sw-bg);
    }
    .lh-aside__sheet { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; align-items: end; }
    .lh-aside__sheet .lh-aside__h { grid-column: 1 / -1; margin-bottom: 2px; }
    .lh-aside__sheet .lh-field { margin-bottom: 0; }
    .lh-grid { grid-template-rows: none; }
    .lh-form, .lh-output { grid-row: auto; }
    .lh-topbar { flex-wrap: wrap; gap: 10px; }
    .lh-topbar__sel { flex: 1 1 auto; }
    .lh-topbar .lh-select { flex: 1 1 auto; max-width: none; }
    .lh-meter { flex: 1 1 100%; order: 3; }
    .lh-topbar .lh-help-btn { margin-left: 0; }
  }
  @media (max-width: 560px) {
    /* Móvil estrecho: la Hoja A4 vuelve a 1 columna (pares no caben). */
    .lh-aside__sheet { grid-template-columns: 1fr; }
  }

  /* ══════════════════════════════════════════════════════════════════════
     MÓVIL (≤640px) · flujo en 2 VISTAS con conmutador "Editar | Vista previa".
     Objetivo: que lo esencial (datos + Guardar/Exportar) quepa con el mínimo
     scroll. No caben formulario + A4 a la vez con utilidad, así que se separan
     en dos pestañas autocontenidas. La barra de acciones queda SIEMPRE visible
     (sticky abajo) en ambas vistas → Guardar/Exportar siempre al alcance del
     pulgar. La "Hoja A4" (config de bajo valor) se ve solo en Editar, compacta.
     Ninguna funcionalidad se elimina: todo accesible vía pestaña/sticky/modal.
     ════════════════════════════════════════════════════════════════════════ */
  @media (max-width: 640px) {
    /* La raíz scrollea con la página (cada vista es corta y autocontenida). */
    .sw-tool-shell__body > .tool-letterhead-root,
    .tool-letterhead-root > .container { overflow: visible; height: auto; }

    /* Topbar compacta: selector full-width arriba, medidor debajo, "Cómo usar"
       como icono al lado del selector para no robar una fila entera. */
    .lh-topbar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 10px; margin-bottom: 10px; }
    .lh-topbar__sel { flex: 1 1 auto; min-width: 0; }
    .lh-topbar .lh-select { flex: 1 1 auto; max-width: none; min-width: 0; }
    .lh-meter { flex: 1 1 100%; order: 3; }
    .lh-topbar .lh-help-btn { flex: 0 0 auto; margin-left: 0; }

    /* Conmutador visible: 2 pestañas grandes (≥40px) tipo segmented. */
    .lh-mtabs {
      display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
      padding: 4px; margin-bottom: 12px;
      background: var(--sw-bg-muted); border: 1px solid var(--sw-border);
      border-radius: var(--sw-radius-lg);
    }
    .lh-mtab {
      display: inline-flex; align-items: center; justify-content: center; gap: 7px;
      min-height: 44px; padding: 0 10px; cursor: pointer;
      border: 1px solid transparent; border-radius: var(--sw-radius-md);
      background: transparent; color: var(--sw-text-muted);
      font: 600 14.5px var(--sw-font-sans);
      transition: background var(--sw-dur-fast) var(--sw-ease-out), color var(--sw-dur-fast) var(--sw-ease-out);
    }
    .lh-mtab svg { color: currentColor; }
    .lh-mtab.is-active {
      background: var(--sw-bg); color: var(--sw-brand-600);
      border-color: var(--sw-border); box-shadow: var(--sw-shadow-xs);
    }
    .lh-mtab:focus-visible { outline: none; box-shadow: var(--sw-shadow-focus); }

    /* El grid pasa a flujo simple; cada vista controla qué se ve. */
    .lh-grid { display: flex; flex-direction: column; gap: 0; min-height: 0; }
    .lh-form, .lh-output, .lh-aside { min-height: 0; }
    .lh-form__scroll, .lh-aside__scroll { overflow: visible; }

    /* Formulario sin recuadro doble (ya hay separación de bloques) + aire al
       pie para no quedar tapado por la barra de acciones sticky. */
    .lh-form { order: 1; border: 0; background: transparent; padding: 0; }
    .lh-aside { order: 2; }
    .lh-output { order: 3; }
    .lh-aside__scroll { flex-direction: column; gap: 12px; }

    /* Hoja A4 (config): 1 columna compacta dentro de la vista Editar. */
    .lh-aside__sheet, .lh-aside__actions {
      flex: 1 1 auto; margin-bottom: 0;
      border: 1px solid var(--sw-border); border-radius: var(--sw-radius-md);
      padding: 12px 14px; background: var(--sw-bg);
    }
    .lh-aside__sheet { display: block; }
    .lh-aside__sheet .lh-field { margin-bottom: 10px; }

    /* Controles a tamaño táctil cómodo (≥42px) en móvil. */
    .lh-field input, .lh-field textarea, .lh-select, .lh-field select { padding: 11px 12px; font-size: 16px; }
    .lh-field input[type="color"] { height: 44px; width: 56px; }
    .lh-field textarea { font-size: 14.5px; }
    .lh-zoom__btn { width: 38px; height: 38px; }
    .lh-sw { width: 28px; height: 28px; }

    /* ── Vista EDITAR (por defecto): form + Hoja A4 + acciones; oculta A4. ── */
    .tool-letterhead-root.lh-mview-edit .lh-output { display: none; }

    /* ── Vista PREVIA: A4 a casi pantalla completa; oculta form y "Hoja A4".
       Las acciones (Guardar/Exportar/…) siguen visibles abajo (sticky). ── */
    .tool-letterhead-root.lh-mview-preview .lh-form,
    .tool-letterhead-root.lh-mview-preview .lh-aside__sheet { display: none; }
    .tool-letterhead-root.lh-mview-preview .lh-output { order: 1; }
    .tool-letterhead-root.lh-mview-preview .lh-aside { order: 2; }
    .tool-letterhead-root.lh-mview-preview .lh-stage { max-height: 68vh; }
    .lh-stage { max-height: 70vh; }

    /* ── Barra de acciones SIEMPRE visible (sticky al pie), en ambas vistas.
       Es lo nuclear: Guardar / Exportar siempre al alcance del pulgar. ── */
    .lh-aside__actions {
      position: sticky; bottom: 0; z-index: 5;
      margin-top: 4px;
      box-shadow: 0 -6px 16px -10px rgba(0,0,0,0.25);
      border-color: var(--sw-border-strong);
    }
    .lh-aside__actions .lh-aside__h { display: none; } /* gana alto: el contexto ya es claro */
    .lh-aside__actions .sw-btn { min-height: 44px; }
    .lh-aside__actrow .sw-btn { min-height: 44px; }
    .lh-status { text-align: center; }
  }

  /* Pantallas muy estrechas (~360): aún más compacto. */
  @media (max-width: 380px) {
    .lh-mtab { font-size: 14px; gap: 5px; padding: 0 6px; }
    .lh-tpls { gap: 6px; }
    .lh-topbar__lbl { display: none; } /* el icono del select ya orienta */
  }

  @media print {
    .sw-tool-app-header,
    .sw-tool-shell__head, .sw-toasts, .sw-ejemplo,
    .sw-tool-seo,
    .lh-topbar,
    .lh-form,
    .lh-aside,
    .lh-output__head,
    .lh-print-hint,
    .sw-modal,
    body > header, body > footer { display: none !important; }
    body { background: #fff !important; }
    .sw-section, .container, .lh-grid, .lh-output, .lh-stage {
      padding: 0 !important; margin: 0 !important; border: 0 !important;
      background: #fff !important; max-height: none !important; overflow: visible !important;
    }
    .lh-grid { display: block !important; }
    .lh-paper {
      box-shadow: none !important;
      border: 0 !important;
      width: 100% !important;
      /* El margen del documento lo aporta el propio papel según el selector
         "Márgenes A4" (--lh-page-margin). @page va a 0 para que el padding del
         papel sea el que manda; así el selector narrow/normal/wide SÍ cambia el
         PDF (antes @page tenía 22mm fijos y el selector no hacía nada). */
      padding: var(--lh-page-margin, 22mm) !important;
      /* Repaso 06-11: la hoja entera (con 0 el pie subía a media página); 296 mm para no saltar a otra hoja. */
      min-height: 296mm !important;
      box-sizing: border-box !important;
      transform: none !important;
      zoom: 1 !important;
    }
    /* Sin margen de página del navegador: el margen real lo da el padding del
       papel (var --lh-page-margin), controlado por el selector de márgenes. */
    @page { size: A4; margin: 0; }
  }

  /* ══════════ 06-11-2026 · PORTÁTIL: de 881 a 1599 px de ancho, o escritorio bajo (≤ 820 px de alto) ══════════
     Con el alto de una pantalla exacta y columnas fijas (620 + 300 px), en un portátil la hoja A4 salía de
     135-300 px de ancho y, a 1152×610, el lienzo medía 98 px de alto. Aquí la página corre: el formulario
     baja con ella y la hoja (y el panel de acciones) se quedan fijos arriba. Por encima de 1600 px de ancho y
     820 de alto todo sigue igual. */
  @media (min-width: 881px) and (max-width: 1599px), (min-width: 881px) and (max-height: 820px) {
    html:has(.tool-letterhead-root), body:has(.tool-letterhead-root) { overflow-x: clip; }
    .sw-tool-shell:has(.tool-letterhead-root) { height: auto; min-height: calc(100dvh - var(--sw-header-h)); }
    .sw-tool-shell:has(.tool-letterhead-root) > .sw-tool-shell__body { flex: 1 0 auto; }
    .sw-tool-shell__body > .tool-letterhead-root,
    .tool-letterhead-root > .container { height: auto; overflow: visible; }
    .lh-grid { flex: 0 0 auto; align-items: start; }
    .lh-form, .lh-form__scroll { overflow: visible; }
    .lh-output, .lh-aside {
      position: sticky; top: calc(var(--sw-header-h) + 12px);
      max-height: calc(100dvh - var(--sw-header-h) - 24px);
    }
  }
  @media (min-width: 1181px) and (max-width: 1599px) {
    .lh-grid { grid-template-columns: minmax(360px, 32%) minmax(0, 1fr) minmax(260px, 21%); gap: 16px; }
    .lh-tpls { grid-template-columns: repeat(3, 1fr); }
  }
  @media (min-width: 881px) and (max-width: 1180px) {
    /* Izquierda: formulario y, al acabarlo, hoja A4 y acciones (Guardar, Exportar PDF).
       Derecha: la hoja, fija arriba mientras rellenas. */
    .lh-grid { grid-template-rows: auto auto; }
    .lh-form   { grid-column: 1; grid-row: 1; }
    .lh-aside  { grid-column: 1; grid-row: 2; position: static; max-height: none; }
    .lh-output { grid-column: 2; grid-row: 1 / span 2; }
    .lh-aside__sheet { grid-template-columns: 1fr; }
  }
  /* ══════════ Pantalla 06-11-2026 (grupo A) · Guardar y Exportar PDF siempre a mano ══════════
     Tableta apaisada (881-1180): las acciones quedaban al final del formulario, fuera de la pantalla. Ahora van
     en una fila encima de la hoja; los ajustes de la hoja A4, al final del formulario.
     Móvil (≤ 640): la barra de acciones «pegada abajo» no se pegaba (su caja estaba debajo del formulario).
     Ahora sale fija al pie mientras se rellena y mientras se mira la vista previa. */
  @media (min-width: 881px) and (max-width: 1180px) {
    .lh-aside, .lh-aside__scroll { display: contents; }
    .lh-grid { grid-template-rows: auto auto 1fr; }
    .lh-form { grid-column: 1; grid-row: 1 / span 2; }
    .lh-aside__sheet { grid-column: 1; grid-row: 3; align-self: start; }
    .lh-aside__actions {
      grid-column: 2; grid-row: 1; align-self: start;
      display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px;
      padding: 8px 10px; margin: 0;
    }
    .lh-aside__actions .lh-aside__h { display: none; }
    .lh-aside__actions > .sw-btn { width: auto; flex: 1 1 auto; }
    .lh-aside__actions .lh-aside__actrow { display: flex; gap: 6px; margin: 0; }
    .lh-aside__actions .lh-status:empty { display: none; }
    .lh-output { grid-column: 2; grid-row: 2 / span 2; }
  }
  @media (max-width: 640px) {
    /* Selector y «Cómo usar» en una fila; la barra de progreso, debajo. */
    .lh-topbar { flex-wrap: wrap; row-gap: 6px; }
    .lh-topbar__sel { flex: 1 1 0; min-width: 0; }
    .lh-topbar .lh-select { min-width: 0; }
    .lh-topbar__lbl { display: none; }
    .lh-aside, .lh-aside__scroll { display: contents; }
    .lh-aside__sheet { order: 2; }
    .tool-letterhead-root.lh-mview-preview .lh-output { order: 1; }
    .lh-aside__actions {
      order: 9; position: sticky; bottom: 0; z-index: 6;
      display: grid; grid-template-columns: 1fr 1fr auto; align-items: stretch; gap: 8px;
      padding: 8px; margin: 4px 0 0;
      background: var(--sw-bg);
    }
    .lh-aside__actions > .sw-btn { width: auto; font-size: 13.5px; white-space: normal; line-height: 1.2; }
    .lh-aside__actions .lh-aside__actrow { display: flex; gap: 6px; margin: 0; }
    /* «Vaciar» y «Borrar» se quedan en su icono (el nombre lo sigue leyendo el lector de pantalla). */
    .lh-aside__actions .lh-aside__actrow .sw-btn { font-size: 0; gap: 0; min-width: 44px; padding: 0 10px; }
    .lh-aside__actions .lh-aside__actrow .sw-btn svg { width: 18px; height: 18px; }
    .lh-aside__actions .lh-status { grid-column: 1 / -1; }
    .lh-aside__actions .lh-status:empty { display: none; }
  }

  /* Variable de margen A4 según el selector (consumida por el padding del papel
     en @media print, arriba). En pantalla el padding base de .lh-paper manda. */
  .lh-paper.margins-narrow { --lh-page-margin: 15mm; }
  .lh-paper.margins-normal { --lh-page-margin: 22mm; }
  .lh-paper.margins-wide   { --lh-page-margin: 30mm; }

  /* Barrido 06-11-2026 · tocables de 44 px en el móvil y en pantallas táctiles. */
  @media (pointer: coarse), (max-width: 768px) {
    #lhTabEdit, #lhTabPrev { min-height: 44px; }
    .lh-sw { width: 44px; height: 44px; }
    #lhZoomOut, #lhZoomIn, #lhZoomFit { min-width: 44px; min-height: 44px; }
    .tool-letterhead-root details > summary { min-height: 44px; padding-top: 12px; box-sizing: border-box; }
  }
