/* ======================================================
   VARIABLES
====================================================== */
:root{
  --bg:#F4F6F8;
  --card:#FFFFFF;
  --text:#111827;
  --muted:#6B7280;
  --line:#E5E7EB;

  --primary:#16A34A;
  --blue:#2563EB;
  --orange:#EA580C;
  --purple:#7C3AED;
  --danger:#DC2626;
  --warn:#D97706;

  --radius:18px;
  --shadow:0 10px 25px rgba(15,23,42,.08);
}

/* ======================================================
   BASE
====================================================== */
*{ box-sizing:border-box }
html,body{ height:100% }

body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:
    radial-gradient(1200px 600px at 10% 0%, rgba(37,99,235,.10), transparent 60%),
    radial-gradient(1200px 600px at 90% 10%, rgba(22,163,74,.10), transparent 60%),
    radial-gradient(1200px 700px at 50% 100%, rgba(234,88,12,.09), transparent 65%),
    var(--bg);
  color:var(--text);
}

a{ color:inherit; text-decoration:none }

/* ======================================================
   TOPBAR
====================================================== */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 16px;
  border-bottom:1px solid var(--line);
  position:sticky;
  top:0;
  background:rgba(244,246,248,.92);
  backdrop-filter:blur(10px);
  z-index:10;
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  font-weight:900;
}

.brand .dot{
  width:10px;height:10px;
  border-radius:999px;
  background:var(--primary);
  box-shadow:0 0 0 6px rgba(22,163,74,.12);
}

.userchip{
  text-align:right;
  font-size:12px;
}

.userchip .hello{
  font-weight:800;
  font-size:14px;
}

.userchip .role{ color:var(--muted) }

/* ======================================================
   NAVIGATION
====================================================== */
.nav{
  display:flex;
  gap:10px;
  padding:10px 16px;
  border-bottom:1px solid var(--line);
  background:rgba(244,246,248,.75);
  overflow-x:auto;
  scrollbar-width:none;
}
.nav::-webkit-scrollbar{ display:none }

.nav a{
  white-space:nowrap;
  padding:8px 12px;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
  font-size:13px;
  font-weight:700;
  box-shadow:0 2px 8px rgba(15,23,42,.04);
  transition:.15s;
}

.nav a:hover{
  transform:translateY(-1px);
  border-color:#CBD5E1;
}

.nav a.active{
  box-shadow:0 12px 28px rgba(15,23,42,.10);
}

.nav a.blue.active{ border-color:rgba(37,99,235,.4) }
.nav a.orange.active{ border-color:rgba(234,88,12,.4) }
.nav a.purple.active{ border-color:rgba(124,58,237,.4) }
.nav a.primary.active{ border-color:rgba(22,163,74,.4) }

/* ======================================================
   DASHBOARD (KPIs)
====================================================== */
.dash-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.dash-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.dash-filters {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    margin-top: 12px;
    align-items: end;
}

.dash-filters-btn {
    display: flex;
    justify-content: flex-end
}

.kpi-grid {
    margin-top: 14px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.kpi {
    border: 1px solid var(--line);
    background: linear-gradient(180deg, #fff, rgba(255, 255, 255, .92));
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .06);
}

.kpi-title {
    font-weight: 900;
    font-size: 12px;
    letter-spacing: .02em;
    color: #374151;
    text-transform: uppercase;
}

.kpi-value {
    margin-top: 6px;
    font-size: 22px;
    font-weight: 1000;
}

.kpi-sub {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    font-weight: 900;
    font-size: 12px;
}

.badge.ghost {
    background: transparent;
    color: var(--muted)
}

.badge.warn {
    border-color: rgba(217, 119, 6, .35);
    background: rgba(217, 119, 6, .10)
}

.badge.danger {
    border-color: rgba(220, 38, 38, .35);
    background: rgba(220, 38, 38, .10)
}

.badge.link {
    border-color: rgba(37, 99, 235, .35);
    background: rgba(37, 99, 235, .10)
}

.dash-split {
    margin-top: 14px;
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 12px;
}

@media (max-width: 860px) {
    .dash-head {
        flex-direction: column
    }

    .dash-actions {
        justify-content: flex-start
    }

    .dash-filters {
        grid-template-columns: 1fr;
    }

    .dash-filters-btn {
        justify-content: flex-start
    }

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

    .dash-split {
        grid-template-columns: 1fr;
    }
}

/* ======================================================
   LAYOUT
====================================================== */
.container{
  max-width:980px;
  margin:0 auto;
  padding:16px;
}

/* ======================================================
   CARDS
====================================================== */
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:14px;
  box-shadow:var(--shadow);
}

.card + .card{ margin-top:14px }
.card.narrow{ max-width:520px; margin:auto }
.card.inner{
  background:linear-gradient(180deg,#fff,rgba(255,255,255,.9));
}

/* ======================================================
   TITRES & TEXTE
====================================================== */
h2{
  margin:6px 0 12px;
  font-weight:900;
}

h3{
  margin:6px 0 10px;
  font-size:16px;
  font-weight:800;
  color:#374151;
}

.muted{ color:var(--muted) }
.small{ font-size:12px }
.low{ color:var(--warn) }

/* ======================================================
   FORMULAIRES
====================================================== */
.form{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-top:10px;
}

label{
  font-size:13px;
  font-weight:700;
  color:#374151;
}

input,select,textarea{
  width:100%;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--line);
  background:#fff;
  box-shadow:0 2px 10px rgba(15,23,42,.03);
}

input:focus,select:focus,textarea:focus{
  outline:none;
  border-color:#93C5FD;
  box-shadow:0 0 0 4px rgba(37,99,235,.12);
}

/* ======================================================
   BOUTONS
====================================================== */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--line);
  background:#fff;
  font-weight:800;
  cursor:pointer;
  box-shadow:0 8px 20px rgba(15,23,42,.06);
  transition:.15s;
}

.btn:hover{ transform:translateY(-1px) }

.btn.small{
  padding:7px 10px;
  font-size:12px;
  border-radius:12px;
}

.btn.primary{ background:var(--primary); color:#fff }
.btn.blue{ background:var(--blue); color:#fff }
.btn.orange{ background:var(--orange); color:#fff }
.btn.purple{ background:var(--purple); color:#fff }
.btn.danger{ background:var(--danger); color:#fff }

/* ======================================================
   ALERTES
====================================================== */
.alert{
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--line);
  margin:10px 0;
}

.alert-success{
  background:rgba(22,163,74,.08);
  border-color:rgba(22,163,74,.25);
}

.alert-danger{
  background:rgba(220,38,38,.08);
  border-color:rgba(220,38,38,.25);
}

/* ======================================================
   LISTES / PRODUITS
====================================================== */
.list{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding:10px;
  border:1px solid var(--line);
  border-radius:16px;
  background:#fff;
  box-shadow:0 8px 18px rgba(15,23,42,.05);
}

.pname{ font-weight:900 }
.qtysel{ width:90px }

/* ======================================================
   TABLES (DESKTOP)
====================================================== */
.table{
  margin-top:10px;
  border:1px solid var(--line);
  border-radius:16px;
  overflow:hidden;
  background:#fff;
  box-shadow:var(--shadow);
}

.thead,.trow{
  display:grid;
  grid-template-columns:90px 1fr 170px 90px 80px 130px 90px;
}

.thead{
  background:#F1F5F9;
  font-weight:900;
}

.trow{
  border-top:1px solid var(--line);
}
.trow:hover{ background:#F9FAFB }

.thead > div,
.trow > div{
  padding:10px 12px;
  font-size:13px;
}

/* ======================================================
   TABLE → CARTES (MOBILE)
====================================================== */
@media(max-width:720px){
  .table{ border:0; background:transparent; box-shadow:none }
  .thead{ display:none }

  .trow{
    display:block;
    margin-top:10px;
    border:1px solid var(--line);
    border-radius:16px;
    box-shadow:0 8px 18px rgba(15,23,42,.05);
  }

  .trow > div{
    display:flex;
    justify-content:space-between;
    padding:10px 12px;
    border-top:1px solid var(--line);
  }

  .trow > div:first-child{ border-top:0 }

  .trow > div::before{
    content:attr(data-label);
    font-weight:700;
    color:var(--muted);
  }
}

/* ======================================================
   TOTAUX
====================================================== */
.totals .totgrid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:12px;
}

.totals .tot{
  padding:12px;
  border-radius:16px;
  border:1px solid var(--line);
  background:#fff;
  box-shadow:0 8px 18px rgba(15,23,42,.05);
}

.totals .big{
  font-size:22px;
  font-weight:900;
  margin-top:6px;
}

/* ======================================================
   MOBILE
====================================================== */
@media(max-width:520px){
  .row{ flex-direction:column; align-items:stretch }
  .qtysel{ width:100% }
  .container{ padding:12px }
}
/* Print helpers */
.print-only {
    display: none;
}

@media print {
    .print-only {
        display: block;
    }

    .no-print {
        display: none !important;
    }

    .print-header {
        margin-bottom: 12px;
        padding-bottom: 10px;
        border-bottom: 1px solid #ddd;
    }

    .print-title {
        font-size: 18px;
        font-weight: 1000;
        margin-bottom: 6px;
    }

    .print-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        font-size: 12px;
        color: #333;
        margin-bottom: 10px;
    }

    .print-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 12px;
    }

    .print-table th,
    .print-table td {
        border: 1px solid #ddd;
        padding: 8px;
    }

    .print-table th {
        background: #f3f4f6;
        text-transform: uppercase;
        letter-spacing: .02em;
        font-size: 11px;
    }

    .print-sign {
        display: flex;
        justify-content: space-between;
        margin-top: 14px;
        font-size: 12px;
    }
}
.print-only {
    display: none;
}

@media print {
    .no-print {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    body {
        background: #fff !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}