/* ==========================================================================
   Primec · Reportería Odoo
   Sistema de estilos. Todos los colores viven aquí como variables: ningún
   otro archivo debe escribir un hexadecimal a mano.
   ========================================================================== */

:root {
    /* Paleta corporativa */
    --primary-50:  #FDF8F1;
    --primary-100: #F4E1C1;
    --primary-200: #E9C68E;
    --primary-300: #D9A05B;
    --primary-500: #B5651D;
    --primary-700: #8C3B1B;
    --primary-900: #5A2A1B;

    /* Superficies */
    --background:     #FAFAF9;
    --surface:        #FFFFFF;
    --surface-subtle: #FBF7F2;
    --surface-hover:  #FFF9F3;

    /* Texto */
    --text-primary:   #35231D;
    --text-secondary: #75665F;
    --text-muted:     #9A8C85;
    --text-on-dark:   #F6EDE2;

    /* Bordes */
    --border:        #ECE5DF;
    --border-strong: #DED8D1;

    /* Semánticos: sólo para estado, nunca como color de marca */
    --success:    #2F7A55;
    --success-bg: #E7F3ED;
    --warning:    #A9741A;
    --warning-bg: #FBF0DC;
    --danger:     #A93226;
    --danger-bg:  #F9E7E5;

    /* Elevación */
    --shadow-sm: 0 1px 2px rgba(90, 42, 27, .05);
    --shadow:    0 1px 2px rgba(90, 42, 27, .04), 0 6px 16px rgba(90, 42, 27, .05);
    --shadow-lg: 0 12px 32px rgba(90, 42, 27, .12);

    --radius:    14px;
    --radius-sm: 8px;

    --sidebar-width: 258px;
    --header-height: 66px;

    --font: "Manrope", "Inter", "DM Sans", -apple-system, BlinkMacSystemFont,
            "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ------------------------------------------------------------------ base -- */

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

html, body { margin: 0; padding: 0; }

body {
    background: var(--background);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

a { color: var(--primary-500); text-decoration: none; }
a:hover { color: var(--primary-700); text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--text-secondary); }
.tiny { font-size: 11.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 12px; }

.neg { color: var(--danger); }

/* --------------------------------------------------------------- layout -- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--primary-900);
    color: var(--text-on-dark);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    overflow-y: auto;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 20px 20px 18px;
    border-bottom: 1px solid rgba(244, 225, 193, .13);
}

.sidebar__logo {
    width: 34px; height: 34px;
    flex: none;
    border-radius: 9px;
    background: linear-gradient(140deg, var(--primary-300), var(--primary-500));
    color: var(--primary-900);
    display: grid; place-items: center;
    font-weight: 800; font-size: 14px; letter-spacing: .02em;
}

.sidebar__title { font-size: 14.5px; font-weight: 700; line-height: 1.2; }
.sidebar__subtitle {
    font-size: 10px; letter-spacing: .15em; text-transform: uppercase;
    color: var(--primary-200); font-weight: 600; margin-top: 2px;
}

.sidebar__nav { padding: 14px 12px 24px; flex: 1; }

.sidebar__section {
    font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
    color: rgba(244, 225, 193, .5); font-weight: 700;
    padding: 16px 10px 7px;
}

.sidebar__link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: rgba(246, 237, 226, .82);
    font-size: 13.4px; font-weight: 500;
    margin-bottom: 2px;
    transition: background .13s ease, color .13s ease;
}
.sidebar__link:hover { background: rgba(217, 160, 91, .14); color: #fff; text-decoration: none; }
.sidebar__link.is-active { background: var(--primary-500); color: #fff; font-weight: 600; }
.sidebar__link.is-active .sidebar__icon { opacity: 1; }
.sidebar__icon { width: 17px; height: 17px; flex: none; opacity: .78; }

.sidebar__footer {
    padding: 14px 18px 18px;
    border-top: 1px solid rgba(244, 225, 193, .13);
    font-size: 11px;
    color: rgba(244, 225, 193, .55);
}

.main {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 0 rgba(217, 160, 91, .22);
    display: flex; align-items: center; gap: 16px;
    padding: 0 26px;
    position: sticky; top: 0; z-index: 40;
}

.topbar__spacer { flex: 1; }

.breadcrumbs { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); }
.breadcrumbs a { color: var(--text-secondary); }
.breadcrumbs__sep { color: var(--primary-300); }
.breadcrumbs__current { color: var(--text-primary); font-weight: 600; }

.topbar__user { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary-100); color: var(--primary-700);
    display: grid; place-items: center;
    font-weight: 700; font-size: 12px;
}
.topbar__username { font-size: 13px; font-weight: 600; line-height: 1.2; }
.topbar__role { font-size: 11px; color: var(--text-secondary); }

/*
 * Barra de progreso de la navegación parcial. Avanza al 70 % y espera ahí:
 * fingir un 100 % antes de tener la respuesta sería mentir sobre el estado.
 */
.nav-progress {
    position: fixed;
    top: var(--header-height); left: var(--sidebar-width); right: 0;
    height: 3px; z-index: 100;
    background: transparent;
    overflow: hidden;
}
.nav-progress::after {
    content: "";
    display: block; height: 100%; width: 0;
    background: linear-gradient(90deg, var(--primary-300), var(--primary-500));
    transition: width .35s ease-out;
}
.nav-progress.is-active::after { width: 70%; }

main.content[aria-busy="true"] { opacity: .55; transition: opacity .12s ease; }

@media (max-width: 1024px) {
    .nav-progress { left: 0; }
}

.content {
    padding: 24px 26px 48px;
    max-width: 1600px;
    width: 100%;
    /* Contenedor de referencia para las grillas: así responden al ancho
       disponible y no al de la ventana. */
    container-type: inline-size;
}

.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 29px; color: var(--primary-900); }
.page-head p { margin: 5px 0 0; color: var(--text-secondary); font-size: 14px; max-width: 900px; }
.page-head__row { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head__actions { margin-left: auto; display: flex; gap: 9px; align-items: center; }

/* ---------------------------------------------------------------- cards -- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card__head {
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card__head h3 { font-size: 15px; font-weight: 600; color: var(--primary-900); }
.card__note { font-size: 11.5px; color: var(--text-muted); }
.card__head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex: none; }

/* ------------------------------------------- filtro por análisis (widget) -- */

/*
 * Resumen de los filtros propios de un análisis, junto a su título.
 * Va en rojo a propósito: si un gráfico muestra menos datos que el resto de la
 * pantalla, tiene que saltar a la vista por qué.
 */
.title-filter-summary {
    margin-left: 6px;
    color: var(--danger);
    font-size: 11.5px;
    font-weight: 800;
    line-height: 1.3;
}

.wfilter-btn {
    position: relative;
    display: inline-grid; place-items: center;
    width: 32px; height: 32px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    transition: background .13s ease, border-color .13s ease, color .13s ease;
}
.wfilter-btn svg { width: 15px; height: 15px; }
.wfilter-btn:hover { background: var(--surface-hover); border-color: var(--primary-300); color: var(--primary-700); }
.wfilter-btn.is-active { background: var(--primary-500); border-color: var(--primary-500); color: #fff; }
.wfilter-btn__count {
    position: absolute; top: -6px; right: -6px;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 9px;
    background: var(--danger); color: #fff;
    font-size: 10px; font-weight: 800; line-height: 16px;
    text-align: center;
}

/* ---------------------------------------------------------------- popover -- */

/*
 * Panel flotante anclado a su disparador. Va con position:fixed y coordenadas
 * calculadas en JS para poder salirse de tarjetas con overflow sin recortarse.
 */
/*
 * Columna flexible: cuando el espacio disponible obliga a limitar la altura
 * (lo hace place() en ui.js), lo que se encoge es el cuerpo, que pasa a tener
 * scroll propio. Cabecera y pie se mantienen siempre visibles.
 * No lleva overflow:hidden porque recortaría la flecha.
 */
.popover {
    position: fixed; z-index: 240;
    width: min(560px, calc(100vw - 20px));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    animation: popover-in .13s ease-out;
    display: flex; flex-direction: column;
}
.popover[hidden] { display: none; }

.popover > form {
    display: flex; flex-direction: column;
    min-height: 0;
    border-radius: inherit;
}

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

/* Flecha: cuadrado rotado, recortado por el borde del panel. */
.popover::before {
    content: "";
    position: absolute;
    left: var(--arrow-x, 50%);
    width: 12px; height: 12px;
    margin-left: -6px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    transform: rotate(45deg);
}
.popover[data-placement="bottom"]::before {
    top: -7px;
    border-right: none; border-bottom: none;
}
.popover[data-placement="top"]::before {
    bottom: -7px;
    border-left: none; border-top: none;
    background: var(--surface);
}

.popover__head {
    flex: none;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: flex-start; gap: 12px;
    background: var(--surface-subtle);
    border-radius: 13px 13px 0 0;
}
.popover__eyebrow {
    font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase;
    color: var(--primary-500); font-weight: 800;
}
.popover__head h3 { font-size: 15px; color: var(--primary-900); margin-top: 2px; }
.popover__x {
    margin-left: auto; flex: none;
    background: none; border: none; padding: 2px;
    color: var(--text-muted); line-height: 0;
}
.popover__x svg { width: 16px; height: 16px; }
.popover__x:hover { color: var(--primary-700); }

.popover__body {
    padding: 16px 18px;
    /* Es la parte que cede altura cuando el panel no cabe entero. */
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
}
.popover__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
    gap: 12px;
}
.popover__hint {
    margin: 14px 0 0;
    font-size: 11.5px; color: var(--text-secondary);
    background: var(--primary-50);
    border-left: 3px solid var(--primary-300);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 8px 11px;
}
.popover__foot {
    flex: none;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    background: var(--surface);
    border-radius: 0 0 13px 13px;
}
.popover__foot .spacer { flex: 1; }

/* -------------------------------------------------- selector con buscador -- */

.xselect { position: relative; min-width: 0; }

.xselect__trigger {
    width: 100%;
    display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 8px 10px;
    font-size: 13px; font-family: inherit;
    color: var(--text-primary);
    text-align: left;
    transition: border-color .13s ease, box-shadow .13s ease;
}
.xselect__trigger:hover:not(:disabled) { border-color: var(--primary-300); }
.xselect__trigger:focus-visible,
.xselect.is-open .xselect__trigger {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 .2rem rgba(181, 101, 29, .12);
}
.xselect__trigger:disabled { background: var(--surface-subtle); color: var(--text-muted); cursor: not-allowed; }

.xselect__value {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.xselect__value.is-placeholder { color: var(--text-muted); }

.xselect__chevron {
    width: 15px; height: 15px; flex: none;
    color: var(--text-secondary);
    transition: transform .15s ease;
}
.xselect.is-open .xselect__chevron { transform: rotate(180deg); color: var(--primary-500); }

.xselect__panel {
    position: fixed; z-index: 260;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    width: max-content;
    max-width: min(380px, calc(100vw - 20px));
    animation: popover-in .12s ease-out;
    /* Igual que el popover: si hay poco espacio, cede la lista, no el buscador. */
    display: flex; flex-direction: column;
}
.xselect__search, .xselect__foot, .xselect__empty { flex: none; }
.xselect__list { flex: 1 1 auto; min-height: 0; }
.xselect__panel[hidden] { display: none; }

.xselect__search {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 11px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-subtle);
}
.xselect__search svg { width: 14px; height: 14px; flex: none; color: var(--text-muted); }
.xselect__search-input {
    flex: 1; min-width: 0;
    border: none; background: none; outline: none;
    font-family: inherit; font-size: 13px;
    color: var(--text-primary);
}
.xselect__search-input::placeholder { color: var(--text-muted); }

/*
 * La altura máxima la fija el JS como «alto de fila × filas visibles», de modo
 * que la fila siguiente quede cortada y se vea que la lista continúa.
 */
.xselect__list {
    list-style: none; margin: 0; padding: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.xselect__option {
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.xselect__option.is-active { background: var(--primary-50); }
.xselect__option.is-selected {
    background: var(--primary-500); color: #fff; font-weight: 600;
}
.xselect__option.is-selected.is-active { background: var(--primary-700); }

.xselect__empty, .xselect__foot {
    padding: 10px 12px;
    font-size: 11.5px; color: var(--text-muted);
}
.xselect__foot {
    border-top: 1px solid var(--border);
    background: var(--surface-subtle);
}

/* Barra de desplazamiento discreta, en tono de la paleta. */
.xselect__list::-webkit-scrollbar { width: 9px; }
.xselect__list::-webkit-scrollbar-track { background: transparent; }
.xselect__list::-webkit-scrollbar-thumb {
    background: var(--primary-100);
    border-radius: 6px;
    border: 2px solid var(--surface);
}
.xselect__list::-webkit-scrollbar-thumb:hover { background: var(--primary-300); }
.xselect__list { scrollbar-width: thin; scrollbar-color: var(--primary-100) transparent; }
.card__body { padding: 18px; }
.card__body--flush { padding: 0; }

.grid { display: grid; gap: 16px; }

/*
 * minmax(0,…) es obligatorio en todas: sin él la columna no baja del ancho
 * mínimo de su contenido y empuja la página al desbordamiento horizontal.
 */
.grid--kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--kpi-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--32 { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.stack { display: grid; gap: 16px; }

/*
 * El número de columnas depende del ancho REAL del área de contenido, no del
 * viewport. Con la barra lateral ocupando 258 px, una ventana de 1.320 px deja
 * ~1.040 px útiles: seis columnas ahí dejan tarjetas de 160 px, demasiado
 * estrechas para un importe. Las consultas de contenedor lo resuelven sin
 * depender de cuánto mide la ventana.
 */
/* Seis tarjetas necesitan ~200 px cada una para que el importe respire. */
@container (max-width: 1279px) {
    .grid--kpi-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@container (max-width: 1000px) {
    .grid--3 { grid-template-columns: minmax(0, 1fr); }
}
/* Cuatro tarjetas aguantan bien hasta ~215 px cada una. */
@container (max-width: 920px) {
    .grid--kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* La columna estrecha de grid--32 aloja un ranking: por debajo de esto no
   caben nombre, barra e importe a la vez. */
@container (max-width: 900px) {
    .grid--32 { grid-template-columns: minmax(0, 1fr); }
}
@container (max-width: 860px) {
    .grid--2 { grid-template-columns: minmax(0, 1fr); }
}
@container (max-width: 700px) {
    .grid--kpi-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (max-width: 460px) {
    .grid--kpi, .grid--kpi-6 { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------------------------ kpi -- */

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 17px;
    box-shadow: var(--shadow-sm);
    display: flex; gap: 13px; align-items: flex-start;
    /* Referencia para que la cifra se escale al ancho de SU tarjeta. */
    container-type: inline-size;
}
.kpi__icon {
    width: 38px; height: 38px; flex: none;
    border-radius: 10px;
    background: var(--primary-100);
    color: var(--primary-500);
    display: grid; place-items: center;
}
.kpi__icon svg { width: 19px; height: 19px; }
.kpi__icon--700 { color: var(--primary-700); }
.kpi__icon--300 { color: var(--primary-300); background: var(--primary-50); }
.kpi__icon--900 { color: var(--primary-900); }

.kpi__label {
    font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
    color: var(--text-secondary); font-weight: 700;
}
/*
 * La cifra nunca debe partirse en dos líneas: "-318,6 / 0 %" o "15,55 / M"
 * se leen como otro número. En vez de permitir el salto, el tamaño se adapta
 * al ancho disponible con clamp() y el texto se mantiene en una sola línea.
 */
.kpi__value {
    font-weight: 700; letter-spacing: -.025em;
    color: var(--primary-900); margin-top: 6px; line-height: 1.1;
    white-space: nowrap;
    font-size: 24px;                       /* respaldo sin container queries */
    font-size: clamp(17px, 9.4cqi, 27px);  /* 9,4 % del ancho de la tarjeta */
}
.kpi__value--sm {
    font-size: 20px;
    font-size: clamp(16px, 8cqi, 21px);
}

.kpi__hint {
    font-size: 11.5px; color: var(--text-secondary); margin-top: 5px;
    /* Una nota larga no debe estirar toda la fila de tarjetas.
       El texto completo queda disponible en el title. */
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
    line-clamp: 2; overflow: hidden;
}

/* --------------------------------------------------------------- source -- */

.source-banner {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary-500);
    border-radius: var(--radius);
    padding: 15px 18px;
    display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
}
.source-banner__dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--primary-500); flex: none;
}
.source-banner__label {
    font-size: 10.5px; letter-spacing: .13em; text-transform: uppercase;
    color: var(--text-secondary); font-weight: 700;
}
.source-banner__value { font-size: 14.5px; font-weight: 600; color: var(--primary-900); margin-top: 2px; }
.source-banner__meta { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.source-banner__right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* --------------------------------------------------------------- badges -- */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px; font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
}
.badge--mockup  { background: var(--primary-100); color: var(--primary-700); }
.badge--excel   { background: var(--primary-300); color: var(--primary-900); }
.badge--api     { background: var(--primary-500); color: #fff; }
.badge--success { background: var(--success-bg); color: var(--success); }
.badge--warning { background: var(--warning-bg); color: var(--warning); }
.badge--danger  { background: var(--danger-bg);  color: var(--danger); }
.badge--processing { background: var(--primary-50); color: var(--primary-300); }
.badge--neutral { background: #F1EEEB; color: var(--text-secondary); }
.badge--soft    { background: var(--primary-50); color: var(--primary-700); font-weight: 600; }

.dot-status { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-status--on  { background: var(--success); }
.dot-status--off { background: var(--text-muted); }

/* -------------------------------------------------------------- botones -- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600;
    transition: background .13s ease, border-color .13s ease, color .13s ease;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 15px; height: 15px; }

.btn--primary { background: var(--primary-500); border-color: var(--primary-500); color: #fff; }
.btn--primary:hover { background: var(--primary-700); border-color: var(--primary-700); color: #fff; }

.btn--secondary { background: var(--primary-100); border-color: var(--primary-100); color: var(--primary-900); }
.btn--secondary:hover { background: var(--primary-300); border-color: var(--primary-300); color: var(--primary-900); }

.btn--ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text-secondary); }
.btn--ghost:hover { background: var(--surface-subtle); color: var(--primary-700); border-color: var(--primary-300); }

.btn--danger { background: var(--surface); border-color: var(--border-strong); color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); border-color: var(--danger); }

.btn--sm { padding: 6px 11px; font-size: 12px; }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }

/* -------------------------------------------------------------- filtros -- */

.filters { margin-bottom: 18px; }
.filters__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
    gap: 13px;
}
.filters__actions {
    display: flex; gap: 9px; align-items: center;
    margin-top: 15px; padding-top: 14px;
    border-top: 1px solid var(--border);
}
.filters__actions .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label {
    font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
    color: var(--text-secondary); font-weight: 700;
}

.input, .select {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface);
    min-width: 0;
}
.select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2375665F' stroke-width='1.6'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 15px;
    padding-right: 30px;
}
.input:focus, .select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 .2rem rgba(181, 101, 29, .12);
}
.input::placeholder { color: var(--text-muted); }

.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.checkbox input { accent-color: var(--primary-500); width: 15px; height: 15px; }

/* --------------------------------------------------------------- tablas -- */

.table-wrap { overflow-x: auto; border-radius: 0 0 var(--radius) var(--radius); }

table.data { border-collapse: collapse; width: 100%; font-size: 12.8px; }

table.data thead th {
    background: var(--surface-subtle);
    color: var(--primary-900);
    text-align: left;
    padding: 10px 12px;
    font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky; top: 0; z-index: 2;
}
table.data thead th.right { text-align: right; }
table.data thead th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
table.data thead th a:hover { color: var(--primary-500); text-decoration: none; }
table.data thead th .sort-arrow { color: var(--primary-500); font-size: 9px; }

table.data tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data tbody td.right { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data tbody tr:last-child td { border-bottom: none; }

table.data tfoot td {
    padding: 11px 12px;
    background: var(--surface-subtle);
    font-weight: 700;
    border-top: 2px solid var(--border);
    font-variant-numeric: tabular-nums;
}
table.data tfoot td.right { text-align: right; }

.cell-strong { font-weight: 600; color: var(--primary-900); }
.cell-truncate { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.cell-ref {
    display: inline-block;
    background: var(--primary-50);
    color: var(--primary-700);
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 11px; font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.table-toolbar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
}
.table-toolbar__count { font-size: 12.5px; color: var(--text-secondary); }
.table-toolbar__count b { color: var(--primary-900); }

/* ------------------------------------------------------------- vacíos --- */

.empty { padding: 52px 24px; text-align: center; }
.empty__icon {
    width: 44px; height: 44px; margin: 0 auto 12px;
    border-radius: 12px; background: var(--primary-50);
    color: var(--primary-300);
    display: grid; place-items: center;
}
.empty__icon svg { width: 22px; height: 22px; }
.empty h4 { font-size: 15px; color: var(--primary-900); margin-bottom: 5px; }
.empty p { color: var(--text-secondary); font-size: 13px; margin: 0 auto; max-width: 460px; }
.empty .btn { margin-top: 16px; }

/* --------------------------------------------------------- paginación --- */

.pagination {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}
.pagination__info { font-size: 12.5px; color: var(--text-secondary); }
.pagination__links { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.pagination__links a, .pagination__links span {
    min-width: 32px; height: 32px;
    padding: 0 9px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12.5px; font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface);
}
.pagination__links a:hover { border-color: var(--primary-300); color: var(--primary-700); text-decoration: none; background: var(--surface-hover); }
.pagination__links .is-current { background: var(--primary-500); border-color: var(--primary-500); color: #fff; }
.pagination__links .is-disabled { opacity: .42; }

/* ------------------------------------------------------------- gráficos -- */

.chart { width: 100%; display: block; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.chart-legend__item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.chart-legend__swatch { width: 10px; height: 10px; border-radius: 3px; }

.chart-tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--primary-900);
    color: #fff;
    padding: 8px 11px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 1.45;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity .12s ease;
    z-index: 200;
    max-width: 280px;
}
.chart-tooltip__title { font-weight: 700; margin-bottom: 2px; }
.chart-tooltip__row { color: var(--primary-200); font-variant-numeric: tabular-nums; }

.rank { display: grid; gap: 2px; }
.rank__row {
    display: flex; align-items: center; gap: 11px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    min-width: 0;
}
.rank__row:last-child { border-bottom: none; }
.rank__pos { width: 20px; font-size: 11.5px; font-weight: 800; color: var(--text-muted); flex: none; }
.rank__name {
    flex: 1 1 auto; min-width: 0;
    font-size: 13px; font-weight: 500;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/*
 * Orden de prioridad cuando falta espacio: primero se recorta el nombre,
 * después se encoge la barra, y el importe NUNCA se corta ni se parte.
 */
/* El factor de encogimiento alto hace que la barra ceda espacio mucho antes
   que el nombre: es el elemento decorativo, no el informativo. */
.rank__bar {
    flex: 0 6 128px; min-width: 26px;
    height: 7px; background: var(--primary-50);
    border-radius: 6px; overflow: hidden;
}
.rank__bar i { display: block; height: 100%; border-radius: 6px; background: var(--primary-500); }
.rank__value {
    flex: none;
    text-align: right; white-space: nowrap;
    font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- alerts -- */

.alert {
    display: flex; gap: 11px; align-items: flex-start;
    padding: 13px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.alert--info    { background: var(--primary-50); border-color: var(--primary-200); color: var(--primary-700); }
.alert--success { background: var(--success-bg); border-color: #C6E2D3; color: var(--success); }
.alert--warning { background: var(--warning-bg); border-color: var(--primary-200); color: var(--warning); }
.alert--danger  { background: var(--danger-bg);  border-color: #EBC7C2; color: var(--danger); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* ------------------------------------------------------------- def list -- */

.deflist { display: grid; gap: 0; }
.deflist__row {
    display: flex; gap: 16px; align-items: baseline;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.deflist__row:last-child { border-bottom: none; }
.deflist__term { width: 200px; flex: none; font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.deflist__value { flex: 1; min-width: 0; font-size: 13.5px; color: var(--text-primary); }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checklist li {
    display: flex; gap: 10px; align-items: flex-start;
    font-size: 13px; color: var(--text-secondary);
}
.checklist li::before {
    content: ""; width: 14px; height: 14px; flex: none; margin-top: 3px;
    border: 1.6px solid var(--primary-300); border-radius: 4px;
}

/* --------------------------------------------------------------- login -- */

.login {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 28px;
    background:
        radial-gradient(1100px 460px at 12% -8%, rgba(244, 225, 193, .5), transparent 60%),
        radial-gradient(760px 380px at 108% 108%, rgba(217, 160, 91, .22), transparent 62%),
        var(--background);
}
.login__card {
    width: 100%; max-width: 408px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.login__accent { height: 4px; background: linear-gradient(90deg, var(--primary-900), var(--primary-500), var(--primary-300)); }
.login__body { padding: 34px 34px 30px; }
.login__brand { display: flex; align-items: center; gap: 11px; margin-bottom: 26px; }
.login__brand .sidebar__logo { width: 38px; height: 38px; font-size: 15px; }
.login__brand-name { font-size: 16px; font-weight: 700; color: var(--primary-900); line-height: 1.2; }
.login__brand-sub { font-size: 10px; letter-spacing: .15em; text-transform: uppercase; color: var(--primary-500); font-weight: 700; margin-top: 2px; }
.login h1 { font-size: 22px; color: var(--primary-900); }
.login__lead { color: var(--text-secondary); font-size: 13.5px; margin: 6px 0 24px; }
.login .field { margin-bottom: 15px; }
.login .btn { width: 100%; padding: 11px; margin-top: 8px; }
.login__foot {
    margin-top: 22px; padding-top: 18px;
    border-top: 1px solid var(--border);
    font-size: 11.5px; color: var(--text-muted);
    display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.field__error { font-size: 12px; color: var(--danger); }

/* ------------------------------------------------------------ responsive - */

.sidebar__toggle { display: none; }
.sidebar__backdrop { display: none; }

/* Las columnas de las grillas las gobiernan las consultas de contenedor de
   más arriba; aquí sólo queda el comportamiento que sí depende de la ventana. */

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .sidebar__backdrop {
        display: block;
        position: fixed; inset: 0;
        background: rgba(53, 35, 29, .45);
        z-index: 50;
    }
    .main { margin-left: 0; }
    .sidebar__toggle {
        display: inline-grid; place-items: center;
        width: 36px; height: 36px;
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-sm);
        background: var(--surface);
        color: var(--primary-900);
    }
    .sidebar__toggle svg { width: 18px; height: 18px; }
}

@media (max-width: 720px) {
    .content { padding: 18px 15px 40px; }
    .topbar { padding: 0 15px; }
    .page-head h1 { font-size: 24px; }
    .deflist__row { flex-direction: column; gap: 3px; }
    .deflist__term { width: auto; }
    .rank__bar { display: none; }
    .breadcrumbs { display: none; }
}

@media print {
    .sidebar, .topbar, .filters, .pagination { display: none; }
    .main { margin-left: 0; }
}
