/* ============================================================
   GLOBAL LAYOUT - Estilos compartidos para TODAS las páginas
   (incluyendo sidebar inyectado por sidebar.js)
   ============================================================ */

html {
    background: #1e2a38; /* sidebar color visible on very first frame */
}

body {
    height: 100vh !important;
    overflow: hidden !important;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f4f7fa;
    opacity: 0; /* sidebar.js fades this in after layout is ready */
}

/* ── App Layout ──────────────────────────────────────────────────────────── */

.app-wrapper {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width, 260px);
    background: #1e2a38;
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 15px rgba(0,0,0,0.15);
    z-index: 1000;
    flex-shrink: 0;
    transition: width 0.25s ease, margin-left 0.25s ease, transform 0.3s ease;
    overflow: hidden;
}

/* ── Botón toggle hamburguesa (siempre visible) ─────────────────────────── */
.sidebar-toggle-btn {
    color: white;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 4px 10px;
    transition: background 0.15s ease, transform 0.2s ease;
}
.sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: white;
    transform: scale(1.05);
}
.sidebar-toggle-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 188, 212, 0.4);
}

/* ── Sidebar colapsado (desktop): se reduce a width 0 ─────────────────── */
@media (min-width: 993px) {
    .app-wrapper.sidebar-collapsed .sidebar {
        width: 0;
        min-width: 0;
        box-shadow: none;
    }
}

.sidebar-header {
    padding: 1.5rem 1.5rem 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header-sucursal {
    margin-top: 0.5rem;
    font-size: 11px;
    color: rgba(255,255,255,0.5);
    letter-spacing: 0.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-brand {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.sidebar-brand i {
    color: var(--accent-color, #00bcd4);
    font-size: 20px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-section {
    padding: 0.5rem 1.5rem;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.35);
    margin-top: 0.75rem;
}

.nav-item {
    padding: 0.65rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    transition: all 0.18s ease;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.nav-item i {
    font-size: 16px;
    width: 18px;
    text-align: center;
}

.nav-item:hover {
    color: white;
    background: rgba(0, 188, 212, 0.12);
}

.nav-item.active {
    color: white;
    background: var(--accent-color, #00bcd4);
    box-shadow: 0 2px 10px rgba(0, 188, 212, 0.3);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
    color: rgba(255,255,255,0.65);
    font-size: 13px;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-sucursal {
    color: rgba(255,255,255,0.4);
    font-size: 11px;
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Main Content ────────────────────────────────────────────────────────── */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: #f4f7fa;
    position: relative; /* needed for search overlay */
    min-width: 0;
}

/* ── Page Header (sticky top bar inside main-content) ────────────────────── */

.page-header,
#app-header {
    background: var(--accent-color, #00bcd4);
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 188, 212, 0.2);
    position: sticky;
    top: 0;
    z-index: 999;
    min-height: 54px;
    gap: 0.75rem;
    flex-shrink: 0;
}

.page-header .page-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: white;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.page-header .page-title i {
    font-size: 1.15rem;
    color: rgba(255,255,255,0.85);
}

.page-header .btn-back {
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    padding: 5px 14px;
    font-weight: 500;
    font-size: 0.85rem;
    color: white;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.page-header .btn-back:hover {
    background: rgba(255,255,255,0.28);
    transform: translateY(-1px);
}

/* ── Search Bar (inside page-header) ─────────────────────────────────────── */

.global-search-wrapper {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.global-search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255,255,255,0.65);
    font-size: 0.88rem;
    pointer-events: none;
    z-index: 1;
}

.global-search-input {
    width: 100%;
    padding: 8px 16px 8px 36px;
    border: none;
    border-radius: 22px;
    background: rgba(255,255,255,0.22);
    color: white;
    outline: none;
    font-size: 0.9rem;
    font-family: inherit;
    transition: background 0.2s;
}

.global-search-input:focus {
    background: rgba(255,255,255,0.32);
}

.global-search-input::placeholder {
    color: rgba(255,255,255,0.6);
}

/* ── Search Results Overlay (full-page panel below header) ───────────────── */

.search-overlay {
    display: none;
    flex-direction: column;
    background: #f4f7fa;
    overflow: hidden;
    position: fixed;
    top: 54px; /* sticky header height */
    left: 260px; /* sidebar width */
    right: 0;
    bottom: 0;
    z-index: 998;
}

.search-overlay.active {
    display: flex;
}

.search-overlay-header {
    background: white;
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
    font-size: 0.9rem;
    color: #6c757d;
}

.search-overlay-header strong {
    color: #1e2a38;
}

.search-overlay-close {
    background: none;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.82rem;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.search-overlay-close:hover {
    background: #f8f9fa;
    color: #333;
}

.search-overlay-body {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    flex: 1;
    align-content: start;
}

.search-col-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #1e2a38;
    padding-bottom: 0.6rem;
    border-bottom: 2px solid var(--accent-color, #00bcd4);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 7px;
}

.search-result-card {
    background: white;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    border: 1px solid #ececec;
    transition: all 0.15s;
}

.search-result-card:hover {
    border-color: var(--accent-color, #00bcd4);
    box-shadow: 0 2px 10px rgba(0,188,212,0.12);
    transform: translateY(-1px);
}

.search-result-card-name {
    font-weight: 600;
    font-size: 0.88rem;
    color: #1e2a38;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-card-detail {
    font-size: 0.78rem;
    color: #6c757d;
}

.search-col-empty {
    color: #b0b8c4;
    font-size: 0.83rem;
    text-align: center;
    padding: 1.5rem 0;
}

.search-col-loading {
    color: #9ca3af;
    font-size: 0.83rem;
    text-align: center;
    padding: 2rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ── Page Content ────────────────────────────────────────────────────────── */

.page-content {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
    width: 100%;
    animation: fadeInPage 0.3s ease-out;
}

@keyframes fadeInPage {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Tables ──────────────────────────────────────────────────────────────── */

.page-content .table thead {
    background: #1e2a38;
    color: white;
}

.page-content .table thead th {
    font-weight: 500;
    font-size: 0.82rem;
    padding: 12px 10px;
    border: none;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.page-content .table tbody td {
    padding: 10px;
    font-size: 0.85rem;
    vertical-align: middle;
}

.page-content .table tbody tr {
    transition: background 0.15s;
}

.page-content .table-hover tbody tr:hover {
    background-color: rgba(0, 188, 212, 0.06);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        position: absolute;
        height: 100vh;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .global-search-wrapper {
        flex: 1;
        max-width: none;
    }
    .search-overlay {
        left: 0; /* sidebar hidden on mobile */
    }
    .search-overlay-body {
        grid-template-columns: repeat(2, 1fr);
        padding: 1rem;
    }
    .page-header {
        padding: 0 1rem;
    }
    .page-content {
        padding: 1rem;
    }
}

/* ── Print ───────────────────────────────────────────────────────────────── */

@media print {
    .sidebar, .page-header, .search-overlay {
        display: none !important;
    }
    .app-wrapper {
        display: block !important;
    }
    .main-content {
        overflow: visible !important;
        position: static !important;
    }
    body {
        height: auto !important;
        overflow: auto !important;
    }
}
