/* ============================================================
   components.css — COMPONENTES de dashboard reutilizables (.crr-*)
   ------------------------------------------------------------
   Bloques de UI moderna: contenedor .crr-ui, cabecera, KPIs,
   tarjetas, tabla .crr-table, filtros, toolbar, botones .crr-btn*,
   paginador, además del conmutador de temas (.crr-theme-switch),
   tarjetas de teléfono, subida de imágenes y los keyframes.
   Todo bajo html.theme-cg salvo el conmutador (también visible
   en clásico para poder salir de él).
   ============================================================ */
html.theme-cg .crr-ui {
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius);
    padding: 22px;
    margin: 8px 0 24px;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    animation: crrFadeUp .4s ease both;
}
html.theme-cg .crr-ui * { box-sizing: border-box; }

html.theme-cg .crr-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
html.theme-cg .crr-title { font-size: 22px; font-weight: 700; margin: 0; color: var(--text); }
html.theme-cg .crr-subtitle { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
/* Chip del dashboard demo (.crr-ui). Acotado a .crr-ui para no colisionar
   con los chips de filtros activos (.crr-chips .crr-chip de table-tools.css). */
html.theme-cg .crr-ui .crr-chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--accent-2); padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }

html.theme-cg .crr-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
@media (max-width: 1100px) { html.theme-cg .crr-kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { html.theme-cg .crr-kpis { grid-template-columns: 1fr; } }
html.theme-cg .crr-kpi {
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px 18px;
    transition: transform var(--speed), box-shadow var(--speed), border-color var(--speed);
    animation: crrFadeUp .45s ease both; animation-delay: calc(var(--d, 0) * .07s);
}
html.theme-cg .crr-kpi:hover { transform: translateY(-4px); border-color: var(--accent); box-shadow: 0 12px 28px rgba(99, 102, 241, .18); }
html.theme-cg .crr-kpi-top { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
html.theme-cg .crr-kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
html.theme-cg .crr-kpi-value { font-size: 26px; font-weight: 700; letter-spacing: .3px; color: var(--text); }
html.theme-cg .crr-kpi-cur { font-size: 15px; color: var(--muted); margin-right: 2px; }
html.theme-cg .crr-kpi-icon { width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto; display: inline-block; position: relative; background: rgba(99, 102, 241, .15); }
html.theme-cg .crr-kpi-icon::after { content: ""; position: absolute; inset: 0; margin: auto; width: 13px; height: 13px; border-radius: 3px; }
html.theme-cg .crr-ic-total::after { background: #818cf8; }
html.theme-cg .crr-ic-page::after  { background: #38bdf8; border-radius: 50%; }
html.theme-cg .crr-ic-money::after { background: #22c55e; }
html.theme-cg .crr-ic-extra::after { background: #f59e0b; transform: rotate(45deg); }

html.theme-cg .crr-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
html.theme-cg .crr-table-wrap { overflow-x: auto; }
html.theme-cg .crr-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
html.theme-cg .crr-table thead th {
    text-align: left; padding: 13px 14px; background: var(--surface-2); color: var(--muted);
    font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0; white-space: nowrap;
}
html.theme-cg .crr-table thead th a { color: inherit; text-decoration: none; }
html.theme-cg .crr-table thead th a:hover { color: var(--accent-2); }
html.theme-cg .crr-table tbody td { padding: 13px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
html.theme-cg .crr-row { animation: crrFadeIn .3s ease both; transition: background var(--speed); }
html.theme-cg .crr-row:hover { background: rgba(99, 102, 241, .08); }
html.theme-cg .crr-row-flag { box-shadow: inset 3px 0 0 #ef4444; }
html.theme-cg .crr-row-warn { box-shadow: inset 3px 0 0 #f59e0b; }
html.theme-cg .crr-strong { font-weight: 600; }
html.theme-cg .crr-muted  { color: var(--muted); }
html.theme-cg .crr-mono   { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; color: var(--muted); }
html.theme-cg .crr-id     { font-weight: 700; color: var(--accent-2); }

html.theme-cg .crr-w-action { width: 44px; text-align: center; }
html.theme-cg .crr-icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); color: var(--accent-2); text-decoration: none; transition: transform var(--speed), background var(--speed); }
html.theme-cg .crr-icon-btn:hover { background: var(--accent); color: #fff; transform: translateX(2px); }
html.theme-cg .crr-arrow { font-size: 18px; line-height: 1; font-weight: 700; }

html.theme-cg .crr-filters td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
html.theme-cg .crr-filters input,
html.theme-cg .crr-filters select {
    width: 100%; min-width: 70px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none;
    transition: border-color var(--speed), box-shadow var(--speed), background var(--speed);
}
html.theme-cg .crr-filters input::placeholder { color: var(--muted); opacity: .7; }
html.theme-cg .crr-filters input:focus,
html.theme-cg .crr-filters select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .2); background: var(--surface); }
html.theme-cg .crr-date-cell { display: flex; flex-direction: column; gap: 6px; min-width: 140px; }

html.theme-cg .crr-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; background: var(--surface-2); border-top: 1px solid var(--border); flex-wrap: wrap; }
html.theme-cg .crr-actions { display: flex; gap: 10px; }
html.theme-cg .crr-btn { border: 1px solid var(--border); border-radius: 9px; padding: 9px 18px; font-size: 13px; font-weight: 600; cursor: pointer; transition: transform var(--speed), background var(--speed), box-shadow var(--speed); }
html.theme-cg .crr-btn:active { transform: scale(.97); }
html.theme-cg .crr-btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(99, 102, 241, .3); }
html.theme-cg .crr-btn-primary:hover { box-shadow: 0 8px 22px rgba(99, 102, 241, .45); }
html.theme-cg .crr-btn-ghost { background: transparent; color: var(--muted); }
html.theme-cg .crr-btn-ghost:hover { color: var(--text); border-color: var(--accent); }
html.theme-cg .crr-pager { display: flex; align-items: center; gap: 6px; }
html.theme-cg .crr-pager a, html.theme-cg .crr-pager span { color: var(--muted); }

@keyframes crrFadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes crrFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ----- Tarjetas de teléfono (notificaciones/dispositivos) ----- */
html.theme-cg .phone-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); }
html.theme-cg .phone-card__title, html.theme-cg .phone-card__strong { color: var(--text); }
html.theme-cg .phone-card__label { color: var(--muted); }
html.theme-cg .phone-card__input { background: var(--surface); border: 1px solid var(--border); color: var(--text); }

/* ----- Subida de imágenes ----- */
html.theme-cg .upload-label { background: var(--surface-2); border: 1px dashed var(--border); }
html.theme-cg .upload-label:hover { box-shadow: 0 4px 12px rgba(0, 0, 0, .25); }
html.theme-cg .upload-label .svg-icon.image { color: var(--muted); }
html.theme-cg .upload-label-hint { color: var(--muted); }
html.theme-cg .action-buttons { background: rgba(0, 0, 0, .35); }

/* ============================================================
   Conmutador de 3 botones (en el menú de usuario, header.tpl):
   .crr-theme-switch con un botón por tema; el activo resaltado.
   UNGATED para que funcione/visualice también en clásico.
   La fila del conmutador (y la de colores de acento) son <div> dentro
   del desplegable; sin fondo propio saldrían transparentes en clásico/claro.
   ┌─ NO REGRESIONAR ──────────────────────────────────────────────────┐
   │ Usar background-COLOR SÓLIDO, NUNCA la banda del sprite bg.png.     │
   │ El sprite solo cubre ~22px; al crecer la fila (p. ej. al añadir la  │
   │ fila de acento) lo que sobra queda TRANSPARENTE -> este bug ya se   │
   │ "arregló" dos veces con el sprite y volvía a fallar al cambiar la   │
   │ altura. Un color sólido rellena toda la altura pase lo que pase.    │
   └────────────────────────────────────────────────────────────────────┘
   Clásico/claro: color del desplegable clásico (slate del sprite, sólido).
   Oscuro: la superficie del tema.
   ============================================================ */
#menu li ul li.crr-theme-li { height: auto; background: #5f6d80; }
html.theme-cg.theme-dark #menu li ul li.crr-theme-li { background: var(--surface); }
.crr-theme-switch { display: flex; gap: 5px; padding: 7px 8px; justify-content: center; flex-wrap: wrap; }
.crr-theme-switch button {
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; flex: 0 0 auto; cursor: pointer; padding: 0;
    border-radius: 7px;
    background: var(--surface-2, #ffffff); color: var(--text, #555);
    border: 1px solid var(--border, #b9c4d6);
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.crr-theme-switch button svg { width: 16px; height: 16px; display: block; }
.crr-theme-switch button:hover { border-color: var(--accent, #4f46e5); color: var(--accent, #4f46e5); }
.crr-theme-switch button.active { background: var(--accent, #4f46e5); color: #fff; border-color: transparent; }
.crr-theme-switch button.active:hover { color: #fff; }

/* Selector de color de acento (junto al conmutador de tema). Solo temas nuevos. */
.crr-accent-switch { display: none; }
html.theme-cg .crr-accent-switch { display: flex; gap: 7px; padding: 2px 10px 9px; justify-content: center; flex-wrap: wrap; }
.crr-accent-dot { width: 18px; height: 18px; border-radius: 50%; padding: 0; cursor: pointer; border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border, #b9c4d6); transition: transform .12s ease; }
.crr-accent-dot:hover { transform: scale(1.15); }
.crr-accent-dot.active { border-color: var(--text, #555); }
.crr-accent-default { background: conic-gradient(#6366f1, #14b8a6, #22c55e, #f59e0b, #f43f5e, #6366f1); }

/* Barra de progreso superior al navegar. z-index 1500: por debajo del
   loader full-screen (#loader, z-9999) para no competir con la "gota". */
.crr-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 1500; opacity: 0; pointer-events: none; border-radius: 0 2px 2px 0; }
html.theme-cg .crr-progress.go { opacity: 1; width: 90%; transition: width 10s cubic-bezier(.1, .7, .4, 1); }
html.theme-cg .crr-progress.done { opacity: 0; width: 100%; transition: width .2s ease, opacity .3s ease .1s; }

/* ============================================================
   Command palette (Ctrl/⌘+K) — lo construye command.js.
   Oculto por defecto; visible solo con .open bajo html.theme-cg.
   ============================================================ */
.crr-cmd-overlay { display: none; }
html.theme-cg .crr-cmd-overlay.open { display: block; position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 2000; }
html.theme-cg .crr-cmd {
    position: fixed; top: 12vh; left: 50%; transform: translateX(-50%);
    width: 560px; max-width: 92vw; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
html.theme-cg .crr-cmd-input {
    width: 100%; box-sizing: border-box; border: 0; border-bottom: 1px solid var(--border);
    background: transparent; color: var(--text); font-size: 16px; padding: 14px 16px; outline: none;
}
html.theme-cg .crr-cmd-list { list-style: none; margin: 0; padding: 6px; max-height: 52vh; overflow: auto; }
html.theme-cg .crr-cmd-item { display: flex; flex-direction: column; gap: 1px; padding: 9px 12px; border-radius: 9px; cursor: pointer; }
html.theme-cg .crr-cmd-item.active { background: var(--surface-3); }
html.theme-cg .crr-cmd-item .lbl { color: var(--text); font-size: 14px; }
html.theme-cg .crr-cmd-item .ctx { color: var(--muted); font-size: 11.5px; }
html.theme-cg .crr-cmd-empty { padding: 16px; color: var(--muted); font-size: 13px; text-align: center; }
html.theme-cg .crr-cmd-hint { display: flex; gap: 12px; justify-content: flex-end; padding: 8px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }

/* ----- Respeta "reducir movimiento" del SO ----- */
@media (prefers-reduced-motion: reduce) {
    html.theme-cg .crr-ui, html.theme-cg .crr-kpi, html.theme-cg .crr-row { animation: none !important; }
    html.theme-cg * { transition: none !important; }
}

/* ============================================================
   TARJETAS DE ESTADÍSTICAS encima de listados (deposits / loans /
   applications). Solo temas nuevos: ocultas por defecto, así el
   clásico no las muestra aunque el markup esté siempre en el HTML.
   ============================================================ */
.crr-stat-cards { display: none; }
html.theme-cg .crr-stat-cards {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 0 0 16px;
}
html.theme-cg .crr-stat-card {
    display: flex; align-items: center; gap: 14px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 15px 18px; box-shadow: var(--shadow);
}
html.theme-cg .crr-stat-ic {
    flex: 0 0 auto; width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent-2);
}
html.theme-cg .crr-stat-ic svg { width: 22px; height: 22px; }
html.theme-cg .crr-stat-body { display: flex; flex-direction: column; min-width: 0; }
html.theme-cg .crr-stat-label { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
html.theme-cg .crr-stat-value { font-size: 22px; font-weight: 600; color: var(--text); line-height: 1.2; }
/* Tarjeta con dos sub-valores (p. ej. agentes / clientes) */
html.theme-cg .crr-stat-split { display: flex; gap: 20px; margin-top: 1px; }
html.theme-cg .crr-stat-split .crr-stat-value { font-size: 19px; }
html.theme-cg .crr-stat-sub { font-size: 11.5px; color: var(--muted); }
/* Estado de carga async: valores atenuados con un leve parpadeo hasta que
   stats.js los rellena. El parpadeo se anula con prefers-reduced-motion. */
html.theme-cg .crr-stat-loading .crr-stat-value { opacity: .4; animation: crr-stat-pulse 1.1s ease-in-out infinite; }
@keyframes crr-stat-pulse { 0%, 100% { opacity: .35; } 50% { opacity: .6; } }
@media (max-width: 900px) {
    html.theme-cg .crr-stat-cards { grid-template-columns: 1fr; }
}
