/* =====================================================
   Control de App — estilos específicos
   ===================================================== */

/* Page header */
.ca-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

/* KPIs */
.ca-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 1.5rem;
}

.ca-kpi {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.15s, box-shadow 0.15s;
}

.ca-kpi:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.06);
}

.ca-kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.ca-kpi-label {
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ca-kpi-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: #1e293b;
    line-height: 1.1;
    margin-top: 2px;
}

/* Toolbar compartido */
.ca-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.ca-search-wrap {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.ca-search-wrap input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s;
}

.ca-search-wrap input:focus {
    border-color: #CA3C42;
    box-shadow: 0 0 0 3px rgba(202, 60, 66, 0.08);
}

.ca-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.8rem;
}

.ca-counter {
    color: #64748b;
    font-size: 0.8rem;
    white-space: nowrap;
    margin-left: auto;
}

.ca-select {
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.85rem;
    background: white;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.ca-select:focus {
    border-color: #CA3C42;
    box-shadow: 0 0 0 3px rgba(202, 60, 66, 0.08);
}

.ca-empty {
    text-align: center;
    padding: 50px 20px;
    color: #94a3b8;
}

.ca-empty p {
    margin: 0 0 16px;
    font-size: 0.95rem;
}

.ca-btn-new {
    height: 40px;
    padding: 0 20px;
    border-radius: 8px;
    font-size: 0.875rem;
}

/* ---- Matriz ---- */
.ca-matriz-wrap {
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: white;
}

.ca-matriz-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 700px;
    font-size: 0.82rem;
}

.ca-matriz-table th,
.ca-matriz-table td {
    padding: 7px 10px;
    text-align: center;
    border-bottom: 1px solid #f1f5f9;
}

.ca-matriz-table th {
    background: #f8fafc;
    font-size: 0.78rem;
    color: #475569;
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 1;
}

/* Columna usuario fija a la izquierda */
.ca-matriz-table th:first-child,
.ca-matriz-table td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background: white;
    z-index: 2;
    min-width: 220px;
    box-shadow: 2px 0 4px rgba(0,0,0,0.04);
}

.ca-matriz-table th:first-child {
    background: #f8fafc;
    z-index: 3;
}

.ca-user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ca-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #CA3C42, #a82d33);
    color: white;
    font-size: 0.78rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}

.ca-avatar.is-me {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.ca-avatar.is-admin {
    background: linear-gradient(135deg, #92400e, #b45309);
}

.ca-user-info {
    flex: 1;
    min-width: 0;
}

.ca-user-name {
    font-weight: 600;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ca-badge-me {
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.ca-badge-admin {
    background: #fef3c7;
    color: #92400e;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.ca-user-email {
    font-size: 0.7rem;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ca-user-progress {
    font-size: 0.7rem;
    color: #64748b;
    margin-top: 2px;
}

.ca-user-progress strong {
    color: #CA3C42;
}

.ca-matriz-table td input[type="checkbox"] {
    width: 17px;
    height: 17px;
    cursor: pointer;
    accent-color: #CA3C42;
}

.ca-matriz-table tr:hover td {
    background: #fffbf2;
}

.ca-matriz-table tr:hover td:first-child {
    background: #fff7ed;
}

/* Icono de módulo en header de matriz */
.ca-mod-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 44px;
}

.ca-mod-header i {
    color: #CA3C42;
    font-size: 0.95rem;
}

.ca-mod-header span {
    font-size: 0.68rem;
    color: #64748b;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ca-mod-count {
    font-size: 0.6rem;
    color: #94a3b8;
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 999px;
    margin-top: 2px;
    font-weight: 600;
}

/* Loading state al guardar */
.ca-saving {
    position: absolute;
    top: 12px;
    right: 12px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.78rem;
    color: #475569;
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.ca-saving.show {
    display: inline-flex;
}

.ca-saving.success {
    color: #059669;
    border-color: #a7f3d0;
    background: #ecfdf5;
}

.ca-saving .spinner {
    width: 12px;
    height: 12px;
    border: 2px solid #e2e8f0;
    border-top-color: #CA3C42;
    border-radius: 50%;
    animation: ca-spin 0.7s linear infinite;
}

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

/* ---- Catálogo (grid de cards) ---- */
.ca-catalogo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.ca-cat-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.15s;
    position: relative;
}

.ca-cat-card:hover {
    border-color: #CA3C42;
    box-shadow: 0 8px 20px rgba(202, 60, 66, 0.08);
    transform: translateY(-2px);
}

.ca-cat-card.inactive {
    opacity: 0.55;
    background: #fafafa;
}

.ca-cat-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ca-cat-icon-big {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #fef2f2;
    color: #CA3C42;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.ca-cat-info {
    flex: 1;
    min-width: 0;
}

.ca-cat-label {
    font-weight: 700;
    font-size: 0.95rem;
    color: #1e293b;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ca-cat-key {
    font-size: 0.72rem;
    color: #94a3b8;
    font-family: 'Courier New', monospace;
    margin-top: 2px;
}

.ca-cat-stats {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
    font-size: 0.78rem;
}

.ca-cat-usage {
    color: #64748b;
}

.ca-cat-usage strong {
    color: #1e293b;
}

.ca-cat-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.ca-cat-actions button {
    flex: 1;
    padding: 6px 10px;
    font-size: 0.78rem;
    border-radius: 6px;
}

.ca-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.ca-badge-activo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 600;
}

.ca-badge-activo.si {
    background: #dcfce7;
    color: #16a34a;
}

.ca-badge-activo.no {
    background: #f1f5f9;
    color: #94a3b8;
}

/* ---- Modal ---- */
.ca-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}

.ca-modal {
    background: white;
    border-radius: 14px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.ca-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #f1f5f9;
}

.ca-modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
}

.ca-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}

.ca-modal-close:hover {
    background: #f1f5f9;
    color: #475569;
}

.ca-modal-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ca-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.ca-form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #475569;
}

.ca-form-group input {
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s;
}

.ca-form-group input:focus {
    border-color: #CA3C42;
    box-shadow: 0 0 0 3px rgba(202, 60, 66, 0.08);
}

.ca-form-group input:read-only {
    background: #f8fafc;
    color: #94a3b8;
    cursor: not-allowed;
}

.ca-required {
    color: #CA3C42;
}

.ca-hint {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 2px;
}

.ca-icon-preview-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ca-icon-preview-wrap input {
    flex: 1;
}

.ca-icon-preview {
    width: 38px;
    height: 38px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #CA3C42;
    font-size: 1.1rem;
    background: #fff7f7;
    flex-shrink: 0;
}

.ca-modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 16px 24px 20px;
    border-top: 1px solid #f1f5f9;
}

.ca-warning-banner {
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 0.82rem;
    color: #713f12;
    margin-bottom: 14px;
    line-height: 1.4;
}

.ca-warning-banner i {
    color: #ca8a04;
    margin-top: 2px;
    flex-shrink: 0;
}

/* Badge cableado vs solo UI */
.ca-cat-wire-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ca-cat-wire-badge.wired {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.ca-cat-wire-badge.unwired {
    background: #fef9c3;
    color: #92400e;
    border: 1px solid #fde047;
}

/* Toggle "Acceso a la app" en cada fila de la matriz */
.ca-acceso-app { display: inline-flex; align-items: center; gap: 6px; margin-top: 7px; font-size: 0.72rem; font-weight: 700; color: #475569; cursor: pointer; }
.ca-acceso-app input { width: 30px; height: 17px; cursor: pointer; accent-color: #CA3C42; }
.ca-acceso-app.ok { color: #059669; cursor: default; }
