/* ============================================================
   RAC App Styles v2 — Grupo Firmas Globales
   Spec: docs/specs/ui/identity-and-styling.md
   Usa design-tokens.css como fuente de variables.
   ============================================================ */

/* === Base === */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
    background-color: var(--color-background);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* === Accesibilidad === */

.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;
}

.skip-link {
    position: absolute;
    top: -48px;
    left: 12px;
    z-index: var(--z-tooltip);
    background: var(--gfg-dark-teal);
    color: white;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: var(--text-sm);
    text-decoration: none;
    transition: top var(--duration-fast) var(--ease-out);
}

.skip-link:focus,
.skip-link:focus-visible {
    top: 8px;
    outline: none;
    box-shadow: var(--shadow-focus);
}

:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-sm);
}

/* === Typography === */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--color-text-primary);
    margin-top: 0;
    line-height: var(--leading-tight);
}

h1 { font-size: var(--text-3xl); font-weight: 700; }
h2 { font-size: var(--text-2xl); font-weight: 600; }
h3 { font-size: var(--text-xl);  font-weight: 600; }
h4 { font-size: var(--text-lg);  font-weight: 500; }

h1:focus { outline: none; }

a, .btn-link {
    color: var(--gfg-dark-teal);
    text-decoration: none;
    transition: var(--transition-colors);
}

a:hover, .btn-link:hover {
    color: var(--teal-5);
}

code {
    font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
    color: var(--gfg-dark-teal);
    background: var(--surface-sunken);
    padding: 1px 6px;
    border-radius: var(--radius-xs);
    font-size: 0.85em;
}

/* === Botones === */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 13px;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 0 14px;
    height: 36px;
    cursor: pointer;
    transition: var(--transition-colors), transform var(--duration-instant) var(--ease-out);
    user-select: none;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn:active {
    transform: translateY(1px);
}

.btn i { font-size: 15px; }

/* Sizes */
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; gap: 4px; }
.btn-sm i { font-size: 13px; }
.btn-lg { height: 44px; padding: 0 18px; font-size: 14px; gap: 8px; }
.btn-lg i { font-size: 18px; }

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    color: var(--gray-600);
    border: none;
}
.btn-icon.btn-sm { width: 28px; height: 28px; }
.btn-icon.btn-lg { width: 44px; height: 44px; }
.btn-icon:hover { background: var(--surface-2); color: var(--gfg-dark-teal); }
.btn-icon:active { background: var(--surface-3); }

/* Primary */
.btn-primary {
    background-color: var(--gfg-turquoise);
    color: var(--gfg-dark-teal);
    border: none;
}
.btn-primary:hover { background-color: #5dd4bf; color: var(--gfg-dark-teal); }
.btn-primary:active { background-color: #4dc8b2; }

/* Secondary */
.btn-secondary,
.btn-outline-secondary {
    background-color: var(--surface-0);
    color: var(--gfg-dark-teal);
    border: 1px solid var(--border-default);
}
.btn-secondary:hover,
.btn-outline-secondary:hover {
    background-color: var(--surface-2);
    border-color: var(--border-strong);
    color: var(--gfg-dark-teal);
}
.btn-secondary:active,
.btn-outline-secondary:active {
    background-color: var(--surface-3);
}

/* Ghost */
.btn-ghost {
    background-color: transparent;
    color: var(--gfg-dark-teal);
    border: none;
}
.btn-ghost:hover { background-color: var(--surface-2); }
.btn-ghost:active { background-color: var(--surface-3); }

/* Danger */
.btn-danger {
    background-color: var(--color-error);
    color: var(--gfg-white);
    border: none;
}
.btn-danger:hover { background-color: #b91c1c; color: var(--gfg-white); }
.btn-danger:active { background-color: #991b1b; }
.btn-danger:focus-visible { box-shadow: var(--shadow-focus-danger); }

/* === Cards === */

.card {
    background-color: var(--surface-0);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    transition: var(--transition-colors), box-shadow var(--duration-fast) var(--ease-out);
}

.card-bordered {
    /* same as default .card */
}

.card-elevated {
    border-color: transparent;
    box-shadow: var(--shadow-sm);
}

.card-elevated:hover { box-shadow: var(--shadow-md); }

.card-clickable {
    cursor: pointer;
}
.card-clickable:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-default);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.card-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 16px;
    color: var(--color-text-primary);
    margin: 0;
}

.card-subtitle {
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--gray-500);
    margin-top: 4px;
}

.card-footer {
    padding-top: var(--space-4);
    margin-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
}

/* === Tablas === */

.table-wrap {
    background: var(--surface-0);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-body);
    font-size: var(--text-sm);
}

.table thead th {
    background-color: var(--surface-1);
    color: var(--gray-600);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-default);
    position: sticky;
    top: 0;
    z-index: 2;
    white-space: nowrap;
}

.table tbody td {
    padding: 10px 12px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-subtle);
    border-left: none;
    border-right: none;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr {
    transition: background-color var(--duration-fast) var(--ease-out);
}

.table tbody tr:hover {
    background-color: var(--surface-2);
}

.table td.num,
.table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.table[data-density="compact"] thead th,
.table[data-density="compact"] tbody td {
    padding: 6px 12px;
}

.table .row-actions {
    display: inline-flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease-out);
}

.table tbody tr:hover .row-actions,
.table tbody tr:focus-within .row-actions {
    opacity: 1;
}

.table tr[data-new="true"] {
    animation: row-flash 800ms var(--ease-out);
}

@keyframes row-flash {
    from { background-color: rgba(113, 228, 209, 0.18); }
    to { background-color: transparent; }
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Vista previa de dimensiones del asiento: cadenas largas que no deben ensanchar el grid.
   El valor completo queda en el title de la celda. */
.table td.dimensions-cell {
    max-width: 260px;
}

.table td.dimensions-cell > code {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Compat con Bootstrap */
.table-striped > tbody > tr:nth-of-type(odd) > *,
.table-striped > tbody > tr:nth-of-type(even) > * {
    background-color: inherit;
}
.table-hover > tbody > tr:hover > * {
    background-color: var(--surface-2);
}

/* === Formularios === */

label, .form-label {
    display: block;
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: var(--text-sm);
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control, .form-select,
input[type="text"], input[type="email"], input[type="number"],
input[type="password"], input[type="search"], input[type="tel"],
input[type="url"], input[type="date"], input[type="datetime-local"],
textarea, select {
    display: block;
    width: 100%;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background-color: var(--surface-0);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--color-text-primary);
    transition: var(--transition-colors);
}

textarea, textarea.form-control {
    height: auto;
    min-height: 96px;
    padding: 8px 12px;
    resize: vertical;
    line-height: var(--leading-snug);
}

.form-control::placeholder, input::placeholder, textarea::placeholder {
    color: var(--gray-400);
}

.form-control:hover, .form-select:hover,
input:hover, select:hover, textarea:hover {
    border-color: var(--border-strong);
}

.form-control:focus, .form-select:focus,
input:focus, select:focus, textarea:focus {
    border-color: var(--gfg-turquoise);
    box-shadow: var(--shadow-focus);
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    border-color: var(--color-success);
}

.invalid, .form-control.invalid {
    border-color: var(--color-error);
}
.invalid:focus, .form-control.invalid:focus {
    box-shadow: var(--shadow-focus-danger);
}

.validation-message,
.form-error {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--color-error);
    font-size: var(--text-xs);
    margin-top: 4px;
}

.form-helper {
    color: var(--gray-500);
    font-size: var(--text-xs);
    margin-top: 4px;
}

.form-group {
    margin-bottom: var(--space-4);
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-start;
}

.form-row > .form-group {
    flex: 1 1 0;
    min-width: 0;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--space-4);
    row-gap: var(--space-3);
    align-items: start;
}

.form-grid-2 > .form-group {
    margin-bottom: 0;
}

.form-grid-2 .form-grid-full {
    grid-column: 1 / -1;
}

@media (max-width: 720px) {
    .form-row > .form-group {
        flex: 1 1 100%;
    }
    .form-grid-2 {
        grid-template-columns: 1fr;
    }
}

.form-hidden-submit {
    display: none;
}

.form-section + .form-section {
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
}

.form-section-title {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
    font-size: var(--text-sm);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--color-text-strong, var(--gfg-dark, #28333b));
}

.form-section-hint {
    margin: 0 0 var(--space-3);
    color: var(--gray-500);
    font-size: var(--text-xs);
}

/* === Badges (dot + text) === */

[class^="badge-"],
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border-radius: var(--radius-pill);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 11px;
    line-height: 1.4;
    border: 1px solid transparent;
    white-space: nowrap;
}

[class^="badge-"]::before,
.badge.has-dot::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-draft       { background: #f4f5f6; color: #4b5359; border-color: #e6e6e5; }
.badge-pending     { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.badge-approved,
.badge-posted,
.badge-validated   { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.badge-exported    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.badge-rejected,
.badge-sendfailed,
.badge-error       { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
/* Integración D365: transitorio (turquesa de marca) y enviado (cian). */
.badge-sending     { background: #f0fbf9; color: #0f6b60; border-color: #a7ecdf; }
.badge-sent        { background: #ecfeff; color: #155e75; border-color: #a5f3fc; }

/* Indicador de línea con normalización de signo (sign-normalization.md). */
.inversion-mark {
    display: inline-block;
    margin-left: 4px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: #f0fbf8;
    color: #28333b;
    border: 1px solid #71E4D1;
    font-size: 11px;
    line-height: 1.4;
    cursor: help;
}

/* === Alerts === */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid;
    border-left-width: 3px;
    padding: 12px 16px;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    line-height: var(--leading-snug);
}
.alert > i:first-child {
    font-size: 18px;
    line-height: 1.2;
    flex-shrink: 0;
}
.alert-success {
    border-color: #bbf7d0;
    border-left-color: var(--color-success);
    background-color: #f0fdf4;
    color: #065f46;
}
.alert-warning {
    border-color: #fed7aa;
    border-left-color: var(--color-warning);
    background-color: #fefce8;
    color: #92400e;
}
.alert-danger {
    border-color: #fecaca;
    border-left-color: var(--color-error);
    background-color: #fef2f2;
    color: #991b1b;
}
.alert-info {
    border-color: #a5f3fc;
    border-left-color: var(--gfg-turquoise);
    background-color: #f0fdfa;
    color: var(--gfg-dark-teal);
}

/* === Modales === */

.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(20, 28, 34, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: var(--z-overlay);
    animation: fade-in var(--duration-fast) var(--ease-out);
}

.modal-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: var(--z-modal);
    width: 92%;
    max-width: 560px;
    animation: modal-in var(--duration-base) var(--ease-out);
}

.modal-dialog.modal-sm { max-width: 420px; }
.modal-dialog.modal-lg { max-width: 720px; }
.modal-dialog.modal-xl { max-width: 1000px; }

.modal-content {
    background: var(--surface-0);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    border: none;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 16px;
}

.modal-body {
    padding: 20px 24px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
    padding: 16px 24px;
    background: var(--surface-1);
    border-top: 1px solid var(--border-subtle);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-in {
    from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)) scale(0.98); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* === Empty state === */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--spacing-2xl) var(--spacing-lg);
    text-align: center;
    color: var(--gray-500);
}

.empty-state .empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--gray-400);
    font-size: 28px;
    margin-bottom: 4px;
}

.empty-state .empty-state-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 16px;
    color: var(--color-text-primary);
    margin: 0;
}

.empty-state .empty-state-message {
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--gray-500);
    max-width: 360px;
    margin: 0;
    line-height: var(--leading-snug);
}

.empty-state .empty-state-cta {
    margin-top: var(--space-3);
}

/* Fallback para <i> suelto en .empty-state (compat v1) */
.empty-state > i {
    font-size: 2rem;
}

/* === Loading placeholder === */

.loading-placeholder {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--spacing-xl);
    color: var(--gray-500);
    justify-content: center;
    font-size: var(--text-sm);
}

.spin {
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* === Skeletons === */

.skeleton {
    display: block;
    background-image: linear-gradient(
        90deg,
        var(--gray-200) 0%,
        var(--gray-100) 50%,
        var(--gray-200) 100%
    );
    background-size: 200% 100%;
    border-radius: var(--radius-sm);
    animation: skeleton-shimmer 1.6s ease-in-out infinite;
}

.skeleton-line {
    height: 12px;
    margin: 6px 0;
}

.skeleton-block {
    width: 100%;
    min-height: 120px;
    border-radius: var(--radius-md);
}

@keyframes skeleton-shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

/* === Toasts === */

.toast-host {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    width: 320px;
    background: var(--surface-0);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--gray-400);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 12px 14px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: toast-in var(--duration-base) var(--ease-out);
    font-family: var(--font-body);
    font-size: var(--text-sm);
}

.toast.toast-success { border-left-color: var(--color-success); }
.toast.toast-warning { border-left-color: var(--color-warning); }
.toast.toast-error   { border-left-color: var(--color-error); }
.toast.toast-info    { border-left-color: var(--gfg-turquoise); }

.toast .toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}
.toast.toast-success .toast-icon { color: var(--color-success); }
.toast.toast-warning .toast-icon { color: var(--color-warning); }
.toast.toast-error   .toast-icon { color: var(--color-error); }
.toast.toast-info    .toast-icon { color: var(--gfg-turquoise); }

.toast .toast-body { flex: 1; }
.toast .toast-title {
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: var(--text-sm);
    margin: 0 0 2px;
}
.toast .toast-message {
    color: var(--gray-600);
    font-size: var(--text-sm);
    margin: 0;
    line-height: var(--leading-snug);
}
.toast .toast-close {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 2px;
    border-radius: var(--radius-xs);
    transition: var(--transition-colors);
    font-size: 14px;
}
.toast .toast-close:hover { color: var(--gray-700); background: var(--surface-2); }

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

@media (max-width: 640px) {
    .toast-host {
        left: 12px; right: 12px; bottom: 12px;
    }
    .toast { width: auto; }
}

/* === Page structure === */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 0 var(--space-5);
    margin-bottom: var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
}

.page-header .page-header-title h1 {
    margin: 0;
    font-size: var(--text-2xl);
    font-weight: 600;
    color: var(--color-text-primary);
}

.page-header .page-header-subtitle {
    margin: 4px 0 0;
    font-size: var(--text-sm);
    color: var(--gray-500);
    font-family: var(--font-body);
}

.page-header .page-header-actions {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* === Breadcrumbs === */

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    margin-bottom: var(--space-3);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    overflow: hidden;
    white-space: nowrap;
}

.breadcrumbs .crumb {
    color: var(--gray-500);
    text-decoration: none;
    transition: var(--transition-colors);
}
.breadcrumbs .crumb:hover { color: var(--gfg-dark-teal); }

.breadcrumbs .crumb.current {
    color: var(--color-text-primary);
    font-weight: 500;
}

.breadcrumbs .crumb-sep {
    color: var(--gray-400);
    font-size: 11px;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .breadcrumbs .crumb:not(.current):not(:first-child) { display: none; }
    .breadcrumbs .crumb-sep:not(:last-of-type) { display: none; }
}

/* === Loading screen (Blazor load progress) === */

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--surface-0);
}

.loading-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    margin-bottom: var(--spacing-lg);
}

.loading-progress {
    position: relative;
    display: block;
    width: 6rem;
    height: 6rem;
}

.loading-progress circle {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 0.5rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--gfg-turquoise);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    text-align: center;
    font-weight: 600;
    font-family: var(--font-heading);
    font-size: var(--text-sm);
    color: var(--gray-500);
    margin-top: var(--spacing-sm);
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Cargando");
}

/* === Blazor error UI === */

#blazor-error-ui {
    color-scheme: light only;
    background: #fef2f2;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: var(--z-tooltip);
    border-top: 3px solid var(--color-error);
    color: #991b1b;
    font-family: var(--font-body);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: var(--color-error);
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
    border-radius: var(--radius-md);
}

.blazor-error-boundary::after {
    content: "Ha ocurrido un error.";
}

/* === Page transition === */

.page-transition {
    animation: page-enter var(--duration-fast) var(--ease-out);
}

@keyframes page-enter {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* === prefers-reduced-motion === */

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

/* === Print === */

@media print {
    .navbar, .app-navbar,
    .sidebar, .app-sidebar,
    .app-footer, .footer,
    .breadcrumbs,
    .toast-host {
        display: none !important;
    }
    body, .page, main, .main-content {
        background: white !important;
        color: black !important;
    }
}

/* === Utility === */

.content { padding-top: var(--spacing-md); }

.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-5); }

.cluster { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.cluster-sm { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

.text-muted { color: var(--gray-500); }
.text-primary-color { color: var(--color-text-primary); }
.text-danger { color: var(--color-error); }
.text-success { color: var(--color-success); }

.tabular-nums { font-variant-numeric: tabular-nums; }

.divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-4) 0;
    border: none;
}

/* ============================================================
   Sidebar chrome (global, no scoped)
   Estas reglas cruzan componentes (NavLink es hijo, SbuSwitcher
   y LoginDisplay son otros componentes) y el modo compacto
   depende de la clase .sidebar.is-compact del MainLayout.
   Blazor scoped CSS no cruza componentes ni soporta :host-context.
   ============================================================ */

/* --- Nav menu --- */

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 4px 0 12px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-menu::-webkit-scrollbar { width: 6px; }
.nav-menu::-webkit-scrollbar-track { background: transparent; }
.nav-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
}
.nav-menu::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.12); }

.nav-group {
    display: flex;
    flex-direction: column;
    position: relative;
}

.nav-group + .nav-group::before {
    content: "";
    display: block;
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 8px 16px;
}

.nav-group-label {
    margin: 0;
    padding: 14px 20px 6px;
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 11px;
    color: var(--chrome-fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar .nav-item,
.sidebar a.nav-item,
.sidebar button.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 32px;
    padding: 6px 10px 6px 16px;
    margin: 0 8px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--chrome-fg);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 400;
    text-decoration: none;
    text-align: left;
    cursor: pointer;
    transition: var(--transition-colors);
    width: calc(100% - 16px);
}

.sidebar .nav-item i {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.55);
    flex-shrink: 0;
    width: 18px;
    text-align: center;
    transition: var(--transition-colors);
}

.sidebar .nav-item-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar .nav-item-shortcut {
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    flex-shrink: 0;
}

.sidebar .nav-item:hover,
.sidebar a.nav-item:hover,
.sidebar button.nav-item:hover {
    background: var(--chrome-hover);
    color: var(--chrome-fg-strong);
    text-decoration: none;
}
.sidebar .nav-item:hover i {
    color: rgba(255, 255, 255, 0.85);
}

.sidebar .nav-item:focus-visible,
.sidebar a.nav-item:focus-visible,
.sidebar button.nav-item:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--gfg-turquoise);
}

.sidebar .nav-item.active,
.sidebar a.nav-item.active {
    background: var(--chrome-active-bg);
    color: var(--chrome-active-fg);
    font-weight: 500;
}
.sidebar .nav-item.active i {
    color: var(--chrome-active-fg);
}

/* --- SBU Switcher --- */

.sbu-switcher {
    position: relative;
    padding: 12px;
}

.sbu-switcher-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    color: var(--chrome-fg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: var(--transition-colors);
    font-family: var(--font-body);
}

.sbu-switcher-trigger:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.18);
}

.sbu-switcher-trigger:focus-visible {
    outline: none;
    border-color: var(--gfg-turquoise);
    box-shadow: var(--shadow-focus);
}

.sbu-switcher-trigger:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.sbu-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    background: var(--teal-4);
    color: var(--gfg-turquoise);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 10px;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.sbu-avatar.sm {
    width: 22px;
    height: 22px;
    font-size: 9px;
}

.sbu-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.2;
}

.sbu-label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-heading);
    font-weight: 500;
}

.sbu-name {
    font-size: 13px;
    font-family: var(--font-heading);
    font-weight: 500;
    color: #fff;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sbu-switcher-trigger i.bi-chevron-expand {
    color: rgba(255, 255, 255, 0.55);
    font-size: 14px;
    flex-shrink: 0;
}

.sbu-popover-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: var(--z-popover);
}

.sbu-popover {
    position: absolute;
    top: calc(100% - 4px);
    left: 12px;
    right: 12px;
    z-index: calc(var(--z-popover) + 1);
    background: var(--surface-0);
    color: var(--color-text-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    animation: sbu-popover-in var(--duration-fast) var(--ease-out);
    min-width: 240px;
}

@keyframes sbu-popover-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sbu-popover-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--surface-1);
}

.sbu-popover-search > i {
    color: var(--gray-400);
    font-size: 13px;
}

.sbu-popover-search input {
    flex: 1;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--color-text-primary);
    outline: none;
}
.sbu-popover-search input:focus { box-shadow: none; }

.sbu-popover-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    max-height: 260px;
    overflow-y: auto;
}

.sbu-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--color-text-primary);
    text-align: left;
    transition: var(--transition-colors);
}

.sbu-option:hover { background: var(--surface-2); }

.sbu-option.is-active {
    background: rgba(113, 228, 209, 0.12);
    color: var(--gfg-dark-teal);
    font-weight: 500;
}

.sbu-option.is-active i.bi-check2 {
    margin-left: auto;
    color: var(--gfg-turquoise);
    font-size: 14px;
}

.sbu-option .sbu-avatar {
    background: var(--surface-2);
    color: var(--gfg-dark-teal);
}

.sbu-option-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sbu-popover-empty {
    padding: 16px 12px;
    text-align: center;
    color: var(--gray-500);
    font-size: 13px;
}

.sbu-popover-footer {
    padding: 6px;
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-1);
}

.sbu-popover-footer .btn {
    width: 100%;
    justify-content: flex-start;
}

/* --- Login display (user footer) --- */

.login-display {
    position: sticky;
    bottom: 0;
    padding: 10px 12px 14px;
    background: rgba(29, 38, 45, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid var(--chrome-border);
    z-index: 2;
}

.user-chip {
    position: relative;
}

.user-chip-main {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 6px 8px;
    background: transparent;
    color: var(--chrome-fg);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: var(--transition-colors);
    font-family: var(--font-body);
}

.user-chip-main:hover,
.user-chip.is-menu-open .user-chip-main {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
}

.user-chip-main:focus-visible {
    outline: none;
    border-color: var(--gfg-turquoise);
    box-shadow: var(--shadow-focus);
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--teal-4);
    color: var(--gfg-turquoise);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 11px;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}

.user-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.2;
}

.user-name {
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 13px;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    font-family: var(--font-body);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 1px;
}

.user-chip-main i.bi-three-dots {
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
    flex-shrink: 0;
}

.user-menu-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: var(--z-popover);
}

.user-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 12px;
    right: 12px;
    z-index: calc(var(--z-popover) + 1);
    background: var(--surface-0);
    color: var(--color-text-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-xl);
    padding: 6px;
    animation: user-menu-in var(--duration-fast) var(--ease-out);
}

@keyframes user-menu-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--color-text-primary);
    text-align: left;
    transition: var(--transition-colors);
}

.user-menu-item i { font-size: 14px; color: var(--gray-500); }

.user-menu-item:hover { background: var(--surface-2); }

.user-menu-item.danger:hover {
    background: #fef2f2;
    color: #991b1b;
}
.user-menu-item.danger:hover i { color: #991b1b; }

.user-login {
    width: 100%;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--chrome-fg);
}
.user-login:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

/* ============================================================
   Modo compacto del sidebar (56px, solo iconos)
   ============================================================ */

.sidebar.is-compact .nav-group-label {
    display: none;
}

.sidebar.is-compact .nav-group + .nav-group::before {
    margin: 8px 8px;
}

.sidebar.is-compact .nav-item,
.sidebar.is-compact a.nav-item,
.sidebar.is-compact button.nav-item {
    justify-content: center;
    padding: 6px;
    margin: 0 6px;
    width: calc(100% - 12px);
    gap: 0;
}

.sidebar.is-compact .nav-item-label,
.sidebar.is-compact .nav-item-shortcut {
    display: none;
}

.sidebar.is-compact .nav-item i {
    font-size: 18px;
    width: auto;
}

/* SBU switcher compacto */
.sidebar.is-compact .sbu-switcher {
    padding: 12px 6px;
}

.sidebar.is-compact .sbu-switcher-trigger {
    padding: 4px;
    justify-content: center;
    gap: 0;
}

.sidebar.is-compact .sbu-body,
.sidebar.is-compact .sbu-switcher-trigger i.bi-chevron-expand {
    display: none;
}

.sidebar.is-compact .sbu-popover {
    left: calc(100% + 8px);
    right: auto;
    top: 8px;
    width: 280px;
}

/* Login compacto */
.sidebar.is-compact .login-display {
    padding: 10px 6px 12px;
}

.sidebar.is-compact .user-chip-main {
    padding: 4px;
    justify-content: center;
    gap: 0;
}

.sidebar.is-compact .user-body,
.sidebar.is-compact .user-chip-main i.bi-three-dots {
    display: none;
}

.sidebar.is-compact .user-menu {
    left: calc(100% + 8px);
    right: auto;
    width: 220px;
    bottom: 0;
}

/* === Journals UI === */

.journal-view-toggle {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: var(--surface-2, #f4f5f6);
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--border-subtle, #eceff1);
}
.journal-view-toggle .btn {
    padding: 4px 10px;
    font-size: 13px;
}
.journal-view-toggle .btn.active {
    background: var(--surface-0, #ffffff);
    color: var(--gfg-dark-teal, #28333b);
    box-shadow: var(--shadow-xs, 0 1px 1px rgba(20,28,34,0.04));
}

.dataset-card {
    background: var(--surface-0, #ffffff);
    border: 1px solid var(--border-subtle, #eceff1);
    border-radius: var(--radius-lg, 12px);
    margin-bottom: var(--spacing-md, 16px);
    overflow: hidden;
}
.dataset-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--spacing-md, 16px);
    padding: var(--spacing-md, 16px);
    border-bottom: 1px solid var(--border-subtle, #eceff1);
    flex-wrap: wrap;
}
.dataset-card-title {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    flex: 1 1 360px;
}
.dataset-card-name {
    font-family: var(--font-heading, 'Montserrat', sans-serif);
    font-size: 15px;
    color: var(--gfg-dark-teal, #28333b);
}
.dataset-card-sub {
    font-size: 13px;
    color: var(--gray-500, #6b7280);
    margin-top: 2px;
}
.dataset-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.dataset-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    font-size: 11px;
    font-family: var(--font-heading, 'Montserrat', sans-serif);
    font-weight: 500;
    border: 1px solid;
    border-radius: var(--radius-pill, 9999px);
}
.dataset-status-pill::before {
    content: none;
}

.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md, 16px);
    padding: var(--spacing-md, 16px);
    background: var(--surface-2, #f4f5f6);
    border: 1px solid var(--border-subtle, #eceff1);
    border-radius: var(--radius-md, 8px);
    margin-bottom: var(--spacing-md, 16px);
    align-items: flex-end;
}
.filters-bar > div {
    display: flex;
    flex-direction: column;
    min-width: 160px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--spacing-md, 16px);
    margin: var(--spacing-md, 16px) 0;
}
.detail-kpi {
    background: var(--surface-0, #ffffff);
    border: 1px solid var(--border-subtle, #eceff1);
    border-radius: var(--radius-md, 8px);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.detail-kpi-label {
    font-size: 11px;
    font-family: var(--font-heading, 'Montserrat', sans-serif);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-500, #6b7280);
}
.detail-kpi-value {
    font-size: 20px;
    font-family: var(--font-heading, 'Montserrat', sans-serif);
    font-weight: 600;
    color: var(--gfg-dark-teal, #28333b);
    font-variant-numeric: tabular-nums;
}
.detail-kpi-value em {
    font-size: 12px;
    font-weight: 400;
    color: var(--gray-500, #6b7280);
    font-style: normal;
    margin-left: 4px;
}

.detail-meta {
    background: var(--surface-1, #fafafa);
    border: 1px solid var(--border-subtle, #eceff1);
    border-radius: var(--radius-md, 8px);
    padding: 12px 16px;
    margin-bottom: var(--spacing-md, 16px);
    font-size: 13px;
    color: var(--gray-600, #4b5359);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.detail-meta code {
    background: var(--surface-sunken, #f7f8f8);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.pagination-bar {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm, 8px);
}

.entry-lines {
    background: var(--surface-1, #fafafa);
    padding: var(--spacing-sm, 8px) var(--spacing-md, 16px);
    border-top: 1px solid var(--border-subtle, #eceff1);
}
.entry-lines table {
    background: transparent;
    margin-bottom: 0;
}

.row-expanded {
    background: var(--surface-2, #f4f5f6);
}
.row-detail td {
    background: var(--surface-1, #fafafa);
}

.concept-snapshot {
    list-style: none;
    padding: 0;
    margin: 0;
}
.concept-snapshot li {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle, #eceff1);
}
.concept-snapshot li:last-child {
    border-bottom: none;
}
