:root {
    --bg: #0d0f14;
    --bg2: #13161d;
    --bg3: #1a1e28;
    --border: #252a38;
    --border2: #2e3548;
    --text: #e2e8f0;
    --text2: #94a3b8;
    --text3: #64748b;
    --accent: #38bdf8;
    --accent2: #0284c7;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #6366f1;
    --font-mono: 'JetBrains Mono', monospace;
    --font-ui: 'Syne', sans-serif;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --transition: 0.18s ease;
}

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

html { font-size: 15px; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    min-height: 100vh;
    line-height: 1.6;
}

/* ─── SCROLLBAR ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ─── NAVBAR ────────────────────────────────────────────────────────────── */
.navbar {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; gap: 1rem;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 56px;
    backdrop-filter: blur(10px);
}

.nav-brand {
    display: flex; align-items: center; gap: 0.5rem;
    text-decoration: none; color: var(--text);
    font-family: var(--font-ui); font-weight: 800; font-size: 1.2rem;
    letter-spacing: 0.05em; flex-shrink: 0;
}
.brand-icon { color: var(--accent); font-size: 1.4rem; }
.brand-accent { color: var(--accent); }

.nav-poles {
    display: flex; gap: 0.4rem; flex-shrink: 0;
}
.pole-badge {
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em;
    text-decoration: none;
    border: 1px solid var(--pole-color, var(--accent));
    color: var(--pole-color, var(--accent));
    background: transparent;
    transition: var(--transition);
    text-transform: uppercase;
}
.pole-badge.active,
.pole-badge:hover {
    background: var(--pole-color, var(--accent));
    color: #fff;
}

.nav-links {
    display: flex; gap: 0.25rem; align-items: center;
    margin-left: auto;
}
.nav-link {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 6px 12px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text2);
    font-size: 0.85rem; font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
    position: relative;
}
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: var(--bg3); color: var(--accent); }
.badge-count {
    background: var(--danger);
    color: #fff;
    border-radius: 99px;
    font-size: 0.65rem; font-weight: 700;
    padding: 1px 5px;
    line-height: 1.4;
}

.nav-user {
    display: flex; align-items: center; gap: 0.5rem;
    flex-shrink: 0;
}
.user-info {
    display: flex; align-items: center; gap: 0.5rem;
    text-decoration: none; color: var(--text2);
    padding: 4px 8px; border-radius: var(--radius);
    transition: var(--transition);
}
.user-info:hover { background: var(--bg3); color: var(--text); }
.user-avatar {
    width: 28px; height: 28px;
    background: var(--accent2);
    color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 700;
}
.user-name { font-size: 0.85rem; font-weight: 600; }
.user-role {
    font-size: 0.65rem; font-weight: 700;
    padding: 1px 6px; border-radius: 99px;
    text-transform: uppercase;
}
.role-admin { background: #7c3aed22; color: #a78bfa; border: 1px solid #7c3aed; }
.role-manager { background: #0284c722; color: #38bdf8; border: 1px solid #0284c7; }
.role-tech { background: #10b98122; color: #34d399; border: 1px solid #10b981; }

.btn-logout {
    background: none; border: 1px solid var(--border2);
    color: var(--text3); cursor: pointer;
    padding: 5px 8px; border-radius: var(--radius);
    font-size: 1rem; text-decoration: none;
    transition: var(--transition);
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

.nav-toggle {
    display: none;
    background: none; border: none;
    color: var(--text); font-size: 1.3rem;
    cursor: pointer; padding: 6px;
    margin-left: auto;
}

.nav-mobile-menu {
    display: none;
    flex-direction: column;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem 1rem;
    gap: 0.25rem;
}
.nav-mobile-menu.open { display: flex; }
.mobile-link, .mobile-pole {
    padding: 10px 12px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text2); font-weight: 600; font-size: 0.9rem;
    transition: var(--transition);
}
.mobile-link:hover { background: var(--bg3); color: var(--text); }
.mobile-pole { color: var(--pole-color, var(--accent)); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.mobile-link.logout { color: var(--danger); }

/* ─── MAIN ──────────────────────────────────────────────────────────────── */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ─── ALERTS ────────────────────────────────────────────────────────────── */
.alerts-container { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.alert {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 14px; border-radius: var(--radius);
    font-size: 0.875rem; font-weight: 500;
    animation: slideIn 0.2s ease;
}
.alert button { background: none; border: none; cursor: pointer; font-size: 1rem; opacity: 0.6; color: inherit; }
.alert button:hover { opacity: 1; }
.alert-success { background: #10b98120; border: 1px solid #10b981; color: #34d399; }
.alert-danger { background: #ef444420; border: 1px solid #ef4444; color: #f87171; }
.alert-warning { background: #f59e0b20; border: 1px solid #f59e0b; color: #fbbf24; }
.alert-info { background: #6366f120; border: 1px solid #6366f1; color: #818cf8; }

/* ─── PAGE HEADER ───────────────────────────────────────────────────────── */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.75rem;
}
.page-title {
    font-family: var(--font-ui); font-size: 1.6rem; font-weight: 800;
    letter-spacing: -0.02em; color: var(--text);
}
.page-title span { color: var(--accent); }

/* ─── CARDS ─────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem;
}
.card-title { font-weight: 700; font-size: 1rem; color: var(--text); }

/* ─── FORMS ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block; margin-bottom: 0.35rem;
    font-size: 0.8rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text3);
}
.form-control {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: var(--font-ui);
    transition: var(--transition);
    outline: none;
    -webkit-appearance: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,0.12); }
.form-control::placeholder { color: var(--text3); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* ─── BUTTONS ───────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-family: var(--font-ui); font-size: 0.875rem; font-weight: 700;
    cursor: pointer; border: none; text-decoration: none;
    transition: var(--transition); letter-spacing: 0.02em;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent2); color: #fff; }
.btn-primary:hover { background: var(--accent); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { filter: brightness(1.1); }
.btn-ghost {
    background: transparent; color: var(--text2);
    border: 1px solid var(--border2);
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); border-color: var(--border2); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 11px 22px; font-size: 1rem; }
.btn-icon { padding: 7px; }

/* ─── SEARCH BAR ────────────────────────────────────────────────────────── */
.search-bar {
    display: flex; gap: 0.75rem; margin-bottom: 1rem;
    flex-wrap: wrap;
}
.search-input-wrap {
    position: relative; flex: 1; min-width: 200px;
}
.search-input-wrap .search-icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text3); pointer-events: none;
}
.search-input-wrap .form-control { padding-left: 34px; }
.filter-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.filter-group select.form-control { min-width: 160px; }

/* ─── STOCK TABLE ───────────────────────────────────────────────────────── */
.stock-table-wrap { overflow-x: auto; }
.stock-table {
    width: 100%;
    border-collapse: collapse;
}
.stock-table th {
    background: var(--bg3);
    padding: 10px 14px;
    text-align: left;
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text3);
    border-bottom: 1px solid var(--border);
    white-space: nowrap; cursor: pointer; user-select: none;
}
.stock-table th:hover { color: var(--text2); }
.stock-table th .sort-icon { opacity: 0.4; margin-left: 4px; }
.stock-table th.sorted .sort-icon { opacity: 1; color: var(--accent); }
.stock-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    font-size: 0.875rem;
}
.stock-table tr:last-child td { border-bottom: none; }
.stock-table tr:hover td { background: var(--bg3); }
.stock-table tbody tr { transition: var(--transition); }

.refs-cell { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.ref-tag {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: var(--bg3);
    border: 1px solid var(--border2);
    padding: 2px 7px; border-radius: 4px;
    color: var(--accent);
    white-space: nowrap;
}
.qty-cell {
    font-family: var(--font-mono); font-weight: 700; font-size: 1rem;
    display: flex; align-items: center; gap: 0.5rem;
}
.qty-alert { color: var(--danger); }
.qty-ok { color: var(--success); }
.qty-warn { color: var(--warning); }

.alerte-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--danger);
    animation: pulse 1.5s infinite;
    display: inline-block; flex-shrink: 0;
}

.statut-badge {
    font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em;
    padding: 2px 8px; border-radius: 99px; text-transform: uppercase;
}
.statut-actif { background: #10b98122; color: #34d399; border: 1px solid #10b98140; }
.statut-obsolete { background: #ef444422; color: #f87171; border: 1px solid #ef444440; }
.statut-attente { background: #f59e0b22; color: #fbbf24; border: 1px solid #f59e0b40; }

/* ─── ITEM DETAIL ───────────────────────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-field { margin-bottom: 1.25rem; }
.detail-label {
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text3); margin-bottom: 0.3rem;
}
.detail-value {
    font-size: 0.9rem; color: var(--text);
    padding: 8px 12px;
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: var(--radius); min-height: 38px;
    word-break: break-word;
}
.detail-value.mono { font-family: var(--font-mono); }
.detail-value a { color: var(--accent); text-decoration: none; }
.detail-value a:hover { text-decoration: underline; }

.qty-controls {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem;
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.qty-display {
    font-family: var(--font-mono); font-size: 2.5rem; font-weight: 700;
    flex: 1; text-align: center;
}
.qty-btn {
    width: 44px; height: 44px;
    border: none; border-radius: 50%;
    font-size: 1.4rem; font-weight: 700;
    cursor: pointer; transition: var(--transition);
    display: flex; align-items: center; justify-content: center;
}
.qty-btn-plus { background: var(--success); color: #fff; }
.qty-btn-plus:hover { filter: brightness(1.15); transform: scale(1.05); }
.qty-btn-minus { background: var(--bg2); color: var(--text2); border: 1px solid var(--border2); }
.qty-btn-minus:hover { border-color: var(--danger); color: var(--danger); }

.photo-thumb {
    width: 100%; border-radius: var(--radius-lg);
    border: 1px solid var(--border2);
    cursor: zoom-in; transition: var(--transition);
    max-height: 280px; object-fit: cover;
}
.photo-thumb:hover { border-color: var(--accent); }

.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 8px 12px;
    background: var(--bg3); border-radius: var(--radius);
    font-size: 0.82rem;
}
.history-delta {
    font-family: var(--font-mono); font-weight: 700; min-width: 40px; text-align: center;
    padding: 2px 6px; border-radius: 4px;
}
.delta-plus { background: #10b98122; color: #34d399; }
.delta-minus { background: #ef444422; color: #f87171; }
.history-date { color: var(--text3); font-size: 0.75rem; margin-left: auto; white-space: nowrap; }

/* ─── COMMANDES ─────────────────────────────────────────────────────────── */
.commandes-grid { display: grid; gap: 1rem; }
.commande-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: var(--transition);
}
.commande-card:hover { border-color: var(--border2); }
.commande-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.priorite-badge {
    font-size: 0.7rem; font-weight: 700; padding: 3px 9px;
    border-radius: 99px; text-transform: uppercase; letter-spacing: 0.05em;
}
.priorite-normal { background: #6366f122; color: #818cf8; border: 1px solid #6366f140; }
.priorite-urgent { background: #f59e0b22; color: #fbbf24; border: 1px solid #f59e0b40; }
.priorite-critique { background: #ef444422; color: #f87171; border: 1px solid #ef444440; animation: pulse 2s infinite; }

.statut-commande {
    font-size: 0.7rem; font-weight: 700; padding: 3px 9px;
    border-radius: 99px; text-transform: uppercase;
}
.statut-demande { background: #f59e0b22; color: #fbbf24; border: 1px solid #f59e0b40; }
.statut-valide { background: #6366f122; color: #818cf8; border: 1px solid #6366f140; }
.statut-commande-en { background: #0284c722; color: #38bdf8; border: 1px solid #0284c740; }
.statut-recu { background: #10b98122; color: #34d399; border: 1px solid #10b98140; }

.commande-items { margin: 0.75rem 0; }
.commande-item-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem; gap: 1rem;
}
.commande-item-row:last-child { border-bottom: none; }

.statut-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ─── DASHBOARD ─────────────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    position: relative; overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--pole-color, var(--accent));
}
.stat-card-label {
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text3); margin-bottom: 0.5rem;
}
.stat-card-value {
    font-family: var(--font-mono); font-size: 2.2rem; font-weight: 700;
    color: var(--text); line-height: 1;
}
.stat-card-sub { font-size: 0.8rem; color: var(--text3); margin-top: 0.4rem; }
.stat-alert { color: var(--danger) !important; }

/* ─── ADMIN ─────────────────────────────────────────────────────────────── */
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td {
    padding: 10px 12px; text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.users-table th {
    background: var(--bg3); font-size: 0.72rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.06em; color: var(--text3);
}
.users-table tr:hover td { background: var(--bg3); }

/* ─── LOGIN ─────────────────────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg);
}
.login-card {
    width: 100%; max-width: 400px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
}
.login-logo {
    text-align: center; margin-bottom: 2rem;
    font-family: var(--font-ui); font-size: 2.5rem; font-weight: 800;
}
.login-logo span { color: var(--accent); }

/* ─── MODAL ─────────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 999;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
    align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--bg2); border: 1px solid var(--border2);
    border-radius: var(--radius-lg); padding: 1.75rem;
    width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto;
    animation: modalIn 0.2s ease;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 1.3rem; }
.modal-close:hover { color: var(--text); }

/* ─── PHOTO ZOOM ────────────────────────────────────────────────────────── */
.photo-zoom-overlay {
    display: none; position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.9);
    align-items: center; justify-content: center; cursor: zoom-out;
}
.photo-zoom-overlay.open { display: flex; }
.photo-zoom-overlay img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius-lg); }

/* ─── EMPTY STATE ───────────────────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 4rem 2rem;
    color: var(--text3);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }

/* ─── MISC ──────────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.text-muted { color: var(--text3); font-size: 0.8rem; }
.text-mono { font-family: var(--font-mono); }
.tag {
    font-size: 0.72rem; font-weight: 700; padding: 2px 8px;
    border-radius: 4px; text-transform: uppercase;
    background: var(--bg3); color: var(--text2); border: 1px solid var(--border2);
}
.flex { display: flex; } .gap-1 { gap: 0.5rem; } .gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* ─── ANIMATIONS ────────────────────────────────────────────────────────── */
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ─── RESPONSIVE ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .nav-links, .nav-poles, .nav-user { display: none; }
    .nav-toggle { display: block; }
}
@media (max-width: 600px) {
    .main-content { padding: 1rem; }
    .page-title { font-size: 1.3rem; }
    .detail-grid { grid-template-columns: 1fr; }
    .stock-table td:nth-child(3), .stock-table th:nth-child(3) { display: none; }
}

/* ─── PRINT (QR) ────────────────────────────────────────────────────────── */
@media print {
    .navbar, .nav-mobile-menu, .alerts-container, .btn { display: none !important; }
    body { background: white; color: black; }
    .qr-print-block { text-align: center; padding: 2rem; }
}
