/*
 * @file layout.css
 * @description Structural CSS for the SPA Shell (Sidebar, Topbar, Login, Vehicle Panel).
 * All color values use CSS custom properties set by ThemeManager on :root.
 * No hardcoded hex colors — only structure, spacing, and typography classes.
 *
 * Loaded via <link> in index.html so it is globally available before any JS runs.
 */

/* ─── Raíz / Cuerpo ───────────────────────────────────────────────────────────── */

html {
    height: 100%;
    width: 100%;
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--typography-font-family, system-ui, sans-serif);
    font-size: var(--typography-base-size, 16px);
    color: var(--color-text, #1a1a1a);
    background: var(--color-background, #f0f4f8);
    transition: background 0.3s ease, color 0.3s ease;
}

/* ─── Contenedor de la Aplicación (Raíz) ─────────────────────────────────────── */

#app-root {
    width: 100vw;
    height: 100vh;
    position: relative;
    /* Evitar selección de texto en la estructura principal */
    user-select: none;
    -webkit-user-select: none;
}

/* ─── Estructura Principal (Shell Grid) ──────────────────────────────────────── */

.shell {
    position: absolute;
    inset: 0;
    display: flex;
    /* Cambiar a columna flex para móviles (Barra Superior + Principal) */
    flex-direction: column;
    pointer-events: none;
    z-index: 10;
}

/* ─── Barra Superior (Topbar) ────────────────────────────────────────────────── */

.topbar {
    /* Sin área de cuadrícula en móviles */
    height: 60px;
    flex-shrink: 0;
    pointer-events: auto;
    background: var(--color-topbar-bg, var(--color-surface, #ffffff));
    color: var(--color-topbar-text, var(--color-text, #1a1a1a));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    /* padding ligeramente menor en móviles */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 20;
    /* Mantener sobre la capa superpuesta del menú lateral */
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    transition: background 0.3s ease, color 0.3s ease;
}

.topbar__left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar__breadcrumbs {
    font-size: 0.9em;
    color: var(--color-text, #4a5568);
    opacity: 0.8;
}

.topbar__breadcrumbs .active {
    color: var(--color-primary);
    font-weight: 600;
    opacity: 1;
}

.topbar__breadcrumbs .sep {
    margin: 0 8px;
    opacity: 0.4;
}

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

.topbar__user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}

.topbar__user-name {
    font-weight: 600;
    font-size: 0.9em;
    color: var(--color-text);
}

.topbar__tenant-name {
    font-size: 0.78em;
    opacity: 0.6;
    color: var(--color-text);
}

.topbar__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9em;
    flex-shrink: 0;
}

.topbar__divider {
    width: 1px;
    height: 24px;
    background: var(--color-text, #000);
    opacity: 0.1;
}

.topbar__icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text);
    opacity: 0.7;
    display: flex;
    align-items: center;
    padding: 6px;
    /* área de clic ligeramente más grande */
    border-radius: 4px;
    transition: opacity 0.2s, background 0.2s;
}

.topbar__icon-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.06);
}

.topbar__menu-btn {
    display: flex;
    /* Visible por defecto en móviles */
}

.topbar__logout {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text);
    font-size: 0.85em;
    font-weight: 600;
    opacity: 0.65;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--spacing-radius, 4px);
    transition: background 0.2s, opacity 0.2s;
}

.topbar__logout:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.06);
}

/* ─── Menú Lateral (Desplegable por defecto para Móviles) ─────────────────────── */

.sidebar-overlay {
    position: fixed;
    inset: 0;
    top: 60px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 14;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.sidebar {
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    width: 250px;
    pointer-events: auto;
    background: var(--color-nav-bg, #1a1a1a);
    color: var(--color-nav-text, #a0aec0);
    display: flex;
    flex-direction: column;
    z-index: 15;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease, color 0.3s ease;
}

.sidebar.mobile-open {
    transform: translateX(0);
}

.sidebar__logo {
    height: 0;
    /* Ocultar por defecto en móviles a menos que se desee, o mantener pequeño */
    display: none;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    font-size: 1.15em;
    font-weight: bold;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
}

.sidebar__logo-icon {
    width: 26px;
    height: 26px;
    background: var(--color-primary);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Estilos de Acordeón */
.sidebar__nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px 0;
    overflow-y: auto;
    gap: 2px;
}

.sidebar__nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-nav-text, #a0aec0);
    text-decoration: none;
    padding: 11px 20px;
    font-size: 0.92em;
    border-left: 3px solid transparent;
    transition: background 0.18s, color 0.18s, border-color 0.18s;
}

.sidebar__nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

/* Estados Activos */
.sidebar__nav-link.active {
    background: rgba(66, 153, 225, 0.13);
    color: #ffffff;
    border-left-color: var(--color-primary, #4299e1);
}

.sidebar__nav-link svg {
    flex-shrink: 0;
    opacity: 0.8;
}

.sidebar__nav-link.active svg {
    color: var(--color-primary, #4299e1);
    opacity: 1;
}

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

.sidebar__accordion {
    display: flex;
    flex-direction: column;
}

.sidebar__accordion-header {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-nav-text, #a0aec0);
    background: none;
    border: none;
    border-left: 3px solid transparent;
    padding: 11px 20px;
    font-size: 0.92em;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.18s, color 0.18s;
}

.sidebar__accordion-header:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.sidebar__accordion-header svg {
    flex-shrink: 0;
    opacity: 0.8;
}

.sidebar__accordion-icon-chevron {
    margin-left: auto;
    transition: transform 0.2s ease;
}

.sidebar__accordion.open .sidebar__accordion-icon-chevron {
    transform: rotate(180deg);
}

.sidebar__accordion-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease;
    background: rgba(0, 0, 0, 0.15);
}

.sidebar__accordion.open .sidebar__accordion-content {
    max-height: 200px;
}

/* Child links inside accordion get extra padding */
.sidebar__accordion-content .sidebar__nav-link {
    padding-left: 48px;
    font-size: 0.85em;
    border-left: none;
    /* remove accent border for inner links to keep it clean */
}

/* ─── Contenido Principal (Transparente) ──────────────────────────────────────── */

.shell-main {
    flex: 1;
    /* Ocupar la altura restante debajo de la barra superior */
    pointer-events: none;
    position: relative;
    overflow: hidden;
}

/* ─── Diseño de Login ─────────────────────────────────────────────────────────── */

.login-backdrop {
    position: absolute;
    inset: 0;
    background: var(--color-background, #f0f4f8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* ─── Floating UI Panel (Vehicle List, Overlays) ──────────────────────────────── */

.floating-panel {
    pointer-events: auto;
    background: var(--color-surface, #ffffff);
    border-radius: var(--spacing-radius, 6px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 20;
}

.floating-panel__header {
    padding: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

.floating-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.floating-panel__footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

/* ─── searchbar row ───────────────────────────────────────────────────────────── */

.search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.panel-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.78em;
    font-weight: bold;
    color: var(--color-text);
    opacity: 0.55;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── Vista de Escritorio (≥ 768px) ────────────────────────────────────────────── */

@media (min-width: 768px) {
    .shell {
        display: grid;
        flex-direction: row;
        /* reiniciar configuración flex */
        grid-template-columns: 240px 1fr;
        grid-template-rows: 60px 1fr;
        grid-template-areas:
            'sidebar topbar'
            'sidebar main';
    }

    .topbar {
        grid-area: topbar;
        padding: 0 24px;
        z-index: 12;
    }

    .topbar__menu-btn {
        display: none;
        /* Ocultar ícono de menú hamburguesa en escritorio */
    }

    /* Deshacer estilos desplegables móviles */
    .sidebar {
        grid-area: sidebar;
        position: relative;
        top: 0;
        width: auto;
        transform: none;
        /* Siempre visible */
        z-index: 13;
    }

    .sidebar__logo {
        display: flex;
        /* Mostrar logo en escritorio */
        height: 60px;
    }

    .sidebar-overlay {
        display: none;
        /* Nunca mostrar capa superpuesta en escritorio */
    }

    .shell-main {
        grid-area: main;
        flex: auto;
        /* reiniciar flex */
    }
}

/* ─── Excepciones para Móviles (< 768px) ─────────────────────────────────────── */
@media (max-width: 767px) {

    /* Ocultar textos no esenciales en pantallas pequeñas */
    .topbar__user-info,
    .topbar__breadcrumbs .sep,
    .topbar__breadcrumbs span:not(.active) {
        display: none;
    }

    .topbar__logout {
        padding: 6px;
    }

    .topbar__logout-text {
        display: none;
        /* solo ícono en pantallas extremadamente pequeñas */
    }
}