/* ============================================================
   Aryzta Order POC — Styles
   Inspiré de l'interface Salesforce Aryzta
   ============================================================ */

/* ─── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:        #0070d2;
    --blue-hover:  #005fb2;
    --blue-light:  #d8edff;
    --red:         #c23934;
    --orange:      #e65000;
    --green:       #2e844a;
    --grey-50:     #f3f3f3;
    --grey-100:    #e5e5e5;
    --grey-300:    #b0b0b0;
    --grey-600:    #5c5c5c;
    --grey-900:    #181818;
    --white:       #ffffff;
    --row-alt:     #f8f9fb;
    --border:      #d8dde6;
    --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius:      4px;
}

html { font-size: 14px; }

body {
    font-family: var(--font);
    font-size: 0.875rem;
    color: var(--grey-900);
    background: var(--grey-50);
    min-width: 320px;
}

/* ─── Bandeau offline ──────────────────────────────────────── */
#offline-banner {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    background: var(--red);
    color: var(--white);
    text-align: center;
    padding: 6px 12px;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
}
body.is-offline #offline-banner { display: block; }
body.is-offline { padding-top: 32px; }

/* ─── En-tête ──────────────────────────────────────────────── */
.app-header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header .logo {
    width: 32px;
    height: 32px;
    background: var(--blue);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 700;
    font-size: 0.75rem;
}

.header-title { flex: 1; min-width: 0; }

.header-label {
    font-size: 0.72rem;
    color: var(--grey-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.app-header h1 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--grey-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.account-selector select {
    display: none; /* remplacé par autocomplete */
}

/* ─── Autocomplete compte ──────────────────────────────────── */
.account-autocomplete {
    position: relative;
    min-width: 260px;
}

.account-autocomplete input {
    width: 100%;
    padding: 6px 32px 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    background: var(--white);
    outline: none;
}
.account-autocomplete input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px var(--blue-light);
}

.account-search-icon {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 0.85em;
    color: var(--grey-300);
}

.account-dropdown {
    position: absolute;
    top: calc(100% + 3px);
    left: 0; right: 0;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    z-index: 200;
    max-height: 260px;
    overflow-y: auto;
}

.account-dropdown-item {
    padding: 7px 12px;
    cursor: pointer;
    font-size: 0.82rem;
    display: flex;
    gap: 8px;
    align-items: baseline;
}
.account-dropdown-item:hover,
.account-dropdown-item.active { background: var(--blue-light); }
.account-dropdown-item .acc-id  { color: var(--grey-600); font-family: monospace; font-size: 0.78rem; }
.account-dropdown-item .acc-name { font-weight: 500; }
.account-dropdown-empty { padding: 10px 12px; color: var(--grey-300); font-size: 0.82rem; }

/* ─── Colonne image produit ────────────────────────────────── */
th.col-img, td.col-img {
    width: 52px;
    min-width: 52px;
    padding: 3px 4px;
    text-align: center;
}

.prod-img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 3px;
    background: var(--grey-50);
    display: block;
    margin: 0 auto;
}

.prod-img-placeholder {
    width: 44px;
    height: 44px;
    background: var(--grey-100);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    margin: 0 auto;
}

.empty-state {
    text-align: center;
    padding: 40px 24px;
    color: var(--grey-300);
    font-size: 0.9rem;
}

/* ─── Barre d'actions ──────────────────────────────────────── */
.action-bar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--grey-900);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--grey-50); border-color: var(--grey-300); }
.btn:active { background: var(--grey-100); }

.btn-primary {
    background: var(--blue);
    color: var(--white);
    border-color: var(--blue);
}
.btn-primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); }

.btn-danger {
    color: var(--red);
    border-color: var(--red);
}
.btn-danger:hover { background: #fef2f2; }

.btn-warning {
    background: var(--orange);
    color: var(--white);
    border-color: var(--orange);
}
.btn-warning:hover { background: #c44600; border-color: #c44600; }

.btn-success {
    background: var(--green);
    color: var(--white);
    border-color: var(--green);
}
.btn-success:hover { background: #236b38; }

/* Badge compteur commandes en attente */
.pending-badge {
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--red);
    color: var(--white);
    border-radius: 50%;
    width: 18px; height: 18px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-left: -6px;
    margin-top: -8px;
    vertical-align: top;
}

/* Flèche inline pour les suggestions */
.arrow-btn {
    cursor: pointer;
    color: var(--blue);
    font-size: 0.9em;
    user-select: none;
}
.arrow-btn:hover { color: var(--blue-hover); }

/* Indicateur connexion dans la barre d'actions */
.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.connection-status.online  { color: var(--green); background: #f0fdf4; border-color: #bbf7d0; }
.connection-status.offline { color: var(--red);   background: #fef2f2; border-color: #fecaca; }
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.online  .status-dot { background: var(--green); }
.offline .status-dot { background: var(--red); animation: pulse-red 1.2s infinite; }

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

.btn-icon { font-size: 1em; }

.action-bar .spacer { flex: 1; }

/* ─── Recherche ────────────────────────────────────────────── */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-box input {
    padding: 5px 10px 5px 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    width: 200px;
    outline: none;
    background: var(--white);
}
.search-box input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); }
.search-box .search-icon {
    position: absolute;
    left: 8px;
    color: var(--grey-300);
    font-size: 0.9em;
    pointer-events: none;
}

/* ─── Filtre période ───────────────────────────────────────── */
.period-select {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    background: var(--white);
    cursor: pointer;
    outline: none;
}
.period-select:focus { border-color: var(--blue); }

/* ─── Zone principale ──────────────────────────────────────── */
.main-content { padding: 12px 16px 80px; }

/* ─── Tableau commandes ────────────────────────────────────── */
.table-wrapper {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    min-width: 900px;
}

thead th {
    background: var(--grey-50);
    border-bottom: 2px solid var(--border);
    padding: 7px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--grey-600);
    white-space: nowrap;
    user-select: none;
}

tbody tr:nth-child(odd)  { background: var(--white); }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover           { background: var(--blue-light); }

tbody tr.out-of-stock { color: var(--grey-300); }
tbody tr.out-of-stock td.col-stock { color: var(--red); }

td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--grey-100);
    vertical-align: middle;
}

/* Colonnes de largeur fixe */
td.col-category  { min-width: 130px; color: var(--grey-600); }
td.col-code      { font-family: monospace; white-space: nowrap; }
td.col-product   { min-width: 200px; }
td.col-last-cde  { white-space: nowrap; color: var(--grey-600); }
td.col-stock     { text-align: right; }
td.col-price     { text-align: right; font-weight: 500; }
td.col-qty-rec   { text-align: right; }
td.col-qty       { width: 70px; }
td.col-disc-rec  { text-align: right; }
td.col-disc      { width: 70px; }
td.col-type      { width: 110px; }
td.col-net       { text-align: right; font-weight: 600; }
td.col-total     { text-align: right; font-weight: 700; color: var(--blue); }

/* ─── Badges suggestions ───────────────────────────────────── */
.qty-suggested {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
}
.qty-chip {
    background: var(--blue-light);
    color: var(--blue);
    border-radius: 10px;
    padding: 1px 7px;
    font-weight: 600;
    cursor: pointer;
}
.qty-chip:hover { background: #b8dcfc; }

.disc-chip {
    background: #f0fdf4;
    color: var(--green);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.disc-chip:hover { background: #dcfce7; }

/* ─── Inputs inline ─────────────────────────────────────────── */
input[type="number"] {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    text-align: right;
    outline: none;
    background: var(--white);
}
input[type="number"]:focus { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); }

/* ─── Radios type remise ────────────────────────────────────── */
.disc-type {
    display: flex;
    gap: 8px;
    font-size: 0.75rem;
}
.disc-type label { display: flex; align-items: center; gap: 3px; cursor: pointer; }

/* ─── Pied de tableau ───────────────────────────────────────── */
.table-footer {
    background: var(--white);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 10px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.total-commande {
    font-size: 1rem;
    font-weight: 700;
}
.total-commande span { color: var(--blue); }

.footer-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.footer-right label { font-size: 0.82rem; font-weight: 500; }
.footer-right input[type="date"] {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    outline: none;
}
.footer-right input[type="date"]:focus { border-color: var(--blue); }

/* ─── Toast notifications ───────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--grey-900);
    color: var(--white);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 0.82rem;
    max-width: 320px;
    opacity: 0;
    transform: translateY(8px);
    animation: toast-in 0.25s forwards, toast-out 0.25s 3s forwards;
}
.toast.toast-success { background: var(--green); }
.toast.toast-error   { background: var(--red); }

@keyframes toast-in  { to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ─── Loader ─────────────────────────────────────────────────── */
.loader-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.7);
    z-index: 998;
    align-items: center;
    justify-content: center;
}
.loader-overlay.active { display: flex; }

.spinner {
    width: 36px; height: 36px;
    border: 4px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Modal large (ajout produit) ──────────────────────────── */
.modal-large {
    width: min(680px, 96vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.modal-header h2 { font-size: 1rem; }

.btn-close {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: var(--grey-600);
    padding: 4px 8px;
    border-radius: var(--radius);
}
.btn-close:hover { background: var(--grey-100); }

/* Liste articles dans le modal */
.ajout-liste {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 52vh;
}

.ajout-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--grey-100);
    cursor: default;
}
.ajout-item:last-child { border-bottom: none; }
.ajout-item:hover      { background: var(--blue-light); }
.ajout-item.already-in { opacity: 0.4; }

.ajout-item .ajout-img {
    width: 36px; height: 36px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 3px;
    background: var(--grey-50);
}
.ajout-item .ajout-info { flex: 1; min-width: 0; }
.ajout-item .ajout-code { font-size: 0.75rem; color: var(--grey-600); font-family: monospace; }
.ajout-item .ajout-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ajout-item .ajout-cat  { font-size: 0.75rem; color: var(--grey-600); }

.btn-ajout-ligne {
    flex-shrink: 0;
    padding: 4px 12px;
    background: var(--blue);
    color: var(--white);
    border: none;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}
.btn-ajout-ligne:hover { background: var(--blue-hover); }
.btn-ajout-ligne:disabled { background: var(--grey-300); cursor: default; }

/* Colonne suppression */
th.col-del, td.col-del { width: 32px; min-width: 32px; text-align: center; padding: 0 2px; }

.btn-del-ligne {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--grey-300);
    font-size: 1rem;
    padding: 2px 4px;
    border-radius: 3px;
    line-height: 1;
}
.btn-del-ligne:hover { color: var(--red); background: #fef2f2; }
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 900;
    align-items: center;
    justify-content: center;
}
.modal-backdrop.active { display: flex; }

.modal {
    background: var(--white);
    border-radius: 6px;
    width: min(480px, 92vw);
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal h2 { font-size: 1rem; margin-bottom: 12px; }
.modal .sim-total { font-size: 1.4rem; font-weight: 700; color: var(--blue); margin: 16px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
    .app-header h1 { font-size: 0.9rem; }
    .action-bar    { padding: 6px 10px; }
    .main-content  { padding: 8px 6px 80px; }

    /* Sur mobile : masquer colonnes secondaires */
    th.col-category, td.col-category,
    th.col-disc-rec, td.col-disc-rec,
    th.col-type,     td.col-type { display: none; }

    .search-box input { width: 140px; }
}
