/* ============================================================
   components.css — Tarjetas, KPIs, formularios, tablas,
   modales, toasts, gráficos SVG y estados de interfaz
   ============================================================ */

/* ---------- Tarjeta ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-head {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.card-head h2,
.card-head h3 { font-size: 1rem; font-weight: 700; }
.card-head p { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

.card-body { padding: var(--sp-5); }
.card-body.flush { padding: 0; }

.card-foot {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

/* ---------- KPI ---------- */

.kpi {
    position: relative;
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow: hidden;
}

/* Punto de color en lugar del antiguo filo lateral */
.kpi::before {
    content: "";
    position: absolute;
    top: 20px;
    left: var(--sp-5);
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--kpi-accent, var(--primary));
}

.kpi-label {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-left: 16px;
}

.kpi-value {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.04em;
    font-variant-numeric: tabular-nums;
    word-break: break-word;
    line-height: 1.15;
}

.kpi-context { font-size: 0.75rem; color: var(--text-soft); font-weight: 500; }

/* La primera tarjeta de cada fila de KPIs manda la jerarquía: tarjeta verde de marca */
.grid-kpi > .kpi:first-child {
    background: linear-gradient(150deg, var(--night-2) 0%, var(--night) 100%);
    border-color: transparent;
    color: #ffffff;
}

.grid-kpi > .kpi:first-child::before { background: #f8e0a8; }
.grid-kpi > .kpi:first-child .kpi-label { color: rgba(255, 255, 255, 0.82); }
.grid-kpi > .kpi:first-child .kpi-context { color: rgba(255, 255, 255, 0.78); }

/* ---------- Botones ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 11px 22px;
    border: 0;
    border-radius: var(--r-md);
    background: var(--primary);
    color: var(--on-primary);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: var(--shadow-primary);
    transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.btn:hover { background: var(--primary-hover); transform: translateY(-1px); }

/* En tema oscuro el verde se aclara para separarse del fondo y el texto
   de los botones pasa a verde muy oscuro para conservar el contraste. */
[data-theme="dark"] .btn { color: var(--on-primary); }
[data-theme="dark"] .btn-secondary { color: var(--primary); }
[data-theme="dark"] .btn-ghost { color: var(--text-muted); }
[data-theme="dark"] .btn-danger { color: #ffffff; }
[data-theme="dark"] .segmented button[aria-pressed="true"],
[data-theme="dark"] .tabs button[aria-selected="true"] { color: var(--on-primary); }
.btn:active { transform: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none; }

/* Secundario Terra: fondo crema, texto verde y borde fino */
.btn-secondary {
    background: var(--surface);
    color: var(--primary-hover);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}
.btn-secondary:hover { background: var(--primary-soft); color: var(--primary-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); transform: none; }

.btn-danger { background: var(--danger-solid); box-shadow: 0 4px 14px rgba(192, 86, 70, 0.24); }
.btn-danger:hover { background: var(--danger-solid); filter: brightness(0.94); }

/* Acciones cortas de fila (Abonar, Liquidar, Pagar): verde suave.
   El verde sólido queda para las acciones que crean un documento. */
.btn.btn-sm:not(.btn-secondary):not(.btn-ghost):not(.btn-danger) {
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: none;
}
.btn.btn-sm:not(.btn-secondary):not(.btn-ghost):not(.btn-danger):hover {
    background: var(--accent-hover);
    color: var(--accent-ink);
}

.btn-sm { padding: 7px 14px; font-size: 0.78rem; }
.btn-icon { padding: 7px; width: 36px; height: 36px; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }

/* ---------- Formularios ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field > label {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--text-muted);
}

.field .hint { font-size: 0.72rem; color: var(--text-soft); font-weight: 500; }
.field .error-text { font-size: 0.72rem; color: var(--danger); font-weight: 700; }

.input,
.select,
.textarea {
    width: 100%;
    padding: 11px 15px;
    border: 1.5px solid transparent;
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.87rem;
    font-weight: 500;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: var(--primary);
    background: var(--surface);
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.input[aria-invalid="true"] { border-color: var(--danger); }

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

.textarea { min-height: 82px; resize: vertical; }

fieldset {
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-4);
    margin: 0;
}

legend { padding: 0 var(--sp-2); font-size: 0.76rem; font-weight: 800; color: var(--text-muted); }

.check {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
}
.check input { width: 17px; height: 17px; accent-color: var(--primary); }

/* Matriz de permisos por rol: una columna de casillas por rol */
.permisos-rol .col-rol { text-align: center; width: 128px; }
.permisos-rol input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; vertical-align: middle; }
.permisos-rol input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.55; }

/* En móvil la columna del administrador (siempre todo, no editable) sobra:
   se oculta para que las casillas de Contador y Vendedor quepan sin desplazar. */
@media (max-width: 560px) {
    table.data.permisos-rol th,
    table.data.permisos-rol td { padding-left: 8px; padding-right: 8px; }
    table.data.permisos-rol td:first-child { white-space: normal; min-width: 118px; }
    .permisos-rol .col-rol { width: auto; }
    .permisos-rol .col-admin { display: none; }
}

/* Grupo de opciones tipo segmento */
.segmented {
    display: inline-flex;
    padding: 4px;
    gap: 3px;
    background: var(--surface-2);
    border-radius: var(--r-pill);
    flex-wrap: wrap;
}

.segmented button {
    padding: 7px 16px;
    border: 0;
    border-radius: var(--r-pill);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
}

.segmented button[aria-pressed="true"] {
    background: var(--primary);
    color: #ffffff;
}

/* ---------- Barra de filtros ---------- */

.filters {
    display: flex;
    align-items: flex-end;
    gap: var(--sp-3);
    flex-wrap: wrap;
    padding: var(--sp-4);
    background: var(--surface);
    border: 0;
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-sm);
}

.filters .field { flex: 1 1 160px; }

.filter-status {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 13px;
    border-radius: var(--r-pill);
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
}

/* ---------- Tablas ---------- */

.table-wrap { width: 100%; overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

table.data caption {
    text-align: left;
    padding: var(--sp-3) var(--sp-5);
    font-size: 0.78rem;
    color: var(--text-muted);
}

table.data th,
table.data td {
    padding: 12px var(--sp-4);
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-2);
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    border-bottom: 0;
}

table.data thead th.sortable { cursor: pointer; user-select: none; }
table.data thead th.sortable:hover { color: var(--primary); }
table.data thead th .sort-mark { margin-left: 4px; font-size: 0.7rem; }

table.data tbody tr { transition: background 0.12s ease; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody td { font-weight: 500; }

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

table.data tfoot td {
    background: var(--surface-2);
    font-weight: 800;
    border-top: 2px solid var(--border-strong);
    border-bottom: 0;
}

table.data td.wrap { white-space: normal; min-width: 190px; font-weight: 600; }

.table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
    padding: var(--sp-4);
    border-bottom: 1px solid var(--border);
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-4);
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-soft);
    font-weight: 600;
    flex-wrap: wrap;
}

/* ---------- Etiquetas de estado ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: var(--r-pill);
    font-size: 0.72rem;
    font-weight: 800;
    white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-neutral { background: var(--surface-2);    color: var(--text-muted); }

/* ---------- Estados de interfaz ---------- */

.state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-7) var(--sp-5);
    text-align: center;
    color: var(--text-muted);
}

.state .state-icon { font-size: 1.9rem; opacity: 0.6; }
.state .state-title { font-weight: 700; color: var(--text); font-family: var(--font-display); }
.state .state-msg { font-size: 0.83rem; max-width: 42ch; font-weight: 500; }

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.banner {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-4);
    border-radius: var(--r-lg);
    border: 0;
    font-size: 0.83rem;
    font-weight: 500;
}

.banner-warning { background: var(--warning-soft); color: var(--warning); }
.banner-danger  { background: var(--danger-soft);  color: var(--danger); }
.banner-info    { background: var(--info-soft);    color: var(--info); }
.banner-success { background: var(--success-soft); color: var(--success); }
.banner strong { display: block; font-weight: 800; }

/* ---------- Toasts ---------- */

.toast-stack {
    position: fixed;
    z-index: 200;
    right: var(--sp-5);
    bottom: var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    max-width: min(380px, calc(100vw - 32px));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-4);
    border-radius: var(--r-lg);
    border: 0;
    border-left: 5px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.2s ease;
}

.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger-solid); }
.toast-warning { border-left-color: var(--c3); }
.toast-info    { border-left-color: var(--primary); }

.toast .toast-title { font-weight: 800; font-size: 0.85rem; }
.toast .toast-msg { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

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

/* ---------- Modales ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 150;
    display: grid;
    place-items: center;
    padding: var(--sp-4);
    background: rgba(46, 50, 48, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    overflow-y: auto;
}

.modal {
    width: min(680px, 100%);
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 0;
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    animation: modal-in 0.18s ease;
}

.modal.modal-wide { width: min(980px, 100%); }
.modal.modal-sm { width: min(430px, 100%); }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(14px) scale(0.985); }
    to { opacity: 1; transform: none; }
}

.modal-head {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-5) var(--sp-4);
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.modal-head h2 { font-size: 1.12rem; }
.modal-head p { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

.modal-body {
    padding: var(--sp-5);
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    flex: 0 0 auto;
    flex-wrap: wrap;
}

.modal-foot .grow { text-align: left; }

/* ---------- Líneas de totales ---------- */

.totals { display: grid; gap: 7px; margin-left: auto; width: min(320px, 100%); }

.totals-line {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-4);
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.totals-line.total {
    padding-top: 8px;
    border-top: 2px solid var(--border-strong);
    font-size: 1.05rem;
    font-weight: 800;
    font-family: var(--font-display);
}

/* ---------- Gráficos SVG ---------- */

.chart {
    position: relative;
    width: 100%;
}

.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart .axis-line { stroke: var(--border-strong); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 5; }
.chart .axis-text { fill: var(--text-soft); font-size: 10px; font-family: var(--font-sans); font-weight: 600; }
.chart .series-line { fill: none; stroke-width: 3.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-dot { stroke: var(--surface); stroke-width: 3; }
.chart .hover-guide { stroke: var(--text-soft); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .bar { transition: opacity 0.12s ease; }
.chart .bar:hover, .chart .slice:hover { opacity: 0.78; cursor: pointer; }
.chart .bar-label { fill: var(--text-muted); font-size: 10px; font-family: var(--font-sans); font-weight: 700; }

.chart-tooltip {
    position: absolute;
    z-index: 5;
    min-width: 140px;
    padding: 9px 12px;
    border-radius: var(--r-md);
    border: 0;
    background: var(--surface);
    box-shadow: var(--shadow-md);
    font-size: 0.76rem;
    pointer-events: none;
    transform: translate(-50%, -110%);
}

.chart-tooltip .tt-title { font-weight: 800; margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-tooltip .tt-key { display: flex; align-items: center; gap: 5px; color: var(--text-muted); font-weight: 500; }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-3);
    padding-top: var(--sp-3);
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }

/* ---------- Barra de progreso (presupuesto, cupos) ---------- */

.meter {
    position: relative;
    height: 8px;
    min-width: 70px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 0;
    overflow: hidden;
}

.meter > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--meter-color, var(--primary));
}

/* ---------- Pestañas ---------- */

.tabs {
    display: flex;
    gap: var(--sp-1);
    padding: 5px;
    background: var(--surface);
    border-radius: var(--r-pill);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

.tabs button {
    padding: 10px var(--sp-5);
    border: 0;
    border-radius: var(--r-pill);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--primary); color: var(--on-primary); }

/* ---------- Tablero: diez indicadores en dos filas ---------- */

.grid-kpi.grid-kpi-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.grid-kpi-5 .kpi { padding: var(--sp-4) 18px; }
.grid-kpi-5 .kpi::before { left: 18px; }
.grid-kpi-5 .kpi-value { font-size: clamp(1.05rem, 1.42vw, 1.4rem); }

@media (max-width: 1180px) {
    .grid-kpi.grid-kpi-5 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

@media (max-width: 560px) {
    .grid-kpi.grid-kpi-5 { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); }
}

/* ---------- Acciones del encabezado de vista ---------- */

.view-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
}

/* ---------- Carga de facturas PDF ---------- */

.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-6) var(--sp-5);
    border: 2px dashed var(--border-strong);
    border-radius: var(--r-lg);
    background: var(--surface-2);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }

.dropzone-icon {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: var(--primary);
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 800;
}

[data-theme="dark"] .dropzone-icon { color: var(--on-primary); }

.dropzone strong { font-family: var(--font-display); font-size: 1rem; }
.dropzone p { font-size: 0.8rem; color: var(--text-muted); max-width: 46ch; }

.import-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.import-row {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.2fr) auto;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.import-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-meta { font-size: 0.76rem; color: var(--text-muted); font-weight: 500; }
.import-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }

@media (max-width: 680px) {
    .import-row { grid-template-columns: 1fr; }
    .import-actions { justify-content: flex-start; }
}

.leido-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--warning);
}

.leido-hint.is-ok { color: var(--text-soft); font-weight: 500; }

.lectura-pdf {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--sp-2) var(--sp-4);
}

.dato-leido {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-sm);
    background: var(--surface);
}

.dato-leido span { font-size: 0.68rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); }
.dato-leido strong { font-size: 0.86rem; font-variant-numeric: tabular-nums; word-break: break-word; }

.texto-extraido summary {
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
}

.texto-extraido pre {
    max-height: 240px;
    overflow: auto;
    margin: var(--sp-2) 0 0;
    padding: var(--sp-3);
    border-radius: var(--r-md);
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- Listas de definición (estados financieros) ---------- */

.fin-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.fin-line.sub { padding-left: var(--sp-4); font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.fin-line.total { border-bottom: 0; border-top: 2px solid var(--border-strong); font-weight: 800; margin-top: 5px; }
.fin-line.grand { font-size: 1.08rem; font-family: var(--font-display); }

@media (max-width: 560px) {
    .card-body { padding: var(--sp-4); }
    .card-head { padding: var(--sp-3) var(--sp-4); }
    .kpi { padding: var(--sp-3) var(--sp-4); }
    .kpi::before { left: var(--sp-4); top: 17px; }
    .kpi-value { font-size: 1.25rem; }
    .modal-body { padding: var(--sp-4); }
    .modal-foot { padding: var(--sp-3) var(--sp-4); }
    .modal-foot .btn { flex: 1 1 auto; }
    .toast-stack { right: var(--sp-3); left: var(--sp-3); bottom: var(--sp-3); max-width: none; }
    .totals { width: 100%; }
}


/* ---------- Tablero ejecutivo ---------- */

/* Los filtros mandan en el tablero: siguen a la vista al desplazarse. */
.dash-filtros { position: sticky; top: 0; z-index: 20; }

.kpi-hero-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); }
.kpi-mini-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--sp-3); }

.kpi-hero { display: flex; flex-direction: column; gap: 7px; }
.kpi-hero .kpi-value { font-size: 1.85rem; }
.kpi-hero .chart-chispa { margin-top: auto; padding-top: var(--sp-3); }

.kpi-delta {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 5px;
    font-size: 0.78rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.kpi-delta.pos { color: var(--success); }
.kpi-delta.neg { color: var(--danger); }
.kpi-delta.neutro { color: var(--text-soft); }
.kpi-delta .kpi-delta-ref { color: var(--text-soft); font-weight: 500; font-size: 0.72rem; }

.kpi-mini { padding: 14px 18px; }
.kpi-mini::before { top: 17px; left: 18px; width: 6px; height: 6px; }
.kpi-mini .kpi-label { font-size: 0.63rem; padding-left: 13px; }
.kpi-mini .kpi-value { font-size: 1.1rem; }
.kpi-mini .kpi-context { font-size: 0.7rem; }

.chart-chispa svg { display: block; width: 100%; height: 34px; }

.dash-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--sp-4);
    align-items: start;
}

.dash-grid > .span-4 { grid-column: span 4; }
.dash-grid > .span-5 { grid-column: span 5; }
.dash-grid > .span-7 { grid-column: span 7; }
.dash-grid > .span-8 { grid-column: span 8; }
.dash-grid > .span-12 { grid-column: span 12; }

@media (max-width: 1180px) {
    .kpi-hero-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-mini-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .dash-grid > .span-4,
    .dash-grid > .span-5,
    .dash-grid > .span-7,
    .dash-grid > .span-8 { grid-column: span 12; }
}

@media (max-width: 640px) {
    .kpi-hero-grid { grid-template-columns: 1fr; }
    .kpi-mini-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dash-filtros { position: static; }
    .kpi-hero .kpi-value { font-size: 1.6rem; }
}


/* ---------- Íconos de línea (Material Symbols) ---------- */

/* La fuente trae solo los íconos que usa la app (index.html). Sin red, el nombre
   del ícono queda recortado dentro de su caja en lugar de desbordar el menú. */
.icono {
    font-family: "Material Symbols Outlined";
    font-weight: normal;
    font-style: normal;
    font-size: 20px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    overflow: hidden;
    font-feature-settings: "liga";
    -webkit-font-feature-settings: "liga";
    -webkit-font-smoothing: antialiased;
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}

.nav-item .nav-icon.icono { width: 22px; height: 22px; font-size: 21px; }
.nav-item[aria-current="page"] .nav-icon.icono { font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24; }
.icon-btn.icono { font-size: 20px; }

/* Títulos de vista y tarjetas con la serif Terra; cifras de totales en monoespaciada */
.view-head h1 { font-size: 1.85rem; font-weight: 700; color: var(--text); }
.card-head h2 { font-size: 1.05rem; }
.totals-line.total span:last-child { font-family: var(--font-mono); }

/* Objetivos táctiles de al menos 44 px */
.nav-item { min-height: 44px; }
@media (max-width: 860px) {
    .icon-btn { width: 44px; height: 44px; }
}

/* ============================================================
   Árbol de usuarios (Configuración) y organizaciones (plataforma)
   ============================================================ */

.arbol { display: flex; flex-direction: column; gap: var(--sp-4); }

.arbol-rama { display: flex; flex-direction: column; gap: var(--sp-2); }

.arbol-titulo {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.arbol-nodo {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    padding: var(--sp-3) var(--sp-4);
}

/* El jefe de la rama se marca con el verde de la marca. */
.arbol-nodo.es-raiz { border-left: 3px solid var(--primary); }

.arbol-nodo.sin-acceso { opacity: 0.62; }

.arbol-quien { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }

.arbol-avatar {
    flex: 0 0 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-hover);
    font-size: 0.72rem;
    font-weight: 800;
}

.arbol-correo { display: block; font-size: 0.78rem; color: var(--text-soft); }
.arbol-modulos { font-size: 0.75rem; color: var(--text-soft); font-variant-numeric: tabular-nums; }

/* Los subordinados cuelgan del administrador con una guía vertical. */
.arbol-hijos {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin-left: var(--sp-5);
    padding-left: var(--sp-4);
    border-left: 2px solid var(--border);
}

.org-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
    gap: var(--sp-4);
}

.org-card {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    padding: var(--sp-5);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.org-card.suspendida { background: var(--surface-2); border-style: dashed; }

.org-head { display: flex; align-items: flex-start; gap: var(--sp-3); }

.org-datos {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-3);
    padding: var(--sp-3) 0;
    border-block: 1px solid var(--border);
}

.org-dato { display: flex; flex-direction: column; }
.org-dato-valor { font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700; }
.org-dato-label {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.org-admins { display: flex; flex-direction: column; gap: var(--sp-2); }
.org-admins li { font-size: 0.84rem; }

@media (max-width: 560px) {
    .arbol-hijos { margin-left: var(--sp-3); padding-left: var(--sp-3); }
    .org-datos { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   Copiloto: lanzador flotante y cajón de conversación
   ============================================================ */

.copi-lanzador {
    position: fixed;
    right: var(--sp-5);
    bottom: var(--sp-5);
    z-index: 70;
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.copi-lanzador:hover { background: var(--primary-hover); transform: translateY(-2px); }
.copi-lanzador .icono { font-size: 24px; }

.copi-cajon {
    position: fixed;
    right: var(--sp-5);
    bottom: calc(var(--sp-5) + 64px);
    z-index: 71;
    width: min(420px, calc(100vw - var(--sp-5) * 2));
    max-height: min(640px, calc(100vh - 140px));
    display: none;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.copi-cajon.abierto { display: flex; }

.copi-cabecera {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.copi-sub { display: block; font-size: 0.72rem; color: var(--text-soft); }

.copi-historial {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: var(--sp-4);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

.copi-msg {
    max-width: 92%;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    font-size: 0.86rem;
    line-height: 1.55;
}

.copi-msg p { margin: 0 0 var(--sp-2); }
.copi-msg p:last-child { margin-bottom: 0; }

/* Lo que escribe la persona: alineado a la derecha, en verde de marca. */
.copi-usuario {
    align-self: flex-end;
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 600;
}

.copi-copiloto {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--border);
    width: 100%;
}

.copi-firma {
    display: block;
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--primary-hover);
    margin-bottom: var(--sp-2);
}

.copi-lista { margin: 0; padding-left: var(--sp-5); display: flex; flex-direction: column; gap: 4px; }

.copi-cifras {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--sp-2);
    margin: var(--sp-2) 0;
}

.copi-cifra {
    display: flex;
    flex-direction: column;
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}

.copi-cifra-label {
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.copi-cifra-valor { font-family: var(--font-mono); font-size: 0.95rem; font-weight: 600; }

.copi-nota { font-size: 0.76rem; line-height: 1.5; }

.copi-acciones, .copi-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }

.copi-chips { padding: 0 var(--sp-4) var(--sp-2); }

.copi-chip {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
}

.copi-chip:hover { border-color: var(--primary); color: var(--primary-hover); }

.copi-entrada {
    display: flex;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.copi-entrada .input { flex: 1 1 auto; }

.copi-msg .table-wrap { margin: var(--sp-2) 0; }
.copi-msg .data th, .copi-msg .data td { font-size: 0.78rem; padding: 6px 8px; }

@media (max-width: 560px) {
    .copi-cajon {
        right: var(--sp-3);
        left: var(--sp-3);
        bottom: calc(var(--sp-3) + 64px);
        width: auto;
        max-height: calc(100vh - 160px);
    }
    .copi-lanzador { right: var(--sp-3); bottom: var(--sp-3); width: 56px; height: 56px; }
}
