/* =========================================================
 * BASE — Variables, reset, layout principal, sidebar
 * ========================================================= */

/* Variables CSS */
:root {
    --primary-color: #f75900;
    --primary-hover: #d94d00;
    --primary-light: #fff5f0;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;

    --bg-color: #ffffff;
    --surface-color: #ffffff;
    --border-color: #e5e7eb;
    --text-color: #1f2937;
    --text-muted: #6b7280;

    --sidebar-width: 260px;
    --header-height: 64px;

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
}

/* Reset y base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--text-color);
    background-color: var(--bg-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-wrap: break-word;
    min-width: 300px;
    overflow-x: auto;
}

/* Layout principal */
.app-container {
    display: flex;
    min-height: 100vh;
    background-color: #f9fafb;
}

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
}

.sidebar-logo {
    height: 50px;
    width: auto;
    max-width: 100%;
}

.login-logo-img {
    width: 100%;
    margin-bottom: 1rem;
}

.mobile-logo-link {
    display: flex;
    align-items: center;
    min-width: 0;
    max-width: calc(100% - 56px);
}

.mobile-logo {
    height: 40px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.hamburger {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background-color: var(--text-color);
    transition: all 0.3s;
    border-radius: 2px;
}

.hamburger.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.hamburger.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.sidebar-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background-color: var(--primary-light);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

.nav-item.active {
    background-color: var(--primary-light);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

.nav-item .nav-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.nav-item .nav-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9375rem;
}

.nav-item .nav-badge {
    background: var(--primary-light);
    color: var(--primary-color);
    font-size: 0.6875rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    margin-left: auto;
}

/* Drag handle */
.nav-item .drag-handle {
    cursor: grab;
    opacity: 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    user-select: none;
    transition: opacity 0.15s;
    padding-right: 0.25rem;
}
.nav-item:hover .drag-handle { opacity: 0.6; }
.nav-item .drag-handle:active { cursor: grabbing; }
.nav-item.dragging {
    opacity: 0.4;
    background-color: var(--primary-light);
}

/* Secciones del sidebar (Favoritos / Categorías) */
.sidebar-section {
    margin-top: 1.25rem;
}
.sidebar-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25rem 1.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
}
.sidebar-section-action {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 0.375rem;
    width: 24px;
    height: 24px;
    line-height: 1;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s;
}
.sidebar-section-action:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-color);
}
.sidebar-list {
    display: flex;
    flex-direction: column;
    min-height: 4px;
}
.sidebar-empty {
    padding: 0.5rem 1.25rem 0.875rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-style: italic;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background-color: #f9fafb;
}

.user-info {
    margin-bottom: 0.75rem;
}

.user-info strong {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-info small {
    color: var(--text-muted);
    font-size: 0.8125rem;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    display: block;
    width: 100%;
    padding: 0.625rem;
    text-align: center;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.875rem;
}

.btn-logout:hover {
    background-color: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    min-height: 100vh;
    min-width: 0;
}

/* Enlaces sueltos dentro de un texto: sin esto salían en el azul por defecto
   del navegador, que en modo oscuro casi no se ve. */
.main-content p a:not([class]),
.main-content li a:not([class]) {
    color: var(--primary-color);
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    color: var(--text-color);
}

.page-header p {
    color: var(--text-muted);
    font-size: 1rem;
}

/* =========================================================
 * OCULTAR EL MENÚ LATERAL (solo escritorio) — js/sidebar-ocultar.js
 * El estado es <html class="sidebar-oculto">. En móvil no aplica: allí
 * el menú ya es un panel que abre y cierra la hamburguesa.
 * ========================================================= */
.btn-sidebar-ocultar {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.btn-sidebar-ocultar:hover,
.btn-sidebar-ocultar:focus-visible {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-sidebar-mostrar {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 150;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-muted);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.btn-sidebar-mostrar:hover,
.btn-sidebar-mostrar:focus-visible {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

@media (min-width: 1024px) {
    .main-content { transition: margin-left 0.3s ease, padding-left 0.3s ease; }

    html.sidebar-oculto .sidebar {
        transform: translateX(-100%);
        visibility: hidden;          /* fuera del orden de tabulación mientras está oculto */
        transition: transform 0.3s ease, visibility 0s linear 0.3s;
    }
    html.sidebar-oculto .main-content {
        margin-left: 0;
        padding-left: calc(2rem + 46px);   /* sitio para el botón flotante de mostrar */
    }
    html.sidebar-oculto .btn-sidebar-mostrar { display: flex; }
}
@media (max-width: 1023px) {
    .btn-sidebar-ocultar { display: none; }
}

/* =========================================================
 * RESPONSIVE — layout base
 * ========================================================= */

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

    .sidebar {
        transform: translateX(-100%);
        width: 100%;
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }

    .sidebar-header {
        display: none;
    }

    .main-content {
        margin-left: 0;
        margin-top: var(--header-height);
        padding: 1.5rem 1rem;
    }

    .page-header h1 {
        font-size: 1.75rem;
    }
}

@media (max-width: 480px) {
    .page-header h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 400px) {
    .main-content {
        padding: 1rem 0.75rem;
    }

    .page-header h1 {
        font-size: 1.375rem;
    }
}
