/* ============================================================
   AppB2B — Souleyrol Espace Professionnel
   Mobile-first, clean, green theme
   ============================================================ */

:root {
    --green-dark:   #1b4332;
    --green:        #2d6a4f;
    --green-light:  #40916c;
    --green-pale:   #d8f3dc;
    --accent:       #f4a261;
    --bg:           #f8f9fa;
    --surface:      #ffffff;
    --border:       #dee2e6;
    --text:         #212529;
    --text-muted:   #6c757d;
    --danger:       #e63946;
    --warning:      #f57c00;
    --info:         #1976d2;
    --radius:       8px;
    --shadow:       0 2px 8px rgba(0,0,0,.08);
    --shadow-lg:    0 4px 20px rgba(0,0,0,.15);
    /* Aliases pour compatibilité avec le reste du CSS existant */
    --green-main:   #2d6a4f;
    --white:        #ffffff;
    --text-light:   #6c757d;
    --red:          #e63946;
    --orange:       #f57c00;
    --blue:         #1976d2;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100dvh; }

/* ---- LOGIN ---- */
.login-container {
    max-width: 380px;
    margin: auto;
    padding: 2rem 1.5rem;
    width: 100%;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo h1 {
    font-size: 2rem;
    color: var(--green-dark);
    font-weight: 700;
}

.login-logo p {
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* ---- FORMS ---- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--white);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--green-main);
}

.form-row {
    display: flex;
    gap: 1rem;
}
.form-row .form-group { flex: 1; }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.4rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--green-main);
    color: var(--white);
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--green-main); color: var(--green-main); }

.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

.icon-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.4rem;
    color: var(--text);
    position: relative;
}

.error-msg { color: var(--red); font-size: 0.85rem; margin-top: 0.5rem; text-align: center; }
.warning-msg { color: var(--orange); font-size: 0.85rem; margin-top: 0.5rem; text-align: center; }

/* ---- TOPBAR (style VidaPOS) ---- */
#app-topbar {
    display: flex;
    align-items: center;
    background: var(--green-dark);
    color: #fff;
    padding: 0 1rem;
    height: 48px;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 0.5rem;
}

.topbar-logo {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.topbar-company {
    font-size: 0.8rem;
    opacity: 0.75;
    margin-left: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
}

.topbar-admin-link {
    background: rgba(255,255,255,0.18);
    color: #fff;
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    white-space: nowrap;
    transition: background 0.15s;
}
.topbar-admin-link:hover { background: rgba(255,255,255,0.3); }

.topbar-icon-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    position: relative;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.topbar-icon-btn:hover { background: rgba(255,255,255,0.15); }

/* ---- NAVIGATION PRINCIPALE ---- */
#main-nav {
    display: flex;
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 48px;
    z-index: 99;
}

.nav-btn {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 0.65rem 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.nav-btn.active {
    color: var(--green-dark);
    border-bottom-color: var(--green-dark);
}

.badge {
    position: absolute;
    top: -2px;
    right: -4px;
    background: var(--red);
    color: var(--white);
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---- VIEWS ---- */
.view { display: none; padding: 1rem; flex: 1; }
.view.active { display: block; }

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
}

.view-header h3 { font-size: 1.2rem; }


/* ---- CATALOGUE SEARCH ---- */
#catalogue-search-bar {
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

#search-products {
    width: 100%;
    padding: 0.55rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--bg);
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
#search-products:focus { border-color: var(--green-light); }

/* ---- ONGLETS CATÉGORIES ---- */
#category-tabs {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    overflow-x: auto;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
#category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
    flex-shrink: 0;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 20px;
    padding: 0.3rem 0.8rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.cat-tab.active {
    background: var(--green-dark);
    border-color: var(--green-dark);
    color: #fff;
}

/* ---- GRILLE PRODUITS ---- */
#products-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    padding: 0.6rem 0.6rem;
}

.product-grid-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1.5px solid var(--border);
    padding: 0.65rem 0.5rem 0.6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    text-align: center;
    transition: border-color 0.15s;
}
.product-grid-card.in-cart {
    border-left: 3px solid var(--green-dark);
}

.pgc-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
}

.pgc-price {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--green);
}

.pgc-qty {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.qty-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--green-dark);
    color: #fff;
    border: none;
    font-size: 1.1rem;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.qty-btn:active { transform: scale(0.93); }

.qty-val {
    font-size: 0.9rem;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
    color: var(--text);
}

/* ---- CART PANEL ---- */
.panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 420px;
    height: 100dvh;
    background: var(--white);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}
.panel.open { right: 0; }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

#cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 1rem;
}

.cart-item {
    display: flex;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f0f0f0;
    gap: 0.5rem;
}

.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; font-size: 0.9rem; }
.cart-item-detail { font-size: 0.8rem; color: var(--text-light); }
.cart-item-total { font-weight: 700; color: var(--green-main); }
.cart-item-remove {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.3rem;
}

#cart-custom-requests {
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border);
}
#cart-custom-requests h4 { font-size: 0.9rem; margin-bottom: 0.5rem; }

.custom-request-item {
    background: var(--green-pale);
    border-radius: var(--radius);
    padding: 0.5rem 0.7rem;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cart-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    background: var(--green-pale);
}

.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.8rem;
}

.cart-options {
    margin-bottom: 0.8rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

/* ---- MODAL ---- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.open { display: flex; }

.modal-content {
    background: var(--white);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 450px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 { margin-bottom: 1rem; }

.modal-actions {
    display: flex;
    gap: 0.8rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* ---- ORDERS LIST ---- */
.order-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.8rem;
    box-shadow: var(--shadow);
}

.order-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.order-date { font-size: 0.85rem; color: var(--text-light); }
.order-total { font-weight: 700; color: var(--green-main); }

.order-status {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.status-pending { background: #fff3e0; color: var(--orange); }
.status-confirmed { background: #e3f2fd; color: var(--blue); }
.status-prepared { background: #e8f5e9; color: var(--green-main); }
.status-delivered { background: var(--green-light); color: var(--green-dark); }
.status-invoiced { background: #f3e5f5; color: #7b1fa2; }
.status-cancelled { background: #ffebee; color: var(--red); }

.order-items-list {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

/* ---- DOCUMENTS ---- */
.doc-section { margin-bottom: 1.5rem; }
.doc-section h4 {
    font-size: 1rem;
    color: var(--green-dark);
    margin-bottom: 0.5rem;
    padding-bottom: 0.3rem;
    border-bottom: 2px solid var(--green-light);
}

.doc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0.5rem;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

/* ---- Toast notifications ---- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--green-dark);
    color: var(--white);
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    z-index: 400;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---- Responsive ---- */
@media (max-width: 400px) {
    .topbar-company { display: none; }
    #products-grid { grid-template-columns: 1fr 1fr; gap: 0.4rem; padding: 0.5rem; }
}
@media (min-width: 640px) {
    #products-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
    #products-grid { grid-template-columns: repeat(4, 1fr); }
    .panel { max-width: 420px; }
}
