:root {
    --bg: #f5f3ee;
    --surface: #ffffff;
    --ink: #1f2a24;
    --muted: #5f6b64;
    --line: #dcd8ce;
    --brand: #2f6b3a;
    --brand-dark: #1f4d28;
    --brand-soft: #e6f0e4;
    --wood: #a86a2c;
    --wood-soft: #f6ead9;
    --ok: #2f6b3a;      --ok-bg: #e3f0e0;
    --warn: #8a5a00;    --warn-bg: #fbefd2;
    --info: #1d5a8a;    --info-bg: #e2eef8;
    --err: #a12a2a;     --err-bg: #fbe5e3;
    --mutedc: #6b6b66;  --muted-bg: #ecebe6;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(31, 42, 36, .06), 0 4px 16px rgba(31, 42, 36, .05);
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); }
a { color: var(--brand); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.15rem; font-weight: 650; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.main { padding-top: 28px; padding-bottom: 40px; min-height: calc(100vh - 140px); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .92em; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Cabecera */
.topbar { background: var(--brand-dark); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 9px; background: var(--wood); font-weight: 700; letter-spacing: .5px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text small { opacity: .75; font-size: .8rem; }
.usernav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.usernav a, .usernav .linkbtn { color: #fff; opacity: .9; font-size: .92rem; }
.user { display: flex; flex-direction: column; text-align: right; line-height: 1.2; }
.user small { opacity: .7; font-family: var(--mono); font-size: .78rem; }
.usernav form { margin: 0; }
.footer { color: var(--muted); font-size: .82rem; padding-top: 18px; padding-bottom: 28px; border-top: 1px solid var(--line); }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
       background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #b9b4a7; background: #faf9f6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.sm { padding: 5px 11px; font-size: .86rem; }
.btn.block { width: 100%; }
.btn.danger-outline { color: var(--err); border-color: #e3b5b0; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); text-decoration: underline; cursor: pointer; }
.linkbtn.danger { color: var(--err); }
:focus-visible { outline: 3px solid #8fbf87; outline-offset: 2px; }

/* Avisos y etiquetas */
.alert { padding: 11px 14px; border-radius: 8px; margin: 0 0 16px; border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border-color: #c4dcbf; }
.alert.err { background: var(--err-bg); color: var(--err); border-color: #efc2bd; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: #efd9a3; }
.alert.err:empty, .validation-summary-valid { display: none; }
.alert ul { margin: 0; padding-left: 18px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; vertical-align: middle; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.muted { background: var(--muted-bg); color: var(--mutedc); }
.chips { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 2px 8px; font-size: .85rem; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.page-head { margin-bottom: 20px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.head-actions form { margin: 0; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-size: .9rem; }

/* Pasos */
.steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 22px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px; border-radius: 999px; background: var(--muted-bg); color: var(--mutedc); font-size: .9rem; font-weight: 550; }
.step span { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #fff; font-size: .8rem; }
.step.current { background: var(--wood-soft); color: var(--wood); }
.step.done { background: var(--ok-bg); color: var(--ok); }
.step.done span { background: var(--ok); color: #fff; }

/* Bloques del panel */
.blocks { display: grid; gap: 18px; }
.block { position: relative; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.block-head h2 { display: flex; align-items: center; gap: 10px; margin: 0; }
.num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font-size: .9rem; font-weight: 700; flex: none; }
.block-actions { margin-top: 14px; display: flex; gap: 8px; }
.block.locked { background: #fbfaf7; }
.block.locked .block-head h2 { color: var(--muted); }
.block.locked .num { background: var(--muted-bg); color: var(--mutedc); }
.lock-msg { display: flex; align-items: center; gap: 8px; color: var(--muted); margin: 0; }
.lock-msg::before { content: ""; width: 14px; height: 14px; flex: none;
    background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 9V7a5 5 0 0 0-10 0v2H5v13h14V9h-2zM9 7a3 3 0 0 1 6 0v2H9V7z'/%3E%3C/svg%3E") center/contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 9V7a5 5 0 0 0-10 0v2H5v13h14V9h-2zM9 7a3 3 0 0 1 6 0v2H9V7z'/%3E%3C/svg%3E") center/contain no-repeat; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv.small { font-size: .88rem; }
.centros { list-style: none; margin: 0; padding: 0; }
.centros li + li { margin-top: 2px; }
.card + .card, .card + section.card { margin-top: 16px; }

/* Tablas */
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); padding: 8px 10px; }
.table td { border-bottom: 1px solid #ece9e1; padding: 10px; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th.right, .table td.right { text-align: right; }

/* Formularios */
.form fieldset { border: 0; padding: 0; margin: 0 0 22px; }
.form legend { font-weight: 650; font-size: 1.02rem; margin-bottom: 12px; color: var(--brand-dark); }
.form.narrow { max-width: 460px; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 4px; }
.field label { font-weight: 550; font-size: .9rem; }
input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid #cfcabd; border-radius: 8px; font: inherit; background: #fff; color: var(--ink); }
input:disabled, input[readonly] { background: #f1efe9; color: var(--muted); }
.centro-doc { margin-bottom: 4px; }
input.num { width: 120px; text-align: right; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--brand); }
.input-validation-error { border-color: var(--err) !important; background: #fffafa !important; }
.field-error { color: var(--err); font-size: .84rem; }
.field-error:empty { display: none; }
.hint { color: var(--muted); font-size: .82rem; }
.static { margin: 0; padding: 9px 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0 4px; cursor: pointer; }
.check input { margin-top: 2px; flex: none; }
.select-table label { cursor: pointer; }

/* Login */
.login { display: grid; place-items: center; padding: 40px 0; }
.login-card { width: 100%; max-width: 400px; }
.login-card .hint { margin: 14px 0 0; text-align: center; }

/* Documentos (contrato y DI) */
.doc { position: relative; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
       padding: 40px 48px; margin-bottom: 20px; font-size: .95rem; }
.doc h3 { font-size: 1rem; margin: 26px 0 10px; color: var(--brand-dark); text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 10px; }
.doc h4 { font-size: .95rem; margin: 0 0 4px; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--brand); padding-bottom: 16px; flex-wrap: wrap; }
.doc-kicker { color: var(--wood); font-weight: 650; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.doc-title { font-size: 1.45rem; margin: 4px 0 2px; }
.doc-sub { color: var(--muted); font-size: .88rem; }
.doc-meta { display: grid; grid-template-columns: max-content max-content; gap: 4px 12px; margin: 0; align-content: start; font-size: .9rem; }
.doc-meta dt { color: var(--muted); }
.doc-meta dd { margin: 0; font-weight: 600; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.party { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.party-role { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--wood); font-weight: 650; margin-bottom: 4px; }
.party-rep { margin-top: 6px; color: var(--muted); font-size: .9rem; }
.clause { margin-bottom: 12px; }
.clause p { margin: 0; text-align: justify; }
.doc-table th { background: var(--brand-soft); color: var(--brand-dark); }
.signatures { display: grid; grid-template-columns: 1fr 1.3fr; gap: 16px; }
.sig { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.sig-img { display: block; max-width: 100%; height: 110px; object-fit: contain; border-bottom: 1px solid var(--ink); margin: 6px 0 8px; }
.hash { word-break: break-all; font-size: .78rem; }
.watermark { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-24deg); font-size: 7rem; font-weight: 800;
             color: rgba(168, 106, 44, .08); pointer-events: none; letter-spacing: .1em; white-space: nowrap; }

.di-sec { border: 1px solid var(--line); border-radius: 8px; padding: 4px 16px 12px; margin-top: 14px; break-inside: avoid; }
.di-sec h3 { margin: 12px 0 10px; }
.di-sec .num { width: 24px; height: 24px; font-size: .8rem; }
.grid-kv { display: grid; grid-template-columns: 240px 1fr; gap: 6px 16px; margin: 0; }
.grid-kv dt { color: var(--muted); }
.grid-kv dd { margin: 0; }
.grid-kv dd.blank { border-bottom: 1px dotted #9d998d; min-height: 1.5em; }
.sign-boxes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.sign-boxes div { border: 1px dashed #b9b4a7; border-radius: 6px; height: 90px; position: relative; }
.sign-boxes span { position: absolute; bottom: 6px; left: 10px; font-size: .76rem; color: var(--muted); }

/* Firma */
.sign-card { margin-bottom: 20px; }
.sigpad { position: relative; border: 2px dashed #b9b4a7; border-radius: 10px; background: #fdfcf9; max-width: 560px; }
.sigpad canvas { display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair; }
.sigpad-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #a9a495; pointer-events: none; font-size: .92rem; }
.sigpad.has-ink .sigpad-hint { display: none; }
.sigpad.has-ink { border-style: solid; border-color: var(--brand); }
.sigpad-actions { margin-top: 6px; }
.discard { margin-top: 14px; text-align: right; }

/* ---------- Back-office ---------- */
.topbar.gestion { background: #3b2a1a; }
.topbar.gestion .brand-mark { background: var(--brand); }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; padding-bottom: 0; }
.mainnav a { color: #fff; opacity: .78; text-decoration: none; padding: 10px 14px; border-bottom: 3px solid transparent; font-weight: 550; font-size: .93rem; }
.mainnav a:hover { opacity: 1; }
.mainnav a.active { opacity: 1; border-bottom-color: #e0b47e; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
       padding: 14px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: border-color .15s; }
.kpi:hover { border-color: #b9b4a7; }
.kpi-num { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.kpi-label { color: var(--muted); font-size: .86rem; }
.kpi.attn { border-color: #e9c77f; background: #fffaf0; }
.kpi.attn .kpi-num { color: var(--warn); }
.filters { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; margin-bottom: 16px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: .88rem; background: #fff; }
.pill:hover { border-color: #b9b4a7; }
.pill.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.search { display: flex; gap: 8px; min-width: 300px; flex: 1; max-width: 460px; }
.sub { color: var(--muted); font-size: .8rem; }
.table .badge + .badge, td .badge { margin-left: 4px; }
.table.compact td { padding: 6px 8px; }
tr.dim td { opacity: .55; }
tr.late td:first-child { color: var(--err); }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 18px; align-items: start; }
.actions-grid .card h2 { margin-bottom: 12px; }
.card.focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.grid.g2 { grid-template-columns: 1fr 1fr; }
.radios { display: flex; gap: 18px; }
.radios .check { margin: 4px 0; }
.label { font-weight: 550; font-size: .9rem; }
form.inline { display: inline; margin: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.wrap-actions { flex-wrap: wrap; }
.wrap-actions form { margin: 0; }
.align-end { justify-content: flex-end; }
details.alta { margin-bottom: 16px; }
details.alta summary { cursor: pointer; }
details.alta[open] summary { margin-bottom: 14px; }
.pwd-box { display: flex; flex-direction: column; gap: 6px; }
.pwd-box code { font-family: var(--mono); font-size: 1.05rem; background: #fff; padding: 2px 10px; border-radius: 6px; border: 1px solid #efd9a3; margin: 0 8px; letter-spacing: .04em; }
.doc-alert { margin-top: 16px; }
.di-sec.internal { background: #fffaf0; border-color: #efd9a3; }
.di-sec.internal p { margin: 0 0 8px; }
.block-head a { font-size: .9rem; }

/* Responsive */
@media (max-width: 760px) {
    .grid { grid-template-columns: 1fr 1fr; }
    .span-3, .span-4 { grid-column: span 2; }
    .parties, .signatures, .sign-boxes { grid-template-columns: 1fr; }
    .grid-kv { grid-template-columns: 1fr; gap: 0 0; }
    .grid-kv dd { margin-bottom: 8px; }
    .doc { padding: 24px 18px; }
    .table { display: block; overflow-x: auto; }
    .user { text-align: left; }
    .watermark { font-size: 4rem; }
}

/* Impresión / PDF */
@media print {
    @page { size: A4; margin: 14mm; }
    body { background: #fff; font-size: 10.5pt; }
    .no-print { display: none !important; }
    .main { padding: 0; min-height: 0; }
    .wrap { max-width: none; padding: 0; }
    .doc { border: 0; box-shadow: none; padding: 0; margin: 0; }
    .doc-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .clause, .signatures, .di-sec { break-inside: avoid; }
    a { color: inherit; text-decoration: none; }
}
