/* ==========================================================
   Console Dibsoft — charte graphique
   ========================================================== */
:root{
  --bg:#F4F5F7;
  --surface:#FFFFFF;
  --surface-2:#EEF0F3;
  --border:#E1E4EA;

  --text:#14171F;
  --text-dim:#5B6172;
  --text-faint:#9BA0AF;

  --sidebar:#14171F;
  --sidebar-text:#B7BCC9;
  --sidebar-border:#262B36;

  --accent:#D98E2B;
  --accent-dim:#B8741A;
  --accent-bg:#FBF0DE;

  --succes:#1E8E5A;
  --succes-bg:#E5F4EC;
  --danger:#C0392B;
  --danger-bg:#FBEAE7;
  --attention:#B8741A;
  --attention-bg:#FBF0DE;
  --info:#2563EB;
  --info-bg:#EAF0FE;

  --rayon:10px;
  --rayon-lg:14px;
  --topbar-h:58px;
  --sidebar-w:224px;
}

*{ box-sizing:border-box; }
html,body{
  margin:0; padding:0;
  background:var(--bg); color:var(--text);
  font-family:'Inter',-apple-system,BlinkMacSystemFont,sans-serif;
  font-size:14.5px; line-height:1.5;
}
a{ color:inherit; text-decoration:none; }
.mono{ font-family:'JetBrains Mono',ui-monospace,monospace; }
h1,h2,h3{ font-family:'Space Grotesk','Inter',sans-serif; margin:0; }

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

.sidebar{
  width:var(--sidebar-w); flex-shrink:0;
  background:var(--sidebar);
  display:flex; flex-direction:column;
  padding:16px 12px;
  position:sticky; top:0; height:100vh;
  overflow-y:auto;
}
.sidebar__brand{
  display:flex; align-items:center; gap:10px;
  padding:6px 8px 18px; border-bottom:1px solid var(--sidebar-border); margin-bottom:10px;
  flex-shrink:0;
}
.sidebar__mark{
  width:32px; height:32px; border-radius:8px;
  background:var(--accent); color:#181008;
  display:flex; align-items:center; justify-content:center;
  font-family:'Space Grotesk'; font-weight:700; font-size:14px;
}
.sidebar__brand-name{ color:#fff; font-weight:600; font-size:14.5px; font-family:'Space Grotesk'; }
.sidebar__brand-sub{ color:#6B7280; font-size:10.5px; margin-top:1px; }

.sidebar__label{
  color:#5B6172; font-size:10px; text-transform:uppercase; letter-spacing:1px;
  font-weight:700; padding:14px 10px 6px;
}
.sidebar__link{
  display:flex; align-items:center; gap:10px;
  padding:9px 10px; border-radius:8px; font-size:13.5px;
  color:var(--sidebar-text); border-left:3px solid transparent;
}
.sidebar__link svg{ flex-shrink:0; opacity:.8; }
.sidebar__link:hover{ background:rgba(255,255,255,0.05); color:#fff; }
.sidebar__link.actif{
  background:rgba(217,142,43,0.12); color:#fff;
  border-left-color:var(--accent); font-weight:600;
}
.sidebar__link.actif svg{ opacity:1; color:var(--accent); }
.sidebar__badge{
  margin-left:auto; font-family:'JetBrains Mono'; font-size:10.5px;
  background:rgba(255,255,255,0.08); color:#9BA0AF; padding:1px 6px; border-radius:20px;
}
.sidebar__link.actif .sidebar__badge{ background:var(--accent); color:#181008; }
.sidebar__link--alerte .sidebar__badge{ background:var(--danger); color:#fff; }

.sidebar__foot{ margin-top:auto; padding-top:12px; border-top:1px solid var(--sidebar-border); flex-shrink:0; }
.sidebar__nav{
  flex:1 1 auto;
  overflow-y:auto;
  overflow-x:hidden;
  min-height:0; /* indispensable en flex column pour qu'overflow fonctionne réellement */
  /* Défilement discret : fine barre au survol plutôt qu'une grosse barre native */
  scrollbar-width:thin;
  scrollbar-color:var(--sidebar-border) transparent;
}
.sidebar__nav::-webkit-scrollbar{ width:6px; }
.sidebar__nav::-webkit-scrollbar-thumb{ background:var(--sidebar-border); border-radius:10px; }
.sidebar__nav::-webkit-scrollbar-track{ background:transparent; }
.sidebar__user{ display:flex; align-items:center; gap:9px; padding:8px; }
.sidebar__avatar{
  width:28px; height:28px; border-radius:50%; background:rgba(255,255,255,0.08);
  display:flex; align-items:center; justify-content:center;
  font-family:'Space Grotesk'; font-size:11.5px; font-weight:600; color:#fff;
}
.sidebar__user-name{ font-size:12.5px; font-weight:600; color:#fff; }
.sidebar__user-role{ font-size:10.5px; color:#6B7280; }

.main{ flex:1; min-width:0; }

.topbar{
  height:var(--topbar-h); background:var(--surface); border-bottom:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between; padding:0 26px;
  position:sticky; top:0; z-index:10;
}
.topbar__title{ font-size:15px; font-weight:600; font-family:'Space Grotesk'; }
.topbar__meta{ display:flex; align-items:center; gap:8px; font-size:12px; color:var(--text-dim); }
.topbar__dot{ width:6px; height:6px; border-radius:50%; background:var(--succes); }

.content{ padding:26px; }

.page-head{ margin-bottom:20px; }
.page-head h1{ font-size:22px; font-weight:700; }
.page-head p{ color:var(--text-dim); font-size:13px; margin-top:4px; max-width:640px; }

/* ---------- Grid & cards ---------- */
.kpi-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:14px; margin-bottom:22px; }
.card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--rayon-lg); }
.card__body{ padding:20px; }
.card__head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.card__title{ font-size:15px; font-weight:600; font-family:'Space Grotesk'; }
.card__sub{ font-size:11.5px; color:var(--text-faint); margin-top:2px; }

.kpi__label{ font-size:11px; text-transform:uppercase; letter-spacing:.5px; color:var(--text-faint); font-weight:700; }
.kpi__value{ font-size:24px; font-weight:700; margin-top:8px; font-family:'Space Grotesk'; }
.kpi__value .unit{ font-size:12px; color:var(--text-dim); font-weight:600; }
.kpi__foot{ font-size:11.5px; color:var(--text-dim); margin-top:7px; }
.kpi__foot.succes{ color:var(--succes); }
.kpi__foot.danger{ color:var(--danger); }

.grid-2{ display:grid; grid-template-columns:1.4fr 1fr; gap:16px; align-items:start; }
.grid-2-eq{ display:grid; grid-template-columns:1fr 1fr; gap:16px; align-items:start; }
@media (max-width:1100px){ .grid-2, .grid-2-eq{ grid-template-columns:1fr; } }

/* ---------- Tables ---------- */
.table-wrap{ overflow-x:auto; }
table{ width:100%; border-collapse:collapse; font-size:13px; }
th{
  text-align:left; padding:0 12px 7px 0; font-size:10.5px; text-transform:uppercase;
  letter-spacing:.5px; color:var(--text-faint); font-weight:700; border-bottom:1px solid var(--border);
}
td{ padding:8px 12px 8px 0; border-bottom:1px solid var(--border); vertical-align:middle; }

/* ---------- Boutons d'action en icônes (colonnes Actions) ---------- */
.actions-icones{ display:flex; align-items:center; gap:4px; flex-wrap:nowrap; }
.btn-icone{
  display:inline-flex; align-items:center; justify-content:center;
  width:26px; height:26px; border-radius:6px; border:1px solid var(--border);
  background:var(--surface); color:var(--text-dim); cursor:pointer; flex-shrink:0;
  transition:background .15s, color .15s, border-color .15s;
}
.btn-icone:hover{ background:var(--surface-2); color:var(--text); }
.btn-icone svg{ width:14px; height:14px; pointer-events:none; }
.btn-icone.icone-danger{ color:var(--danger); border-color:rgba(192,57,43,0.25); }
.btn-icone.icone-danger:hover{ background:var(--danger-bg); }
.btn-icone.icone-succes{ color:var(--succes); border-color:rgba(30,142,90,0.25); }
.btn-icone.icone-succes:hover{ background:var(--succes-bg); }
.btn-icone.icone-attention{ color:var(--attention); border-color:rgba(184,116,26,0.25); }
.btn-icone.icone-attention:hover{ background:var(--attention-bg); }
form.form-icone{ display:inline-flex; }
tr:last-child td{ border-bottom:none; }
.fade{ color:var(--text-dim); }

/* ---------- Badges ---------- */
.badge{ display:inline-flex; align-items:center; padding:3px 9px; border-radius:20px; font-size:11.5px; font-weight:600; }
.badge--succes{ background:var(--succes-bg); color:var(--succes); }
.badge--attention{ background:var(--attention-bg); color:var(--attention); }
.badge--danger{ background:var(--danger-bg); color:var(--danger); }
.badge--info{ background:var(--info-bg); color:var(--info); }
.badge--neutre{ background:var(--surface-2); color:var(--text-dim); }

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; gap:6px; padding:8px 14px; border-radius:8px;
  border:1px solid transparent; font-size:13px; font-weight:600; cursor:pointer;
}
.btn-accent{ background:var(--accent); color:#fff; }
.btn-accent:hover{ background:var(--accent-dim); }
.btn-danger{ background:var(--danger); color:#fff; }
.btn-ghost{ background:transparent; border-color:var(--border); color:var(--text-dim); }
.btn-ghost:hover{ background:var(--surface-2); }
.btn-sm{ padding:5px 10px; font-size:12px; }

/* ---------- Alerts ---------- */
.alert{ padding:12px 15px; border-radius:9px; font-size:13px; margin-bottom:14px; }
.alert-info{ background:var(--info-bg); color:var(--info); }
.alert-danger{ background:var(--danger-bg); color:var(--danger); }
.alert-succes{ background:var(--succes-bg); color:var(--succes); }

/* ---------- Bars ---------- */
.bar-row{ margin-bottom:13px; }
.bar-row__top{ display:flex; justify-content:space-between; font-size:12.5px; margin-bottom:5px; }
.bar-track{ height:8px; background:var(--surface-2); border-radius:6px; overflow:hidden; }
.bar-fill{ height:100%; background:var(--accent); border-radius:6px; }

/* ---------- Stat mini list ---------- */
.stat-row{ display:flex; justify-content:space-between; align-items:center; padding:10px 0; border-bottom:1px solid var(--border); font-size:13px; }
.stat-row:last-child{ border-bottom:none; }

/* ---------- Forms ---------- */
.field{ margin-bottom:14px; }
.field label{ display:block; font-size:12.5px; font-weight:600; margin-bottom:6px; }
.field input, .field select, .field textarea{
  width:100%; padding:9px 11px; border:1px solid var(--border); border-radius:8px;
  font-family:inherit; font-size:13.5px; background:#fff; color:var(--text);
}

/* ---------- Empty state ---------- */
.empty{ font-size:12.5px; color:var(--text-faint); background:var(--surface-2); border:1px dashed var(--border); border-radius:9px; padding:14px; }

/* ---------- Connexion ---------- */
.login-shell{
  min-height:100vh; display:flex; align-items:center; justify-content:center;
  background:var(--sidebar);
  padding:20px;
}
.login-card{
  width:100%; max-width:340px; background:var(--surface); border-radius:var(--rayon-lg);
  padding:28px 26px; border:1px solid var(--border);
}
.login-card__brand{ display:flex; align-items:center; gap:10px; margin-bottom:22px; }

/* ---------- Accordéon ---------- */
.acc{ background:var(--surface); border:1px solid var(--border); border-radius:var(--rayon-lg); margin-bottom:14px; overflow:hidden; }
.acc__head{
  list-style:none; cursor:pointer; padding:16px 20px; display:flex; align-items:center; justify-content:space-between;
  font-family:'Space Grotesk'; font-size:14.5px; font-weight:600; user-select:none;
}
.acc__head::-webkit-details-marker{ display:none; }
.acc__head::after{
  content:''; width:9px; height:9px; border-right:2px solid var(--text-faint); border-bottom:2px solid var(--text-faint);
  transform:rotate(-45deg); transition:transform .15s; flex-shrink:0; margin-left:12px;
}
.acc[open] > .acc__head::after{ transform:rotate(45deg); }
.acc__head .acc__sub{ font-family:'Inter'; font-size:11.5px; font-weight:400; color:var(--text-faint); margin-top:3px; }
.acc__body{ padding:0 20px 20px; border-top:1px solid var(--border); }

/* ---------- Formulaires : lignes de champs multi-colonnes ---------- */
.ligne-champs{ display:flex; gap:14px; flex-wrap:wrap; }
.ligne-champs > .field{ flex:1; min-width:150px; }

/* ---------- Bouton hamburger (mobile uniquement) ---------- */
.btn-menu-mobile{
  display:none; background:none; border:1px solid var(--border); border-radius:8px;
  width:36px; height:36px; align-items:center; justify-content:center; cursor:pointer; flex-shrink:0;
  color:var(--text);
}
.btn-menu-mobile svg{ pointer-events:none; }

.sidebar__overlay{ display:none; }

@media (max-width:820px){
  html, body{ overflow-x:hidden; max-width:100vw; }

  .app-shell{ display:block; }

  .btn-menu-mobile{ display:flex; }

  /* Sidebar devient un tiroir plein écran qui glisse depuis la gauche */
  .sidebar{
    position:fixed; top:0; left:0; height:100vh; width:260px; max-width:82vw;
    flex-direction:column; overflow-y:auto; overflow-x:hidden;
    transform:translateX(-100%); transition:transform .22s ease;
    z-index:1000; box-shadow:0 0 40px rgba(0,0,0,.25);
  }
  .sidebar.ouverte{ transform:translateX(0); }
  .sidebar__foot{ display:flex; }

  .sidebar__overlay{
    display:none; position:fixed; inset:0; background:rgba(20,23,31,.55); z-index:900;
  }
  .sidebar__overlay.visible{ display:block; }

  .main{ width:100%; }

  .topbar{ padding:0 14px; gap:10px; }
  .topbar__title{ font-size:14px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .topbar__meta{ display:none; }

  .content{ padding:14px; }
  .page-head h1{ font-size:19px; }
  .page-head p{ font-size:12.5px; }

  .card__body{ padding:15px; }
  .card__head{ flex-wrap:wrap; gap:10px; align-items:flex-start; }
  .card__head > div:first-child{ min-width:0; }
  .card__head > div{ flex-wrap:wrap !important; gap:8px !important; }
  .card__head form{ width:100%; }
  .card__head form .btn{ width:100%; }

  .kpi-grid{ grid-template-columns:repeat(2,1fr); gap:10px; }
  .kpi__value{ font-size:19px; }

  /* Toutes les grilles à 2 colonnes passent en 1 colonne */
  .grid-2, .grid-2-eq, .two-col{ grid-template-columns:1fr; }

  /* Formulaires de filtre (méthode GET) : empilés, boutons pleine largeur */
  form[method="get"]{ flex-direction:column !important; align-items:stretch !important; }
  form[method="get"] .field{ min-width:100% !important; width:100% !important; }
  form[method="get"] .btn{ width:100%; justify-content:center; }
  form[method="get"] a.btn{ width:100%; }

  /* Champs multi-colonnes des formulaires de saisie : empilés */
  .ligne-champs{ flex-direction:column; gap:0; }
  .ligne-champs > .field{ min-width:100%; width:100%; }

  /* Tables : on autorise le retour à la ligne dans les cellules d'action
     plutôt que de forcer une largeur qui dépasse l'écran */
  td{ white-space:normal !important; }
  table{ font-size:12px; }
  th{ font-size:9.5px; }
  .btn-sm{ padding:6px 10px; margin-bottom:4px; display:inline-flex; }

  /* Cartes plan / applications */
  .plan-grid, .app-grid{ grid-template-columns:1fr; }

  /* Boutons pleine largeur dans les en-têtes d'action de page */
  .page-head + div > .btn,
  .page-head + div > a.btn{ width:100%; text-align:center; }
}

@media (max-width:480px){
  .kpi-grid{ grid-template-columns:1fr; }
  .sidebar{ width:82vw; }
  .card__body{ padding:13px; }
  .login-card{ padding:22px 18px; }
}
