/* ============================================================
   NAFA — style-web.css
   Layout tablette (≥ 768px) et PC (≥ 1024px)
   Inspiré du template location/css/style-web.css
   Zéro changement de couleur, zéro changement backend
   ============================================================ */

/* Sur mobile : cacher sidebar + top-navbar */
.sidebar,
#top-navbar {
    display: none;
}

/* ============================================================
   TABLETTE : ≥ 768px
   ============================================================ */
@media (min-width: 768px) {

    :root {
        --sidebar-width: 240px;
        --sidebar-collapsed-width: 72px;
        --navbar-height: 64px;
    }

    /* Reset body */
    html, body {
        background: var(--bg);
        min-height: 100vh;
        overflow-x: hidden;
    }

    /* App = row flex */
    #app {
        max-width: none;
        width: 100%;
        min-height: 100vh;
        border-radius: 0;
        border: none;
        box-shadow: none;
        display: flex;
        flex-direction: row;
        padding-bottom: 0;
    }

    /* Pages */
    .page {
        min-height: auto;
    }

    .page.active {
        padding-bottom: 24px;
    }

    .bottom-spacer {
        height: 24px;
    }

    /* Cacher le bas de navigation mobile */
    #bottom-nav {
        display: none !important;
    }

    /* Cacher les boutons mobiles flottants logout/download */
    #logout-top,
    #download-top {
        display: none !important;
    }

    /* ---- SIDEBAR ---- */
    .sidebar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: var(--sidebar-width);
        height: 100vh;
        background: var(--white);
        border-right: 1px solid #E5E7EB;
        flex-direction: column;
        z-index: 200;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.06);
        transition: width 0.25s ease;
    }

    .sidebar.collapsed {
        width: var(--sidebar-collapsed-width);
    }

    /* Marque / logo */
    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 20px 20px 16px;
        border-bottom: 1px solid #E5E7EB;
        transition: padding 0.25s ease;
        flex-shrink: 0;
    }

    .sidebar.collapsed .sidebar-brand {
        padding: 16px;
        justify-content: center;
    }

    .sidebar-logo {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        background: var(--primary-light);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .sidebar-logo img {
        width: 28px;
        height: 28px;
        object-fit: contain;
    }

    .sidebar-title {
        font-size: 18px;
        font-weight: 700;
        color: var(--primary-dark);
        letter-spacing: -0.3px;
        white-space: nowrap;
        overflow: hidden;
        transition: opacity 0.2s ease, width 0.25s ease;
    }

    .sidebar.collapsed .sidebar-title {
        display: none;
    }

    /* Navigation liens */
    .sidebar-nav {
        flex: 1;
        overflow-y: auto;
        padding: 12px 10px;
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .sidebar-nav .nav-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        width: 100%;
        padding: 12px 14px;
        border-radius: 12px;
        color: var(--text-light);
        font-size: 14px;
        font-weight: 500;
        background: none;
        border: none;
        cursor: pointer;
        font-family: 'Poppins', sans-serif;
        transition: background 0.2s ease, color 0.2s ease;
        min-width: auto;
        text-align: left;
        justify-content: flex-start;
    }

    .sidebar.collapsed .sidebar-nav .nav-item {
        justify-content: center;
        padding: 12px;
    }

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

    .sidebar-nav .nav-item svg {
        flex-shrink: 0;
    }

    .sidebar-badge {
        margin-left: auto;
        padding: 2px 8px;
        border-radius: 10px;
        font-size: 11px;
        font-weight: 700;
        line-height: 1.4;
        min-width: 20px;
        text-align: center;
    }

    .sidebar-badge[data-badge-page="sale"],
    .sidebar-badge[data-badge-page="purchases"] {
        background: var(--primary-light);
        color: var(--primary-dark);
    }

    .sidebar-badge[data-badge-page="expense"] {
        background: var(--danger-light);
        color: var(--danger-dark);
    }

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

    .sidebar-nav .nav-item.active {
        color: var(--primary);
        background: var(--primary-light);
        font-weight: 600;
    }

    /* Bas de la sidebar */
    .sidebar-bottom {
        padding: 12px 10px;
        border-top: 1px solid #E5E7EB;
        flex-shrink: 0;
    }

    .sidebar-logout {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        padding: 10px 14px;
        border: none;
        background: none;
        color: var(--danger);
        font-family: 'Poppins', sans-serif;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        border-radius: 10px;
        transition: background 0.2s ease;
    }

    .sidebar.collapsed .sidebar-logout {
        justify-content: center;
        padding: 10px;
    }

    .sidebar.collapsed .sidebar-logout span {
        display: none;
    }

    .sidebar-logout:hover {
        background: var(--danger-light);
    }

    /* Bouton réduire/agrandir la sidebar */
    .sidebar-collapse-btn {
        position: absolute;
        top: 22px;
        right: -14px;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: var(--white);
        border: 1px solid #E5E7EB;
        color: var(--text-light);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 210;
        box-shadow: 0 2px 6px rgba(0,0,0,0.08);
        transition: all 0.2s ease;
    }

    .sidebar-collapse-btn:hover {
        background: var(--primary-light);
        border-color: var(--primary);
        color: var(--primary);
    }

    .sidebar.collapsed .sidebar-collapse-btn {
        right: -14px;
        transform: rotate(180deg);
    }

    /* ---- MAIN WRAPPER ---- */
    #main-wrapper {
        display: flex;
        margin-left: var(--sidebar-width);
        flex: 1;
        min-height: 100vh;
        flex-direction: column;
        transition: margin-left 0.25s ease;
    }

    .sidebar.collapsed ~ #main-wrapper {
        margin-left: var(--sidebar-collapsed-width);
    }

    /* ---- TOP NAVBAR ---- */
    #top-navbar {
        display: flex;
        position: sticky;
        top: 0;
        height: var(--navbar-height);
        background: var(--white);
        border-bottom: 1px solid #E5E7EB;
        align-items: center;
        justify-content: space-between;
        padding: 0 24px;
        z-index: 150;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    }

    .navbar-brand {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .navbar-brand img {
        width: 28px;
        height: 28px;
        object-fit: contain;
    }

    #page-title {
        font-size: 16px;
        font-weight: 600;
        color: var(--text);
    }

    .navbar-actions {
        display: flex;
        align-items: center;
        gap: 8px;
        position: relative;
    }

    .navbar-menu-btn {
        width: 36px;
        height: 36px;
        border-radius: 8px;
        border: 1px solid #E5E7EB;
        background: var(--white);
        color: var(--text-light);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .navbar-menu-btn:hover {
        background: var(--primary-light);
        border-color: var(--primary);
        color: var(--primary);
    }

    /* Dropdown navbar */
    .navbar-dropdown {
        position: absolute;
        top: calc(100% + 10px);
        right: 0;
        width: 220px;
        background: var(--white);
        border: 1px solid #E5E7EB;
        border-radius: 14px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.10);
        padding: 6px;
        display: none;
        flex-direction: column;
        gap: 2px;
        z-index: 300;
    }

    .navbar-dropdown.open {
        display: flex;
    }

    .navbar-dropdown-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
        border-radius: 10px;
        background: none;
        border: none;
        cursor: pointer;
        font-family: 'Poppins', sans-serif;
        font-size: 13px;
        font-weight: 500;
        color: var(--text);
        text-align: left;
        transition: background 0.15s ease;
    }

    .navbar-dropdown-item:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

    .navbar-dropdown-logout {
        color: var(--danger) !important;
    }

    .navbar-dropdown-logout:hover {
        background: var(--danger-light) !important;
        color: var(--danger) !important;
    }

    /* ---- CONTENT ---- */
    #content {
        flex: 1;
        overflow-y: auto;
    }

    /* Header pages : ajuster sticky top sous la navbar */
    .header {
        top: var(--navbar-height);
        z-index: 100;
    }

    /* Cacher le btn-back sur PC (navigation via sidebar) */
    .btn-back {
        display: none;
    }

    /* Dashboard header row horizontal on desktop */
    #page-dashboard .header-row {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
    }

    #page-dashboard .filter-bar {
        align-self: auto;
        flex-shrink: 0;
    }

    /* Métriques : 3 colonnes sur tablette */
    .metrics-grid {
        grid-template-columns: repeat(3, 1fr);
        padding: 20px 24px;
        gap: 16px;
        margin-top: 56px;
    }

    /* Section padding adapté */
    .section {
        padding: 0 24px 16px;
    }

    /* Form pages centrées */
    .form-page {
        max-width: 560px;
        margin: 20px auto 0;
        padding: 24px;
    }

    /* Login centrée */
    .login-container {
        max-width: 420px;
        margin: 0 auto;
    }

    /* FAB caché sur tablette (actions via sidebar) */
    #fab-container {
        display: none !important;
    }

    /* Filter bar spacing */
    .filter-bar {
        margin-top: 20px;
    }
}

/* ============================================================
   PC / DESKTOP : ≥ 1024px
   ============================================================ */
@media (min-width: 1024px) {

    /* Métriques : 4 colonnes sur grand écran */
    .metrics-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
        padding: 24px 28px;
        margin-top: 56px;
    }

    .metric-card-full {
        grid-column: span 2;
    }

    /* Section padding plus large */
    .section {
        padding: 0 28px 20px;
    }

    /* Header */
    .header {
        padding: 20px 28px 16px;
    }

    /* Dashboard : 2 colonnes pour les sections du bas */
    #page-dashboard .section {
        padding: 0 28px 20px;
    }

    /* Form pages pleine largeur sur PC */
    .form-page {
        max-width: none;
        padding: 20px 28px;
        margin-top: 20px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0 24px;
    }

    .form-page .input-group {
        margin-bottom: 20px;
    }

    .form-page .btn-full {
        grid-column: 1 / -1;
    }

    .form-page .input-group-full {
        grid-column: 1 / -1;
    }

    /* Product chips full-width rows on desktop */
    .product-chips {
        flex-direction: column;
        gap: 12px;
    }

    .product-chip {
        flex: 1 0 auto;
        min-width: 100%;
        max-width: 100%;
        padding: 12px 16px;
        flex-wrap: nowrap;
        overflow: hidden;
    }

    .product-chip-info {
        flex: 1 1 auto;
        min-width: 180px;
        overflow: hidden;
    }

    .product-chip-name {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chip-qty,
    .chip-price {
        width: 72px;
        padding: 6px 8px;
        font-size: 13px;
    }

    .chip-remove {
        width: 28px;
        height: 28px;
        border-radius: 8px;
    }

    .chip-remove {
        flex-shrink: 0;
    }

    /* Client info card compact on desktop */
    .client-info-card {
        gap: 6px;
    }

    .client-info-debt {
        margin-top: 4px;
        margin-left: 0;
    }

    /* Tableau / listes plus lisibles */
    .list-container {
        padding: 0;
        
    }

    /* Filter bar spacing */
    .filter-bar {
        margin-top: 20px;
    }

    /* Sidebar toujours visible et étendue */
    :root {
        --sidebar-width: 260px;
    }
}

/* ============================================================
   GRAND ÉCRAN : ≥ 1440px
   ============================================================ */
@media (min-width: 1440px) {

    :root {
        --sidebar-width: 280px;
    }

    .metrics-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 24px;
        padding: 28px 36px;
        margin-top: 56px;
    }

    .section {
        padding: 0 36px 24px;
    }

    .header {
        padding: 24px 36px 18px;
    }

    .form-page {
        max-width: 700px;
        margin-top: 20px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0 20px;
    }

    .form-page .input-group {
        margin-bottom: 20px;
    }

    .form-page .btn-full {
        grid-column: 1 / -1;
    }

    .form-page .input-group-full {
        grid-column: 1 / -1;
    }
}
