/* ══════════════════════════════════════════════════════════════════════
   MDM Console — Styles
   ══════════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary:   #ffffff;
    --bg-secondary: #f8fafc;
    --bg-card:      #ffffff;
    --bg-hover:     #f1f5f9;
    --border:       #e2e8f0;
    --text-primary: #1e293b;
    --text-muted:   #64748b;
    --accent:       #f97316;
    --accent-hover: #c2570c;
    --green:        #22c55e;
    --red:          #ef4444;
    --orange:       #f97316;
    --blue:         #3b82f6;
    --yellow:       #eab308;
    --sidebar-w:    240px;
    --radius:       10px;
    --transition:   0.2s ease;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ══════════════════════════════════════════════════════════════════════
   Sidebar
   ══════════════════════════════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    font-size: 17px;
    font-weight: 700;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
}
.sidebar-brand i { font-size: 22px; }
.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    transition: all var(--transition);
    font-weight: 500;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item i { width: 18px; text-align: center; }
.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}
.sidebar-footer button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    transition: color var(--transition);
}
.sidebar-footer button:hover { color: var(--red); }

/* ══════════════════════════════════════════════════════════════════════
   Main Content
   ══════════════════════════════════════════════════════════════════════ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.topbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h1 { font-size: 16px; font-weight: 600; flex: 1; }
#menu-toggle {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 16px; display: none;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}
.online-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}
#server-status-dot { font-size: 8px; color: var(--text-muted); }
#server-status-dot.online { color: var(--green); }
#btn-refresh {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer; font-size: 15px;
    padding: 6px; border-radius: 6px; transition: all var(--transition);
}
#btn-refresh:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Pages ────────────────────────────────────────────────────────────── */
.page { display: none; padding: 24px; animation: fadeIn 0.2s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ══════════════════════════════════════════════════════════════════════
   Stats Grid
   ══════════════════════════════════════════════════════════════════════ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(59,130,246,0.15); color: var(--blue); }
.stat-icon.green  { background: rgba(34,197,94,0.15);  color: var(--green); }
.stat-icon.red    { background: rgba(239,68,68,0.15);  color: var(--red); }
.stat-icon.orange { background: rgba(249,115,22,0.15); color: var(--orange); }
.stat-value { font-size: 28px; font-weight: 700; display: block; }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════════════
   Cards
   ══════════════════════════════════════════════════════════════════════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 20px; }
.grid-2  { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mt-4 { margin-top: 16px; }

/* ══════════════════════════════════════════════════════════════════════
   Table
   ══════════════════════════════════════════════════════════════════════ */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { border-bottom: 1px solid var(--border); }
.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ══════════════════════════════════════════════════════════════════════
   Badges & Status
   ══════════════════════════════════════════════════════════════════════ */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-online  { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-offline { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.badge-active  { background: rgba(249,115,22,0.15); color: var(--accent); }
.badge-lost    { background: rgba(239,68,68,0.15);  color: var(--red); }
.badge-success { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-failed  { background: rgba(239,68,68,0.15);  color: var(--red); }
.badge-pending { background: rgba(234,179,8,0.15);  color: var(--yellow); }
.badge-sent    { background: rgba(59,130,246,0.15); color: var(--blue); }

/* Statut vente à crédit */
.badge-actif   { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-solde   { background: rgba(59,130,246,0.15); color: var(--blue); }
.badge-defaut  { background: rgba(239,68,68,0.15);  color: var(--red); }
.badge-annule  { background: rgba(100,116,139,0.15); color: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════════════
   Top progress bar (NProgress-style)
   ══════════════════════════════════════════════════════════════════════ */
#api-progress {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    width: 0%;
    background: var(--accent);
    z-index: 9999;
    border-radius: 0 2px 2px 0;
    transition: width 0.25s ease, opacity 0.4s ease;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 0 8px rgba(249,115,22,0.6);
}
#api-progress.active {
    opacity: 1;
}

/* ══════════════════════════════════════════════════════════════════════
   Buttons
   ══════════════════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 8px; font-size: 13px;
    font-weight: 500; cursor: pointer; border: none;
    transition: all var(--transition); text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger  { background: rgba(239,68,68,0.15); color: var(--red); }
.btn-danger:hover  { background: var(--red); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover   { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm      { padding: 4px 10px; font-size: 12px; }
.w-full      { width: 100%; justify-content: center; }

/* État chargement bouton */
.btn.loading, .cmd-btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}
.btn.loading::before, .cmd-btn.loading::before {
    content: '';
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
    flex-shrink: 0;
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* ══════════════════════════════════════════════════════════════════════
   Forms
   ══════════════════════════════════════════════════════════════════════ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 9px 12px;
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}
.form-group input:focus,
.form-group select:focus { border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.page-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.search-box {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px 12px; flex: 1; min-width: 200px;
}
.search-box i { color: var(--text-muted); }
.search-box input { background: none; border: none; color: var(--text-primary); outline: none; width: 100%; font-size: 14px; }
.page-toolbar select {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text-primary); padding: 8px 12px;
    font-size: 13px; outline: none; cursor: pointer;
}

/* ══════════════════════════════════════════════════════════════════════
   Battery indicator
   ══════════════════════════════════════════════════════════════════════ */
.battery-bar {
    display: flex; align-items: center; gap: 6px; font-size: 12px;
}
.battery-track {
    width: 44px; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden;
}
.battery-fill { height: 100%; border-radius: 4px; }
.battery-fill.high   { background: var(--green); }
.battery-fill.medium { background: var(--orange); }
.battery-fill.low    { background: var(--red); }

/* ══════════════════════════════════════════════════════════════════════
   Modal
   ══════════════════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; backdrop-filter: blur(4px);
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.2s ease;
}
.modal-sm  { max-width: 380px; }
.modal-lg  { max-width: 860px; width: 95vw; }

.log-tab {
    padding: 6px 12px;
    font-size: 11px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: var(--bg-secondary);
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.log-tab:hover  { background: var(--bg-hover); color: var(--text-primary); }
.log-tab.active { background: var(--bg-primary); color: var(--text-primary); }

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 18px; padding: 2px;
    transition: color var(--transition);
}
.modal-close:hover { color: var(--red); }
.modal-body { padding: 20px; }

/* ══════════════════════════════════════════════════════════════════════
   Command Grid
   ══════════════════════════════════════════════════════════════════════ */
.command-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.cmd-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 8px;
    text-align: center;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-primary);
    transition: all var(--transition);
    display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.cmd-btn i { font-size: 18px; }
.cmd-btn:hover { border-color: var(--accent); background: rgba(249,115,22,0.1); }
.cmd-btn.danger:hover { border-color: var(--red); background: rgba(239,68,68,0.1); color: var(--red); }
.cmd-btn.active { border-color: var(--accent); background: rgba(249,115,22,0.15); color: var(--accent); }

/* ══════════════════════════════════════════════════════════════════════
   Toast
   ══════════════════════════════════════════════════════════════════════ */
#toast-container {
    position: fixed; bottom: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 9999;
}
.toast {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; padding: 12px 16px;
    font-size: 13px; box-shadow: 0 4px 20px rgba(15, 23, 42, 0.1);
    animation: slideIn 0.3s ease;
    min-width: 280px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ══════════════════════════════════════════════════════════════════════
   Activity Feed
   ══════════════════════════════════════════════════════════════════════ */
.activity-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 8px 0; border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
    width: 8px; height: 8px; border-radius: 50%;
    margin-top: 4px; flex-shrink: 0;
}
.activity-dot.success { background: var(--green); }
.activity-dot.failed  { background: var(--red); }
.activity-dot.pending { background: var(--yellow); }
.activity-text { font-size: 13px; }
.activity-time { font-size: 11px; color: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════════════
   Misc
   ══════════════════════════════════════════════════════════════════════ */
.empty-state {
    text-align: center; padding: 32px; color: var(--text-muted);
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.instructions { padding-left: 20px; line-height: 2.2; }
.instructions li { font-size: 14px; color: var(--text-muted); }
.instructions strong { color: var(--text-primary); }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-top: 10px; }
.alert-error { background: rgba(239,68,68,0.1); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.mt-2 { margin-top: 8px; }
.text-muted { color: var(--text-muted); font-size: 12px; }
.device-name { font-weight: 600; }
.device-model { font-size: 12px; color: var(--text-muted); }

/* ── Device checklist (apply policy modal) ───────────────────────────── */
.device-check {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 6px; cursor: pointer;
    transition: background var(--transition);
}
.device-check:hover { background: var(--bg-hover); }
.device-check input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }

/* ── QR Enrollment ───────────────────────────────────────────────────── */
.qr-container {
    display: inline-flex;
    padding: 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin: 0 auto;
    min-height: 280px;
    align-items: center;
    justify-content: center;
}
.qr-container canvas, .qr-container img { display: block; }

/* ── Sale summary (modal détail vente) ───────────────────────────────── */
.sale-summary {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
    margin-bottom: 12px;
}
.sale-summary > div {
    background: var(--bg-secondary); padding: 12px; border-radius: 8px;
    text-align: center; border: 1px solid var(--border);
}
.sale-summary .lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.sale-summary .val { font-size: 18px; font-weight: 700; margin-top: 4px; }

/* ── Échéances list ──────────────────────────────────────────────────── */
.echeances-list { display: grid; gap: 8px; }
.echeance-item {
    display: grid; grid-template-columns: 1fr 1fr 1fr auto;
    gap: 10px; align-items: center;
    background: var(--bg-secondary); padding: 10px 12px;
    border-radius: 8px; border: 1px solid var(--border); font-size: 13px;
}
.echeance-item.paye { opacity: 0.55; }
.echeance-item .ech-date { font-weight: 600; }
.echeance-item .ech-montant { color: var(--green); font-weight: 600; }
.echeance-item .ech-status { color: var(--text-muted); font-size: 12px; }

/* ══════════════════════════════════════════════════════════════════════
   Auth overlay (login + 2FA)
   ══════════════════════════════════════════════════════════════════════ */
.auth-overlay {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #f8fafc 0%, #fff7ed 100%);
    z-index: 2000;
    padding: 20px;
}
.auth-overlay.hidden { display: none; }
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 26px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
    animation: slideUp 0.25s ease;
}
.auth-brand {
    display: flex; align-items: center; gap: 10px;
    font-size: 17px; font-weight: 700;
    color: var(--accent);
    margin-bottom: 20px;
}
.auth-brand i { font-size: 22px; }
.auth-step h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
}
.auth-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 18px;
    line-height: 1.5;
}
.auth-sub strong { color: var(--text-primary); }
.auth-otp-input {
    font-size: 22px !important;
    text-align: center;
    letter-spacing: 10px;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
    font-weight: 600;
}
.auth-error {
    background: rgba(239, 68, 68, 0.08);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    margin-bottom: 14px;
}
.auth-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 14px;
    font-size: 13px;
}
.btn-link {
    background: none; border: none; padding: 4px 0;
    color: var(--accent); cursor: pointer; font-size: 13px;
    text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }
.btn-link:disabled { color: var(--text-muted); cursor: not-allowed; text-decoration: none; }
#btn-logout {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer; font-size: 15px;
    padding: 6px; border-radius: 6px; transition: all var(--transition);
}
#btn-logout:hover { background: var(--bg-hover); color: var(--red); }

/* ══════════════════════════════════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    #menu-toggle { display: block; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .command-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
    .stats-grid { grid-template-columns: 1fr; }
}
