/* ==============================================================
   MaCommande — Custom CSS (Vuexy-inspired, farm theme)
   ============================================================== */

/* --- CSS Variables --- */
:root {
    --primary: #5b8c3e;
    --primary-rgb: 91, 140, 62;
    --primary-hover: #4a7332;
    --primary-light: #e8f0e3;
    --primary-dark: #3d6b28;
    --secondary: #808390;
    --success: #28c76f;
    --danger: #ff4c51;
    --warning: #ff9f43;
    --info: #00bad1;
    --body-bg: #f5f5f5;
    --card-bg: #fff;
    --text-color: #5d596c;
    --text-muted: #a5a3ae;
    --heading-color: #444050;
    --border-color: #e6e6e8;
    --sidebar-bg: #2f3349;
    --sidebar-width: 260px;
    --navbar-height: 60px;
    --radius: 0.5rem;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.12);
    --font: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* --- Base --- */
body {
    font-family: var(--font);
    color: var(--text-color);
    background: var(--body-bg);
}

h1, h2, h3, h4, h5, h6 { color: var(--heading-color); font-weight: 600; }

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

/* --- Bootstrap overrides --- */
.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:active, .btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.text-primary { color: var(--primary) !important; }
.bg-primary { background-color: var(--primary) !important; }
.bg-primary-subtle { background-color: var(--primary-light) !important; }
.border-primary { border-color: var(--primary) !important; }

.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--primary-rgb), 0.25);
}
.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* --- Cards (Vuexy-style) --- */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--card-bg);
}
.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* --- Status badges (label style) --- */
.bg-label-primary { background: var(--primary-light) !important; color: var(--primary) !important; }
.bg-label-success { background: #ddf6e8 !important; color: #28c76f !important; }
.bg-label-danger { background: #ffe2e3 !important; color: #ff4c51 !important; }
.bg-label-warning { background: #fff0e1 !important; color: #ff9f43 !important; }
.bg-label-info { background: #d6f4f8 !important; color: #00bad1 !important; }
.bg-label-secondary { background: #ebebed !important; color: #808390 !important; }

/* --- Stat icons --- */
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

/* --- Feature icons (Home page) --- */
.feature-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

/* ==============================================================
   PUBLIC LAYOUT
   ============================================================== */
.public-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.public-navbar {
    background: var(--primary) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.public-navbar .navbar-brand {
    font-weight: 700;
    font-size: 1.2rem;
}

.public-main {
    flex: 1;
}

.public-footer {
    background: #fff;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.85rem;
}


/* ==============================================================
   ORDER WIZARD
   ============================================================== */
.wizard-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    max-width: 500px;
    margin: 0 auto;
}

.wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.step-number {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--border-color);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s;
}
.wizard-step.active .step-number {
    background: var(--primary);
    color: #fff;
}
.wizard-step.done .step-number {
    background: var(--success);
    color: #fff;
}

.step-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}
.wizard-step.active .step-label { color: var(--primary); }

.wizard-connector {
    flex: 1;
    height: 2px;
    background: var(--border-color);
    margin: 0 8px;
    margin-bottom: 18px;
    transition: background 0.3s;
}
.wizard-connector.active { background: var(--primary); }

/* --- Product selection --- */
.category-header {
    background: #f8f8f8;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}
.category-header .bi {
    color: var(--primary);
}

.product-row {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}
.product-row:hover { background: #fafafa; }
.product-row.selected { background: var(--primary-light); }
.product-row:last-child { border-bottom: none; }

.product-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius);
    flex-shrink: 0;
    margin-right: 12px;
}

/* Réordonnancement du catalogue au glisser-déposer (/admin/catalogue) */
.poignee-glisse {
    cursor: grab;
}
.poignee-glisse:active {
    cursor: grabbing;
}
tr.ligne-glissee {
    opacity: 0.45;
    background: var(--primary-light);
}
/* Bootstrap peint le fond sur les cellules (--bs-table-bg) : c'est là qu'il faut le changer. */
tr.ligne-categorie > td {
    --bs-table-bg: #f8f8f8;
}
tr.ligne-categorie > td .bi:not(.bi-grip-vertical) {
    color: var(--primary);
}
tr.ligne-glissee > td {
    --bs-table-bg: var(--primary-light);
}
/* Modale « Ordre des producteurs » : liste réordonnée au glisser-déposer */
.liste-ordre .list-group-item {
    cursor: grab;
    user-select: none;
}
.liste-ordre .list-group-item:active {
    cursor: grabbing;
}
.liste-ordre .list-group-item.ligne-glissee {
    opacity: 0.45;
    background: var(--primary-light);
}

.product-info {
    flex: 1;
    min-width: 0;
}
.product-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.product-price {
    display: inline-block;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.85rem;
    margin-top: 2px;
}

/* Prix et unité en bout de ligne, l'un sous l'autre (/produits) */
.product-tarif {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    margin-left: 16px;
    line-height: 1.2;
    white-space: nowrap;
}
.product-tarif-prix {
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary);
}
.product-tarif-unite,
.product-unite {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* /produits : les produits d'une catégorie en tuiles. Colonnes de 320 px au moins, donc trois
   sur grand écran, deux sur tablette et une sur téléphone, sans point de rupture à entretenir. */
.grille-produits {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    gap: 10px;
    padding: 12px;
}
.tuile-produit {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.tuile-produit:hover {
    border-color: rgba(var(--primary-rgb), 0.45);
    box-shadow: var(--shadow);
}
.tuile-produit .product-thumb,
.tuile-produit .product-tarif {
    margin: 0;
}
.tuile-produit.tuile-indisponible {
    opacity: 0.65;
}
/* Trois lignes au plus : le texte complet reste lisible au survol (attribut title). */
.tuile-description {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    margin-top: 2px;
    line-height: 1.35;
}

/* --- Quantity selector --- */
.quantity-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
    flex-shrink: 0;
}
.quantity-selector .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.quantity-value {
    width: 28px;
    text-align: center;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-muted);
}
.quantity-value.has-items {
    color: var(--primary);
}

/* --- Synthèse de la commande (étape « Produits » de /commander, tiers de droite) --- */
@media (min-width: 992px) {
    /* Reste en vue pendant le défilement de la liste ; la colonne s'étire sur toute sa hauteur. */
    .synthese-commande {
        position: sticky;
        top: 1rem;
    }
    /* Au-delà d'une demi-hauteur d'écran, la liste défile seule : total et boutons restent visibles. */
    .synthese-lignes {
        max-height: 50vh;
        overflow-y: auto;
    }
}
.synthese-commande .min-w-0 {
    min-width: 0;
}

/* --- Floating summary --- */
.floating-summary {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--primary);
    color: white;
    padding: 12px 0;
    z-index: 1000;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.15);
}

/* ==============================================================
   ADMIN LAYOUT (Vuexy-style sidebar)
   ============================================================== */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #b4b2bf;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-header .bi { font-size: 1.4rem; color: var(--primary); }

.sidebar-brand { letter-spacing: 0.5px; }

.sidebar-close {
    color: #b4b2bf;
    margin-left: auto;
    text-decoration: none;
    font-size: 1.2rem;
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: var(--radius);
    color: #b4b2bf;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}
.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}
.sidebar-link.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.4);
}
.sidebar-link .bi { font-size: 1.2rem; width: 22px; text-align: center; }

.sidebar-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 8px 0;
}

.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

.admin-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.admin-topbar {
    background: var(--card-bg);
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.admin-main {
    flex: 1;
    padding: 0 24px;
}

.sidebar-toggle { font-size: 1.4rem; color: var(--text-color); text-decoration: none; }

/* Tables */
.table { font-size: 0.9rem; }
.table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    border-bottom-width: 2px;
}
.cursor-pointer { cursor: pointer; }
.cursor-pointer:hover { background: #f8f8f8; }

/* Validation messages */
.validation-message { color: var(--danger); font-size: 0.8rem; margin-top: 4px; }

/* Textes d'exemple des champs : plus clairs que le gris de Bootstrap, pour qu'un exemple ne
   passe pas pour une valeur déjà saisie. opacity: 1 neutralise l'atténuation de Firefox. */
.form-control::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* ==============================================================
   RESPONSIVE
   ============================================================== */
@media (max-width: 991px) {
    .admin-sidebar {
        transform: translateX(-100%);
    }
    .sidebar-open .admin-sidebar {
        transform: translateX(0);
    }
    .admin-content {
        margin-left: 0;
    }
    .admin-main {
        padding: 0 12px;
    }
}

@media (max-width: 575px) {
    .wizard-steps { gap: 0; }
    .step-number { width: 30px; height: 30px; font-size: 12px; }
    .wizard-connector { margin: 0 4px; margin-bottom: 4px; }

    .product-row { padding: 8px 12px; }
    .quantity-selector { gap: 4px; }
    .quantity-selector .btn { width: 28px; height: 28px; }

    .floating-summary { padding: 10px 0; font-size: 0.9rem; }
}

/* Spinner for loading states */
.spinner-border-sm { width: 1rem; height: 1rem; border-width: 0.15em; }

/* Smooth page transitions */
.card { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Configuration initiale (/setup) ------------------------------------ */
.setup-layout {
    min-height: 100vh;
    background: linear-gradient(160deg, var(--primary-light) 0%, #f7f8f9 45%);
    padding: 2.5rem 1rem 4rem;
}

.setup-shell {
    max-width: 880px;
    margin: 0 auto;
}

.setup-header {
    text-align: center;
    margin-bottom: 2rem;
}

.setup-header .bi {
    font-size: 2.6rem;
    color: var(--primary);
}

.setup-reference {
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    background: #fff;
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 999px;
    padding: 0.15rem 0.75rem;
}

/* Texte de présentation saisi en Markdown (/admin/personnalisation, affiché sur l'accueil) */
.presentation-accueil {
    max-width: 820px;
}
/* Avec photo : la photo à gauche, le texte à droite ; l'un sous l'autre sur écran étroit. */
.presentation-accueil.avec-photo {
    max-width: 1100px;
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 2rem;
    align-items: start;
}
.presentation-photo {
    display: block;
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.presentation-accueil:not(.avec-photo) .presentation-photo {
    max-height: 420px;
    object-fit: cover;
}
@media (max-width: 767px) {
    .presentation-accueil.avec-photo {
        grid-template-columns: minmax(0, 1fr);
        gap: 1.25rem;
    }
}
.presentation-miniature {
    width: 96px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius);
    flex-shrink: 0;
}
.contenu-markdown > :first-child { margin-top: 0; }
.contenu-markdown > :last-child { margin-bottom: 0; }
.contenu-markdown h1,
.contenu-markdown h2,
.contenu-markdown h3,
.contenu-markdown h4 {
    color: var(--primary-dark);
    font-weight: 700;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}
.contenu-markdown a { color: var(--primary); }
.contenu-markdown img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
}
.contenu-markdown blockquote {
    border-left: 4px solid var(--primary);
    background: var(--primary-light);
    padding: 0.5rem 1rem;
    border-radius: 0 var(--radius) var(--radius) 0;
}
.contenu-markdown blockquote > :last-child { margin-bottom: 0; }
.contenu-markdown table {
    width: 100%;
    margin-bottom: 1rem;
    border-collapse: collapse;
}
.contenu-markdown th,
.contenu-markdown td {
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
}
.zone-markdown {
    font-family: SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.9rem;
    min-height: 320px;
}
