/* ============================================================
   DASHBOARD PHARMACIEN — VERSION NETTOYÉE & PREMIUM
   ============================================================ */

/* ── Variables ── */
:root {
    --primary:    #2563eb;
    --success:    #16a34a;
    --warning:    #f59e0b;
    --danger:     #dc2626;
    --bg:         #f0f4fb;
    --card:       #ffffff;
    --text:       #111827;
    --muted:      #6b7280;
    --radius:     18px;
    --shadow-sm:  0 4px 12px  rgba(0,0,0,0.05);
    --shadow-md:  0 10px 30px rgba(0,0,0,0.07);
    --shadow-lg:  0 20px 45px rgba(0,0,0,0.12);
    --transition: 0.3s ease;
}

body { background: var(--bg); }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.dashboard {
    max-width: 1280px;
    margin: 0 auto;
    padding: 40px 24px 80px;
}

/* ============================================================
   HEADER
   ============================================================ */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 36px;
    gap: 24px;
}

.dashboard-header h1 {
    margin: 0 0 6px;
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.subtitle {
    color: var(--muted);
    font-size: 0.95rem;
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Logo pharmacie ── */
.pharmacy-logo {
    width: 88px;
    height: 88px;
    border-radius: var(--radius);
    object-fit: cover;
    box-shadow: var(--shadow-md);
    border: 3px solid white;
    flex-shrink: 0;
}

/* ── Boutons d'action ── */
.action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 20px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--text);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    border: 1.5px solid transparent;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
    white-space: nowrap;
}

.action.primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 14px rgba(37,99,235,0.3);
}

.action.outline {
    background: transparent;
    border-color: var(--primary);
    color: var(--primary);
}

.action:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.action.primary:hover {
    box-shadow: 0 8px 24px rgba(37,99,235,0.4);
    background: #1d4ed8;
}

.action.outline:hover {
    background: rgba(37,99,235,0.05);
}

/* ============================================================
   ALERTES
   ============================================================ */
.alerts {
    display: grid;
    gap: 12px;
    margin-bottom: 32px;
}

.alert-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-radius: 14px;
    font-weight: 600;
    font-size: 0.92rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid transparent;
    animation: slideInAlert 0.4s ease forwards;
}

.alert-box::before {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.alert-box.danger {
    background: #fef2f2;
    color: #991b1b;
    border-left-color: var(--danger);
}

.alert-box.danger::before { content: "🚨"; }

.alert-box.warning {
    background: #fffbeb;
    color: #92400e;
    border-left-color: var(--warning);
}

.alert-box.warning::before { content: "⚠️"; }

@keyframes slideInAlert {
    from { opacity: 0; transform: translateX(-12px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   KPI GRID
   ============================================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.kpi-card {
    background: linear-gradient(160deg, #ffffff, #f8faff);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-md);
    border: 1.5px solid rgba(0,0,0,0.04);
    border-left: 5px solid #e5e7eb;
    transition: transform var(--transition), box-shadow var(--transition);
    position: relative;
    overflow: hidden;
}

/* Décoration de fond subtile */
.kpi-card::after {
    content: "";
    position: absolute;
    right: -20px; top: -20px;
    width: 90px; height: 90px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.03;
    pointer-events: none;
}

.kpi-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.kpi-card.success { border-left-color: var(--success); }
.kpi-card.warning { border-left-color: var(--warning); }
.kpi-card.danger  { border-left-color: var(--danger); }

.kpi-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.kpi-header h4 {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-card > span:first-child {
    font-size: 0.88rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.kpi-number {
    font-size: 2.4rem;
    font-weight: 800;
    color: var(--primary);
    display: block;
    margin: 8px 0 4px;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.kpi-card.success .kpi-number { color: var(--success); }
.kpi-card.warning .kpi-number { color: var(--warning); }
.kpi-card.danger  .kpi-number { color: var(--danger); }

/* ── Badges évolution ── */
.kpi-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
    flex-shrink: 0;
}

.kpi-badge.positive  { background: #dcfce7; color: #15803d; }
.kpi-badge.negative  { background: #fee2e2; color: #b91c1c; }
.kpi-badge.neutral   { background: #f3f4f6; color: #6b7280; }

/* ── Sparkline ── */
.sparkline {
    height: 52px !important;
    margin-top: 10px;
    opacity: 0.85;
}

/* ── Tooltip info ── */
.info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px; height: 18px;
    font-size: 11px;
    cursor: help;
    color: var(--muted);
    background: #f3f4f6;
    border-radius: 50%;
    position: relative;
    font-style: normal;
    margin-left: 4px;
    vertical-align: middle;
}

.info::after {
    content: "Nombre de boîtes disponibles pour tous les médicaments";
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateX(-50%) translateY(4px);
    z-index: 10;
}

.info:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   CHARTS
   ============================================================ */
.charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.chart-box {
    background: linear-gradient(160deg, #ffffff, #f9fafb);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1.5px solid rgba(0,0,0,0.04);
    transition: transform var(--transition), box-shadow var(--transition);
    display: flex;
    flex-direction: column;
    height: fit-content;
}

.chart-box:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.chart-box h3 {
    margin: 0 0 14px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 220px;
    flex-shrink: 0;
}

.chart-wrapper canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

/* ============================================================
   LISTES — TOP / CRITIQUE / ACTIVITÉ
   ============================================================ */
.top-products,
.critical-stock,
.recent-activity {
    margin-top: 40px;
}

.top-products h3,
.critical-stock h3,
.recent-activity h3 {
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Ligne commune pour tous les items */
.top-item,
.critical-item,
.activity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: linear-gradient(160deg, #ffffff, #f9fafb);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    border: 1.5px solid rgba(0,0,0,0.03);
    transition: transform var(--transition), box-shadow var(--transition);
}

.top-item:hover,
.critical-item:hover,
.activity-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.top-list,
.critical-list,
.activity-list {
    display: grid;
    gap: 10px;
}

.med-name {
    font-weight: 600;
    color: var(--text);
    font-size: 0.95rem;
}

.med-qty {
    font-weight: 700;
    font-size: 0.9rem;
}

.critical-item .med-qty { color: var(--danger); }
.top-item      .med-qty { color: var(--success); }

.activity-date {
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
}

/* Rang top produits */
.top-item { counter-increment: top-rank; }

/* ============================================================
   ANIMATIONS SCROLL
   ============================================================ */
.animate {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.55s ease, transform 0.55s ease;
}

.animate.show {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================
   RESPONSIVE — TABLETTE (≤ 1024px)
   ============================================================ */
@media (max-width: 1024px) {

    .dashboard { padding: 28px 20px 60px; }

    .dashboard-header h1 { font-size: 24px; }

    .charts { grid-template-columns: 1fr; }

    .chart-wrapper { height: 200px; }
}

/* ============================================================
   RESPONSIVE — MOBILE (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

    .dashboard { padding: 20px 14px 60px; }

    /* Header */
    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .dashboard-header h1 { font-size: 22px; }

    .header-right {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: 12px;
    }

    /* Actions en scroll horizontal */
    .header-actions {
        display: flex;
        overflow-x: auto;
        gap: 10px;
        padding-bottom: 4px;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }

    .header-actions::-webkit-scrollbar { display: none; }

    .action {
        flex-shrink: 0;
        padding: 10px 16px;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    /* Logo */
    .pharmacy-logo {
        width: 68px;
        height: 68px;
        border-radius: 14px;
    }

    /* KPI — 2 colonnes */
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }

    .kpi-card { padding: 16px; }
    .kpi-number { font-size: 2rem; }

    /* Charts */
    .charts { grid-template-columns: 1fr; gap: 16px; }
    .chart-box { padding: 18px; }
    .chart-wrapper { height: 180px; }

    /* Listes */
    .top-item,
    .critical-item,
    .activity-item { padding: 12px 14px; }

    .activity-item { flex-wrap: wrap; gap: 6px; }
    .activity-date { width: 100%; }
}

/* ============================================================
   RESPONSIVE — PETIT MOBILE (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {

    .dashboard { padding: 16px 12px 50px; }

    .dashboard-header h1 { font-size: 19px; }
    .subtitle { font-size: 0.83rem; }

    /* KPI → 1 colonne */
    .kpi-grid { grid-template-columns: 1fr; gap: 12px; }

    .kpi-number { font-size: 1.9rem; }

    .chart-box { padding: 14px; }
    .chart-box h3 { font-size: 0.75rem; }
    .chart-wrapper { height: 160px; }

    .med-name { font-size: 0.88rem; }
    .med-qty  { font-size: 0.85rem; }

    /* Actions — plus petites */
    .action { padding: 9px 13px; font-size: 0.8rem; }
}