/* Colores de marca FERRAGRO (verde #047835). Cada token tiene versión clara y oscura. */
:root {
    color-scheme: light;
    --ink: #1f2926;
    --ink-2: #3a4541;
    --muted: #66736d;
    --line: #dce3df;
    --line-soft: #edf0ee;
    --paper: #f5f7f5;
    --white: #ffffff;
    --surface-2: #f7f9f7;
    --input: #ffffff;
    --green: #047835;
    --green-dark: #035a28;
    --green-pale: #e6f2ea;
    --green-soft: #cfe8d9;
    --link: #04662d;
    --on-green: #ffffff;
    --step-done: #0b5a2f;
    --step-done-bg: #dcefe3;
    --step-pending: #85918b;
    --step-pending-bg: #eef1ef;
    --amber: #a05b13;
    --amber-ink: #6d481e;
    --amber-pale: #fff2dc;
    --red: #a33e36;
    --red-ink: #8a2d20;
    --red-pale: #fbecea;
    --red-line: #efc8c2;
    --nav-bg: #ffffff;
    --nav-ink: #1f2926;
    --nav-muted: #5d6a64;
    --nav-line: #d3ddd7;
    --focus: #3f9f68;
    --shadow: 0 12px 34px rgb(26 44 37 / 7%);
    --velo-login: linear-gradient(100deg, rgb(245 247 245 / 96%) 0%, rgb(245 247 245 / 90%) 38%, rgb(245 247 245 / 45%) 58%, rgb(245 247 245 / 0%) 78%);
    font-family: 'DM Sans', 'Segoe UI', sans-serif;
    color: var(--ink);
    background: var(--paper);
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}
/* Modo oscuro: sigue la preferencia del sistema, salvo que la persona elija el claro. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --ink: #e4ebe7;
        --ink-2: #c9d4ce;
        --muted: #97a59f;
        --line: #2c3b35;
        --line-soft: #23302b;
        --paper: #0f1513;
        --white: #161f1c;
        --surface-2: #1b2622;
        --input: #111a17;
        --green: #3db871;
        --green-dark: #7fd6a2;
        --green-pale: #132b20;
        --green-soft: #1d4a33;
        --link: #6fcf97;
        --on-green: #06170d;
        --step-done: #8be0ae;
        --step-done-bg: #173726;
        --step-pending: #7d8a84;
        --step-pending-bg: #202b27;
        --amber: #e0a45a;
        --amber-ink: #f0cf9e;
        --amber-pale: #33260f;
        --red: #e27a70;
        --red-ink: #f3b3aa;
        --red-pale: #3a1b18;
        --red-line: #6b302a;
        --nav-bg: #0b100e;
        --nav-ink: #eef4f0;
        --nav-muted: #a9b8b1;
        --nav-line: #33443d;
        --focus: #6fcf97;
        --shadow: 0 12px 34px rgb(0 0 0 / 35%);
        --velo-login: linear-gradient(100deg, rgb(11 16 14 / 95%) 0%, rgb(11 16 14 / 88%) 38%, rgb(11 16 14 / 45%) 58%, rgb(11 16 14 / 0%) 78%);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --ink: #e4ebe7;
    --ink-2: #c9d4ce;
    --muted: #97a59f;
    --line: #2c3b35;
    --line-soft: #23302b;
    --paper: #0f1513;
    --white: #161f1c;
    --surface-2: #1b2622;
    --input: #111a17;
    --green: #3db871;
    --green-dark: #7fd6a2;
    --green-pale: #132b20;
    --green-soft: #1d4a33;
    --link: #6fcf97;
    --on-green: #06170d;
    --step-done: #8be0ae;
    --step-done-bg: #173726;
    --step-pending: #7d8a84;
    --step-pending-bg: #202b27;
    --amber: #e0a45a;
    --amber-ink: #f0cf9e;
    --amber-pale: #33260f;
    --red: #e27a70;
    --red-ink: #f3b3aa;
    --red-pale: #3a1b18;
    --red-line: #6b302a;
    --nav-bg: #0b100e;
    --nav-ink: #eef4f0;
    --nav-muted: #a9b8b1;
    --nav-line: #33443d;
    --focus: #6fcf97;
    --shadow: 0 12px 34px rgb(0 0 0 / 35%);
    --velo-login: linear-gradient(100deg, rgb(11 16 14 / 95%) 0%, rgb(11 16 14 / 88%) 38%, rgb(11 16 14 / 45%) 58%, rgb(11 16 14 / 0%) 78%);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar {
    min-height: 68px; display: flex; align-items: center; gap: 38px; padding: 0 5vw;
    color: var(--nav-ink); background: var(--nav-bg); border-bottom: 3px solid var(--green);
}
.brand { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.brand-logo { display: block; width: auto; height: 26px; }
.brand-logo-oscuro { display: none; }
:root[data-theme="dark"] .brand-logo-claro { display: none; }
:root[data-theme="dark"] .brand-logo-oscuro { display: block; }
.brand-copy { padding-left: 14px; border-left: 1px solid var(--nav-line); color: var(--nav-muted); font-size: 11px; line-height: 1.25; }
.topnav { display: flex; align-items: stretch; align-self: stretch; gap: 25px; }
.topnav a { display: flex; align-items: center; gap: 8px; color: var(--nav-muted); font-size: 13px; border-bottom: 2px solid transparent; }
.topnav a:hover { color: var(--nav-ink); }
.topnav a[aria-current="page"] { color: var(--nav-ink); border-bottom-color: var(--green); }
.user-menu { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.user-name { max-width: 210px; overflow: hidden; color: var(--nav-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-button { color: var(--nav-ink); border-color: var(--nav-line); }
.topbar .icon-button:hover { border-color: var(--green); }
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; }
.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle .icono-sol { display: none; }
:root[data-theme="dark"] .theme-toggle .icono-sol { display: block; }
:root[data-theme="dark"] .theme-toggle .icono-luna { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .brand-logo-claro { display: none; }
    :root:not([data-theme="light"]) .brand-logo-oscuro { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .icono-sol { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .icono-luna { display: none; }
}
.user-menu form { margin: 0; }
/* Menú de celular: oculto en escritorio. */
.menu-toggle, .menu-cuenta { display: none; }
.menu-toggle svg { width: 18px; height: 18px; }
.menu-toggle .icono-cerrar { display: none; }
.page-shell { width: min(1440px, 100% - 10vw); margin: 0 auto; padding: 34px 0 64px; }

.page-heading, .detail-heading { display: flex; align-items: end; justify-content: space-between; gap: 22px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 8px; color: var(--green); font-family: 'IBM Plex Mono', monospace; font-size: 10px; font-weight: 600; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 31px; line-height: 1.13; font-weight: 600; }
h2 { margin-bottom: 0; font-size: 16px; font-weight: 600; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 12px; min-height: 38px; padding: 0 14px; border: 1px solid transparent; border-radius: 4px; font-size: 12px; font-weight: 600; cursor: pointer; transition: background .15s, border .15s, transform .15s; }
.button:hover:not(.is-disabled) { transform: translateY(-1px); }
.button-primary { color: var(--on-green); background: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-quiet { color: var(--ink); background: var(--white); border-color: var(--line); }
.button-quiet:hover { border-color: var(--green); background: var(--surface-2); }
.button.is-disabled { color: var(--step-pending); pointer-events: none; }
.icon-button { min-height: 32px; padding: 0 10px; color: var(--ink-2); background: transparent; border: 1px solid var(--line); border-radius: 3px; font-size: 11px; cursor: pointer; }
.icon-button:hover { border-color: var(--green); color: var(--ink); }

.page-heading-note { margin: 0; color: var(--muted); font-size: 11px; }

/* Tarjetas de pendientes por paso (también filtran). */
.step-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary-card {
    position: relative; display: grid; gap: 2px; padding: 14px 16px 13px; overflow: hidden;
    color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow);
    transition: border-color .15s, transform .15s;
}
.summary-card::before { position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--line); content: ''; }
.summary-card:hover { border-color: var(--green); transform: translateY(-1px); }
.summary-card.is-active { background: var(--green-pale); border-color: var(--green); }
.summary-card.is-active::before { background: var(--green); }
.summary-label { color: var(--ink-2); font-size: 12px; font-weight: 600; }
.summary-count { color: var(--green-dark); font-family: 'IBM Plex Mono', monospace; font-size: 26px; font-weight: 600; line-height: 1.15; }
.summary-note { color: var(--muted); font-size: 10px; }

/* Filtros con etiqueta visible. */
.filter-panel { display: grid; gap: 10px; margin-bottom: 8px; padding: 14px 16px; background: var(--white); border: 1px solid var(--line); border-radius: 6px; }
.filter-grid { display: grid; gap: 10px 12px; align-items: end; }
.filter-grid-main { grid-template-columns: minmax(200px, 2fr) repeat(3, minmax(120px, 1fr)) minmax(160px, 1.4fr); }
.filter-grid-steps { grid-template-columns: repeat(3, minmax(130px, 1fr)) auto; }
.filter-field { display: grid; gap: 5px; min-width: 0; }
.filter-label { color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.filter-field select, .filter-field input { width: 100%; height: 36px; padding: 0 10px; color: var(--ink); background: var(--input); border: 1px solid var(--line); border-radius: 4px; font-size: 12px; }
.filter-field select:focus, .filter-field input:focus { border-color: var(--green); }
.search-field { position: relative; display: block; }
.search-field > span { position: absolute; top: 5px; left: 10px; color: var(--muted); font-size: 19px; }
.search-field input { padding-left: 33px; }
.filter-actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.filter-actions .button { min-height: 36px; }

/* Tabla. */
.table-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px; color: var(--muted); font-size: 12px; }
.table-meta strong { color: var(--ink); }
.button-small { min-height: 32px; padding: 0 12px; font-size: 11px; }
.table-scroll { overflow-x: auto; background: var(--white); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
.invoice-table { width: 100%; border-collapse: collapse; text-align: left; }
.invoice-table th { position: sticky; top: 0; z-index: 1; padding: 11px 14px; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); font-family: 'IBM Plex Mono', monospace; font-size: 9px; font-weight: 500; text-transform: uppercase; white-space: nowrap; }
.invoice-table td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; font-size: 12px; }
.invoice-row { transition: background .12s; }
.invoice-row:hover { background: var(--surface-2); }
.invoice-row:last-child td { border-bottom: 0; }
.cell-invoice { min-width: 170px; }
.invoice-number { display: block; width: fit-content; color: var(--link); font-family: 'IBM Plex Mono', monospace; font-size: 14px; font-weight: 600; }
.invoice-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 5px; }
.invoice-chip { padding: 2px 7px; color: var(--amber-ink); background: var(--amber-pale); border-radius: 999px; font-size: 9px; font-weight: 600; white-space: nowrap; }
.invoice-chip.is-printed { color: var(--ink-2); background: var(--step-pending-bg); }
.invoice-chip.is-logistics { color: var(--step-done); background: var(--step-done-bg); }
.invoice-chip.is-received { color: var(--on-green); background: var(--green); }
.invoice-origin { color: var(--muted); font-size: 10px; }
.cell-progress { width: 96px; }
.progress-label { display: block; margin-bottom: 6px; color: var(--ink-2); font-size: 11px; font-weight: 600; white-space: nowrap; }
.progress-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; width: 66px; }
.progress-bar span { height: 5px; background: var(--step-pending-bg); border-radius: 3px; }
.progress-bar span.is-done { background: var(--green); }

/* Píldoras de paso: el mismo ancho siempre, marcado o no (la fila no se mueve). */
.step-pills { display: grid; grid-template-columns: repeat(3, minmax(150px, 180px)); gap: 8px; }
.step-form, .row-unmark { margin: 0; }
.step-pill {
    display: flex; align-items: center; gap: 8px; width: 100%; min-height: 42px; padding: 6px 9px;
    color: var(--ink-2); background: var(--white); border: 1px solid var(--line); border-radius: 8px;
    font: inherit; text-align: left; list-style: none;
}
.step-pill::-webkit-details-marker { display: none; }
.pill-icon { display: grid; place-items: center; width: 20px; height: 20px; flex: 0 0 20px; border: 2px solid var(--step-pending); border-radius: 50%; font-size: 11px; font-weight: 700; }
.pill-text { display: grid; min-width: 0; line-height: 1.2; }
.pill-name { overflow: hidden; font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.pill-meta { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.step-pill.is-pending { border-style: dashed; }
.step-pill.is-done { color: var(--step-done); background: var(--step-done-bg); border-color: var(--green-soft); }
.step-pill.is-done .pill-icon { color: var(--on-green); background: var(--green); border-color: var(--green); }
.step-pill.is-done .pill-meta { color: var(--step-done); opacity: .85; }
.step-pill.is-action { cursor: pointer; transition: border-color .12s, background .12s, box-shadow .12s; }
.step-pill.is-pending.is-action .pill-meta { color: var(--link); font-weight: 600; }
.step-pill.is-pending.is-action:hover { border-style: solid; border-color: var(--green); background: var(--green-pale); }
.step-pill.is-pending.is-action:hover .pill-icon { border-color: var(--green); }
.step-pill.is-done.is-action:hover { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-pale); }
.row-unmark[open] > form { top: 48px; right: auto; left: 0; width: 250px; }
.unmark-info { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
.htmx-request .step-pill, .step-form.htmx-request .step-pill { opacity: .55; }

.date-cell { color: var(--muted); font-family: 'IBM Plex Mono', monospace; font-size: 10px !important; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.text-action { color: var(--link); font-size: 11px; font-weight: 600; }
.text-action span { margin-left: 4px; }
.empty-state { height: 170px; text-align: center; }
.empty-state strong, .empty-state span { display: block; }
.empty-state span { margin-top: 6px; color: var(--muted); font-size: 11px; }
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; color: var(--muted); font-size: 11px; }
.pagination .button { min-height: 34px; }

/* Indicadores del detalle de factura. */
.step-indicator { display: grid; place-items: center; width: 22px; height: 22px; flex: 0 0 22px; border-radius: 50%; font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 600; }
.step-indicator.is-done { color: var(--step-done); background: var(--step-done-bg); }
.step-indicator.is-pending { color: var(--step-pending); background: var(--step-pending-bg); }

.breadcrumbs { display: flex; gap: 10px; margin-bottom: 21px; color: var(--muted); font-size: 11px; }
.breadcrumbs a { color: var(--green); }
.form-layout { max-width: 780px; margin: 0 auto; }
.form-heading { margin: 10px 0 23px; }
.form-heading p:last-child { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.invoice-form { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; padding: 24px; background: var(--white); border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow); }
.field { display: grid; gap: 7px; color: var(--ink-2); font-size: 11px; font-weight: 600; }
.field input, .field textarea { width: 100%; padding: 10px 11px; color: var(--ink); background: var(--input); border: 1px solid var(--line); border-radius: 3px; font-size: 13px; font-weight: 400; }
.field input { height: 40px; }
.field input[readonly] { color: var(--green-dark); background: var(--green-pale); font-family: 'IBM Plex Mono', monospace; font-weight: 600; }
.field textarea { resize: vertical; }
.field small { color: var(--muted); font-size: 10px; font-weight: 400; }
.field-wide { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 9px; padding-top: 5px; }
.notice { margin-bottom: 15px; padding: 12px 14px; border-left: 3px solid var(--amber); color: var(--amber-ink); background: var(--amber-pale); font-size: 12px; }

.detail-heading { align-items: center; margin-bottom: 27px; }
.detail-heading h1 { font-family: 'IBM Plex Mono', monospace; font-size: 28px; }
.detail-subtitle { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(230px, .75fr); gap: 34px; }
.detail-main, .detail-aside { min-width: 0; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 0 11px; border-bottom: 1px solid var(--line); }
.section-heading > span { color: var(--muted); font-size: 10px; }
.detail-steps { margin: 0 0 30px; }
.detail-step { position: relative; display: flex; align-items: center; gap: 12px; min-height: 68px; border-bottom: 1px solid var(--line-soft); }
.detail-step-copy { display: grid; flex: 1; gap: 4px; }
.detail-step-copy strong { font-size: 12px; font-weight: 600; }
.detail-step-copy span { color: var(--muted); font-size: 10px; }
.step-action { min-height: 29px; color: var(--link); border-color: var(--line); }
.unmark-menu { position: relative; }
.unmark-menu summary { list-style: none; cursor: pointer; }
.unmark-menu summary::-webkit-details-marker { display: none; }
.unmark-menu[open] form { position: absolute; z-index: 2; top: 36px; right: 0; display: grid; gap: 8px; width: 225px; padding: 12px; background: var(--white); border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow); }
.unmark-menu label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; }
.unmark-menu input { width: 100%; height: 32px; padding: 5px 7px; color: var(--ink); background: var(--input); border: 1px solid var(--line); border-radius: 3px; }
.history-heading { margin-top: 30px; }
.timeline { position: relative; margin: 0; padding: 17px 0 0 10px; list-style: none; }
.timeline::before { position: absolute; top: 25px; bottom: 14px; left: 16px; width: 1px; background: var(--line); content: ''; }
.timeline li { position: relative; display: flex; gap: 14px; padding-bottom: 22px; }
.timeline-marker { position: relative; z-index: 1; width: 13px; height: 13px; flex: 0 0 13px; margin-top: 3px; border: 3px solid var(--green-pale); border-radius: 50%; background: var(--green); }
.timeline-entry { flex: 1; }
.timeline-entry > div { display: flex; justify-content: space-between; gap: 16px; }
.timeline-entry strong { font-size: 11px; }
.timeline-entry time { color: var(--muted); font-family: 'IBM Plex Mono', monospace; font-size: 9px; white-space: nowrap; }
.timeline-entry p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.old-values { margin-top: 8px; color: var(--muted); font-size: 10px; }
.old-values summary { cursor: pointer; }
.old-values pre { max-width: 100%; overflow: auto; padding: 10px; background: var(--surface-2); font-size: 10px; }
.history-empty { color: var(--muted); font-size: 11px; }
.fact-data { margin: 0; }
.fact-data div { padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.fact-data dt { margin-bottom: 5px; color: var(--muted); font-size: 10px; }
.fact-data dd { margin: 0; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Página de inicio: foto de campo de fondo con un velo que da contraste al texto. */
.pagina-inicio {
    min-height: 100vh;
    background:
        var(--velo-login),
        image-set(url('/static/img/fondo-campo.webp') type('image/webp'), url('/static/img/fondo-campo.jpg') type('image/jpeg')) center bottom / cover no-repeat,
        var(--paper);
}
.login-layout { display: flex; align-items: center; min-height: calc(100vh - 150px); }
.login-copy { max-width: 540px; padding: 38px 0; animation: arrive .55s ease-out both; }
.login-insignia { display: block; width: min(360px, 80vw); height: auto; margin-bottom: 30px; filter: drop-shadow(0 10px 24px rgb(0 0 0 / 18%)); }
.login-copy h1 { font-size: 47px; line-height: 1.1; }
.login-copy h1 span { color: var(--green); }
.login-description { max-width: 430px; margin: 17px 0 26px; color: var(--ink-2); font-size: 15px; line-height: 1.7; }
.button-login { min-height: 45px; }
.login-ayuda { display: block; width: fit-content; margin-top: 18px; color: var(--link); font-size: 14px; font-weight: 600; }
.login-ayuda:hover { text-decoration: underline; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes arrive { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1180px) {
    .filter-grid-main { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filter-search { grid-column: 1 / -1; }
    .step-pills { grid-template-columns: repeat(3, minmax(132px, 160px)); }
}
@media (max-width: 900px) {
    /* La barra deja logo, Tema y el botón de menú; los módulos pasan a un panel desplegable. */
    .topbar { position: relative; z-index: 20; }
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; width: 38px; padding: 0; }
    .topbar.menu-abierto .menu-toggle .icono-menu { display: none; }
    .topbar.menu-abierto .menu-toggle .icono-cerrar { display: block; }
    .user-menu .user-name, .user-menu > form { display: none; }
    .topnav {
        position: absolute; top: 100%; right: 0; left: 0; display: none; flex-direction: column; gap: 0;
        padding: 8px 15px 14px; background: var(--nav-bg); border-bottom: 3px solid var(--green); box-shadow: var(--shadow);
    }
    .topbar.menu-abierto .topnav { display: flex; }
    .topnav a { min-height: 48px; padding: 0 6px; font-size: 15px; border-bottom: 1px solid var(--nav-line); }
    .topnav a[aria-current="page"] { color: var(--green); font-weight: 600; border-bottom-color: var(--nav-line); box-shadow: inset 3px 0 0 var(--green); padding-left: 12px; }
    .menu-cuenta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; color: var(--nav-muted); font-size: 13px; }
    .menu-cuenta form { margin: 0; }
    .page-shell { width: min(100% - 44px, 760px); }
    .step-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filter-grid-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-actions { grid-column: 1 / -1; }
    .topbar { gap: 22px; padding: 0 22px; }
    .detail-grid { grid-template-columns: 1fr; gap: 24px; }
    .detail-aside { padding-top: 3px; }
    .fact-data { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
    .login-copy h1 { font-size: 40px; }
}
@media (max-width: 640px) and (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .pagina-inicio { --velo-login: linear-gradient(180deg, rgb(11 16 14 / 90%) 0%, rgb(11 16 14 / 80%) 65%, rgb(11 16 14 / 45%) 100%); }
}
@media (max-width: 640px) {
    .topbar { min-height: 60px; gap: 16px; padding: 0 15px; }
    .brand-copy, .user-name, .theme-toggle-texto { display: none; }
    .brand-logo { height: 21px; }
    .user-menu { gap: 7px; }
    .icon-button { min-height: 30px; padding: 0 7px; }
    .page-shell { width: calc(100% - 30px); padding: 25px 0 44px; }
    .page-heading { align-items: start; }
    .page-heading h1 { font-size: 26px; }
    .page-heading-note { display: none; }
    .step-summary { gap: 8px; }
    .summary-card { padding: 11px 12px; }
    .summary-count { font-size: 21px; }
    .summary-note { display: none; }
    .filter-panel { padding: 12px; }
    .filter-grid-main, .filter-grid-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .table-scroll { overflow: visible; background: transparent; border: 0; box-shadow: none; }
    .invoice-table, .invoice-table tbody { display: block; width: 100%; }
    .invoice-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
    .invoice-row { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; margin-bottom: 9px; padding: 11px 12px; background: var(--white); border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow); }
    .invoice-row td { display: block; padding: 5px 0; border: 0; }
    .invoice-row td[data-label="Factura"] { grid-column: 1 / 2; }
    .invoice-row td[data-label="Avance"] { grid-column: 2 / 3; grid-row: 1; justify-self: end; width: auto; }
    .invoice-row td[data-label="Pasos"] { grid-column: 1 / -1; padding-top: 8px; }
    .invoice-row td[data-label="Último cambio"] { grid-column: 1 / 2; color: var(--muted); }
    .invoice-row td[data-label="Acciones"] { grid-column: 2 / 3; align-self: center; }
    .step-pills { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
    .step-pill { width: 100%; gap: 6px; padding: 6px 7px; }
    .pill-icon { width: 18px; height: 18px; flex-basis: 18px; }
    .table-meta { flex-wrap: wrap; }
    .pagination { gap: 8px; }
    .pagination .button { padding: 0 8px; font-size: 10px; }
    .pagination > span { font-size: 9px; }
    .invoice-form { grid-template-columns: 1fr; gap: 14px; padding: 17px; }
    .field-wide, .form-actions { grid-column: 1; }
    .detail-heading { align-items: start; }
    .detail-heading h1 { font-size: 23px; }
    .detail-heading .button { padding: 0 9px; font-size: 10px; }
    .timeline-entry > div { display: grid; gap: 4px; }
    .timeline-entry time { white-space: normal; }
    .fact-data { grid-template-columns: 1fr; }
    .pagina-inicio {
        --velo-login: linear-gradient(180deg, rgb(245 247 245 / 90%) 0%, rgb(245 247 245 / 80%) 65%, rgb(245 247 245 / 45%) 100%);
        background-image: var(--velo-login), image-set(url('/static/img/fondo-campo-1024.webp') type('image/webp'), url('/static/img/fondo-campo-1024.jpg') type('image/jpeg'));
    }
    :root[data-theme="dark"] .pagina-inicio { --velo-login: linear-gradient(180deg, rgb(11 16 14 / 90%) 0%, rgb(11 16 14 / 80%) 65%, rgb(11 16 14 / 45%) 100%); }
    .login-layout { min-height: calc(100vh - 110px); }
    .login-copy { padding: 15px 0 28px; }
    .login-insignia { margin-bottom: 22px; }
    .login-copy h1 { font-size: 37px; }
    .login-description { font-size: 13px; }
}

/* Archivo histórico */
.archive-note { max-width: 780px; margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.archive-alert { margin: 0 0 16px; padding: 10px 14px; color: var(--red-ink); background: var(--red-pale); border: 1px solid var(--red-line); border-radius: 3px; font-size: 13px; }
.archive-result { margin: 0 0 16px; padding: 12px 14px; background: var(--green-pale); border: 1px solid var(--line); border-radius: 3px; font-size: 13px; }
.archive-result ul { margin: 8px 0 0; padding-left: 18px; }
.archive-admin { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.archive-admin h2 { margin: 0 0 6px; font-size: 15px; }
.archive-admin p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.archive-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Administración de usuarios y roles. */
.admin-block { margin-top: 26px; }
.admin-block h2 { margin: 0 0 12px; font-size: 15px; }
.admin-block-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; }
.admin-search { max-width: 460px; margin-bottom: 12px; }
.user-row, .search-result {
    display: grid; grid-template-columns: minmax(200px, 1.2fr) 190px minmax(280px, 2fr) auto; align-items: center; gap: 14px 18px;
    padding: 14px 16px; margin-bottom: 8px; background: var(--white); border: 1px solid var(--line); border-radius: 4px;
}
.search-result { grid-template-columns: minmax(200px, 1fr) 190px auto; }
.user-who { display: grid; gap: 3px; min-width: 0; }
.user-who strong { font-size: 13px; }
.user-who span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; }
.user-who small { color: var(--muted); font-size: 10px; }
.user-profile { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 600; }
.user-profile select { height: 34px; padding: 0 8px; color: var(--ink); background: var(--input); border: 1px solid var(--line); border-radius: 3px; font-size: 12px; }
.user-roles { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.role-chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; font-size: 11px; cursor: pointer; }
.role-chip:has(input:checked) { color: var(--step-done); background: var(--step-done-bg); border-color: var(--green-soft); }
.role-chip input { margin: 0; accent-color: var(--green); }
.user-save { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.user-ok { color: var(--step-done); font-size: 11px; }
.user-error { max-width: 220px; color: var(--red-ink); font-size: 11px; }
@media (max-width: 980px) {
    .user-row, .search-result { grid-template-columns: 1fr; }
    .user-save { justify-content: flex-start; }
}

/* Aviso cuando una acción HTMX falla en el servidor. */
.aviso-error {
    position: fixed; right: 16px; bottom: 16px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); margin: 0;
    padding: 12px 16px; color: var(--red-ink); background: var(--red-pale); border: 1px solid var(--red-line); border-radius: 4px;
    box-shadow: var(--shadow); font-size: 13px;
}
.aviso-error[hidden] { display: none; }
