/* ═══════════════════════════════════════════════════════════════
   91STUDIO — LAYOUT SHELL v3.0.0 (Apple HIG)
   CSS Grid : sidebar (240→64→hidden) + main (flex:1) + panel (400-600px)
   Bottom nav mobile pill shape 6 items
   Sidebar Apple HIG : fond #f5f5f7, sections 9px uppercase, items 13px
   ═══════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────
   1. SHELL GRID — Conteneur principal
   ─────────────────────────────────────────── */
.app-shell {
    display: grid;
    grid-template-columns: var(--shell-sidebar-width, 240px) 1fr;
    grid-template-rows: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg-primary);
    transition: grid-template-columns var(--transition-base);
}

/* Panel ouvert — 3 colonnes */
.app-shell.shell-panel-open {
    grid-template-columns: var(--shell-sidebar-width, 240px) 1fr var(--shell-panel-width, 480px);
}

/* Sidebar collapsed — 64px */
.app-shell.shell-sidebar-collapsed {
    --shell-sidebar-width: 64px;
}

/* Sidebar collapsed + panel */
.app-shell.shell-sidebar-collapsed.shell-panel-open {
    grid-template-columns: 64px 1fr var(--shell-panel-width, 480px);
}

/* Sidebar hidden (mobile) */
.app-shell.shell-sidebar-hidden {
    grid-template-columns: 1fr;
}
.app-shell.shell-sidebar-hidden.shell-panel-open {
    grid-template-columns: 1fr;
}

/* ───────────────────────────────────────────
   2. SIDEBAR — Navigation principale
   ─────────────────────────────────────────── */
.shell-sidebar {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    width: var(--shell-sidebar-width, 240px);
    height: 100vh;
    height: 100dvh;
    position: sticky;
    top: 0;
    background: var(--surface-sidebar, #f5f5f7);
    border-right: 0.5px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--transition-base), background-color 0.3s ease;
    z-index: 50;
}

/* Logo en haut */
.shell-sidebar-logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-md);
    min-height: 56px;
    text-decoration: none;
    color: var(--text-primary);
    flex-shrink: 0;
}
.shell-sidebar-logo .logo-91 {
    font-weight: 700;
    font-size: 20px;
    letter-spacing: -0.04em;
}
.shell-sidebar-logo .logo-studio {
    font-weight: 300;
    font-size: 20px;
    letter-spacing: 0.1em;
}

/* Bouton collapse sidebar */
.shell-sidebar-collapse {
    position: absolute;
    top: 16px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-tertiary);
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast), background var(--transition-fast);
}
.shell-sidebar:hover .shell-sidebar-collapse {
    opacity: 1;
}
.shell-sidebar-collapse:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ───────────────────────────────────────────
   3. GROUPES DE NAVIGATION — Principaux|Outils|IA
   ─────────────────────────────────────────── */
.shell-nav {
    flex: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
    overflow-y: auto;
}

.shell-nav-group {
    margin-bottom: var(--spacing-xs);
}

.shell-nav-group-label {
    padding: var(--spacing-sm) var(--spacing-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    user-select: none;
}

/* Lien de navigation */
.shell-nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
    font-weight: 400;
    min-height: 36px;
    transition: background var(--transition-fast), color var(--transition-fast);
    position: relative;
    cursor: pointer;
}
.shell-nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Lien actif — fond + barre gauche accent */
.shell-nav-item.active {
    background: var(--bg-active);
    color: var(--text-primary);
    font-weight: 500;
}
.shell-nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent-blue);
}

.shell-nav-item svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.shell-nav-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ───────────────────────────────────────────
   4. SIDEBAR COLLAPSED — Icônes only 64px
   ─────────────────────────────────────────── */
.app-shell.shell-sidebar-collapsed .shell-sidebar {
    width: 64px;
}

.app-shell.shell-sidebar-collapsed .shell-sidebar-logo .logo-studio {
    display: none;
}

.app-shell.shell-sidebar-collapsed .shell-nav-group-label {
    display: none;
}

.app-shell.shell-sidebar-collapsed .shell-nav-item span {
    display: none;
}

.app-shell.shell-sidebar-collapsed .shell-nav-item {
    justify-content: center;
    padding: 8px;
}

.app-shell.shell-sidebar-collapsed .shell-nav-item.active::before {
    top: 8px;
    bottom: 8px;
}

/* Tooltip au hover en collapsed */
.app-shell.shell-sidebar-collapsed .shell-nav-item {
    position: relative;
}
.app-shell.shell-sidebar-collapsed .shell-nav-item[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    padding: 4px 10px;
    background: var(--text-primary);
    color: var(--bg-primary);
    font-size: var(--font-size-xs);
    font-weight: 500;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 100;
    transition: opacity var(--transition-fast);
}
.app-shell.shell-sidebar-collapsed .shell-nav-item[data-tooltip]:hover::after {
    opacity: 1;
}

/* Section utilisateur bas */
.app-shell.shell-sidebar-collapsed .shell-user-section .shell-user-name,
.app-shell.shell-sidebar-collapsed .shell-user-section .shell-user-role {
    display: none;
}

/* ───────────────────────────────────────────
   5. SECTION UTILISATEUR — Bas de sidebar
   ─────────────────────────────────────────── */
.shell-user-section {
    flex-shrink: 0;
    padding: var(--spacing-sm) var(--spacing-sm);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.shell-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.shell-user-info {
    flex: 1;
    min-width: 0;
}

.shell-user-name {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shell-user-role {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    text-transform: none;
    letter-spacing: -0.08px;
}

/* ───────────────────────────────────────────
   6. MAIN CONTENT — Zone principale flex:1
   ─────────────────────────────────────────── */
.shell-main {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    background: var(--bg-primary);
}

.app-shell.shell-sidebar-hidden .shell-main {
    grid-column: 1;
}

/* ───────────────────────────────────────────
   7. PANEL — Panneau droit resizable 400-600px
   ─────────────────────────────────────────── */
.shell-panel {
    grid-column: 3;
    grid-row: 1;
    width: var(--shell-panel-width, 480px);
    min-width: 400px;
    max-width: 600px;
    height: 100vh;
    height: 100dvh;
    position: sticky;
    top: 0;
    background: var(--surface-card);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition-theme);
}

.shell-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    min-height: 48px;
    flex-shrink: 0;
}

.shell-panel-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.shell-panel-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.shell-panel-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.shell-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
}

/* Resize handle entre main et panel */
.shell-panel-resize {
    position: absolute;
    left: -3px;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
    transition: background var(--transition-fast);
}
.shell-panel-resize:hover,
.shell-panel-resize.dragging {
    background: var(--accent-blue);
}

/* Panel hidden par défaut */
.shell-panel {
    display: none;
}
.app-shell.shell-panel-open .shell-panel {
    display: flex;
}

/* ───────────────────────────────────────────
   8. BOTTOM NAV — Mobile pill shape 6 items
   ─────────────────────────────────────────── */
.shell-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--surface-card);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-xs) var(--spacing-sm);
    padding-bottom: calc(var(--spacing-xs) + env(safe-area-inset-bottom, 0px));
}

.shell-bottom-nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-around;
    max-width: 480px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: 100px;
    padding: 4px;
}

.shell-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 4px 0;
    min-width: 0;
    flex: 1;
    border-radius: 100px;
    color: var(--text-tertiary);
    text-decoration: none;
    transition: color var(--transition-fast), background var(--transition-fast);
}
.shell-bottom-nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.shell-bottom-nav-item span {
    font-size: 9px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 52px;
    text-align: center;
}

/* Item actif — pill */
.shell-bottom-nav-item.active {
    background: var(--bg-active);
    color: var(--text-primary);
}

/* ───────────────────────────────────────────
   9. MOBILE HEADER — Full-width sticky top
   ─────────────────────────────────────────── */
.shell-mobile-header {
    display: none;
}

/* ───────────────────────────────────────────
   10. MOBILE — < 640px : sidebar hidden, header + bottom nav visible
   ─────────────────────────────────────────── */
@media (max-width: 639px) {
    .app-shell {
        grid-template-columns: 1fr;
    }
    .app-shell.shell-panel-open {
        grid-template-columns: 1fr;
    }

    .shell-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform var(--transition-base);
        z-index: 200;
        box-shadow: var(--shadow-xl);
    }
    .app-shell.shell-sidebar-mobile-open .shell-sidebar {
        transform: translateX(0);
    }

    /* Overlay derrière sidebar mobile */
    .shell-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 199;
    }
    .app-shell.shell-sidebar-mobile-open .shell-sidebar-overlay {
        display: block;
    }

    /* Header mobile visible */
    .main-header {
        position: sticky !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 48px !important;
        display: flex !important;
        align-items: center;
        padding: 0 16px !important;
        background: var(--bg-primary) !important;
        border-bottom: 1px solid var(--border-color) !important;
        transform: none !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        z-index: 100 !important;
        gap: 12px;
    }
    .main-header .btn-menu {
        display: flex !important;
        order: -1;
        padding: 8px;
        background: transparent;
        border: none;
        border-radius: 8px;
        color: var(--text-primary);
        flex-shrink: 0;
    }
    .main-header .page-title {
        flex: 1;
        text-align: center;
        font-size: 15px !important;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .main-header .header-actions {
        margin-left: 0;
        flex-shrink: 0;
    }

    .shell-main {
        grid-column: 1;
        padding-bottom: 72px; /* Espace pour bottom nav */
    }

    .shell-bottom-nav {
        display: block;
    }

    /* Panel en mobile = full screen overlay */
    .shell-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        max-width: none;
        min-width: 0;
        z-index: 150;
        border-radius: 0;
        border-left: none;
    }

    /* Feedback btn au-dessus du bottom nav */
    #feedback-floating-btn {
        bottom: 80px !important;
        right: 16px !important;
        padding: 12px !important;
        border-radius: 50% !important;
        touch-action: none;
    }
    #feedback-floating-btn span {
        display: none;
    }
}

/* ───────────────────────────────────────────
   11. TABLET — 640px-767px : sidebar collapsed 64px icônes, pas de bottom nav
   ─────────────────────────────────────────── */
@media (min-width: 640px) and (max-width: 767px) {
    .app-shell {
        --shell-sidebar-width: 64px;
    }
    .shell-sidebar {
        width: 64px;
    }
    .shell-sidebar-logo .logo-studio,
    .shell-nav-group-label,
    .shell-nav-item span,
    .shell-user-name,
    .shell-user-role {
        display: none;
    }
    .shell-nav-item {
        justify-content: center;
        padding: 8px;
    }
    .shell-nav-item.active::before {
        top: 8px;
        bottom: 8px;
    }
    /* Bottom nav masquée en tablet */
    .shell-bottom-nav {
        display: none;
    }
}

/* ───────────────────────────────────────────
   12. TABLET/iPAD — 768px-1023px : sidebar collapsed 64px, panel actif
   ─────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
    .app-shell {
        --shell-sidebar-width: 64px;
    }
    .shell-sidebar {
        width: 64px;
    }
    .shell-sidebar-logo .logo-studio,
    .shell-nav-group-label,
    .shell-nav-item span,
    .shell-user-name,
    .shell-user-role {
        display: none;
    }
    .shell-nav-item {
        justify-content: center;
        padding: 8px;
    }
    .shell-nav-item.active::before {
        top: 8px;
        bottom: 8px;
    }
    /* Bottom nav masquée en tablet */
    .shell-bottom-nav {
        display: none;
    }

    /* Panel secondaire actif dès 768px (iPad) */
    .app-shell.shell-panel-open {
        grid-template-columns: 64px 1fr var(--shell-panel-width, 400px);
    }
    .shell-panel {
        min-width: 320px;
        max-width: 400px;
    }
}

/* iPad portrait — panel 320px */
@media (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
    .app-shell.shell-panel-open {
        grid-template-columns: 64px 1fr 320px;
    }
    .shell-panel {
        min-width: 280px;
        max-width: 320px;
    }
}

/* iPad landscape — panel 400px */
@media (min-width: 768px) and (max-width: 1023px) and (orientation: landscape) {
    .app-shell.shell-panel-open {
        grid-template-columns: 64px 1fr 400px;
    }
    .shell-panel {
        min-width: 360px;
        max-width: 400px;
    }
}

/* ───────────────────────────────────────────
   13. DESKTOP — Layout complet
   ─────────────────────────────────────────── */
@media (min-width: 1024px) {
    .shell-sidebar-overlay {
        display: none !important;
    }
    .shell-bottom-nav {
        display: none;
    }
}

/* ───────────────────────────────────────────
   14. ULTRA — >2560px ajustements
   ─────────────────────────────────────────── */
@media (min-width: 2560px) {
    .shell-main {
        max-width: 2200px;
    }
}

/* ───────────────────────────────────────────
   15. FEEDBACK BUTTON — Draggable touch support
   ─────────────────────────────────────────── */
#feedback-floating-btn {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
#feedback-floating-btn.dragging {
    opacity: 0.8;
    transition: none !important;
    transform: none !important;
}
