/* ==========================================================================
   Rediseño: base sobria + móvil primero
   (se carga después de app.css y ajusta su apariencia)
   ========================================================================== */
:root {
    --bg: #f6f7fb;
    --line: #e8eaf1;
    --shadow: 0 1px 2px rgba(21, 26, 45, .04);
}
body { background: var(--bg); padding-bottom: 92px; }
.bg-decor { display: none; }

/* ---------- Cabecera única: marca · pasos · ayuda ---------- */
.appbar {
    position: sticky; top: 0; z-index: 30; height: 64px; box-sizing: border-box;
    padding: 0 max(24px, calc((100vw - 1180px) / 2 + 24px));
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
    background: rgba(255, 255, 255, .96); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
}
.appbar .brand { gap: 10px; min-width: 0; }
.appbar .brand-mark { width: 34px; height: 34px; border-radius: 10px; box-shadow: none; }
.appbar .brand-mark .ico { width: 18px; height: 18px; }
.appbar .brand-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-end { display: flex; justify-content: flex-end; }

.stepper { position: static; display: flex; align-items: center; gap: 10px; margin: 0; padding: 0; max-width: none; grid-template-columns: none; }
.stepper .step { flex-direction: row; gap: 8px; padding: 4px 6px; border-radius: 10px; }
.stepper .step:not(:disabled):hover { background: var(--surface-2); }
.stepper .step-dot {
    width: 26px; height: 26px; border-width: 1.5px; font-size: 12.5px; font-weight: 700; color: var(--muted);
    transform: none !important; box-shadow: none !important;
}
.stepper .step-label { font-size: 13px; }
.stepper .step.done .step-dot { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.stepper .step.active .step-dot { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 0 0 4px rgba(79, 70, 229, .12) !important; }
.stepper .step.active .step-label { color: var(--ink); }
.step-line { width: 32px; height: 2px; border-radius: 2px; background: var(--line); transition: background .4s; }
.step.done + .step-line { background: var(--accent); }

.mstep { display: none; }

/* ---------- Contenedor y paneles sobrios ---------- */
.shell { padding-top: 24px; }
.panel {
    background: #fff; backdrop-filter: none; border: 1px solid var(--line); border-radius: 16px;
    box-shadow: var(--shadow); padding: 28px 32px 32px;
}
.panel-head { margin-bottom: 18px; }
.panel-head h1 { font-size: 26px; margin-bottom: 6px; }
.panel-head .lead { font-size: 15px; }
.eyebrow { display: none; }
.section-title { margin: 20px 0 10px; font-size: 14.5px; }

/* Ayuda como enlace plegable */
.help { border: 0; background: transparent; margin: -4px 0 16px; }
.help summary { padding: 4px 0; font-size: 13.5px; color: var(--accent); }
.help summary::after { margin-left: 6px; }
.help[open] { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 2px; }
.help-body { padding: 6px 0 14px; }

.dropzone { min-height: 210px; border-radius: 16px; background: #fafbfd; }
.file-card, .custom-vars, .table-wrap, .map-row, .card-sub, .tpl-card, .fmt-box, .sheet-card, .ed-field { box-shadow: none; }
.custom-vars { border: 1px solid var(--line); background: #fff; }
.chip { box-shadow: none; animation-duration: .3s; }

/* ---------- Paso 1: dos columnas en escritorio ---------- */
.dr-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
@media (min-width: 1100px) {
    .dr-grid { grid-template-columns: 360px minmax(0, 1fr); gap: 28px; align-items: start; }
    .dr-side .section-title:first-of-type { margin-top: 18px; }
    .dr-side .file-card { flex-wrap: wrap; }
    .dr-side .file-actions { width: 100%; }
    .dr-side .file-actions { justify-content: space-between; }
    .dr-side .sheet-cards { grid-template-columns: 1fr; }
    .dr-main .table-head .section-title { margin-top: 0; }
    .dr-main .table-wrap { max-height: calc(100vh - 330px); min-height: 320px; }
}
.client-list { display: none; }

/* ---------- Barra inferior con la acción principal ---------- */
.navbar { background: rgba(255, 255, 255, .97); padding-top: 12px; padding-bottom: 12px; }
#btnNext { height: 46px; padding: 0 22px; border-radius: 12px; font-size: 14.5px; }
#btnNext.ready { animation: none; }
.gen-cta { display: none; }

/* ---------- Paso 2 ---------- */
.t-short { display: none; }
.tpl-card { border-width: 1px; }
.tpl-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px -12px rgba(21, 26, 45, .25); }

/* ---------- Paso 3 ---------- */
.review-tabs { display: none; }
.seg-tabs { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; background: #eceef5; border-radius: 12px; margin-bottom: 14px; }
.seg-tabs button { height: 40px; border: 0; border-radius: 9px; background: transparent; font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg-tabs button.on { background: #fff; color: var(--accent-ink); box-shadow: 0 1px 3px rgba(21, 26, 45, .1); font-weight: 700; }
#rvBadge { font-size: 12px; font-weight: 700; margin-left: 4px; }
#rvBadge.ok { color: var(--ok); }
#rvBadge.warn { color: var(--warn); }

/* =================================================== Tablet (≤ 980px) */
@media (max-width: 980px) {
    .appbar { grid-template-columns: auto 1fr auto; }
    .stepper .step-label { display: none; }
    .stepper { justify-content: center; }
    .review-tabs { display: grid; }
    .review-grid[data-view="map"] .review-right { display: none; }
    .review-grid[data-view="preview"] .review-left { display: none; }
    .preview-stage { height: calc(100vh - 330px); min-height: 380px; }
}

/* =================================================== Móvil (≤ 640px) */
@media (max-width: 640px) {
    body { padding-bottom: 84px; }
    .appbar { height: 56px; padding: 0 16px; grid-template-columns: 1fr auto; }
    .appbar .brand-title { font-size: 15px; }
    .appbar .stepper { display: none; }
    #btnHowTo span { display: none; }
    #btnHowTo { width: 38px; height: 38px; padding: 0; }

    /* Progreso del asistente como barra */
    .mstep {
        display: flex; flex-direction: column; gap: 8px; position: sticky; top: 56px; z-index: 29;
        padding: 10px 16px 10px; background: #fff; border-bottom: 1px solid var(--line);
    }
    .mstep-top { display: flex; justify-content: space-between; font-size: 12.5px; }
    .mstep-top span { color: var(--muted); }
    .mstep-bars { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
    .mstep-bars span { height: 4px; border-radius: 4px; background: #e3e5ee; transition: background .4s; }
    .mstep-bars span.on { background: var(--accent); }

    .shell { padding: 14px 12px 20px; }
    .panel { padding: 20px 16px 22px; border-radius: 14px; }
    .panel-head h1 { font-size: 22px; }
    .panel-head .lead { font-size: 14px; }

    /* Barra inferior: botón principal de ancho completo */
    .navbar { padding: 12px 16px 14px; gap: 10px; }
    #btnBack { width: 50px; height: 50px; padding: 0; flex-shrink: 0; border-radius: 13px; }
    #btnBack span { display: none; }
    #btnNext { flex: 1; height: 50px; border-radius: 13px; font-size: 15px; justify-content: center; }
    #btnNext span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* Paso 1 */
    .dropzone { min-height: 180px; padding: 22px 16px; }
    .help-grid { gap: 12px; }
    .file-card { gap: 10px; }
    .file-actions { width: 100%; justify-content: space-between; }
    #columnChips, #customChips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
    #columnChips::-webkit-scrollbar, #customChips::-webkit-scrollbar { display: none; }
    #columnChips .chip, #customChips .chip { flex-shrink: 0; }
    .custom-vars { padding: 2px 12px 12px; }
    .custom-vars-head .hint { display: none; }
    .custom-vars-head .btn { width: 100%; }
    .table-head { gap: 8px; }
    .table-tools { width: 100%; }
    .table-tools .search { flex: 1; }
    .search input { width: 100%; }
    #dataWrap, #scrollHint, .dr-main > .hint { display: none !important; }
    .client-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; }
    .cl-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-bottom: 1px solid #f0f1f6; cursor: pointer; }
    .cl-item:last-child { border-bottom: 0; }
    .cl-item input { width: 19px; height: 19px; accent-color: var(--accent); flex-shrink: 0; }
    .cl-item span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
    .cl-item b { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .cl-item small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .cl-item.off b, .cl-item.off small { opacity: .45; text-decoration: line-through; }

    /* Paso 2: selector de tres partes y plantillas en filas */
    .tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; overflow: visible; }
    .tab { justify-content: center; padding: 9px 4px; }
    .tab .ico { display: none; }
    .t-long { display: none; }
    .t-short { display: inline; }
    .gallery { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    .tpl-card {
        display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 12px; row-gap: 2px;
        align-items: center; padding: 10px 12px; border-radius: 14px;
    }
    .tpl-card:hover { transform: none; }
    .tpl-card.selected::after { top: 50%; right: 12px; transform: translateY(-50%); width: 24px; height: 24px; font-size: 13px; }
    .tpl-thumb { grid-row: 1 / span 2; grid-column: 1; width: 56px; height: 72px; border-radius: 6px; }
    .tpl-thumb.word-thumb .ico { width: 26px; height: 26px; }
    .tpl-thumb::after { display: none; }
    .tpl-top { grid-column: 2; }
    .tpl-top .tpl-icon { display: none; }
    .tpl-name { font-size: 14.5px; }
    .tpl-desc { display: none; }
    .tpl-vars { grid-column: 2; }
    .tpl-vars .var:nth-child(n + 3) { display: none; }
    .tpl-actions { grid-column: 3; grid-row: 1 / span 2; margin: 0; }
    .tpl-card.selected .tpl-actions { margin-right: 30px; }
    .tpl-actions [data-act="use"] { display: none; }
    .upload-grid { gap: 18px; }
    .doc-mock { display: none; }

    /* Paso 3 */
    .map-row { padding: 12px; }
    .preview-stage { height: calc(100vh - 290px); min-height: 360px; padding: 12px; }
    .preview-bar .icon-btn { width: 42px; height: 42px; }

    /* Paso 4: formatos como lista con interruptores */
    .formats { grid-template-columns: minmax(0, 1fr); gap: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
    .fmt-box {
        display: grid; grid-template-columns: 40px minmax(0, 1fr) 46px; grid-template-rows: auto auto; column-gap: 12px; row-gap: 1px;
        align-items: center; padding: 12px 14px; border: 0; border-bottom: 1px solid #f0f1f6; border-radius: 0; animation: none;
    }
    .fmt:last-child .fmt-box { border-bottom: 0; }
    .fmt-box:hover { transform: none; box-shadow: none; }
    .fmt-icon { grid-row: 1 / span 2; width: 40px; height: 40px; margin: 0; }
    .fmt-box b { grid-column: 2; font-size: 14px; }
    .fmt-box small { grid-column: 2; font-size: 12px; }
    .fmt-check {
        position: static; grid-column: 3; grid-row: 1 / span 2; width: 44px; height: 26px; border: 0; border-radius: 999px;
        background: #d6d9e4; transform: none !important; position: relative;
    }
    .fmt-check .ico { display: none; }
    .fmt-check::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .3s var(--spring); }
    .fmt input:checked + .fmt-box { background: #fff; box-shadow: none; }
    .fmt input:checked + .fmt-box .fmt-check { background: var(--accent); }
    .fmt input:checked + .fmt-box .fmt-check::after { transform: translateX(18px); }

    .progress-hero h1, .done-hero h1 { font-size: 22px; }
    .done-actions .btn { width: 100%; }
    .done-footer .btn { width: 100%; }

    /* Editor a pantalla completa en móvil */
    .ed-top { padding: 0 10px; gap: 6px; height: 56px; }
    .ed-sub, #btnEditorNew, .ed-sep, #btnRedo { display: none; }
    .ed-name .ico { display: none; }
    .ed-name input { font-size: 14px; }
    #btnEditorSave { padding: 0 12px; height: 38px; }
    #btnEdPreview { width: 38px; padding: 0; }
    .ed-tabs { padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
    .ed-tabs::-webkit-scrollbar { display: none; }
    .ed-tab { padding: 0 10px; flex-shrink: 0; }
    .ed-tabs .rb-pages { display: none; }
    .ed-data-toggle { margin-left: auto; flex-shrink: 0; }
    .ed-panel { padding: 6px 10px; gap: 6px; }
    .ed-panel .rb-btn span { display: none; }
    .ed-panel .rb-btn { width: 40px; padding: 0; justify-content: center; }
    .ed-panel .rb-field { font-size: 0; gap: 4px; }
    .ed-panel .rb-sep { display: none; }
    /* Barra de formato: solo lo esencial para no ocupar varias filas */
    .toolbar-slot .ql-strike, .toolbar-slot .ql-script, .toolbar-slot .ql-background, .toolbar-slot .ql-blockquote,
    .toolbar-slot .ql-link, .toolbar-slot .ql-clean, .toolbar-slot .ql-header, .toolbar-slot .ql-indent, .toolbar-slot .tb-label { display: none !important; }
    .toolbar-slot .ql-toolbar.ql-snow .ql-formats { margin-right: 6px; }
    .ql-snow .ql-picker.ql-font { width: 96px; }
    .ed-work .editor-paper { padding: 12px 8px 40px; }
    /* Datos del cliente: panel que sube desde abajo */
    .ed-data {
        position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 56vh; z-index: 45;
        border-left: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -12px 32px rgba(21, 26, 45, .2); animation: sheetUp .3s var(--ease);
    }
    .ed-data::before { content: ''; width: 40px; height: 4px; border-radius: 4px; background: #d6d9e4; align-self: center; margin: -6px 0 2px; flex-shrink: 0; }
    @keyframes sheetUp { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
    .ed-status { gap: 10px; padding: 0 10px; }
    #stPaper, #stPages { display: none; }
    .ed-help { left: 10px; right: 10px; width: auto; }
}

@media (max-width: 640px) {
    #btnBack.is-first { display: none; }
    .cl-more { border: 0; background: #fafbfd; padding: 12px; font: 600 13px Inter, sans-serif; color: var(--accent); cursor: pointer; }
    .dr-main .table-more { display: none; }
}

@media (max-width: 640px) {
    .tpl-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
    .tpl-vars { flex-wrap: nowrap; overflow: hidden; }
    .tpl-vars .var { flex-shrink: 0; }
}

@media (max-width: 640px) {
    .fmt-check { align-self: center; justify-self: end; }
    .fmt input:checked + .fmt-box { border-color: #f0f1f6; }
    .fmt:last-child input:checked + .fmt-box { border-color: transparent; }
}

/* Nombres largos de plantilla: máximo 2 líneas */
.tpl-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
