/* ==========================================================================
   Sistema de diseño del parque
   - Los colores del negocio llegan desde PHP (Theme::cssVars) como variables.
   - Tailwind (CDN) se carga con preflight desactivado: sus utilidades pueden
     sobrescribir estos componentes, y el reset de abajo tiene especificidad 0.
   - No usar bg-white / text-gray-800 en las vistas: usar tokens y componentes
     para que el modo oscuro funcione solo.
   ========================================================================== */

:root {
    --brand: #0f6b4c; --brand-rgb: 15,107,76; --brand-hover: #0d5c41; --brand-deep: #073022;
    --on-brand: #fff; --brand-text: #0f6b4c;
    --accent: #c6f24e; --accent-rgb: 198,242,78; --accent-hover: #b6df47; --on-accent: #0d1a12;

    --bg: #f3f5f1;
    --surface: #ffffff;
    --surface-2: #f9faf7;
    --surface-3: #eef1ea;
    --line: #e5e8e1;
    --line-strong: #d1d6cc;
    --text: #131a15;
    --text-2: #3c473f;
    --muted: #66716a;
    --faint: #929c93;

    --success: #137a38; --success-soft: #e5f5ea; --success-line: #bde4c9;
    --danger: #bd3026;  --danger-soft: #fcebe9;  --danger-line: #f3c4bf;
    --warning: #8f5208; --warning-soft: #fdf2da; --warning-line: #f0d599;
    --info: #1a62a6;    --info-soft: #e6f1fb;    --info-line: #bcd9f1;
    --purple: #6a3bce;  --purple-soft: #f0eafd;  --purple-line: #d8cbf7;

    --r-sm: 8px; --r: 12px; --r-lg: 18px; --r-xl: 24px;
    --shadow-sm: 0 1px 2px rgba(18,28,22,.05);
    --shadow: 0 1px 3px rgba(18,28,22,.06), 0 8px 22px -10px rgba(18,28,22,.14);
    --shadow-lg: 0 24px 60px -18px rgba(12,22,16,.32);

    --sidebar-w: 256px;
    --sidebar-rail: 76px;
    --topbar-h: 60px;
    --bottomnav-h: 62px;

    --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Bricolage Grotesque', 'Plus Jakarta Sans', system-ui, sans-serif;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0e1210;
    --surface: #161b18;
    --surface-2: #121714;
    --surface-3: #212824;
    --line: #272f2a;
    --line-strong: #39433c;
    --text: #edf2ee;
    --text-2: #c6cec8;
    --muted: #97a29a;
    --faint: #6f7a72;

    --success: #63d68a; --success-soft: #12311f; --success-line: #1f4d31;
    --danger: #ff8a80;  --danger-soft: #3a1815;  --danger-line: #5c2822;
    --warning: #f2bd5c; --warning-soft: #35270c; --warning-line: #564016;
    --info: #7cc0f7;    --info-soft: #122a40;    --info-line: #1e4566;
    --purple: #b79bff;  --purple-soft: #261c45;  --purple-line: #3d2d6b;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 22px -10px rgba(0,0,0,.6);
    --shadow-lg: 0 24px 60px -18px rgba(0,0,0,.75);
    color-scheme: dark;
}

/* ── Reset (especificidad 0) ─────────────────────────────────────────── */
:where(*, ::before, ::after) { box-sizing: border-box; border-width: 0; border-style: solid; border-color: var(--line); }
:where(html) { line-height: 1.5; -webkit-text-size-adjust: 100%; tab-size: 4; }
:where(body) { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
:where(h1, h2, h3, h4, h5, h6) { margin: 0; font-size: inherit; font-weight: inherit; }
:where(p, figure, blockquote, dl, dd, pre, hr) { margin: 0; }
:where(hr) { height: 0; border-top-width: 1px; }
:where(ol, ul, menu) { list-style: none; margin: 0; padding: 0; }
:where(img, svg, video, canvas) { display: block; max-width: 100%; }
:where(img, video) { height: auto; }
:where(button, input, select, textarea, optgroup) { font: inherit; color: inherit; margin: 0; padding: 0; letter-spacing: inherit; }
:where(button, [type="button"], [type="submit"], [type="reset"]) { background: transparent; cursor: pointer; -webkit-appearance: button; }
:where(button:disabled) { cursor: not-allowed; }
:where(a) { color: inherit; text-decoration: none; }
:where(table) { border-collapse: collapse; text-indent: 0; }
:where(th) { text-align: left; font-weight: 700; }
:where(textarea) { resize: vertical; }
:where(fieldset, legend) { margin: 0; padding: 0; min-width: 0; }
:where(summary) { cursor: pointer; }
:where([hidden]) { display: none !important; }
:where(:focus-visible) { outline: 3px solid rgba(var(--brand-rgb), .45); outline-offset: 2px; }

/* ── Tipografía y utilidades ─────────────────────────────────────────── */
.font-display { font-family: var(--font-display); letter-spacing: -.015em; }
.text-muted { color: var(--muted); }
.text-faint { color: var(--faint); }
.text-secondary { color: var(--text-2); }
.text-brand { color: var(--brand-text); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }
.tabular { font-variant-numeric: tabular-nums; }
.link { color: var(--brand-text); font-weight: 700; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.bg-surface { background: var(--surface); }
.bg-surface-2 { background: var(--surface-2); }
.bg-surface-3 { background: var(--surface-3); }
.border-line { border-color: var(--line); }
.divider { height: 1px; background: var(--line); border: 0; }
.stack > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 24px; }
.truncate-1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.break-anywhere { overflow-wrap: anywhere; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* ── Encabezado de página ────────────────────────────────────────────── */
.page-head { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; }
.page-title { font-family: var(--font-display); font-size: clamp(1.45rem, 2.4vw, 1.9rem); font-weight: 700; letter-spacing: -.022em; line-height: 1.15; }
.page-sub { color: var(--muted); font-size: .92rem; margin-top: 5px; max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
    .page-head { margin-bottom: 16px; }
    .page-actions { width: 100%; }
    .page-actions > .btn, .page-actions > form { flex: 1 1 auto; }
    .page-actions > form > .btn { width: 100%; }
}

/* ── Tarjetas ────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-title { font-family: var(--font-display); font-weight: 650; font-size: 1.06rem; letter-spacing: -.012em; display: flex; align-items: center; gap: 10px; }
.card-sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.card-body { padding: 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
@media (max-width: 640px) {
    .card-head, .card-body, .card-foot { padding-left: 16px; padding-right: 16px; }
    .card-body { padding-top: 16px; padding-bottom: 16px; }
}

/* ── Botones ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--r);
    font-weight: 700; font-size: .88rem; line-height: 1.2; text-align: center; white-space: nowrap;
    cursor: pointer; user-select: none; text-decoration: none;
    transition: background-color .15s, border-color .15s, box-shadow .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--brand); color: var(--on-brand); box-shadow: 0 10px 20px -12px rgba(var(--brand-rgb), .9); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-accent { background: var(--accent); color: var(--on-accent); }
.btn-accent:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-3); color: var(--text); }
.btn-secondary:hover { background: var(--line); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-outline:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { background: #bd3026; color: #fff; }
.btn-danger:hover { background: #a3271f; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.btn-danger-soft:hover { border-color: var(--danger); }
.btn-success { background: #137a38; color: #fff; }
.btn-success:hover { background: #0f662e; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .79rem; border-radius: 10px; gap: 6px; }
.btn-lg { min-height: 50px; padding: 0 24px; font-size: .98rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; flex: none; }
.btn-sm.btn-icon { width: 34px; }
@media (pointer: coarse) { .btn-sm { min-height: 40px; } .btn-sm.btn-icon { width: 40px; } }

/* ── Formularios ─────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: .82rem; font-weight: 700; color: var(--text-2); }
.label .req { color: var(--danger); }
.label .opt { color: var(--faint); font-weight: 500; }
.input, .select, .textarea {
    width: 100%; min-width: 0; min-height: 44px; padding: 10px 14px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--line-strong); border-radius: var(--r);
    font-size: .92rem; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); opacity: 1; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(var(--brand-rgb), .15); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--muted); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"], .is-invalid {
    border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(189,48,38,.13);
}
.textarea { min-height: 96px; line-height: 1.55; }
.select {
    -webkit-appearance: none; appearance: none; padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237d877f' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input[type="color"] { padding: 4px; height: 44px; cursor: pointer; }
.input[type="file"] { padding: 8px; }
.input[type="file"]::file-selector-button { font: inherit; font-weight: 700; font-size: .8rem; margin-right: 12px; padding: 6px 12px; border: 0; border-radius: 8px; background: var(--surface-3); color: var(--text); cursor: pointer; }
.input-sm { min-height: 36px; padding: 6px 12px; font-size: .84rem; border-radius: 10px; }
@media (max-width: 640px) { .input, .select, .textarea { font-size: 16px; } }

.help { font-size: .77rem; color: var(--muted); line-height: 1.45; }
.field-error { font-size: .78rem; color: var(--danger); font-weight: 700; }

.input-group { position: relative; display: block; }
.input-group > .input-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; z-index: 1; font-size: .9rem; }
.input-group > .input-icon ~ .input, .input-group > .input-icon ~ .select { padding-left: 40px; }
.input-group > .input-action { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--muted); }
.input-group > .input-action:hover { background: var(--surface-3); color: var(--text); }
.input-group.has-action > .input { padding-right: 46px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .col-full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; } }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: .86rem; line-height: 1.5; }
.check input { width: 19px; height: 19px; margin-top: 1px; accent-color: var(--brand); flex: none; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; margin: 0; z-index: 1; }
.switch > span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 999px; transition: background .2s; }
.switch > span::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,.3); transition: transform .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 4px rgba(var(--brand-rgb), .25); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); }

/* Píldoras seleccionables: <label class="chip"><input type="radio" ...><span>Texto</span></label> */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { position: relative; display: inline-flex; cursor: pointer; }
.chip > input { position: absolute; opacity: 0; width: 1px; height: 1px; left: 50%; bottom: 0; }
.chip > span { display: inline-flex; align-items: center; gap: 9px; min-height: 42px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: .88rem; transition: background .15s, border-color .15s; }
.chip:hover > span { border-color: var(--muted); }
.chip > input:checked + span { background: var(--surface-3); border-color: var(--brand); }
.chip > input:checked + span::before { content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900; font-size: 10px; width: 20px; height: 20px; margin-left: -8px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.chip > input:focus-visible + span { outline: 3px solid rgba(var(--brand-rgb), .4); outline-offset: 2px; }

/* Tarjeta seleccionable: <label class="choice"><input type="radio"><span class="choice-body">…</span></label> */
.choice { position: relative; display: block; cursor: pointer; min-width: 0; }
.choice > input { position: absolute; opacity: 0; width: 1px; height: 1px; left: 50%; bottom: 0; }
.choice > .choice-body { position: relative; display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 15px 16px; border: 1.5px solid var(--line); border-radius: var(--r-lg); background: var(--surface); transition: border-color .15s, background .15s, box-shadow .15s; }
.choice:hover > .choice-body { border-color: var(--line-strong); }
.choice > input:checked + .choice-body { border-color: var(--brand); background: rgba(var(--brand-rgb), .06); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .16); }
.choice > input:focus-visible + .choice-body { outline: 3px solid rgba(var(--brand-rgb), .4); outline-offset: 2px; }
.choice-check { position: absolute; top: 12px; right: 12px; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; font-size: 10px; color: transparent; }
.choice > input:checked + .choice-body .choice-check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ── Insignias ───────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 700; line-height: 1.5; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-purple  { background: var(--purple-soft);  color: var(--purple); }
.badge-brand   { background: rgba(var(--brand-rgb), .12); color: var(--brand-text); }
.badge-accent  { background: var(--accent); color: var(--on-accent); }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Indicadores (KPI) ───────────────────────────────────────────────── */
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; min-width: 0; box-shadow: var(--shadow-sm); }
.stat-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.stat-label { font-size: .79rem; color: var(--muted); font-weight: 700; }
.stat-value { font-family: var(--font-display); font-size: 1.65rem; font-weight: 700; letter-spacing: -.025em; line-height: 1.15; margin-top: 8px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-foot { font-size: .76rem; color: var(--muted); margin-top: 5px; }
.stat-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(var(--brand-rgb), .11); color: var(--brand-text); flex: none; font-size: .9rem; }
.stat-icon.is-success { background: var(--success-soft); color: var(--success); }
.stat-icon.is-danger  { background: var(--danger-soft);  color: var(--danger); }
.stat-icon.is-warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.is-info    { background: var(--info-soft);    color: var(--info); }
.stat-icon.is-purple  { background: var(--purple-soft);  color: var(--purple); }
.stat.is-feature { background: var(--brand-deep); color: #fff; border-color: transparent; }
.stat.is-feature .stat-label, .stat.is-feature .stat-foot { color: rgba(255,255,255,.74); }
.stat.is-feature .stat-value { color: var(--accent); }
.stat.is-feature .stat-icon { background: rgba(255,255,255,.13); color: #fff; }
@media (max-width: 640px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 13px 14px; }
    .stat-value { font-size: 1.25rem; }
    .stat-icon { width: 28px; height: 28px; font-size: .75rem; border-radius: 8px; }
    .stats > .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* ── Tablas ──────────────────────────────────────────────────────────── */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; font-size: .86rem; }
.table th { padding: 11px 16px; font-size: .74rem; font-weight: 700; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { font-weight: 800; background: var(--surface-2); border-top: 1px solid var(--line-strong); border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * { margin-left: 4px; vertical-align: middle; }
.table .actions > form { display: inline-block; }
.table tr.is-muted td { color: var(--muted); }
.table tr.is-muted .cell-strike { text-decoration: line-through; }

/* En celular cada fila es una tarjeta. Añadir data-label="Columna" a cada <td>.
   Solo en pantalla: una hoja A4 mide menos de 760px y la tabla debe imprimirse como tabla. */
@media screen and (max-width: 760px) {
    .table-cards thead { display: none; }
    .table.table-cards, .table-cards tbody, .table-cards tfoot, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
    .table-cards tbody tr:last-child { border-bottom: 0; }
    .table.table-cards td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 4px 0; border: 0; text-align: right; white-space: normal; background: transparent; min-width: 0; overflow-wrap: anywhere; }
    .table-cards td::before { content: attr(data-label); font-size: .74rem; color: var(--muted); font-weight: 700; text-align: left; flex: none; }
    .table-cards td:not([data-label])::before { content: none; }
    .table.table-cards td.td-title { justify-content: flex-start; text-align: left; font-weight: 700; padding-bottom: 8px; }
    .table.table-cards td.actions { justify-content: flex-end; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
    .table-cards td.actions > * { margin-left: 0; }
    .table.table-cards td[colspan] { justify-content: center; text-align: center; }
    .table.table-cards td.hide-mobile { display: none; }
}

/* ── Barra de herramientas / filtros ─────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar > .field { flex: 0 1 180px; }
.search { position: relative; flex: 1 1 240px; min-width: 0; }
.search > i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search > .input { padding-left: 40px; }
@media (max-width: 640px) { .toolbar > .field { flex: 1 1 calc(50% - 5px); } }

.segmented { display: inline-flex; gap: 2px; padding: 4px; background: var(--surface-3); border-radius: var(--r); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented > a, .segmented > button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; padding: 0 14px; border-radius: 9px; font-size: .81rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.segmented > a:hover, .segmented > button:hover { color: var(--text); }
.segmented > .is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented.is-block { display: flex; }
.segmented.is-block > * { flex: 1; }

/* ── Avisos ──────────────────────────────────────────────────────────── */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); font-size: .86rem; line-height: 1.5; }
.alert > i { margin-top: 3px; flex: none; }
.alert-info    { background: var(--info-soft);    border-color: var(--info-line);    color: var(--info); }
.alert-success { background: var(--success-soft); border-color: var(--success-line); color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  border-color: var(--danger-line);  color: var(--danger); }

/* ── Estado vacío ────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 44px 20px; }
.empty-icon { width: 58px; height: 58px; margin: 0 auto 14px; border-radius: 18px; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); font-size: 1.3rem; }
.empty-title { font-weight: 800; }
.empty-text { color: var(--muted); font-size: .86rem; margin: 4px auto 0; max-width: 44ch; }
.empty > .btn { margin-top: 16px; }

/* ── Avatar y listas ─────────────────────────────────────────────────── */
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .78rem; background: rgba(var(--brand-rgb), .13); color: var(--brand-text); flex: none; overflow: hidden; }
.avatar-lg { width: 52px; height: 52px; font-size: 1rem; }
.person { display: flex; align-items: center; gap: 12px; min-width: 0; text-align: left; }
.person-name { font-weight: 700; line-height: 1.3; }
.person-sub { color: var(--muted); font-size: .77rem; line-height: 1.4; }
.list > * + * { border-top: 1px solid var(--line); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 20px; min-width: 0; }

.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px 22px; }
.dl dt { font-size: .75rem; color: var(--muted); font-weight: 700; }
.dl dd { font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
@media (max-width: 480px) { .dl { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; } }

/* ── Progreso por pasos ──────────────────────────────────────────────── */
.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .35s ease; }
.progress.is-brand > span { background: var(--brand); }
.progress.is-danger > span { background: var(--danger); }
.progress.is-warning > span { background: #e9a23b; }

/* ── Paginación ──────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); }
.pagination .pages { display: flex; gap: 4px; flex-wrap: wrap; }
.page-link { min-width: 36px; height: 36px; padding: 0 10px; display: grid; place-items: center; border-radius: 10px; font-size: .8rem; font-weight: 700; color: var(--text-2); }
.page-link:hover { background: var(--surface-3); }
.page-link.is-active { background: var(--brand); color: var(--on-brand); }
.page-link.is-disabled { opacity: .35; pointer-events: none; }

/* ── Ventanas modales ────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 90; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(8,14,10,.55); backdrop-filter: blur(3px); }
.modal.is-open { display: flex; animation: fade-in .15s ease; }
.modal-panel { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-panel.is-wide { max-width: 720px; }
.modal-panel > form { display: flex; flex-direction: column; min-height: 0; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 0; }
.modal-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; letter-spacing: -.015em; }
.modal-body { padding: 16px 22px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface-2); }
@media (max-width: 600px) {
    .modal { align-items: flex-end; padding: 0; }
    .modal-panel, .modal-panel.is-wide { max-width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 22px 22px 0 0; }
    .modal-foot > .btn { flex: 1; }
}

/* ── Avisos flotantes (toasts) ───────────────────────────────────────── */
.toasts { position: fixed; z-index: 100; top: calc(12px + env(safe-area-inset-top)); right: 12px; display: flex; flex-direction: column; gap: 10px; width: min(390px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; padding: 13px 12px 13px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); animation: toast-in .25s ease; transition: opacity .25s, transform .25s; font-size: .87rem; font-weight: 600; line-height: 1.45; }
.toast.is-leaving { opacity: 0; transform: translateY(-8px); }
.toast-icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; flex: none; font-size: .8rem; background: var(--info-soft); color: var(--info); }
.toast-success .toast-icon { background: var(--success-soft); color: var(--success); }
.toast-error .toast-icon   { background: var(--danger-soft);  color: var(--danger); }
.toast-warning .toast-icon { background: var(--warning-soft); color: var(--warning); }
.toast-text { flex: 1; padding-top: 4px; overflow-wrap: anywhere; }
.toast-close { width: 28px; height: 28px; border-radius: 8px; color: var(--faint); flex: none; }
.toast-close:hover { background: var(--surface-3); color: var(--text); }

@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── SweetAlert2 con el mismo estilo ─────────────────────────────────── */
.swal2-popup { background: var(--surface) !important; color: var(--text) !important; font-family: var(--font) !important; border-radius: var(--r-xl) !important; padding: 1.4em 1.2em !important; }
.swal2-title { color: var(--text) !important; font-family: var(--font-display) !important; font-size: 1.3rem !important; }
.swal2-html-container { color: var(--text-2) !important; font-size: .92rem !important; }
.swal2-actions { gap: 10px; flex-wrap: wrap; }
.swal2-popup .swal2-textarea, .swal2-popup .swal2-input, .swal2-popup .swal2-select { background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--r); font-size: .95rem; }
.swal2-validation-message { background: var(--danger-soft) !important; color: var(--danger) !important; }

/* ==========================================================================
   Estructura: barra lateral, barra superior, navegación móvil
   ========================================================================== */
.sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; width: var(--sidebar-w);
    display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line);
    transition: width .2s ease, transform .25s ease;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 10px 14px; min-height: 68px; }
.brand-link { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; overflow: hidden; flex: none; font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; }
.brand-mark.has-logo { background: #fff; border: 1px solid var(--line); padding: 3px; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-mark.is-wide { width: 76px; border-radius: 10px; }
/* Con logo apaisado queda menos sitio: el nombre usa hasta dos líneas en vez de cortarse */
.brand-mark.is-wide + .brand-text .brand-name { white-space: normal; font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.brand-mark.is-wide + .brand-text .brand-sub { display: none; }
.brand-name { display: block; font-family: var(--font-display); font-weight: 750; font-size: 1.02rem; line-height: 1.15; letter-spacing: -.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub { display: block; font-size: .7rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-text { min-width: 0; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.sidebar-close { display: none; }

.sidebar-cta { padding: 4px 12px 2px; }
.sidebar-cta .btn { width: 100%; }

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 2px 12px 14px; scrollbar-width: thin; }
.nav-group-title { font-size: .69rem; font-weight: 800; letter-spacing: .03em; color: var(--faint); padding: 15px 10px 6px; white-space: nowrap; }
.nav-link { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 40px; padding: 0 10px; margin-top: 2px; border-radius: 10px; color: var(--text-2); font-weight: 600; font-size: .875rem; white-space: nowrap; text-align: left; }
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.is-active { background: var(--surface-3); color: var(--text); font-weight: 800; }
.nav-icon { width: 20px; text-align: center; color: var(--muted); font-size: .95rem; flex: none; }
.nav-link.is-active .nav-icon { color: var(--brand-text); }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-badge { min-width: 22px; height: 20px; padding: 0 6px; border-radius: 6px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-size: .7rem; font-weight: 800; }
.nav-link.is-active .nav-badge { background: var(--surface); }
.nav-badge.is-accent, .nav-link.is-active .nav-badge.is-accent { background: var(--accent); color: var(--on-accent); }
.nav-status { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; margin-right: 6px; }
.nav-status.is-on { background: #22a954; box-shadow: 0 0 0 3px rgba(34,169,84,.18); }
.nav-caret { font-size: .65rem; color: var(--faint); transition: transform .2s; }
.nav-folder.is-open > .nav-link .nav-caret { transform: rotate(90deg); }
.nav-sub { display: none; margin: 2px 0 4px 19px; padding-left: 10px; border-left: 1px solid var(--line); }
.nav-folder.is-open > .nav-sub { display: block; }
.nav-sub .nav-link { min-height: 34px; font-size: .835rem; }

.sidebar-foot { border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.theme-switch { display: flex; width: 100%; }
.theme-switch > button { flex: 1; }
.user-block { position: relative; display: flex; align-items: center; gap: 10px; padding: 12px 2px 2px; }
.user-text { flex: 1; min-width: 0; }
.user-name { font-weight: 800; font-size: .84rem; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-mail { color: var(--muted); font-size: .73rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { position: absolute; bottom: calc(100% - 4px); right: 0; min-width: 190px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); display: none; z-index: 5; }
.user-menu.is-open { display: block; }
.theme-rail-btn { display: none; }

.app-main { margin-left: var(--sidebar-w); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; min-width: 0; transition: margin-left .2s ease; }
.topbar { position: sticky; top: 0; z-index: 40; height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: var(--bg); border-bottom: 1px solid var(--line); }
.crumbs { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; font-size: .85rem; color: var(--muted); font-weight: 600; }
.crumbs strong { color: var(--text); font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs .crumb-brand { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-date { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.caja-pill { display: inline-flex; align-items: center; gap: 9px; height: 34px; padding: 0 13px 0 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .78rem; font-weight: 800; white-space: nowrap; }
.caja-pill .nav-status { margin: 0; }
.topbar-menu { display: none; }

.content { width: 100%; max-width: 1320px; margin: 0 auto; padding: 24px 28px 48px; flex: 1; min-width: 0; }
.content.is-narrow { max-width: 900px; }
.content.is-wide { max-width: none; }

.sidebar-overlay { position: fixed; inset: 0; z-index: 55; background: rgba(8,14,10,.5); display: none; }
.bottomnav { display: none; }

/* Escritorio: barra lateral contraída (solo iconos) */
@media (min-width: 1024px) {
    html.sidebar-rail .sidebar { width: var(--sidebar-rail); }
    html.sidebar-rail .app-main { margin-left: var(--sidebar-rail); }
    html.sidebar-rail .brand-link, html.sidebar-rail .nav-label, html.sidebar-rail .nav-badge,
    html.sidebar-rail .nav-caret, html.sidebar-rail .nav-sub, html.sidebar-rail .user-text,
    html.sidebar-rail .user-menu-btn, html.sidebar-rail .theme-switch, html.sidebar-rail .cta-label { display: none !important; }
    html.sidebar-rail .sidebar-head { justify-content: center; padding-left: 0; padding-right: 0; }
    html.sidebar-rail .sidebar-nav, html.sidebar-rail .sidebar-cta, html.sidebar-rail .sidebar-foot { padding-left: 14px; padding-right: 14px; }
    html.sidebar-rail .sidebar-cta .btn { padding: 0; }
    html.sidebar-rail .nav-link { justify-content: center; padding: 0; gap: 0; position: relative; }
    html.sidebar-rail .sidebar .nav-status { position: absolute; top: 8px; right: 8px; margin: 0; width: 7px; height: 7px; }
    html.sidebar-rail .nav-group-title { font-size: 0; padding: 7px 8px; }
    html.sidebar-rail .nav-group-title::after { content: ''; display: block; height: 1px; background: var(--line); }
    html.sidebar-rail .user-block { justify-content: center; }
    html.sidebar-rail .theme-rail-btn { display: grid; margin: 0 auto; }
    html.sidebar-rail .user-menu { left: calc(100% + 10px); right: auto; bottom: 0; }
}
.rail-tip { position: fixed; z-index: 95; transform: translateY(-50%); padding: 7px 12px; border-radius: 9px; background: var(--text); color: var(--surface); font-size: .78rem; font-weight: 700; white-space: nowrap; pointer-events: none; box-shadow: var(--shadow); }

/* Tableta y celular */
@media (max-width: 1023.98px) {
    .sidebar { width: min(300px, 86vw); transform: translateX(-102%); box-shadow: none; }
    html.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    html.sidebar-open .sidebar-overlay { display: block; animation: fade-in .2s ease; }
    html.sidebar-open body { overflow: hidden; }
    .sidebar-collapse { display: none; }
    .sidebar-close { display: grid; }
    .app-main { margin-left: 0; }
    .topbar { padding: 0 12px; height: 56px; gap: 8px; }
    .topbar-menu { display: grid; }
    .topbar-date, .crumbs .crumb-brand, .crumbs .crumb-sep, .topbar-new { display: none !important; }
    .content { padding: 16px 14px calc(var(--bottomnav-h) + 28px + env(safe-area-inset-bottom)); }
    .bottomnav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
    .bottomnav > a, .bottomnav > button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: .67rem; font-weight: 800; color: var(--muted); min-width: 0; }
    .bottomnav i { font-size: 1.08rem; }
    .bottomnav > .is-active { color: var(--brand-text); }
    .bottomnav .bn-main > span:first-child { width: 48px; height: 48px; margin-top: -22px; border-radius: 16px; display: grid; place-items: center; background: var(--brand); color: var(--on-brand); box-shadow: 0 10px 22px -8px rgba(var(--brand-rgb), .85); border: 3px solid var(--surface); }
    .bottomnav .bn-badge { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-size: .62rem; }
    /* Barra de acciones fija sobre la navegación móvil: <div class="actionbar is-sticky"> */
    /* 18px abajo: el botón central "+" sobresale de la navegación y no debe rozar los botones */
    .actionbar.is-sticky { position: sticky; bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); z-index: 30; margin-left: -14px; margin-right: -14px; padding: 10px 14px 18px; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -10px 24px -18px rgba(0,0,0,.35); }
    .actionbar.is-sticky > .btn { flex: 1; }
    html.has-modal .bottomnav { display: none; }
}
@media (max-width: 400px) { .caja-pill .caja-pill-text { display: none; } .caja-pill { padding: 0 11px; } }

.actionbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-items: center; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ── Impresión: siempre en claro y sin navegación ────────────────────── */
@media print {
    :root, :root[data-theme="dark"] {
        --bg: #fff; --surface: #fff; --surface-2: #f7f8f6; --surface-3: #eef1ea; --line: #d9ddd5; --line-strong: #c3c9bd;
        --text: #111; --text-2: #333; --muted: #555; --faint: #777;
        --success: #137a38; --success-soft: #e5f5ea; --success-line: #bde4c9;
        --danger: #bd3026;  --danger-soft: #fcebe9;  --danger-line: #f3c4bf;
        --warning: #8f5208; --warning-soft: #fdf2da; --warning-line: #f0d599;
        --info: #1a62a6;    --info-soft: #e6f1fb;    --info-line: #bcd9f1;
        --purple: #6a3bce;  --purple-soft: #f0eafd;  --purple-line: #d8cbf7;
        color-scheme: light;
    }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    .sidebar, .sidebar-overlay, .topbar, .bottomnav, .toasts, .page-actions, .actionbar, .no-print { display: none !important; }
    .app-main { margin: 0 !important; min-height: 0; }
    .content { max-width: none !important; padding: 0 !important; }
    .card, .stat { box-shadow: none; break-inside: avoid; }
    .table-wrap { overflow: visible; }
}
