:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #121726;
  --muted: #5f6678;
  --line: #e1e5ef;
  --brand: #7c3aed;
  --brand-ink: #ffffff;
  --brand-soft: #efe7ff;
  --good: #0f9d63;
  --good-soft: #dcf5ea;
  --warn: #b45309;
  --warn-soft: #fff3dc;
  --bad: #d93025;
  --shadow: 0 1px 2px rgba(18, 23, 38, .05), 0 8px 28px rgba(18, 23, 38, .07);
  --radius: 16px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e111a;
    --surface: #161a26;
    --surface-2: #1f2433;
    --text: #eef1f8;
    --muted: #9aa2b5;
    --line: #2a3042;
    --brand: #9b6bff;
    --brand-soft: #2a1d4a;
    --good: #3fcf8e;
    --good-soft: #10301f;
    --warn: #f5b04c;
    --warn-soft: #33260f;
    --bad: #ff6b5e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.15; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 42px; padding: .55rem 1rem;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600;
  text-decoration: none; white-space: nowrap; transition: transform .08s, filter .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--bad); }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: 1.05rem; padding: .75rem 1.4rem; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; border-radius: 10px; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent; display: inline-grid; place-items: center; cursor: pointer; font-size: 1.15rem; }
.icon-btn:hover { background: var(--surface-2); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; text-decoration: none; letter-spacing: -0.02em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.topbar .spacer { flex: 1; }
.cv-switch { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-weight: 600; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .brand span, .topbar .brand { font-size: 0; gap: 0; }
  .topbar #btn-download span { display: none; }
}

/* Layout editor + vista previa */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 24px; max-width: 1400px; margin: 0 auto; padding: 20px 16px 100px; }
.editor { min-width: 0; }
.preview-col { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 92px); overflow: auto; min-width: 0; scrollbar-width: thin; }
.mobile-tabs { display: none; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding-bottom: 110px; }
  .preview-col { position: static; max-height: none; overflow: visible; }
  .layout[data-tab="edit"] .preview-col, .layout[data-tab="preview"] .editor { display: none; }
  .mobile-tabs {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 30; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 6px; box-shadow: var(--shadow);
  }
  .mobile-tabs button { min-height: 46px; border: 0; border-radius: 12px; background: transparent; font-weight: 700; cursor: pointer; }
  .mobile-tabs button[aria-selected="true"] { background: var(--brand); color: #fff; }
}
.score-pill { font-size: .75rem; padding: 1px 7px; border-radius: 99px; background: var(--good-soft); color: var(--good); }
.mobile-tabs button[aria-selected="true"] .score-pill { background: rgba(255,255,255,.25); color: #fff; }

/* Tarjetas / secciones del editor */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.ed-sec { margin-bottom: 12px; }
.ed-sec > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 16px 18px; font-weight: 700; font-size: 1.02rem;
}
.ed-sec > summary::-webkit-details-marker { display: none; }
.ed-sec > summary::after { content: '▾'; margin-left: auto; color: var(--muted); transition: transform .15s; }
.ed-sec[open] > summary::after { transform: rotate(180deg); }
.ed-sec > summary .count { font-weight: 600; font-size: .8rem; color: var(--muted); background: var(--surface-2); border-radius: 99px; padding: 1px 8px; }
.ed-body { padding: 0 18px 18px; }

.field { display: grid; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field > label, .label { font-weight: 600; font-size: .85rem; }
.input, textarea.input, select.input {
  width: 100%; min-height: 44px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); outline: none;
}
textarea.input { resize: vertical; min-height: 96px; line-height: 1.45; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid2.stack-sm { grid-template-columns: 1fr; } }
.hint { font-size: .78rem; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: .85rem; cursor: pointer; margin-bottom: 10px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

.entry { border: 1px solid var(--line); border-radius: 12px; padding: 14px 14px 4px; margin-bottom: 10px; background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.entry-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.entry-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-tools { display: flex; gap: 2px; }
.entry-tools button { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.entry-tools button:hover { background: var(--surface-2); color: var(--text); }
.entry-tools button:disabled { opacity: .3; cursor: default; }
.row-inline { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 8px; }

.photo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.photo-row img, .photo-row .ph { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }

/* Diseño */
.tpl-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
@media (max-width: 480px) { .tpl-grid { grid-template-columns: repeat(2, 1fr); } }
.tpl-btn { position: relative; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); padding: 8px; cursor: pointer; text-align: center; font-weight: 600; font-size: .85rem; }
.tpl-btn[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.tpl-thumb { height: 58px; border-radius: 6px; margin-bottom: 6px; background: #fff; border: 1px solid #e5e7eb; position: relative; overflow: hidden; }
.tpl-thumb i { position: absolute; display: block; background: #d1d5db; border-radius: 2px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--text); }

/* ATS */
.ats { padding: 16px 18px; margin-bottom: 16px; }
.ats-top { display: flex; align-items: center; gap: 14px; }
.ring { --p: 0; --c: var(--good); width: 64px; height: 64px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; }
.ats h3 { font-size: 1rem; }
.ats ul { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.ats li { display: flex; gap: 8px; font-size: .86rem; }
.ats li::before { content: '!'; flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--warn-soft); color: var(--warn); font-weight: 800; font-size: .72rem; display: grid; place-items: center; margin-top: 1px; }
.ats li.ok::before { content: '✓'; background: var(--good-soft); color: var(--good); }
.ats .more { border: 0; background: none; color: var(--brand); font-weight: 600; cursor: pointer; padding: 6px 0 0; }

/* Vista previa (hoja escalada) */
.preview-wrap { position: relative; width: 100%; }
.sheet-scaler { transform-origin: top left; width: max-content; }
#preview .cv { box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 20px 50px rgba(18,23,38,.14); }

/* Diálogos */
dialog { border: 0; padding: 0; width: min(640px, 100%); max-height: min(92vh, 900px); border-radius: 22px; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(8, 10, 18, .55); backdrop-filter: blur(2px); }
@media (max-width: 640px) { dialog { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 22px 22px 0 0; max-height: 94vh; } }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 6px 20px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.dlg-head h2 { font-size: 1.2rem; flex: 1; }
.dlg-body { padding: 6px 20px 24px; }
.section { padding: 14px 0; border-top: 1px solid var(--line); }
.section:first-child { border-top: 0; padding-top: 4px; }
.section h3 { font-size: 1rem; margin-bottom: 8px; }
.stack { display: grid; gap: 8px; }
.steps-list { margin: 0 0 14px; padding-left: 1.2rem; display: grid; gap: 4px; }
.notice { border-radius: 12px; padding: 12px 14px; background: var(--surface-2); font-size: .9rem; margin: 10px 0; }
.notice.warn { background: var(--warn-soft); }
.notice.good { background: var(--good-soft); }

.ex-group { margin: 6px 0 16px; }
.ex-group h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.ex-card { text-align: left; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 12px; cursor: pointer; font-weight: 600; min-height: 56px; }
.ex-card:hover { border-color: var(--brand); background: var(--brand-soft); }

.cv-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.cv-list li { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.cv-list li.current { border-color: var(--brand); background: var(--brand-soft); }
.cv-list .main { flex: 1; min-width: 0; cursor: pointer; }
.cv-list .main b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pro-list { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 10px; }
.pro-list li { display: flex; gap: 10px; align-items: flex-start; }
.pro-list li::before { content: '✓'; flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--good-soft); color: var(--good); display: grid; place-items: center; font-weight: 800; font-size: .8rem; margin-top: 1px; }
.price-tag { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 2px; }
.price-tag b { font-size: 2.2rem; letter-spacing: -0.03em; }
.price-tag s { color: var(--muted); }
.err { color: var(--bad); font-size: .85rem; min-height: 1.2em; margin: 4px 0 0; }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { flex: 1; min-width: 0; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 10px 10px 18px; border-radius: 999px; display: flex; gap: 12px; align-items: center; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.toast button { background: transparent; border: 0; color: var(--brand); font-weight: 700; cursor: pointer; padding: 6px 10px; }

/* Donaciones */
.donate-btn { min-height: 38px; padding: .4rem .8rem; font-size: .92rem; }
@media (max-width: 640px) { .donate-btn span { display: none; } }
.donate p { margin: 0 0 12px; }
.donate-hero { font-size: 2.6rem; text-align: center; margin: 4px 0 8px; }
.donate-reason { background: var(--good-soft); border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.donate-facts { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 6px; }
.donate-facts li { display: flex; gap: 8px; font-size: .92rem; }
.donate-facts li::before { content: '✓'; color: var(--good); font-weight: 800; }
.donate-links { display: grid; gap: 8px; margin-bottom: 12px; }
.donate-link { justify-content: space-between; text-align: left; }
.donate-link small { font-weight: 500; font-size: .8rem; opacity: .8; }
.donate-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }

#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  body { background: #fff !important; }
  #print-root { display: block !important; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Cotiza ---------- */
.doc-switch { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-weight: 600; max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sum-card { padding: 16px 18px; margin-bottom: 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sum-card .total { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; }
.sum-card .lbl { font-size: .8rem; color: var(--muted); }
.sum-card .spacer { flex: 1; }
.status-chip { font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.status-chip.sent { background: #e0ecff; color: #1d4ed8; }
.status-chip.accepted { background: var(--brand-soft); color: var(--brand); }
.status-chip.paid { background: var(--good-soft); color: var(--good); }
.status-chip.rejected { background: #fde2e2; color: #b91c1c; }
.item-row { display: grid; grid-template-columns: 1fr 64px 110px 32px; gap: 6px; align-items: start; margin-bottom: 8px; }
.item-row .line { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); text-align: right; margin-top: -4px; }
@media (max-width: 480px) { .item-row { grid-template-columns: 1fr 56px 92px 28px; } }
.totals-box { display: grid; gap: 4px; margin-top: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: .92rem; }
.totals-box div { display: flex; justify-content: space-between; }
.totals-box .grand { font-weight: 800; font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }
.seg3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.seg3 button { min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: .88rem; cursor: pointer; }
.seg3 button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stats3 div { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.stats3 b { display: block; font-size: 1rem; overflow-wrap: anywhere; }
.stats3 span { font-size: .75rem; color: var(--muted); }
.doc-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.doc-list li { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.doc-list li.current { border-color: var(--brand); background: var(--brand-soft); }
.doc-list .top { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.doc-list .top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-list .acts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.logo-row img, .logo-row .ph { width: 64px; height: 64px; object-fit: contain; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }

/* Manual de uso (shared/manual.js) */
.manual h3 { font-size: 1rem; margin: 18px 0 6px; }
.manual ol, .manual ul { margin: 0; padding-left: 1.3em; }
.manual li { margin: 6px 0; }
.manual-note { margin-top: 16px; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); font-size: .9rem; }
.manual-links { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 14px 0 16px; font-size: .9rem; }
.topbar .brand { white-space: nowrap; }
@media (max-width: 400px) { .topbar .donate-btn span { display: none; } }
