/* ══════════════════════════════════════════════
   app.css - Estilos del CRUD Flask.
   Manual de Identidad Visual Corporativa USB.

   Colores institucionales:
     Naranja USB:  #EF7D00
     Negro USB:    #1D1D1B
   Tipografia: Montserrat (Google Fonts)
   ══════════════════════════════════════════════ */


/* ───────── VARIABLES ───────── */
:root {
    --primary: #EF7D00;
    --primary-hover: #d46e00;
    --bg: #f5f5f5;
    --bg-secondary: #e8e8e8;
    --text: #1D1D1B;
    --text-light: #6c757d;
    --sidebar-header: #1D1D1B;
    --white: #ffffff;
}


/* ───────── BASE ───────── */

body {
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg);
    color: var(--text);
}


/* ───────── ESTRUCTURA DE PAGINA ───────── */

.page {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
}


/* ───────── SIDEBAR ───────── */

.sidebar {
    background-color: #1D1D1B;
}

.sidebar .top-row {
    min-height: 3.5rem;
    background-color: #111110;
    border-bottom: 2px solid #EF7D00;
    justify-content: flex-start;
}

.navbar-brand {
    font-size: 1.1rem;
    color: var(--white) !important;
    text-decoration: none;
}


/* ───────── BARRA SUPERIOR MAIN ───────── */

main > .top-row {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid #c5c5c5;
    justify-content: flex-end;
    height: 3.5rem;
    display: flex;
    align-items: center;
    color: var(--text);
}

.top-row a, .top-row .btn-link {
    white-space: nowrap;
    margin-left: 1.5rem;
    text-decoration: none;
    color: var(--text);
}

.top-row a:hover, .top-row .btn-link:hover {
    text-decoration: underline;
}


/* ───────── TOGGLE MOVIL ───────── */

.navbar-toggler {
    appearance: none;
    cursor: pointer;
    width: 3.5rem;
    height: 2.5rem;
    position: absolute;
    top: 0.5rem;
    right: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.8%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
}

.navbar-toggler:checked {
    background-color: rgba(0, 0, 0, 0.15);
}


/* ───────── ITEMS DE NAVEGACION ───────── */

.nav-item {
    font-size: 0.9rem;
    padding-bottom: 0.25rem;
}

.nav-item:first-of-type {
    padding-top: 0.75rem;
}

.nav-item:last-of-type {
    padding-bottom: 1rem;
}

.nav-item .nav-link {
    color: rgba(255, 255, 255, 0.8);
    background: none;
    border: none;
    border-radius: 6px;
    min-height: 2.6rem;
    display: flex;
    align-items: center;
    line-height: 1.3;
    width: 100%;
    text-decoration: none;
    transition: all 0.15s ease;
    white-space: normal;
    word-break: break-word;
    padding-top: 0.3rem;
    padding-bottom: 0.3rem;
}

.nav-item .nav-link i {
    margin-right: 0.6rem;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.5);
}

.nav-item .nav-link.active {
    background-color: var(--primary);
    color: var(--white);
}

.nav-item .nav-link.active i {
    color: var(--white);
}

.nav-item .nav-link:hover {
    background-color: rgba(239, 125, 0, 0.2);
    color: var(--white);
}

.nav-item .nav-link:hover i {
    color: var(--primary);
}

/* Tabs dentro del contenido principal (no en sidebar) */
.nav-tabs {
    border-bottom: 2px solid #dee2e6;
}
.nav-tabs .nav-link {
    color: var(--text);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    padding: 10px 20px;
    font-weight: 500;
    margin-bottom: -2px;
}
.nav-tabs .nav-link i {
    color: var(--text-light);
}
.nav-tabs .nav-link.active {
    background-color: transparent;
    color: var(--primary);
    border-bottom: 3px solid var(--primary);
    font-weight: 600;
}
.nav-tabs .nav-link.active i {
    color: var(--primary);
}
.nav-tabs .nav-link:hover:not(.active) {
    background-color: transparent;
    color: var(--primary);
    border-bottom: 3px solid rgba(239, 125, 0, 0.3);
}
.nav-tabs .nav-link:hover:not(.active) i {
    color: var(--primary);
}

.nav-scrollable {
    display: none;
}

.navbar-toggler:checked ~ .nav-scrollable {
    display: block;
}

/* Separadores de seccion en sidebar */
.nav-section-label {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
}

/* Toggle de secciones colapsables */
.nav-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.nav-section-toggle:hover .nav-section-label {
    color: var(--primary);
}

.nav-section-chevron {
    font-size: 0.65rem;
    transition: transform 0.25s ease;
    color: rgba(255, 255, 255, 0.35);
}

.nav-section-toggle[aria-expanded="true"] .nav-section-chevron {
    transform: rotate(0deg);
}

.nav-section-toggle[aria-expanded="false"] .nav-section-chevron {
    transform: rotate(-90deg);
}

/* Boton toggle sidebar flotante (estilo Streamlit) */
.sidebar-toggle {
    position: fixed;
    left: 250px;
    top: 4.2rem;
    z-index: 100;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #c5c5c5;
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: left 0.3s ease, background-color 0.15s ease;
    font-size: 0.7rem;
    color: var(--text);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
    transform: translateX(-50%);
    padding: 0;
}

.sidebar-toggle:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.page.sidebar-hidden .sidebar-toggle {
    left: 12px;
    transform: translateX(0);
}



/* ───────── BOTONES (override Bootstrap) ───────── */

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--white);
}

.btn-primary:active {
    background-color: #c45535 !important;
    border-color: #c45535 !important;
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

/* Boton de guardar */
.btn-save {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.btn-save:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--white);
}

/* Botones de accion en tabla (editar/eliminar) */
.btn-action {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: all 0.15s ease;
}

.btn-action-edit {
    color: var(--text);
    border: 1px solid #c5c5c5;
    background: var(--white);
}

.btn-action-edit:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(231, 111, 81, 0.08);
}

.btn-action-delete {
    color: #999;
    border: 1px solid #c5c5c5;
    background: var(--white);
}

.btn-action-delete:hover {
    color: #dc3545;
    border-color: #dc3545;
    background: rgba(220, 53, 69, 0.08);
}


/* ───────── TABLAS ───────── */

.table {
    --bs-table-bg: var(--white);
    --bs-table-striped-bg: #f5f5f5;
    border-color: #d5d5d5;
}

.table thead {
    background-color: var(--sidebar-header);
    color: var(--white);
}

.table thead th {
    background-color: var(--sidebar-header);
    color: var(--white);
    border-color: var(--sidebar-header);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}


/* ───────── CARDS / FORMULARIOS ───────── */

.card {
    background-color: var(--white);
    border: 1px solid #c5c5c5;
    border-radius: 8px;
}

.card-header {
    background-color: var(--bg-secondary);
    color: var(--text);
    font-weight: 600;
    border-bottom: 1px solid #c5c5c5;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(231, 111, 81, 0.25);
}


/* ───────── ALERTAS ───────── */

.alert-info {
    background-color: #d6eef8;
    border-color: #b8dff0;
    color: #264653;
}

.alert-warning {
    background-color: #fdf3e0;
    border-color: #f4d9a6;
    color: #8a6d3b;
}

.alert-success {
    background-color: #d5efe8;
    border-color: #a8ddd0;
    color: #1a6b55;
}

.alert-danger {
    background-color: #fce4e4;
    border-color: #f5c6c6;
    color: #8b3030;
}


/* ───────── PAGINACION ───────── */

.pagination-bar {
    padding: 0.5rem 0;
}

.pagination-info {
    color: var(--text-light);
    font-size: 0.82rem;
}

.pagination .page-link {
    color: var(--text);
    border-color: #c5c5c5;
    background-color: var(--white);
    font-size: 0.82rem;
    padding: 0.3rem 0.6rem;
}

.pagination .page-link:hover {
    color: var(--primary);
    border-color: var(--primary);
    background-color: rgba(231, 111, 81, 0.08);
}

.pagination .page-item.active .page-link {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.pagination .page-item.disabled .page-link {
    color: #bbb;
    border-color: #d5d5d5;
    background-color: var(--bg);
}


/* ───────── RESPONSIVE ───────── */

@media (min-width: 641px) {

    .page {
        flex-direction: row;
    }

    .sidebar {
        width: 250px;
        min-width: 250px;
        height: 100vh;
        position: sticky;
        top: 0;
        transition: width 0.3s ease, min-width 0.3s ease;
        overflow: hidden;
    }

    .page.sidebar-hidden .sidebar {
        width: 0;
        min-width: 0;
    }

    main > .top-row {
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .navbar-toggler {
        display: none;
    }

    .nav-scrollable {
        display: block;
        height: calc(100vh - 3.5rem);
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.15) transparent;
    }

    .nav-scrollable::-webkit-scrollbar {
        width: 5px;
    }

    .nav-scrollable::-webkit-scrollbar-thumb {
        background: rgba(255,255,255,0.15);
        border-radius: 3px;
    }

    main .top-row,
    article {
        padding-left: 2rem !important;
        padding-right: 1.5rem !important;
    }
}

@media (max-width: 640.98px) {
    .sidebar-toggle {
        display: none;
    }

    .top-row {
        justify-content: space-between;
    }

    .top-row a, .top-row .btn-link {
        margin-left: 0;
    }

    /* Tablas: scroll horizontal en vez de desbordar */
    .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Barra superior: usuario + rol + boton en dos lineas si no cabe */
    .user-info {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.35rem !important;
        font-size: 0.78rem;
    }

    .user-info .badge {
        font-size: 0.65rem;
    }

    /* Hero: apilar icono y texto verticalmente */
    .streamlit-hero {
        flex-direction: column;
        text-align: center;
        padding: 1.2rem 1rem;
        gap: 1rem;
    }

    .streamlit-hero-icon {
        width: 60px;
        height: 60px;
    }

    .streamlit-hero-icon i {
        font-size: 1.8rem;
    }

    .streamlit-hero-text h3 {
        font-size: 1.1rem;
    }

    /* Graficos: altura adaptable */
    .graficos-container {
        height: calc(100vh - 6rem);
    }

    .graficos-header {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
    }

    /* Home: header mas compacto */
    .home-header h1 {
        font-size: 1.5rem;
    }
}


/* ───────── HOME ───────── */

.home-header h1 {
    color: var(--primary);
    font-weight: 700;
}

.home-header .lead {
    color: var(--text);
    font-size: 1.15rem;
}

.text-primary-custom {
    color: var(--primary);
    font-size: 1.1rem;
}

/* Hero Streamlit */
.streamlit-hero {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    background: linear-gradient(135deg, #E76F51 0%, #F4A261 100%);
    border-radius: 12px;
    text-decoration: none;
    color: var(--white);
    box-shadow: 0 4px 20px rgba(231, 111, 81, 0.3);
    transition: all 0.25s ease;
}

.streamlit-hero:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(231, 111, 81, 0.45);
    color: var(--white);
    text-decoration: none;
}

.streamlit-hero-icon {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.streamlit-hero-icon i {
    font-size: 2.5rem;
}

.streamlit-hero-text h3 {
    margin: 0 0 0.4rem 0;
    font-weight: 700;
    font-size: 1.25rem;
}

.streamlit-hero-text p {
    margin: 0 0 0.75rem 0;
    opacity: 0.9;
    font-size: 0.92rem;
    line-height: 1.4;
}

.streamlit-hero-btn {
    display: inline-block;
    padding: 0.4rem 1.2rem;
    background: var(--white);
    color: var(--primary);
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    transition: all 0.15s ease;
}

.streamlit-hero:hover .streamlit-hero-btn {
    background: rgba(255, 255, 255, 0.95);
}


/* ───────── GRAFICOS (iframe) ───────── */

.graficos-container {
    height: calc(100vh - 3.5rem);
    display: flex;
    flex-direction: column;
    padding: 0;
}

.graficos-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--white);
    border-bottom: 1px solid #c5c5c5;
    flex-shrink: 0;
}

.graficos-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--primary);
    font-weight: 600;
}

.graficos-iframe-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.graficos-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.graficos-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--text);
}

.graficos-loading .spinner-border {
    color: var(--primary) !important;
    width: 2.5rem;
    height: 2.5rem;
}

.graficos-error {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text);
}

.graficos-error i {
    font-size: 3rem;
    color: #F4A261;
    display: block;
    margin-bottom: 1rem;
}

.graficos-error h5 {
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.graficos-error code {
    display: inline-block;
    background: var(--sidebar-header);
    color: var(--white);
    padding: 0.5rem 1.2rem;
    border-radius: 6px;
    font-size: 0.9rem;
}


/* ───────── LOGIN ───────── */

.login-body {
    background: linear-gradient(135deg, #ededed 0%, #DADADA 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.login-card {
    background: var(--white);
    border-radius: 12px;
    padding: 2.5rem 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border: 1px solid #c5c5c5;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header i {
    font-size: 2.5rem;
    color: var(--primary);
    display: block;
    margin-bottom: 0.75rem;
}

.login-header h4 {
    color: var(--text);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.btn-login {
    padding: 0.6rem;
    font-size: 1rem;
    font-weight: 500;
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-light);
}

/* Barra superior: info de usuario */
.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.user-info .badge {
    font-weight: 500;
    font-size: 0.72rem;
}


/* ───────── DESEMPENO (Visualizacion) ───────── */

.desempeno-container {
    padding-top: 1rem;
}

.desempeno-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.desempeno-header h4 {
    color: var(--primary);
    font-weight: 600;
    margin: 0;
}

.desempeno-legend {
    font-size: 0.82rem;
    color: var(--text-light);
}

/* Grid grupal */
.desempeno-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0.5rem;
}

.desempeno-grid-cell {
    background: var(--white);
    border: 1px solid #d5d5d5;
    border-radius: 6px;
    padding: 0.25rem;
    text-align: center;
    overflow: hidden;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.desempeno-grid-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(231, 111, 81, 0.2);
    border-color: var(--primary);
}

.desempeno-grid-label {
    font-size: 0.7rem;
    color: var(--text);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.desempeno-mini-chart {
    width: 100%;
    height: 150px;
}

/* Panel de comentarios */
.desempeno-comments {
    max-height: 500px;
    overflow-y: auto;
}

.desempeno-comments h6 {
    color: var(--primary);
    font-weight: 600;
}

.desempeno-comments .badge {
    font-size: 0.75rem;
    vertical-align: middle;
}

/* Responsive grid */
@media (max-width: 1200px) {
    .desempeno-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

@media (max-width: 768px) {
    .desempeno-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .desempeno-mini-chart {
        height: 120px;
    }
}

/* Salomé avatar - pulso mientras habla */
.salome-avatar {
    transition: all 0.3s ease;
}
.salome-hablando {
    animation: salomePulso 1.5s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(46, 196, 182, 0.7);
}
@keyframes salomePulso {
    0% { box-shadow: 0 0 0 0 rgba(46, 196, 182, 0.7); transform: scale(1); }
    50% { box-shadow: 0 0 20px 8px rgba(46, 196, 182, 0.3); transform: scale(1.03); }
    100% { box-shadow: 0 0 0 0 rgba(46, 196, 182, 0.7); transform: scale(1); }
}
