/* =====================================================================
   Anvexo Facturación — sistema de diseño
   Sin dependencias externas. Claro y oscuro.
   ===================================================================== */

/* ---------------------------------------------------------- tokens */
:root {
    --brand-50:  #eef4ff;
    --brand-100: #dbe6fe;
    --brand-200: #bfd3fe;
    --brand-300: #93b4fd;
    --brand-400: #608cfa;
    --brand-500: #3b66f6;
    --brand-600: #2549eb;
    --brand-700: #1d37d8;
    --brand-800: #1e30af;
    --brand-900: #1e2e8a;

    --ink-50:  #f8fafc;
    --ink-100: #f1f5f9;
    --ink-200: #e2e8f0;
    --ink-300: #cbd5e1;
    --ink-400: #94a3b8;
    --ink-500: #64748b;
    --ink-600: #475569;
    --ink-700: #334155;
    --ink-800: #1e293b;
    --ink-900: #0f172a;
    --ink-950: #020617;

    --ok-50:   #ecfdf5;
    --ok-500:  #10b981;
    --ok-600:  #059669;
    --ok-700:  #047857;

    --warn-50:  #fffbeb;
    --warn-500: #f59e0b;
    --warn-600: #d97706;
    --warn-700: #b45309;

    --bad-50:  #fef2f2;
    --bad-500: #ef4444;
    --bad-600: #dc2626;
    --bad-700: #b91c1c;

    --info-50: #eff6ff;
    --info-500:#3b82f6;
    --info-600:#2563eb;

    /* superficies */
    --bg:          var(--ink-100);
    --surface:     #ffffff;
    --surface-2:   var(--ink-50);
    --surface-3:   var(--ink-100);
    --border:      var(--ink-200);
    --border-soft: var(--ink-100);
    --text:        var(--ink-800);
    --text-soft:   var(--ink-500);
    --text-faint:  var(--ink-400);
    --accent:      var(--brand-600);
    --accent-soft: var(--brand-50);
    --accent-text: #ffffff;

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow:    0 4px 12px rgba(15, 23, 42, .08), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12), 0 4px 8px rgba(15, 23, 42, .04);

    --header-h: 56px;
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:          var(--ink-950);
        --surface:     #0d1526;
        --surface-2:   #111c30;
        --surface-3:   #16233b;
        --border:      #1e304d;
        --border-soft: #172439;
        --text:        var(--ink-100);
        --text-soft:   var(--ink-400);
        --text-faint:  var(--ink-500);
        --accent:      var(--brand-400);
        --accent-soft: #16234a;
        --accent-text: #04102b;
        --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
        --shadow:    0 4px 12px rgba(0, 0, 0, .45);
        --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    }
}

:root[data-theme="dark"] {
    --bg:          var(--ink-950);
    --surface:     #0d1526;
    --surface-2:   #111c30;
    --surface-3:   #16233b;
    --border:      #1e304d;
    --border-soft: #172439;
    --text:        var(--ink-100);
    --text-soft:   var(--ink-400);
    --text-faint:  var(--ink-500);
    --accent:      var(--brand-400);
    --accent-soft: #16234a;
    --accent-text: #04102b;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
    --shadow:    0 4px 12px rgba(0, 0, 0, .45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -.011em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: .95rem; }
p  { margin: 0 0 .75rem; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; vertical-align: middle; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

::selection { background: var(--accent-soft); color: var(--text); }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .85em; }

/* -------------------------------------------------------- cabecera */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: .25rem;
    padding: 0 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -.02em;
    color: var(--text);
    margin-right: 1rem;
    white-space: nowrap;
}
.topbar__brand:hover { text-decoration: none; }
.topbar__brand .mark {
    width: 26px; height: 26px;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    display: grid;
    place-items: center;
    font-size: .75rem;
    font-weight: 800;
    flex: none;
}

.topnav { display: flex; align-items: center; gap: .125rem; flex: 1; min-width: 0; }

.topnav a {
    position: relative;
    padding: .45rem .7rem;
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    font-weight: 500;
    white-space: nowrap;
}
.topnav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.topnav a.is-active { color: var(--text); font-weight: 600; }
.topnav a.is-active::after {
    content: "";
    position: absolute;
    left: .7rem; right: .7rem; bottom: -13px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
}

.topbar__right { display: flex; align-items: center; gap: .375rem; margin-left: auto; }

/* --------------------------------------------------------- layout */
.page {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}
.page--narrow { max-width: 880px; }
.page--wide   { max-width: 100%; }

.page-head {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.page-head__text { min-width: 0; flex: 1; }
.page-head__sub { color: var(--text-soft); margin: .2rem 0 0; font-size: .875rem; }
.page-head__actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.stack   { display: grid; gap: 1rem; }
.stack-sm{ display: grid; gap: .5rem; }
.row     { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.row-tight { display: flex; align-items: center; gap: .25rem; }
.spacer  { flex: 1; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px)  { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 680px)  {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* Contenido principal + columna lateral, que se apila en pantallas pequeñas */
.grid-sidebar { grid-template-columns: minmax(0, 1fr) 330px; }
.grid-split   { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1000px) {
    .grid-sidebar, .grid-split { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------- tarjeta */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}
.card__head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .875rem 1.125rem;
    border-bottom: 1px solid var(--border-soft);
}
.card__title { font-size: .9375rem; font-weight: 650; }
.card__body { padding: 1.125rem; }
.card__body--tight { padding: .75rem; }
.card__foot {
    padding: .75rem 1.125rem;
    border-top: 1px solid var(--border-soft);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* --------------------------------------------------------- botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .5rem .875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    font-size: .875rem;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease, border-color .12s ease, box-shadow .12s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    box-shadow: var(--shadow-xs);
}
.btn--primary:hover { filter: brightness(1.07); background: var(--accent); }

.btn--danger { color: var(--bad-600); border-color: var(--border); }
.btn--danger:hover { background: var(--bad-50); border-color: var(--bad-500); }
:root[data-theme="dark"] .btn--danger:hover { background: rgba(239, 68, 68, .14); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .btn--danger:hover { background: rgba(239, 68, 68, .14); }
}

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-3); }

.btn--sm { padding: .3rem .6rem; font-size: .8125rem; border-radius: var(--radius-sm); }
.btn--lg { padding: .65rem 1.15rem; font-size: .9375rem; }
.btn--block { width: 100%; }
.btn--icon { padding: .45rem; width: 34px; height: 34px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }

/* ------------------------------------------------------ formularios */
.field { display: grid; gap: .3rem; margin-bottom: .875rem; }
.field__label {
    font-size: .8125rem;
    font-weight: 550;
    color: var(--text-soft);
}
.field__hint { font-size: .75rem; color: var(--text-faint); }
.field__error { font-size: .75rem; color: var(--bad-600); font-weight: 500; }

.input, .select, .textarea {
    width: 100%;
    padding: .5rem .625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .875rem;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-300); }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:disabled, .select:disabled, .textarea:disabled {
    background: var(--surface-3);
    color: var(--text-soft);
    cursor: not-allowed;
}
.input.is-invalid { border-color: var(--bad-500); }
.textarea { min-height: 84px; resize: vertical; }

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .625rem center;
    padding-right: 2rem;
}

.input--money { text-align: right; font-variant-numeric: tabular-nums; }

.check { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .875rem; }
.check input[type="checkbox"], .check input[type="radio"] {
    width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0;
}

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
@media (max-width: 780px) {
    .form-grid, .form-grid--2 { grid-template-columns: minmax(0, 1fr); }
    .form-grid .span-2, .form-grid .span-3 { grid-column: span 1; }
}

.fieldset { border: 0; margin: 0 0 1.5rem; padding: 0; }
.fieldset__legend {
    font-size: .8125rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-faint);
    margin-bottom: .75rem;
    padding-bottom: .4rem;
    border-bottom: 1px solid var(--border-soft);
    width: 100%;
}

/* ----------------------------------------------------------- tablas */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    -webkit-overflow-scrolling: touch;
}

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.table th {
    text-align: left;
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-faint);
    padding: .625rem .75rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--surface);
}
.table td {
    padding: .7rem .75rem;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-clickable { cursor: pointer; }
.table .t-right  { text-align: right; }
.table .t-center { text-align: center; }
.table .t-num    { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .t-nowrap { white-space: nowrap; }
.table tfoot td {
    font-weight: 650;
    border-top: 2px solid var(--border);
    background: var(--surface-2);
}
.table--compact td { padding: .45rem .625rem; }

.table__primary { font-weight: 550; color: var(--text); }
.table__meta { color: var(--text-soft); font-size: .8125rem; }

/* -------------------------------------------------------- etiquetas */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    border: 1px solid transparent;
}
.badge--ok    { background: var(--ok-50);   color: var(--ok-700);   border-color: rgba(16,185,129,.25); }
.badge--warn  { background: var(--warn-50); color: var(--warn-700); border-color: rgba(245,158,11,.25); }
.badge--bad   { background: var(--bad-50);  color: var(--bad-700);  border-color: rgba(239,68,68,.25); }
.badge--info  { background: var(--info-50); color: var(--info-600); border-color: rgba(59,130,246,.25); }
.badge--muted { background: var(--surface-3); color: var(--text-soft); border-color: var(--border); }
.badge--brand { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

:root[data-theme="dark"] .badge--ok    { background: rgba(16,185,129,.14);  color: #34d399; }
:root[data-theme="dark"] .badge--warn  { background: rgba(245,158,11,.14);  color: #fbbf24; }
:root[data-theme="dark"] .badge--bad   { background: rgba(239,68,68,.14);   color: #f87171; }
:root[data-theme="dark"] .badge--info  { background: rgba(59,130,246,.14);  color: #60a5fa; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .badge--ok    { background: rgba(16,185,129,.14);  color: #34d399; }
    :root:not([data-theme="light"]) .badge--warn  { background: rgba(245,158,11,.14);  color: #fbbf24; }
    :root:not([data-theme="light"]) .badge--bad   { background: rgba(239,68,68,.14);   color: #f87171; }
    :root:not([data-theme="light"]) .badge--info  { background: rgba(59,130,246,.14);  color: #60a5fa; }
}

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: currentColor; }

/* ----------------------------------------------------------- avisos */
.alert {
    display: flex;
    gap: .625rem;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: .875rem;
    margin-bottom: 1rem;
}
.alert__icon { flex: none; margin-top: .1rem; }
.alert__body { min-width: 0; flex: 1; }
.alert__title { font-weight: 650; margin-bottom: .15rem; }
.alert--ok   { background: var(--ok-50);   border-color: rgba(16,185,129,.3);  color: var(--ok-700); }
.alert--bad  { background: var(--bad-50);  border-color: rgba(239,68,68,.3);   color: var(--bad-700); }
.alert--warn { background: var(--warn-50); border-color: rgba(245,158,11,.3);  color: var(--warn-700); }
.alert--info { background: var(--info-50); border-color: rgba(59,130,246,.3);  color: var(--info-600); }

/* --------------------------------------------------------- métricas */
.metric { display: grid; gap: .3rem; }
.metric__label {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-faint);
}
.metric__value {
    font-size: 1.625rem;
    font-weight: 680;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}
.metric__sub { font-size: .8125rem; color: var(--text-soft); }
.metric__delta { font-size: .8125rem; font-weight: 600; }
.metric__delta--up   { color: var(--ok-600); }
.metric__delta--down { color: var(--bad-600); }

/* barra de progreso / comparativa */
.bar {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}
.bar__fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s ease; }
.bar__fill--ok   { background: var(--ok-500); }
.bar__fill--warn { background: var(--warn-500); }
.bar__fill--bad  { background: var(--bad-500); }

/* mini gráfico de columnas */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 56px; }
.spark__col {
    flex: 1;
    min-width: 4px;
    border-radius: 3px 3px 1px 1px;
    background: var(--surface-3);
    position: relative;
}
.spark__col > span {
    position: absolute;
    inset: auto 0 0 0;
    border-radius: 3px 3px 1px 1px;
    background: var(--accent);
    display: block;
}
.spark__col--ok  > span { background: var(--ok-500); }
.spark__col--bad > span { background: var(--bad-500); }

/* --------------------------------------------------------- vacíos */
.empty {
    text-align: center;
    padding: 3.5rem 1.5rem;
    color: var(--text-soft);
}
.empty__icon {
    width: 48px; height: 48px;
    margin: 0 auto .875rem;
    border-radius: var(--radius-lg);
    display: grid; place-items: center;
    background: var(--surface-3);
    color: var(--text-faint);
}
.empty__title { font-weight: 650; color: var(--text); margin-bottom: .25rem; }

/* ------------------------------------------------------- desplegable */
.dropdown { position: relative; display: inline-block; }
.dropdown__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: .3rem;
    z-index: 60;
    display: none;
}
.dropdown.is-open .dropdown__menu { display: block; }
.dropdown__item {
    display: flex;
    align-items: center;
    gap: .55rem;
    width: 100%;
    padding: .45rem .6rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    font-size: .875rem;
    text-align: left;
    cursor: pointer;
}
.dropdown__item:hover { background: var(--surface-3); text-decoration: none; }
.dropdown__item--danger { color: var(--bad-600); }
.dropdown__sep { height: 1px; background: var(--border-soft); margin: .3rem 0; }
.dropdown__label {
    padding: .4rem .6rem .25rem;
    font-size: .7rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-faint);
}

/* ------------------------------------------------------------ modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-backdrop.is-open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow: auto;
    border: 1px solid var(--border);
}
.modal--wide { max-width: 900px; }
.modal__head {
    display: flex; align-items: center; gap: .75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-soft);
}
.modal__body { padding: 1.25rem; }
.modal__foot {
    display: flex; justify-content: flex-end; gap: .5rem;
    padding: .875rem 1.25rem;
    border-top: 1px solid var(--border-soft);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    position: sticky;
    bottom: 0;
}

/* ------------------------------------------------------------ toast */
.toasts {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 200;
    display: grid;
    gap: .5rem;
    max-width: min(420px, calc(100vw - 2rem));
}
.toast {
    display: flex;
    gap: .625rem;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: .875rem;
    animation: toast-in .22s cubic-bezier(.2, .8, .3, 1);
}
.toast--ok   { border-left: 3px solid var(--ok-500); }
.toast--bad  { border-left: 3px solid var(--bad-500); }
.toast--warn { border-left: 3px solid var(--warn-500); }
.toast--info { border-left: 3px solid var(--info-500); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

/* ------------------------------------------------------ buscador/filtros */
.toolbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    padding: .75rem 1.125rem;
    border-bottom: 1px solid var(--border-soft);
}
.search {
    position: relative;
    flex: 1;
    min-width: 180px;
    max-width: 380px;
}
.search .input { padding-left: 2.1rem; }
.search__icon {
    position: absolute;
    left: .65rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .3rem .6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: .8125rem;
    cursor: pointer;
}
.chip:hover { background: var(--surface-3); text-decoration: none; }
.chip.is-active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/* ------------------------------------------------------- paginación */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1.125rem;
    border-top: 1px solid var(--border-soft);
    font-size: .8125rem;
    color: var(--text-soft);
    flex-wrap: wrap;
}
.pagination__links { display: flex; gap: .25rem; }
.pagination__links a, .pagination__links span {
    min-width: 32px;
    height: 32px;
    padding: 0 .5rem;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
}
.pagination__links a:hover { background: var(--surface-3); text-decoration: none; }
.pagination__links .is-current {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}
.pagination__links .is-disabled { opacity: .4; pointer-events: none; }

/* ------------------------------------------------------ autocompletar */
.combo { position: relative; }
.combo__list {
    position: absolute;
    left: 0; right: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    z-index: 70;
    display: none;
    padding: .25rem;
}
.combo.is-open .combo__list { display: block; }
.combo__opt {
    padding: .45rem .6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: .875rem;
}
.combo__opt:hover, .combo__opt.is-active { background: var(--accent-soft); }
.combo__opt small { display: block; color: var(--text-soft); font-size: .78rem; }
.combo__empty { padding: .6rem; color: var(--text-soft); font-size: .8125rem; text-align: center; }

/* ------------------------------------------------- editor de líneas */
.lines { width: 100%; border-collapse: collapse; }
.lines th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-faint);
    font-weight: 600;
    text-align: left;
    padding: .4rem .4rem;
    border-bottom: 1px solid var(--border);
}
.lines td { padding: .2rem .25rem; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.lines .input, .lines .select, .lines .textarea {
    border-color: transparent;
    background: transparent;
    padding: .4rem .45rem;
}
.lines tr:hover .input, .lines tr:hover .select { border-color: var(--border); background: var(--surface); }
.lines .input:focus, .lines .select:focus { background: var(--surface); }
.lines__handle { color: var(--text-faint); cursor: grab; padding-top: .55rem; }
.lines__total { text-align: right; font-variant-numeric: tabular-nums; padding-top: .65rem; font-weight: 550; }

.totals { display: grid; gap: .35rem; margin-left: auto; max-width: 340px; }
.totals__row { display: flex; justify-content: space-between; gap: 2rem; font-size: .875rem; }
.totals__row--grand {
    border-top: 2px solid var(--border);
    margin-top: .35rem;
    padding-top: .55rem;
    font-size: 1.125rem;
    font-weight: 700;
}
.totals__label { color: var(--text-soft); }
.totals__value { font-variant-numeric: tabular-nums; font-weight: 550; }

/* ------------------------------------------------------ ajustes/nav */
.settings { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .settings { grid-template-columns: minmax(0, 1fr); } }

.sidenav { display: grid; gap: .125rem; }
.sidenav a {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    gap: .625rem;
    align-items: center;
    padding: .55rem .7rem;
    border-radius: var(--radius);
    color: var(--text);
}
.sidenav a:hover { background: var(--surface-3); text-decoration: none; }
.sidenav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidenav small { display: block; color: var(--text-soft); font-weight: 400; font-size: .75rem; line-height: 1.3; }
.sidenav a.is-active small { color: var(--accent); opacity: .8; }
.sidenav svg { color: var(--text-faint); }
.sidenav a.is-active svg { color: var(--accent); }

/* --------------------------------------------------------- pestañas */
.tabs {
    display: flex;
    gap: .25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
    overflow-x: auto;
}
.tabs a {
    padding: .55rem .875rem;
    color: var(--text-soft);
    font-weight: 550;
    font-size: .875rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* ------------------------------------------------- pantalla de acceso */
.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) { .auth { grid-template-columns: minmax(0, 1fr); } }

.auth__form {
    display: grid;
    place-items: center;
    padding: 2rem 1.5rem;
    background: var(--surface);
}
.auth__inner { width: 100%; max-width: 380px; }
.auth__aside {
    background: linear-gradient(150deg, var(--brand-700), var(--brand-900) 70%, #101a4d);
    color: #fff;
    padding: 3rem;
    display: grid;
    align-content: center;
    gap: 1rem;
}
@media (max-width: 900px) { .auth__aside { display: none; } }
.auth__aside h2 { font-size: 1.75rem; letter-spacing: -.02em; }
.auth__aside p { color: rgba(255, 255, 255, .82); font-size: 1rem; max-width: 42ch; }
.auth__points { display: grid; gap: .625rem; margin-top: .5rem; }
.auth__point { display: flex; gap: .625rem; align-items: flex-start; color: rgba(255,255,255,.9); font-size: .9375rem; }

/* ------------------------------------------- icono de tema claro/oscuro */
.theme-icon-dark  { display: none; }
:root[data-theme="dark"] .theme-icon-dark  { display: inline; }
:root[data-theme="dark"] .theme-icon-light { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-icon-dark  { display: inline; }
    :root:not([data-theme="light"]) .theme-icon-light { display: none; }
}
:root[data-theme="light"] .theme-icon-light { display: inline; }
:root[data-theme="light"] .theme-icon-dark  { display: none; }

/* -------------------------------------------------- utilidades */
@media (max-width: 640px) { .hide-sm { display: none; } }
.muted { color: var(--text-soft); }
.faint { color: var(--text-faint); }
.small { font-size: .8125rem; }
.tiny  { font-size: .75rem; }
.bold  { font-weight: 650; }
.right { text-align: right; }
.center{ text-align: center; }
.nowrap{ white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok  { color: var(--ok-600); }
.bad { color: var(--bad-600); }
.warn{ color: var(--warn-600); }
.hidden { display: none !important; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }

/* --------------------------------------------------------- impresión */
@media print {
    .topbar, .page-head__actions, .toolbar, .pagination, .toasts { display: none !important; }
    body { background: #fff; }
    .card { border: 0; box-shadow: none; }
    .page { padding: 0; max-width: 100%; }
}
