:root {
  --bg: #f4f6f9; --surface: #ffffff; --text: #1b2430; --muted: #5d6b7a; --border: #dde3ea;
  --primary: #0f4c81; --primary-text: #ffffff; --accent: #e8f0f8;
  --ok: #1d7a46; --ok-bg: #e6f4ec; --warn: #9a5b00; --warn-bg: #fff4e0; --bad: #b42318; --bad-bg: #fdecea;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c; --surface: #1a2129; --text: #e6ebf0; --muted: #9aa8b6; --border: #2c3640;
    --primary: #5ea3e0; --primary-text: #0b1a28; --accent: #1f2d3b;
    --ok: #6fcf97; --ok-bg: #16301f; --warn: #f2b45a; --warn-bg: #33270f; --bad: #f28b82; --bad-bg: #3a1a18;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; gap: 10px; align-items: center; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.topbar nav { display: flex; gap: 4px; }
.progress { height: 4px; background: var(--border); }
#progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .25s; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px 120px; }
h1 { font-size: 22px; margin: 8px 0 4px; }
h2 { font-size: 18px; margin: 20px 0 8px; }
p.lead { color: var(--muted); margin: 0 0 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
label { display: block; font-weight: 600; margin: 14px 0 6px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
input, select, textarea { width: 100%; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

button { font: inherit; cursor: pointer; border-radius: 8px; padding: 10px 16px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; padding: 8px 10px; }
button.small { padding: 6px 10px; font-size: 14px; }
button:disabled { opacity: .5; cursor: default; }

.options { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.option { text-align: left; padding: 14px; border-radius: var(--radius); }
.option strong { display: block; font-size: 17px; }
.option span { color: var(--muted); font-size: 14px; }
.option.selected { border: 2px solid var(--primary); background: var(--accent); }

.actions { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; gap: 8px;
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
.actions > div { display: flex; gap: 8px; }

.suggest { border-left: 4px solid var(--primary); background: var(--accent); border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
.suggest h3 { margin: 0 0 6px; font-size: 15px; }
.suggest ul { margin: 0; padding-left: 18px; }
.alert { border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 13px; padding: 6px 10px; border-radius: 999px; }
.chip.selected { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.item-row { display: grid; gap: 8px; grid-template-columns: 1fr; border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 10px 0; }
.item-row .grid3 { display: grid; gap: 8px; grid-template-columns: 1fr 1fr 1fr; }
.item-row label { margin: 0 0 4px; font-size: 13px; }

.comunes { margin-top: 6px; }
.comun { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: start; padding: 10px; margin: 6px 0;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.comun img, .comun .sinfoto { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 28px; }
.comun-txt { font-size: 14px; min-width: 0; }
.comun details { margin-top: 4px; }
.comun details p { margin: 4px 0; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); }
.foto-item { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.foto-item img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.btn-file { display: inline-block; cursor: pointer; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 14px; font-weight: 400; margin: 0; }
.doc-fotos { display: flex; flex-wrap: wrap; gap: 12px; }
.doc-fotos figure { margin: 0; width: 150px; text-align: center; font-size: 12px; }
.doc-fotos img { width: 150px; height: 150px; object-fit: contain; border: 1px solid #ccc; }
@media (max-width: 520px) {
  .comun { grid-template-columns: 52px 1fr auto; gap: 8px; padding: 8px; }
  .comun img, .comun .sinfoto { width: 52px; height: 52px; }
  .brand small, .nav-texto { display: none; }
}
.pegar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px;
  padding: 12px; border: 2px dashed var(--border); border-radius: 10px; color: var(--muted); font-size: 14px; }
.pegar:focus { outline: 2px solid var(--primary); }
.cat.web { max-height: none; overflow: visible; }
.result.elegido { background: var(--ok-bg); border-radius: 8px; padding: 10px; border-bottom: 0; }
.cat { border-top: 1px dashed var(--border); margin-top: 8px; max-height: 420px; overflow-y: auto; }
.result { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: 0; }
.muted { color: var(--muted); font-size: 14px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
.toast.show { opacity: 1; }

/* Documento formal (formatos del área usuaria) */
.doc-marco { overflow-x: auto; }
.doc.formal { font-family: "Century Gothic", "Segoe UI", Arial, sans-serif; font-size: 12px; line-height: 1.4; max-width: 820px; margin: 0 auto; color: #111; }
.doc.formal p { margin: 4px 0; text-align: justify; }
.doc.formal ul { margin: 4px 0; padding-left: 20px; }
.doc.formal ul.letras { list-style: none; padding-left: 8px; }
.doc-membrete { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #999; padding-bottom: 6px; }
.doc-logo { max-height: 60px; max-width: 60%; }
.doc-entidad { display: flex; flex-direction: column; font-size: 12px; }
.doc-anio { text-align: center; font-style: italic; font-size: 11px; margin: 6px 0 !important; }
.doc.formal .doc-titulo { font-size: 13px; text-align: center; margin: 12px 0 8px; text-transform: uppercase; }
.doc-subtitulo { text-align: center; font-weight: 700; margin: 8px 0 4px !important; }
.doc.formal table { width: 100%; border-collapse: collapse; }
.doc.formal th, .doc.formal td { border: 1px solid #555; padding: 5px 7px; vertical-align: top; font-size: 12px; }
.doc-cab th { width: 32%; text-align: left; background: #f0f0f0; }
.doc-cuerpo.dos .doc-etq { width: 26%; text-align: left; font-weight: 700; background: #fafafa; }
.doc-sec { font-weight: 700; margin-bottom: 4px; }
.doc.formal .tabla { margin: 6px 0; }
.doc.formal .tabla th { background: #e8e8e8; text-align: center; font-size: 11px; }
.doc.formal .tabla td.c { text-align: center; } .doc.formal .tabla td.r { text-align: right; }
.doc-bien { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; border-bottom: 1px dotted #bbb; padding: 6px 0; }
.doc-bien-txt { flex: 1; }
.doc-bien-img { margin: 0; width: 120px; text-align: center; font-size: 9px; color: #555; }
.doc-bien-img img { width: 120px; height: 110px; object-fit: contain; }
.doc.formal .mini { font-size: 10px; color: #444; }
.formula { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 8px auto; padding: 8px 14px; background: #eee; border: 1px solid #aaa; width: fit-content; font-weight: 700; font-style: italic; }
.frac { display: inline-flex; flex-direction: column; text-align: center; }
.frac span:first-child { border-bottom: 1px solid #111; padding-bottom: 2px; }
.doc-firmas { display: flex; justify-content: space-around; gap: 24px; margin-top: 56px; flex-wrap: wrap; }
.doc-firma { text-align: center; min-width: 220px; font-size: 11px; }
.doc-firma .linea { border-top: 1px dotted #111; margin-bottom: 4px; }
.doc-pie { margin-top: 24px; border-top: 1px solid #999; padding-top: 4px; text-align: right; font-size: 10px; color: #444; }
details.clausula { border-bottom: 1px solid var(--border); padding: 8px 0; }
details.clausula summary { cursor: pointer; }
details.clausula textarea { margin: 8px 0; font-size: 14px; }

/* Documento imprimible */
.doc { background: #fff; color: #111; padding: 28px; border-radius: 4px; font-family: "Times New Roman", Georgia, serif; font-size: 15px; }
.doc h1 { text-align: center; font-size: 18px; text-transform: uppercase; }
.doc h2 { font-size: 15px; text-transform: uppercase; margin-top: 18px; }
.doc table th, .doc table td { border: 1px solid #999; }
.doc .firma { margin-top: 60px; text-align: center; }

@media (max-width: 520px) {
  .item-row .grid3 { grid-template-columns: 1fr 1fr; }
  .doc { padding: 16px; }
}
@media print {
  body { background: #fff; }
  .no-print, .actions, .topbar, .progress { display: none !important; }
  main { padding: 0; max-width: none; }
  .doc { padding: 0; }
}
