/* ==========================================================================
   style.css — Estructura y componentes del sistema
   Las tonalidades de color viven en themes.css (variables CSS)
   ========================================================================== */

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg-app);
    color: var(--text-main);
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-soft);
    padding: 10px 20px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand-mini { display: flex; align-items: center; gap: 10px; }
.brand-logo {
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
}
.brand-name { font-weight: 600; font-size: 1.1rem; color: var(--text-main); }

.topbar-right { display: flex; align-items: center; gap: 16px; }

.btn-icon {
    background: var(--bg-app);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    width: 36px; height: 36px;
    cursor: pointer;
    font-size: 1rem;
    transition: background .15s ease;
}
.btn-icon:hover { background: var(--color-primary-light); }

.profile-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.profile-info { display: flex; flex-direction: column; line-height: 1.2; }
.profile-name { font-weight: 600; font-size: .92rem; }
.profile-role { font-size: .78rem; color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: .82rem; }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { filter: brightness(0.94); }

.btn-danger { background: #E05A5A; color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }

.btn-secondary { background: var(--bg-app); color: var(--text-main); border: 1px solid var(--border-soft); }
.btn-secondary:hover { background: var(--color-primary-light); }

.btn-azure { background: #ffffff; color: #2b2b2b; border: 1px solid var(--border-soft); }
.btn-azure:hover { background: #f3f3f3; }
.azure-icon { color: #0078D4; font-weight: 700; }

/* ---------- Layout general (sidebar a la derecha) ---------- */
.app-layout {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - 58px);
}

.content-area {
    flex: 1 1 auto;
    padding: 24px;
    min-width: 0;
    transition: margin-right .2s ease;
}

.welcome-panel {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* ---------- Sidebar (derecha) ---------- */
.sidebar {
    width: 270px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-soft);
    height: calc(100vh - 58px);
    position: sticky;
    top: 58px;
    display: flex;
    flex-direction: column;
    transition: width .2s ease, transform .2s ease, opacity .2s ease;
    overflow: hidden;
}
.sidebar.is-collapsed {
    width: 0;
    border-left: none;
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--border-soft);
    white-space: nowrap;
}

.sidebar-nav { padding: 10px; white-space: nowrap; flex: 1 1 auto; overflow-y: auto; }

.menu-link {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    outline: none;
    text-align: left;
    padding: 11px 12px;
    border-radius: 8px;
    font-size: .92rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
}
.menu-link:hover { background: var(--color-primary-light); }
.menu-link:focus-visible { box-shadow: 0 0 0 2px var(--color-primary); }
.menu-link-single.active { background: var(--color-primary-light); color: var(--color-primary); }

.btn-open-sidebar {
    position: fixed;
    right: 14px;
    top: 74px;
    width: 42px; height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--color-primary);
    color: #fff;
    font-size: 1.1rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.18);
    cursor: pointer;
    z-index: 25;
}

/* ---------- Pie del menú: perfil del usuario activo + Cerrar sesión ---------- */
.sidebar-footer {
    flex-shrink: 0;
    margin-top: auto;
    padding: 14px;
    border-top: 1px solid var(--border-soft);
    white-space: normal;
}
.sidebar-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.sidebar-profile .profile-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-profile .profile-info { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.sidebar-profile .profile-name {
    font-weight: 700;
    font-size: .88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-profile .profile-role { font-size: .76rem; color: var(--text-muted); }

.btn-logout-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    background: transparent;
    color: var(--text-main);
    font-size: .86rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-logout-footer:hover { background: var(--color-primary-light); border-color: var(--color-primary); }

/* ---------- Login ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--bg-app), var(--color-primary-light));
}
.login-wrapper { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
    background: var(--bg-panel);
    border-radius: 14px;
    padding: 32px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.12);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-logo {
    width: 54px; height: 54px;
    border-radius: 12px;
    background: var(--color-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.2rem;
    margin: 0 auto 10px;
}
.login-brand h1 { font-size: 1.15rem; margin: 4px 0; }
.login-brand p { color: var(--text-muted); font-size: .85rem; margin: 0; }

.login-card form label { display: block; font-size: .82rem; font-weight: 600; margin: 12px 0 6px; }
.login-card form input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    font-size: .92rem;
    background: var(--bg-app);
    color: var(--text-main);
}
.login-card form input:focus { outline: 2px solid var(--color-primary); }
.login-card .btn { margin-top: 18px; }

.login-divider { text-align: center; margin: 18px 0; position: relative; color: var(--text-muted); font-size: .8rem; }
.login-divider::before, .login-divider::after {
    content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border-soft);
}
.login-divider::before { left: 0; }
.login-divider::after { right: 0; }

.login-footer { text-align: center; font-size: .78rem; color: var(--text-muted); margin-top: 18px; }

/* ---------- Popups (modal de aviso) ---------- */
.popup-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.popup-overlay[hidden] {
    display: none;
}
.popup-box {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 28px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    position: relative;
    box-shadow: 0 12px 30px rgba(0,0,0,0.25);
}
.popup-icon { font-size: 2rem; margin-bottom: 8px; }
.popup-error .popup-icon { color: #E05A5A; }
.popup-close {
    position: absolute; top: 10px; right: 12px;
    background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted);
}
.popup-box h3 { margin: 6px 0; }
.popup-box p { color: var(--text-muted); font-size: .9rem; }

/* ---------- Tooltip / botones de información con popup flotante ---------- */
.info-btn-wrap { position: relative; display: inline-flex; }
.info-btn {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    border: none;
    font-size: .74rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.info-tooltip {
    position: absolute;
    z-index: 50;
    background: #2c2f36;
    color: #fff;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: .8rem;
    line-height: 1.35;
    width: max-content;
    max-width: 240px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
    opacity: 0;
    visibility: hidden;
    transition: opacity .12s ease;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
}
.info-btn-wrap:hover .info-tooltip,
.info-btn-wrap:focus-within .info-tooltip,
.info-btn-wrap.show-tooltip .info-tooltip { opacity: 1; visibility: visible; }
.info-tooltip::after {
    content: '';
    position: absolute;
    top: 100%; left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #2c2f36;
}

/* ---------- Details / ayuda (fondo gris opaco, letras blancas en el título) ---------- */
details.help-box {
    margin: 16px 0;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    overflow: hidden;
}
details.help-box summary {
    background: #5c6470;
    color: #ffffff;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
details.help-box summary::-webkit-details-marker { display: none; }
details.help-box summary::before { content: '❔ '; }
details.help-box .help-content {
    padding: 14px;
    background: var(--bg-panel);
    font-size: .88rem;
    color: var(--text-main);
}

/* ---------- Vistas / tarjetas de contenido ---------- */
.view-card {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 18px;
}
.view-title {
    display: flex; align-items: center; gap: 10px;
    margin-top: 0;
}
.view-subtitle { color: var(--text-muted); font-size: .88rem; margin: 0; }

/* ---------- Formularios genéricos ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin: 16px 0;
}
.form-field label {
    display: flex; align-items: center; gap: 6px;
    font-size: .85rem; font-weight: 600; margin-bottom: 6px;
}
.form-field input[type="text"],
.form-field input[type="date"],
.form-field input[type="number"],
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 9px 10px;
    border-radius: 7px;
    border: 1px solid var(--border-soft);
    background: var(--bg-app);
    color: var(--text-main);
    font-size: .88rem;
}

.check-group, .radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin: 8px 0 16px;
}
.check-group label, .radio-group label {
    display: flex; align-items: center; gap: 6px;
    font-size: .88rem;
    background: var(--bg-app);
    border: 1px solid var(--border-soft);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

/* ---------- Tabla genérica ---------- */
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}
table.data-table th, table.data-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: top;
}
table.data-table th {
    background: var(--color-primary-light);
    font-weight: 700;
}
table.data-table tr:hover { background: var(--bg-app); }

/* ---------- FAQ ---------- */
.faq-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Configuración: selector de temas ---------- */
.theme-options { display: flex; gap: 16px; flex-wrap: wrap; margin: 16px 0; }
.theme-card {
    border: 2px solid var(--border-soft);
    border-radius: 10px;
    padding: 14px;
    width: 160px;
    cursor: pointer;
    text-align: center;
}
.theme-card.selected { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.theme-swatch { height: 50px; border-radius: 6px; margin-bottom: 8px; }

/* ---------- Status / feedback ---------- */
.form-status { margin-top: 10px; font-size: .85rem; font-weight: 600; }
.form-status.ok { color: #2f9e57; }
.form-status.warn { color: #b8860b; }

/* ---------- Badge modo demo ---------- */
.demo-badge {
    display: inline-block;
    background: #FFF3CD;
    color: #7a5b00;
    border: 1px solid #f0d888;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: .78rem;
    font-weight: 700;
    margin-bottom: 12px;
    text-align: center;
    width: 100%;
}
.demo-badge-inline { width: auto; margin-bottom: 0; }

/* ---------- Breadcrumb ---------- */
.breadcrumb-bar {
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: 14px;
}
.breadcrumb-item.breadcrumb-current { color: var(--color-primary); font-weight: 700; }
.breadcrumb-sep { margin: 0 6px; }

/* ---------- Tabs de navegación (submenú horizontal) ---------- */
.tabs-bar {
    display: flex;
    gap: 4px;
    background: var(--bg-panel);
    border-radius: 10px;
    padding: 6px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.tab-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
}
.tab-link:hover { background: var(--color-primary-light); color: var(--text-main); }
.tab-link.active {
    color: var(--color-primary);
    background: var(--color-primary-light);
    border-bottom: 2px solid var(--color-primary);
}
.tab-icon { font-size: .95rem; }

/* ---------- Encabezado de vista (título + acciones) ---------- */
.view-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.view-title-big {
    margin: 0 0 8px;
    font-size: 1.4rem;
    color: var(--color-primary);
    font-weight: 800;
}
.view-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Tablas con scroll horizontal en pantallas angostas ---------- */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive table.data-table { min-width: 560px; }

/* ---------- Fondo oscuro tras el menú lateral en móvil/tablet ---------- */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    top: 58px;
    background: rgba(0,0,0,0.35);
    z-index: 29;
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */

/* ----- Tablets (≤ 1024px): el menú pasa a superponerse sobre el contenido ----- */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        right: 0;
        top: 58px;
        z-index: 30;
        box-shadow: -6px 0 18px rgba(0,0,0,0.18);
        height: calc(100vh - 58px);
        width: 300px;
    }
    .content-area { padding: 20px; }
}

/* ----- Tablets pequeñas / celulares en horizontal (≤ 860px) ----- */
@media (max-width: 860px) {
    .sidebar { width: 280px; }
    .form-grid { grid-template-columns: 1fr; }
    .theme-options { justify-content: center; }
}

/* ----- Celulares (≤ 600px) ----- */
@media (max-width: 600px) {
    .topbar { padding: 8px 12px; }
    .brand-name { display: none; } /* el logo "SG" ya identifica la app; libera espacio */
    .demo-badge-inline { font-size: .68rem; padding: 4px 8px; }

    .content-area { padding: 14px; }
    .welcome-panel, .view-card { padding: 16px; border-radius: 10px; }

    .sidebar { width: 85vw; max-width: 320px; }
    .btn-open-sidebar { right: 10px; top: 68px; width: 46px; height: 46px; }

    /* Objetivos táctiles más grandes (mínimo ~40-44px recomendado) */
    .btn-icon { width: 40px; height: 40px; }
    .info-btn { width: 24px; height: 24px; font-size: .8rem; }
    .btn { padding: 11px 16px; }
    .check-group label, .radio-group label { padding: 10px 14px; }

    /* Breadcrumb y pestañas se acomodan en una sola línea con scroll */
    .breadcrumb-bar { font-size: .76rem; white-space: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tabs-bar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tab-link { flex-shrink: 0; padding: 9px 12px; font-size: .84rem; }

    .view-title-big { font-size: 1.2rem; }
    .view-header-row { flex-direction: column; align-items: stretch; }
    .view-actions { justify-content: flex-start; }

    .login-wrapper { padding: 14px; }
    .login-card { padding: 22px; }

    .popup-box { padding: 22px; width: 92%; }

    .theme-card { width: 130px; }

    .sidebar-profile .profile-name { font-size: .84rem; }
}

/* ----- Celulares muy pequeños (≤ 380px) ----- */
@media (max-width: 380px) {
    .sidebar { width: 90vw; }
    .form-field label { flex-wrap: wrap; }
    .btn-block { font-size: .88rem; }
}
