:root {
    --bg-main: #0f1320;
    --bg-sidebar: #12172a;
    --bg-card: #1a2033;
    --bg-card-hover: #202744;
    --border-color: #262e47;
    --text-main: #e6e8f0;
    --text-muted: #8891ac;
    --accent: #6366f1;
    --accent-hover: #7779f5;
    --accent-soft: rgba(99, 102, 241, 0.15);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-width: 260px;
}

* { box-sizing: border-box; }

body {
    background: var(--bg-main);
    color: var(--text-main);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 0.92rem;
}

a { text-decoration: none; }

/* ---------- Layout ---------- */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform .2s ease;
}

.sidebar-brand {
    padding: 1.25rem 1.4rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand .logo-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
}

.sidebar-brand strong { font-size: 1.02rem; letter-spacing: .2px; }
.sidebar-brand small { color: var(--text-muted); font-size: .72rem; }

.sidebar-nav { padding: 1rem .75rem; flex: 1; overflow-y: auto; }

.sidebar-section-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: .8rem .6rem .3rem;
}

.sidebar-nav .nav-link {
    color: var(--text-muted);
    padding: .62rem .75rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: .7rem;
    font-size: .87rem;
    margin-bottom: 2px;
}

.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-nav .nav-link:hover {
    background: var(--bg-card-hover);
    color: var(--text-main);
}

.sidebar-nav .nav-link.active {
    background: var(--accent-soft);
    color: #c7c9ff;
    font-weight: 600;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

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

.topbar {
    height: 68px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    background: rgba(15, 19, 32, 0.85);
    position: sticky;
    top: 0;
    z-index: 900;
    backdrop-filter: blur(6px);
}

.topbar .page-title { font-size: 1.15rem; font-weight: 600; }
.topbar .page-subtitle { color: var(--text-muted); font-size: .8rem; }

.content-area { padding: 1.75rem; flex: 1; }

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    color: var(--text-main);
    overflow: hidden;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.stat-card {
    padding: 1.25rem 1.4rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    transition: transform .15s ease, border-color .15s ease;
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--accent); }

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-card .stat-text { min-width: 0; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--text-muted); font-size: .78rem; }

/* ---------- Tables ---------- */
.table {
    color: var(--text-main);
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-main);
    --bs-table-striped-bg: rgba(255,255,255,.02);
    --bs-table-hover-bg: var(--bg-card-hover);
    --bs-table-hover-color: var(--text-main);
    --bs-table-border-color: var(--border-color);
    margin-bottom: 0;
}
.table thead th {
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
    padding: .9rem 1rem;
    white-space: nowrap;
}
.table td, .table th {
    border-color: var(--border-color);
    vertical-align: middle;
    padding: .85rem 1rem;
    color: var(--text-main);
}
.table-hover tbody tr { transition: background-color .12s ease; }
.table-hover tbody tr:hover { background: var(--bg-card-hover); }
.table tbody tr:last-child td { border-bottom: none; }

.style-block {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: .85rem 1rem;
    margin-bottom: .85rem;
    background: var(--bg-main);
}
.style-block-title {
    font-weight: 600;
    font-size: .82rem;
    margin-bottom: .6rem;
    color: var(--text-main);
}
.form-select-sm, .form-control-color.form-control-sm { font-size: .82rem; }

.code-pill {
    background: var(--bg-card-hover);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: .3rem .7rem;
    border-radius: 20px;
    font-family: 'Courier New', monospace;
    font-size: .78rem;
    letter-spacing: .02em;
    display: inline-block;
}

.qr-thumb-btn {
    width: 34px; height: 34px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--border-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #111;
    font-size: 1.05rem;
    padding: 0;
}
.qr-thumb-btn:hover { border-color: var(--accent); }

.current-logo-info {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: .5rem .75rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-top: .5rem;
}
.current-logo-info img {
    width: 32px; height: 32px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    padding: 2px;
    flex-shrink: 0;
}
.current-logo-info span { color: var(--text-muted); font-size: .8rem; word-break: break-all; }

/* ---------- Forms ---------- */
.form-control, .form-select {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.form-control:focus, .form-select:focus {
    background: var(--bg-main);
    color: var(--text-main);
    border-color: var(--accent);
    box-shadow: 0 0 0 .2rem var(--accent-soft);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label { font-size: .82rem; color: var(--text-muted); margin-bottom: .35rem; }
.form-control-color { height: 42px; }

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-outline-light-soft {
    border: 1px solid var(--border-color);
    color: var(--text-main);
    background: transparent;
}
.btn-outline-light-soft:hover { background: var(--bg-card-hover); color: var(--text-main); }

/* Garde-fou : certaines classes utilitaires Bootstrap (text-muted, etc.)
   utilisent des couleurs pensées pour un thème clair et deviennent
   illisibles sur fond sombre. On force la couleur de notre thème. */
.text-muted { color: var(--text-muted) !important; }
.form-text { color: var(--text-muted); }

.dropdown-menu {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 12px 28px rgba(0,0,0,.35);
}
.dropdown-item { color: var(--text-main); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--bg-card-hover); color: var(--text-main); }
.dropdown-divider { border-color: var(--border-color); }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.modal-header { border-bottom: 1px solid var(--border-color); }
.modal-footer { border-top: 1px solid var(--border-color); }

/* ---------- Misc ---------- */
.avatar-circle {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: .85rem;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top left, #1a2144, var(--bg-main) 60%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2.25rem;
}

.qr-preview-box {
    background: #fff;
    border-radius: 14px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
}

/* La carte d'aperçu suit le défilement pour rester visible pendant qu'on
   modifie le formulaire à gauche (uniquement quand les colonnes sont
   côte à côte, cf. media query ci-dessous). Le parent .row garde son
   comportement "stretch" par défaut : la colonne reste aussi haute que
   le formulaire, ce qui laisse de la place à la carte pour "coller"
   pendant le défilement. */
.qr-preview-sticky {
    position: sticky;
    top: calc(68px + 1.75rem); /* hauteur de la topbar + padding du contenu */
    align-self: flex-start; /* la carte elle-même ne s'étire pas dans sa colonne */
}

@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .qr-preview-sticky { position: static; }
}
