/* aed_manager - Estilos centrales */

:root {
    --sidebar-width: 220px;
    --navbar-height: 56px;
    --btn-radius: 0.4rem;
    --btn-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --btn-shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.12);
    --btn-transition: all 0.2s ease;
    /* Colores KPI suaves (no chillones) */
    --kpi-blue: #5b7c99;
    --kpi-amber: #a68b5b;
    --kpi-green: #5a7a5a;
    --kpi-gray: #6b7280;
    --kpi-slate: #495057;
    --kpi-primary: #5b7c99;
}

/* ---------- Evitar barra de desplazamiento lateral ---------- */
html {
    overflow-x: hidden;
}
.app-body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    max-width: 100vw;
}
.app-body .container-fluid {
    max-width: 100%;
    overflow-x: hidden;
}
.app-main {
    min-width: 0;
    overflow-x: hidden;
}
.app-panel {
    min-width: 0;
    max-width: 100%;
}
.app-content {
    max-width: 100%;
    min-width: 0;
}
.table-responsive {
    max-width: 100%;
}

/* ---------- Encabezado de página (estilo Formación) ---------- */
.page-header-card {
    position: relative;
    background: linear-gradient(135deg, #fff 0%, #f8fafc 100%);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-left: 4px solid var(--kpi-primary);
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}
.page-header-card::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -3%;
    width: 140px;
    height: 140px;
    background: var(--kpi-primary);
    opacity: 0.06;
    border-radius: 50%;
    z-index: 0;
}
.page-header-card > * {
    position: relative;
    z-index: 1;
}
.page-header-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
    display: flex;
    align-items: center;
}
.page-header-subtitle {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0.2rem 0 0 0;
}
.page-header-actions {
    flex-shrink: 0;
}

/* ---------- KPIs compactos (estilo Formación, más pequeños, colores suaves) ---------- */
.kpi-pro {
    border-left: 4px solid var(--kpi-blue);
    padding: 0;
    min-height: 52px;
    border-radius: 0.375rem;
    overflow: hidden;
}
.kpi-pro .kpi-pro-label {
    background: #f8f9fa;
    padding: 0.25rem 0.6rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    border-bottom: 1px solid #e9ecef;
}
.kpi-pro .kpi-pro-value {
    padding: 0.35rem 0.6rem;
    font-size: 1rem;
    font-weight: 700;
    color: #1f2937;
}
.kpi-pro.kpi-pro-success { border-left-color: var(--kpi-green); }
.kpi-pro.kpi-pro-success .kpi-pro-value { color: var(--kpi-green); }
.kpi-pro.kpi-pro-warning { border-left-color: var(--kpi-amber); }
.kpi-pro.kpi-pro-warning .kpi-pro-value { color: var(--kpi-amber); }
.kpi-pro.kpi-pro-gray { border-left-color: var(--kpi-gray); }
.kpi-pro.kpi-pro-gray .kpi-pro-value { color: var(--kpi-gray); }
.kpi-pro.kpi-pro-dark { border-left-color: var(--kpi-slate); }
.kpi-pro.kpi-pro-dark .kpi-pro-value { color: var(--kpi-slate); }
.kpi-pro.kpi-pro-danger { border-left-color: #9b6b6b; }
.kpi-pro.kpi-pro-danger .kpi-pro-value { color: #9b6b6b; }
.kpi-pro.kpi-pro-info { border-left-color: #6b8a9e; }
.kpi-pro.kpi-pro-info .kpi-pro-value { color: #6b8a9e; }

/* ---------- Base responsive ---------- */

body {
    font-family: var(--bs-body-font-family);
    background-color: #e9ecef;
}

/* Panel enmarcado para el contenido (área principal) */
.app-panel {
    flex: 1;
    min-width: 0;
    margin: 1rem;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.06);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .app-panel {
        margin: 1.25rem;
    }
}

@media (min-width: 1200px) {
    .app-panel {
        margin: 1.5rem;
    }
}

/* ========== Botones unificados (estilo profesional) ========== */
.btn {
    border-radius: var(--btn-radius);
    font-weight: 500;
    padding: 0.5rem 1rem;
    transition: var(--btn-transition);
    box-shadow: var(--btn-shadow);
    border-width: 1px;
}

.btn:hover {
    box-shadow: var(--btn-shadow-hover);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.875rem;
    border-radius: calc(var(--btn-radius) * 0.9);
}

.btn-sm:hover {
    transform: translateY(-0.5px);
}

.btn-lg {
    padding: 0.6rem 1.25rem;
    font-size: 1.05rem;
    border-radius: calc(var(--btn-radius) * 1.1);
}

/* Primario */
.btn-primary {
    background: linear-gradient(180deg, #0d6efd 0%, #0b5ed7 100%);
    border-color: #0a58ca;
}

.btn-primary:hover {
    background: linear-gradient(180deg, #0b5ed7 0%, #0952c4 100%);
    border-color: #0a58ca;
}

/* Secundario */
.btn-secondary {
    background: linear-gradient(180deg, #6c757d 0%, #5c636a 100%);
    border-color: #565e64;
    color: #fff;
}

.btn-secondary:hover {
    background: linear-gradient(180deg, #5c636a 0%, #495057 100%);
    border-color: #565e64;
    color: #fff;
}

/* Outline */
.btn-outline-primary,
.btn-outline-secondary,
.btn-outline-danger,
.btn-outline-success {
    background: #fff;
}

.btn-outline-primary:hover {
    background: rgba(13, 110, 253, 0.08);
}

.btn-outline-secondary:hover {
    background: rgba(108, 117, 125, 0.08);
}

.btn-outline-danger:hover {
    background: rgba(220, 53, 69, 0.08);
}

.btn-outline-success:hover {
    background: rgba(25, 135, 84, 0.08);
}

/* Danger / Success */
.btn-danger {
    background: linear-gradient(180deg, #dc3545 0%, #bb2d3b 100%);
    border-color: #b02a37;
}

.btn-danger:hover {
    background: linear-gradient(180deg, #bb2d3b 0%, #a52834 100%);
    border-color: #b02a37;
}

.btn-success {
    background: linear-gradient(180deg, #198754 0%, #157347 100%);
    border-color: #146c43;
}

.btn-success:hover {
    background: linear-gradient(180deg, #157347 0%, #13653f 100%);
    border-color: #146c43;
}

/* Info / Warning (por si se usan) */
.btn-info {
    background: linear-gradient(180deg, #0dcaf0 0%, #0aa2c0 100%);
    border-color: #0992b0;
}

.btn-warning {
    background: linear-gradient(180deg, #ffc107 0%, #e0a800 100%);
    border-color: #d39e00;
    color: #212529;
}

/* ---------- Navbar responsive ---------- */
.navbar {
    min-height: var(--navbar-height);
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
}

.navbar-brand {
    font-weight: 600;
    max-width: 50vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 576px) {
    .navbar-brand { max-width: none; }
}

.navbar-toggler {
    padding: 0.4rem 0.5rem;
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    overflow-y: auto;
    z-index: 1020;
    background: #fff;
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.06);
}

.sidebar-link {
    border-radius: 0.25rem;
    transition: background-color 0.15s ease;
}

.sidebar-link:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.sidebar-link.active {
    background-color: var(--bs-primary);
    color: var(--bs-white) !important;
}

/* ---------- Main content responsive ---------- */
.app-main {
    flex: 1;
    min-width: 0;
    min-height: calc(100vh - var(--navbar-height));
}

.main-with-sidebar {
    margin-left: var(--sidebar-width);
}

.main-without-sidebar {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.app-content {
    width: 100%;
    min-width: 0;
}

/* Padding del contenido según breakpoint (cuando el hijo tiene p-4) */
.app-panel .app-content > div.p-4,
.app-panel .app-content > div[class*="p-4"],
.app-content > div.p-4,
.app-content > div[class*="p-4"] {
    padding: 0.75rem !important;
}

@media (min-width: 576px) {
    .app-panel .app-content > div.p-4,
    .app-panel .app-content > div[class*="p-4"],
    .app-content > div.p-4,
    .app-content > div[class*="p-4"] {
        padding: 1rem !important;
    }
}

@media (min-width: 768px) {
    .app-panel .app-content > div.p-4,
    .app-panel .app-content > div[class*="p-4"],
    .app-content > div.p-4,
    .app-content > div[class*="p-4"] {
        padding: 1.25rem !important;
    }
}

@media (min-width: 992px) {
    .app-panel .app-content > div.p-4,
    .app-panel .app-content > div[class*="p-4"],
    .app-content > div.p-4,
    .app-content > div[class*="p-4"] {
        padding: 1.5rem !important;
    }
}

/* Flash messages */
.flash-messages .alert {
    max-width: 100%;
}

/* ---------- Cards y contenido ---------- */
.card {
    border-radius: 0.375rem;
}

/* Cabeceras de página: título + botón que se adapten a móvil */
.page-header,
.d-flex.justify-content-between.align-items-center.mb-4,
.d-flex.justify-content-between.align-items-center.mb-3 {
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Tablas: scroll horizontal en móvil */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive .table {
    margin-bottom: 0;
    min-width: 600px;
}

@media (max-width: 575.98px) {
    .table-responsive .table {
        font-size: 0.875rem;
    }
    .table-responsive .table th,
    .table-responsive .table td {
        padding: 0.5rem 0.35rem;
        white-space: nowrap;
    }
    .table-responsive .table th:first-child,
    .table-responsive .table td:first-child {
        position: sticky;
        left: 0;
        background: #fff;
        z-index: 1;
        box-shadow: 2px 0 4px rgba(0,0,0,0.06);
    }
    .table-responsive .table thead th:first-child {
        background: #f8f9fa;
    }
}

/* Dashboard: tabla con sticky header, zebra suave, más separación */
.table-dashboard-wrap {
    max-height: 70vh;
    overflow-y: auto;
}
.table-dashboard thead th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    z-index: 1;
    box-shadow: 0 1px 0 0 #dee2e6;
}
.table-dashboard tbody tr {
    vertical-align: middle;
}
.table-dashboard td {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
}

/* ---------- Tablet: sidebar un poco más estrecho ---------- */
@media (min-width: 1200px) and (max-width: 1399.98px) {
    :root {
        --sidebar-width: 200px;
    }
}

/* ---------- Ventana pequeña/tablet: sidebar como drawer y botón menú visible ---------- */
@media (max-width: 1199.98px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 1040;
        width: min(280px, 85vw);
        max-width: 280px;
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0.25rem 0 1rem rgba(0, 0, 0, 0.15);
    }
    .sidebar-link {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-top: 0.6rem !important;
        padding-bottom: 0.6rem !important;
    }
    .main-with-sidebar {
        margin-left: 0;
    }
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1035;
        cursor: pointer;
    }
    .navbar .sidebar-toggler {
        min-width: 48px;
        min-height: 48px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Evitar barra de desplazamiento horizontal en toda la app */
.app-body,
.app-body .container-fluid {
    max-width: 100vw;
    overflow-x: hidden;
}
.app-main {
    overflow-x: hidden;
}
.app-content {
    max-width: 100%;
}
.app-panel {
    max-width: 100%;
}
.table-responsive {
    max-width: 100%;
}

/* ---------- Dashboard cards responsive ---------- */
@media (max-width: 575.98px) {
    .table-dashboard-wrap {
        max-height: 60vh;
    }
}
