/* ==========================================================================
   MiBot CRM SaaS - Estilos Base y Layout Sidebar
   ========================================================================== */

/* Set padding to keep content from hitting the edges */
.body-content {
    margin-top: 15px;
    padding-left: 15px;
    padding-right: 15px;
}

/* Override the default bootstrap behavior where horizontal description lists 
   will truncate terms that are too long to fit in the left column 
*/
.dl-horizontal dt {
    white-space: normal;
}

/* Permitir que los controles de formulario ocupen el ancho de sus contenedores Bootstrap */
.form-control,
.form-select {
    max-width: none;
}

/* ==========================================================================
   Estructura Principal del Layout (Sidebar + Contenido)
   ========================================================================== */

:root {
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 68px;
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
    --sidebar-active-bg: rgba(59, 130, 246, 0.15);
    --sidebar-accent: #25d366;
    --sidebar-transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Tokens del Sistema de Headers Estandarizados */
    --header-bg-gradient: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
    --header-title-color: #ffffff;
    --header-subtitle-color: #c7d2fe;
    --header-radius: 20px;
    --header-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
}

body.has-sidebar {
    overflow-x: hidden;
    background-color: #f8fafc;
}

.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* --------------------------------------------------------------------------
   Barra Lateral (Sidebar)
   -------------------------------------------------------------------------- */
.app-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    z-index: 1040;
    transition: var(--sidebar-transition);
    user-select: none;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
}

/* Header del Sidebar */
.app-sidebar-header {
    height: 64px;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    gap: 0.5rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none !important;
    color: #ffffff !important;
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand-icon {
    font-size: 1.5rem;
    color: var(--sidebar-accent);
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    overflow: hidden;
}

.sidebar-brand-title {
    color: #f8fafc;
    font-size: 0.9rem;
    letter-spacing: -0.2px;
}

.sidebar-brand-subtitle {
    font-size: 0.65rem;
    color: #38bdf8;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.btn-sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--sidebar-transition);
    flex-shrink: 0;
}

.btn-sidebar-toggle:hover {
    background: var(--sidebar-hover-bg);
    color: #ffffff;
}

/* Cuerpo de Navegación */
.sidebar-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.85rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Scrollbar estilizada */
.sidebar-body::-webkit-scrollbar {
    width: 4px;
}
.sidebar-body::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

/* Títulos de sección */
.sidebar-section-heading {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: #64748b;
    padding: 0.65rem 0.75rem 0.25rem 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Enlaces del Sidebar */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    color: var(--sidebar-text) !important;
    text-decoration: none !important;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    transition: var(--sidebar-transition);
    white-space: nowrap;
    position: relative;
}

.sidebar-link i.sidebar-icon {
    font-size: 1.15rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
    color: #94a3b8;
    transition: var(--sidebar-transition);
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover-bg);
    color: #ffffff !important;
}

.sidebar-link:hover i.sidebar-icon {
    color: #ffffff;
    transform: scale(1.08);
}

.sidebar-link.active {
    background-color: var(--sidebar-active-bg);
    color: #ffffff !important;
    font-weight: 600;
    box-shadow: inset 3px 0 0 0 #3b82f6;
}

.sidebar-link.active i.sidebar-icon {
    color: #38bdf8;
}

.sidebar-link-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Footer / Usuario */
.app-sidebar-footer {
    padding: 0.85rem;
    border-top: 1px solid var(--sidebar-border);
    background-color: rgba(15, 23, 42, 0.6);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.sidebar-user-card {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    overflow: hidden;
}

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #334155;
    color: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
    line-height: 1.2;
}

.sidebar-user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #f8fafc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    display: inline-block;
    font-size: 0.65rem;
    margin-top: 2px;
}

.sidebar-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
}

.sidebar-btn-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none !important;
    white-space: nowrap;
    transition: var(--sidebar-transition);
}

/* --------------------------------------------------------------------------
   Estado Colapsado (Mini-Sidebar Desktop)
   -------------------------------------------------------------------------- */
@media (min-width: 992px) {
    .app-layout.sidebar-collapsed .app-sidebar {
        width: var(--sidebar-collapsed-width);
        min-width: var(--sidebar-collapsed-width);
    }

    .app-layout.sidebar-collapsed .sidebar-brand-text,
    .app-layout.sidebar-collapsed .sidebar-section-heading,
    .app-layout.sidebar-collapsed .sidebar-link-text,
    .app-layout.sidebar-collapsed .sidebar-user-info,
    .app-layout.sidebar-collapsed .sidebar-btn-action-text {
        display: none !important;
    }

    .app-layout.sidebar-collapsed .app-sidebar-header {
        justify-content: center;
        padding: 0 0.5rem;
    }

    .app-layout.sidebar-collapsed .sidebar-brand {
        display: none;
    }

    .app-layout.sidebar-collapsed .sidebar-link {
        justify-content: center;
        padding: 0.65rem 0;
        position: relative;
    }

    .app-layout.sidebar-collapsed .sidebar-link i.sidebar-icon {
        width: auto;
        font-size: 1.25rem;
    }

    .app-layout.sidebar-collapsed .sidebar-section-divider {
        display: block;
        height: 1px;
        background: var(--sidebar-border);
        margin: 0.4rem 0.5rem;
    }

    .app-layout.sidebar-collapsed .app-sidebar-footer {
        padding: 0.6rem 0.4rem;
        align-items: center;
    }

    .app-layout.sidebar-collapsed .sidebar-user-card {
        justify-content: center;
    }

    .app-layout.sidebar-collapsed .sidebar-actions-grid {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .app-layout.sidebar-collapsed .sidebar-btn-action {
        padding: 0.45rem 0;
    }

    /* Floating Tooltips on Hover when collapsed */
    .app-layout.sidebar-collapsed .sidebar-link:hover::after {
        content: attr(data-title);
        position: absolute;
        left: calc(var(--sidebar-collapsed-width) + 8px);
        top: 50%;
        transform: translateY(-50%);
        background-color: #1e293b;
        color: #ffffff;
        padding: 0.35rem 0.65rem;
        border-radius: 6px;
        font-size: 0.78rem;
        font-weight: 500;
        white-space: nowrap;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        border: 1px solid #334155;
        z-index: 1060;
        pointer-events: none;
        animation: fadeInTooltip 0.15s ease-out forwards;
    }
}

@keyframes fadeInTooltip {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* --------------------------------------------------------------------------
   Área de Contenido Principal
   -------------------------------------------------------------------------- */
.app-main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background-color: #f8fafc;
    transition: var(--sidebar-transition);
}

.app-main-content > main {
    flex: 1;
}

/* --------------------------------------------------------------------------
   Header y Drawer para Móviles (< 992px)
   -------------------------------------------------------------------------- */
.app-mobile-header {
    display: none;
    height: 56px;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 1035;
    opacity: 0;
    transition: opacity 0.25s ease-in-out;
}

@media (max-width: 991.98px) {
    .app-mobile-header {
        display: flex;
    }

    .app-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        height: 100vh;
        width: 270px;
        min-width: 270px;
        transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .app-layout.mobile-sidebar-open .app-sidebar {
        left: 0;
    }

    .app-layout.mobile-sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
    }
}

/* ==========================================================================
   SISTEMA ESTANDARIZADO DE HEADERS Y CABECERAS DE VISTAS (SAAS STANDARD)
   ========================================================================== */

.view-container,
.page-container,
.dashboard-container,
.campanias-container,
.bots-dashboard,
.calendario-dashboard,
.contact-dashboard {
    max-width: 1400px;
    margin: 24px auto;
    padding: 0 20px;
}

/* Top Bar de Navegación / Retorno */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none !important;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #475569 !important;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-back:hover {
    background: #f1f5f9;
    color: #0f172a !important;
    transform: translateX(-2px);
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.08);
}

/* Header Card Principal */
.header-card,
.header-banner {
    background: var(--header-bg-gradient);
    color: var(--header-title-color);
    border-radius: var(--header-radius);
    padding: 26px 30px;
    margin-bottom: 24px;
    box-shadow: var(--header-shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-title-box h1,
.header-title-box h2,
.header-card h1,
.header-card h2 {
    font-size: 26px;
    font-weight: 800;
    margin: 0 0 6px 0;
    letter-spacing: -0.5px;
    color: var(--header-title-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-title-box p,
.header-card p {
    color: var(--header-subtitle-color);
    font-size: 14px;
    margin: 0;
    font-weight: 400;
    line-height: 1.4;
}

.header-title-box p strong,
.header-card p strong {
    color: #ffffff;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Botones de Acción de Header */
.btn-header-primary {
    background: #6366f1;
    color: #ffffff !important;
    font-weight: 700;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 12px;
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
}

.btn-header-primary:hover {
    background: #4f46e5;
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.45);
}

.btn-header-success {
    background: #10b981;
    color: #ffffff !important;
    font-weight: 700;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 12px;
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
}

.btn-header-success:hover {
    background: #059669;
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.45);
}

.btn-header-outline {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff !important;
    font-weight: 700;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 12px;
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(4px);
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-header-outline:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff !important;
    transform: translateY(-1px);
}

/* Selector de Contexto / Cliente en Header */
.header-select-pill {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    padding: 7px 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #ffffff;
    backdrop-filter: blur(4px);
}

.header-select-pill label {
    font-size: 11px;
    font-weight: 800;
    color: #c7d2fe;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

.header-select-pill select {
    background: transparent;
    border: none;
    color: #ffffff;
    font-weight: 700;
    font-size: 13.5px;
    outline: none;
    cursor: pointer;
}

.header-select-pill select option {
    background: #1e1b4b;
    color: #ffffff;
}
