/* =========================================================
   Devices Fixer - Feuille de style principale
   Theme clair par defaut + theme sombre via [data-theme="dark"]
   ========================================================= */

:root {
    --bg:            #f4f6fb;
    --bg-alt:        #ffffff;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --border:        #e2e8f0;
    --text:          #1e293b;
    --text-muted:    #64748b;
    --primary:       #4f46e5;
    --primary-dark:  #4338ca;
    --primary-soft:  #eef2ff;
    --accent:        #7c3aed;
    --success:       #16a34a;
    --success-soft:  #dcfce7;
    --danger:        #dc2626;
    --danger-soft:   #fee2e2;
    --warning:       #d97706;
    --warning-soft:  #fef3c7;
    --info:          #0284c7;
    --info-soft:     #e0f2fe;
    --shadow:        0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
    --radius:        12px;
    --radius-sm:     8px;
    --sidebar-w:     264px;
}

[data-theme="dark"] {
    --bg:            #0f172a;
    --bg-alt:        #1e293b;
    --surface:       #1e293b;
    --surface-2:     #172033;
    --border:        #334155;
    --text:          #e2e8f0;
    --text-muted:    #94a3b8;
    --primary:       #818cf8;
    --primary-dark:  #6366f1;
    --primary-soft:  #312e81;
    --accent:        #a78bfa;
    --success:       #4ade80;
    --success-soft:  #14532d;
    --danger:        #f87171;
    --danger-soft:   #7f1d1d;
    --warning:       #fbbf24;
    --warning-soft:  #78350f;
    --info:          #38bdf8;
    --info-soft:     #075985;
    --shadow:        0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    transition: background .2s ease, color .2s ease;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .6rem; font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 6px;
    font-size: .875em;
}

/* =========================================================
   CONNEXION
   ========================================================= */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #2563eb 100%);
}
[data-theme="dark"] .login-page {
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 55%, #0f172a 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .28);
    padding: 34px 30px;
}

.login-logo {
    text-align: center;
    margin-bottom: 22px;
}
.login-logo .emoji { font-size: 2.6rem; display: block; }
.login-logo h1 { margin: 8px 0 2px; color: var(--primary); }
.login-logo p { margin: 0; color: var(--text-muted); font-size: .9rem; }

.login-accounts {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
    font-size: .82rem;
    color: var(--text-muted);
    text-align: center;
}

/* =========================================================
   MISE EN PAGE (sidebar + contenu)
   ========================================================= */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand strong { display: block; font-size: 1.1rem; color: var(--primary); }
.sidebar-brand span { font-size: .8rem; color: var(--text-muted); }

.sidebar-nav { padding: 12px 10px; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 13px;
    margin-bottom: 4px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: .93rem;
    text-align: left;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-item .nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    border-radius: 999px;
    font-size: .72rem;
    padding: 1px 8px;
    font-weight: 700;
}
.nav-item.active .nav-badge { background: rgba(255, 255, 255, .28); }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: .87rem;
}
.user-chip .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    flex: 0 0 32px;
}
.user-chip small { display: block; color: var(--text-muted); font-size: .76rem; }

.content { flex: 1; min-width: 0; padding: 22px 26px 60px; }

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.topbar h1 { margin: 0; }
.topbar .spacer { flex: 1; }

.menu-toggle {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text);
}

/* =========================================================
   SECTIONS
   ========================================================= */
.section { display: none; animation: fade .18s ease; }
.section.active { display: block; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* =========================================================
   CARTES
   ========================================================= */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.card-header h2 { margin: 0; }
.card-header .spacer { flex: 1; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
}
.stat-card .stat-label { color: var(--text-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-size: 1.65rem; font-weight: 700; margin-top: 4px; word-break: break-word; }
.stat-card.is-success { border-left-color: var(--success); }
.stat-card.is-warning { border-left-color: var(--warning); }
.stat-card.is-danger  { border-left-color: var(--danger); }
.stat-card.is-info    { border-left-color: var(--info); }

.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}
.quick-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: var(--text);
    transition: transform .15s ease, border-color .15s ease;
}
.quick-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.quick-card .qc-icon { font-size: 1.6rem; display: block; margin-bottom: 6px; }
.quick-card strong { display: block; }
.quick-card small { color: var(--text-muted); }

/* =========================================================
   FORMULAIRES
   ========================================================= */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 16px;
}
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: .87rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-alt);
    color: var(--text);
    font: inherit;
    font-size: .94rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
.form-control::placeholder { color: var(--text-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 90px; resize: vertical; }

.field-error {
    display: block;
    color: var(--danger);
    font-size: .8rem;
    margin-top: 4px;
    min-height: 1em;
}
.form-control.is-invalid { border-color: var(--danger); }

.form-hint { font-size: .82rem; color: var(--text-muted); }

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 16px;
}
.toolbar .form-group { margin: 0; }

/* =========================================================
   BOUTONS
   ========================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s ease, transform .1s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-sm  { padding: 6px 10px; font-size: .83rem; }
.btn-icon { padding: 6px 9px; font-size: .95rem; }
.btn-block { width: 100%; }

[data-theme="dark"] .btn-primary,
[data-theme="dark"] .btn-success,
[data-theme="dark"] .btn-danger,
[data-theme="dark"] .btn-warning { color: #0f172a; }

.theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    cursor: pointer;
    font: inherit;
    font-size: .87rem;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.theme-toggle:hover { border-color: var(--primary); }

/* =========================================================
   TABLEAUX
   ========================================================= */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.table th, .table td {
    padding: 11px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table thead th {
    background: var(--surface-2);
    font-weight: 650;
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: var(--text-muted);
    white-space: nowrap;
}
.table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table tbody tr:hover { background: var(--primary-soft); }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .actions-cell { white-space: nowrap; display: flex; gap: 6px; }

.table tr.row-danger,
.table tr.row-danger:nth-child(even) { background: var(--danger-soft); }
.table tr.row-danger:hover { background: color-mix(in srgb, var(--danger-soft) 80%, var(--danger)); }

.thumb {
    width: 50px; height: 50px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    display: block;
}
.thumb-placeholder {
    width: 50px; height: 50px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
    display: grid;
    place-items: center;
    font-size: .6rem;
    color: var(--text-muted);
    text-align: center;
    padding: 2px;
    line-height: 1.1;
}

.empty-state {
    padding: 34px 18px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state .emoji { font-size: 2rem; display: block; margin-bottom: 8px; }

/* =========================================================
   BADGES / ALERTES
   ========================================================= */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 650;
    white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-muted   { background: var(--surface-2);    color: var(--text-muted); }

.alert {
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    margin-bottom: 14px;
    font-size: .92rem;
}
.alert-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.alert-danger  { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.alert-info    { background: var(--info-soft);    border-color: var(--info);    color: var(--info); }

/* =========================================================
   NOTIFICATIONS (liste)
   ========================================================= */
.notif-item {
    display: flex;
    gap: 12px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 9px;
    background: var(--surface-2);
}
.notif-item.is-unread { border-left: 4px solid var(--primary); }
.notif-item.type-low_stock { background: var(--danger-soft); border-color: var(--danger); }
.notif-item.type-low_stock .notif-date { color: var(--danger); }
.notif-item .notif-icon { font-size: 1.3rem; }
.notif-item .notif-body { flex: 1; min-width: 0; }
.notif-item .notif-date { font-size: .78rem; color: var(--text-muted); }

/* =========================================================
   TOASTS
   ========================================================= */
#toast-zone {
    position: fixed;
    top: 18px; right: 18px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 9px;
    max-width: min(360px, calc(100vw - 36px));
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 12px 15px;
    font-size: .9rem;
    animation: toast-in .2s ease;
}
.toast.is-success { border-left-color: var(--success); }
.toast.is-danger  { border-left-color: var(--danger); }
.toast.is-warning { border-left-color: var(--warning); }
.toast.hide { animation: toast-out .25s ease forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }

/* =========================================================
   MODALES
   ========================================================= */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 28px 16px;
    z-index: 2000;
    overflow-y: auto;
}
.modal-backdrop.open { display: flex; }

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
    width: 100%;
    max-width: 620px;
    margin: auto;
}
.modal.modal-lg { max-width: 900px; }

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; flex: 1; }
.modal-close {
    background: transparent;
    border: 0;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px 6px;
}
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* =========================================================
   CAMERA / OCR
   ========================================================= */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
    padding: 9px 16px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font: inherit;
    font-size: .9rem;
    font-weight: 600;
}
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.camera-stage {
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    max-width: 560px;
    aspect-ratio: 4 / 3;
    display: grid;
    place-items: center;
    margin-bottom: 12px;
}
.camera-stage video,
.camera-stage img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.camera-stage .placeholder { color: #94a3b8; font-size: .9rem; padding: 20px; text-align: center; }

.ocr-progress {
    height: 8px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
    margin: 10px 0;
}
.ocr-progress span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--primary);
    transition: width .2s ease;
}

/* =========================================================
   VENDEUR - recherche et vente
   ========================================================= */
.sell-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 16px;
}
.sell-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.sell-card.is-out { opacity: .65; }
.sell-card .sc-head { display: flex; gap: 12px; }
.sell-card .sc-head img,
.sell-card .sc-head .thumb-placeholder { width: 64px; height: 64px; flex: 0 0 64px; }
.sell-card .sc-head img { object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.sell-card .sc-title { font-weight: 650; }
.sell-card .sc-meta { font-size: .82rem; color: var(--text-muted); }
.sell-card .sc-prices { display: flex; gap: 14px; font-size: .85rem; flex-wrap: wrap; }
.sell-card .calc-box {
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: .9rem;
}
.sell-card .calc-box .commission-value { color: var(--success); font-weight: 700; }
.sell-card .calc-box .profit-value { font-weight: 650; }
.sell-card .calc-box.is-negative { border-color: var(--danger); color: var(--danger); }
.sell-card .calc-box.is-negative .commission-value { color: var(--danger); }

/* =========================================================
   TICKET
   ========================================================= */
.ticket {
    width: 302px;
    margin: 0 auto;
    background: #fff;
    color: #000;
    font-family: "Courier New", Courier, monospace;
    font-size: 13px;
    line-height: 1.5;
    padding: 14px 16px;
    border: 1px dashed #999;
    border-radius: 6px;
}
.ticket hr { border: 0; border-top: 1px dashed #000; margin: 8px 0; }
.ticket .t-center { text-align: center; }
.ticket .t-title { font-size: 17px; font-weight: bold; letter-spacing: 1px; }
.ticket .t-row { display: flex; justify-content: space-between; gap: 10px; }
.ticket .t-sep { text-align: center; letter-spacing: 1px; }

/* =========================================================
   PAGINATION
   ========================================================= */
.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 14px;
    flex-wrap: wrap;
    font-size: .88rem;
}

/* =========================================================
   PAGE INSTALLATION
   ========================================================= */
.install-page { padding: 40px 16px; background: var(--bg); }
.install-card {
    max-width: 760px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}
.install-list { line-height: 1.9; padding-left: 18px; }
.install-errors { color: var(--danger); }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 900px) {
    .menu-toggle { display: inline-block; }
    .sidebar {
        position: fixed;
        z-index: 1500;
        left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, .35);
    }
    .sidebar.open { transform: none; }
    .content { padding: 16px 14px 60px; }
    .sell-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    body { font-size: 14px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card .stat-value { font-size: 1.25rem; }
    .card { padding: 15px; }
    .table th, .table td { padding: 9px 8px; }
}

/* =========================================================
   IMPRESSION
   ========================================================= */
@media print {
    body { background: #fff; color: #000; }
    .sidebar, .topbar, .no-print, #toast-zone, .modal-footer, .btn { display: none !important; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; padding: 0; }
    /* Seule une modale ouverte est imprimee ; les autres restent masquees. */
    .modal-backdrop { display: none !important; }
    .modal-backdrop.open {
        display: block !important;
        position: static;
        background: none;
        padding: 0;
        overflow: visible;
    }
    .modal { box-shadow: none; max-width: 100%; }
    .modal-close { display: none !important; }
    .ticket { border: 0; width: 100%; }
    @page { margin: 8mm; }
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}
