/* =========================================================================
   FATHIE SOHLA ELECTRONIQUE — feuille de style de l'application (PWA)
   Mobile-first, thème clair/sombre automatique.
   ========================================================================= */

:root {
    --primary: #0f766e;
    --primary-600: #0d9488;
    --primary-700: #0f766e;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
    --nav-w: 240px;
    --header-h: 56px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface-2: #172033;
        --border: #334155;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    }
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-600); text-decoration: none; }

/* ---------- Splash ---------- */
.splash {
    position: fixed; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 24px;
    background: var(--bg); z-index: 50;
}
.splash__logo {
    width: 72px; height: 72px; border-radius: 20px;
    background: var(--primary); color: #fff; font-weight: 800; font-size: 28px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow);
}
.splash__spinner, .spinner {
    width: 28px; height: 28px; border: 3px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout applicatif ---------- */
.layout { display: flex; min-height: 100%; }

.sidebar {
    width: var(--nav-w); background: var(--surface); border-right: 1px solid var(--border);
    position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column;
    padding: 0 12px 16px; gap: 4px; z-index: 20;
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 9px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9px; border: 2px solid var(--surface); }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.sidebar__brand {
    display: flex; align-items: center; gap: 10px; padding: 16px 10px;
    font-weight: 700; font-size: 15px;
    position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.sidebar__brand .logo {
    width: 34px; height: 34px; border-radius: 9px; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.nav-link {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px;
    border-radius: 10px; color: var(--text); font-weight: 500; cursor: pointer;
    border: none; background: none; width: 100%; text-align: left;
}
.nav-link .ico { font-size: 18px; width: 22px; text-align: center; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary-600); }
.sidebar__spacer { flex: 1; }

.main { flex: 1; margin-left: var(--nav-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; padding: 0 18px; position: sticky; top: 0; z-index: 10;
}
.topbar__title { font-weight: 700; font-size: 17px; }
.topbar__spacer { flex: 1; }
.topbar__user { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}

.sync-chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
    border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
    font-size: 12px; font-weight: 600; cursor: pointer; color: var(--text-muted);
    white-space: nowrap;
}
.sync-chip:hover { filter: brightness(.97); }
.sync-chip--offline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.sync-chip--pending { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }

/* Recherche globale */
.search { position: relative; }
.search__input {
    width: 180px; max-width: 40vw; padding: 7px 12px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface-2); outline: none; font-size: 13px;
}
.search__input:focus { border-color: var(--primary); background: var(--surface); width: 240px; }
.search__results {
    position: absolute; top: calc(100% + 6px); right: 0; width: 320px; max-width: 86vw;
    max-height: 60vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 30; padding: 4px;
}
.search__group { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); padding: 8px 10px 4px; font-weight: 700; }
.search__item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.search__item:hover { background: var(--surface-2); }
.search__sub { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.content { padding: 18px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* Barre de navigation basse (mobile) */
.bottomnav { display: none; }

/* ---------- Composants ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat__label { color: var(--text-muted); font-size: 13px; }
.stat__value { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.stat__sub { font-size: 12px; color: var(--text-muted); }

.section-title { font-size: 14px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin: 22px 0 10px; }

/* ---------- CRM : tableau de pipeline (colonnes par statut) ---------- */
.crm-board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(200px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.crm-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 80px; }
.crm-col__head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.crm-col__count { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-size: 12px; color: var(--text-muted); }
.crm-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow); }
.crm-card:hover { border-color: var(--primary-600); }

/* ---------- Produit : scan + galerie d'images ---------- */
.input-scan { display: flex; gap: 6px; align-items: stretch; }
.input-scan .input { flex: 1; }
.btn--scan { padding: 0 12px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; cursor: pointer; font-size: 18px; }
.btn--scan:hover { border-color: var(--primary-600); }
.prod-gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.prod-thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.prod-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prod-thumb__del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; }
.prod-thumb--add { display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--text-muted); cursor: pointer; }
.prod-thumb--add:hover { border-color: var(--primary-600); color: var(--primary-600); }
/* Vignette dans les listes (produits) */
.list-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; display: block; background: var(--surface-2); border: 1px solid var(--border); }
.list-thumb--empty { display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--text-muted); }
/* Fiche produit (lecture seule) */
.fiche-info { margin-top: 6px; }
.fiche-info__row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.fiche-info__k { color: var(--text-muted); }
.fiche-info__v { font-weight: 600; text-align: right; }
.fiche-desc { margin: 12px 0 0; font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.fiche-codes { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.fiche-code { display: flex; flex-direction: column; gap: 4px; }
.fiche-code__label { font-size: 12px; color: var(--text-muted); }
.fiche-code img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.hint { font-size: 12px; color: var(--text-muted); margin: -4px 0 10px; line-height: 1.4; }
.code-thumb { position: relative; display: inline-block; margin-top: 8px; }
.code-thumb img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.code-thumb__del { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--danger); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; }

/* ---------- Caméra (scan / capture photo) ---------- */
.cam { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.92); display: flex;
    flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px; }
.cam__box { position: relative; width: 100%; max-width: 520px; }
.cam__video { width: 100%; max-height: 70vh; border-radius: 14px; background: #000; object-fit: cover; }
.cam__frame { position: absolute; inset: 12%; border: 2px solid rgba(255,255,255,.85); border-radius: 14px;
    box-shadow: 0 0 0 100vmax rgba(0,0,0,.25); pointer-events: none; }
.cam__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.cam__actions .btn { background: #fff; color: #0f172a; }
.cam__actions .btn--primary { background: var(--primary); color: #fff; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); font-weight: 600; cursor: pointer; transition: filter .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; }
.btn--block { width: 100%; }
.btn--sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.input, .select, textarea.input {
    width: 100%; padding: 11px 12px; border: 1px solid var(--border);
    border-radius: 10px; background: var(--surface-2); outline: none;
}
.input:focus, .select:focus { border-color: var(--primary); background: var(--surface); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row--between { justify-content: space-between; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

.badge { display: inline-flex; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge--success { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge--warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge--danger  { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.badge--muted   { background: var(--surface-2); color: var(--text-muted); }

.empty { text-align: center; color: var(--text-muted); padding: 40px 16px; }

/* Scan caméra natif (Capacitor) : rend l'interface transparente pour laisser
   apparaître le flux caméra derrière la WebView. */
body.scanning { background: transparent !important; }
body.scanning .layout, body.scanning .toasts { visibility: hidden; }

/* ---------- Login ---------- */
.auth {
    min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth__card { width: 100%; max-width: 400px; }
.auth__logo {
    width: 60px; height: 60px; border-radius: 16px; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 22px;
    margin: 0 auto 16px;
}
.auth__title { text-align: center; font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.auth__sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }
.auth__switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--text-muted); }

/* ---------- Page d'accueil (vitrine) ---------- */
.landing { max-width: 1080px; margin: 0 auto; padding: 24px 20px 48px; }
.landing__hero {
    text-align: center; padding: 40px 16px 28px;
    background: radial-gradient(1200px 400px at 50% -80px, color-mix(in srgb, var(--primary) 22%, transparent), transparent);
    border-radius: 20px;
}
.landing__brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; margin-bottom: 18px; }
.landing__brand .logo { width: 40px; height: 40px; border-radius: 12px; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; }
.landing__title { font-size: clamp(26px, 5vw, 40px); font-weight: 800; line-height: 1.15; margin: 6px auto; max-width: 720px; }
.landing__sub { color: var(--text-muted); font-size: clamp(15px, 2.4vw, 18px); max-width: 620px; margin: 12px auto 22px; }
.landing__cta-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.landing__cta { padding: 13px 22px; font-size: 16px; font-weight: 700; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.landing__cta--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.landing__cta:hover { transform: translateY(-1px); }
.landing__note { color: var(--text-muted); font-size: 13px; margin-top: 14px; }
.landing__features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 34px 0; }
.feature { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.feature__ico { font-size: 26px; line-height: 1; }
.feature__t { font-weight: 700; margin-bottom: 3px; }
.feature__d { color: var(--text-muted); font-size: 13px; }
.landing__auth { display: flex; justify-content: center; margin: 8px 0 32px; scroll-margin-top: 20px; }
.landing__auth .auth__card { width: 100%; max-width: 420px; padding: 22px; }
.auth__tabs { display: flex; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.auth__tab { flex: 1; padding: 9px; border: 0; background: transparent; border-radius: 9px; font-weight: 700; color: var(--text-muted); cursor: pointer; }
.auth__tab--active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.landing__footer { text-align: center; color: var(--text-muted); font-size: 13px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---------- Aide (guide en iframe) ---------- */
.aide-frame { width: 100%; height: calc(100vh - 210px); min-height: 500px; border: 1px solid var(--border); border-radius: 12px; background: #fff; display: block; }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
.pos__cart { position: sticky; top: calc(var(--header-h) + 18px); }
.pos__results { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.prod-card {
    border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer;
    background: var(--surface); display: flex; flex-direction: column; gap: 4px;
}
.prod-card:hover { border-color: var(--primary); }
.prod-card__img {
    width: 100%; height: 96px; object-fit: cover; border-radius: 8px;
    background: var(--surface-2); margin-bottom: 6px; display: block;
}
.prod-card__img--empty {
    display: flex; align-items: center; justify-content: center;
    font-size: 34px; color: var(--text-muted);
}
.prod-card__body { display: flex; flex-direction: column; gap: 4px; }
.prod-card__name { font-weight: 600; font-size: 14px; }
.prod-card__price { color: var(--primary-600); font-weight: 700; }
.prod-card__stock { font-size: 12px; color: var(--text-muted); }
.cart-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cart-line__name { flex: 1; font-size: 14px; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-weight: 700; }
.cart-total { display: flex; justify-content: space-between; font-weight: 800; font-size: 18px; margin: 12px 0; }
.pay-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.pay-mode { padding: 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; text-align: center; cursor: pointer; background: var(--surface-2); }
.pay-mode.active { border-color: var(--primary); color: var(--primary-600); font-weight: 700; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: max-content; max-width: 92vw; }
.toast { padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); color: #fff; font-weight: 600; font-size: 14px; animation: toastin .2s ease; }
.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--info { background: #334155; }
@keyframes toastin { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 40px rgba(0,0,0,.3); }
.modal__head { padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.modal__body { padding: 18px; }
.modal__foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--text-muted); line-height: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .sidebar { display: none; }
    .main { margin-left: 0; padding-bottom: 64px; }
    .pos { grid-template-columns: 1fr; }
    .pos__cart { position: static; }
    .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid.cols-3 { grid-template-columns: 1fr; }

    .bottomnav {
        display: flex; position: fixed; inset: auto 0 0 0; height: 60px;
        background: var(--surface); border-top: 1px solid var(--border);
        z-index: 20; padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .bottomnav button {
        flex: 1; border: none; background: none; cursor: pointer; color: var(--text-muted);
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        font-size: 11px;
    }
    .bottomnav button .ico { font-size: 20px; }
    .bottomnav button.active { color: var(--primary-600); }
}

@media (max-width: 520px) {
    .grid.cols-2 { grid-template-columns: 1fr; }
    .content { padding: 14px; }
}
