/* ERP proC — identité visuelle : bleu nuit, blanc, gris clair, touches de vert.
   Surcouche légère au-dessus de Tabler (Bootstrap 5) : un seul système de design. */

:root {
  --erp-navy: #0f1f3d;
  --erp-navy-2: #172c52;
  --erp-navy-3: #20396a;
  --erp-green: #2fb170;
  --erp-green-dark: #1f8f58;
  --erp-bg: #f3f5f9;
  --erp-surface: #ffffff;
  --erp-border: #e1e6ef;
  --erp-text: #1d2b44;
  --erp-muted: #6b7a93;
  --erp-sidebar-w: 268px;
  --erp-sidebar-w-collapsed: 72px;
  --erp-topbar-h: 62px;

  --tblr-primary: #17325e;
  --tblr-primary-rgb: 23, 50, 94;
  --tblr-success: #2fb170;
  --tblr-success-rgb: 47, 177, 112;
  --tblr-body-bg: var(--erp-bg);
  --tblr-body-color: var(--erp-text);
  --tblr-border-radius: 10px;
  --tblr-font-sans-serif: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }
body.erp-body {
  background: var(--erp-bg);
  color: var(--erp-text);
  font-family: var(--tblr-font-sans-serif);
  overflow-x: hidden;
}

/* ---------- Structure ---------- */
.erp-shell { display: flex; min-height: 100vh; }
.erp-main {
  flex: 1 1 auto;
  min-width: 0;                      /* évite tout défilement horizontal global */
  margin-left: var(--erp-sidebar-w);
  display: flex; flex-direction: column;
  transition: margin-left .2s ease;
}
body.sidebar-collapsed .erp-main { margin-left: var(--erp-sidebar-w-collapsed); }
.erp-content { flex: 1 1 auto; padding: 1.5rem; max-width: 1600px; width: 100%; margin: 0 auto; }
.erp-footer { padding: 1rem 1.5rem; color: var(--erp-muted); font-size: .8rem; }

/* ---------- Barre latérale ---------- */
.erp-sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 1040;
  width: var(--erp-sidebar-w);
  background: linear-gradient(180deg, var(--erp-navy) 0%, var(--erp-navy-2) 100%);
  color: #cfd8ea;
  display: flex; flex-direction: column;
  transition: width .2s ease, transform .25s ease;
  overflow: hidden;
}
body.sidebar-collapsed .erp-sidebar { width: var(--erp-sidebar-w-collapsed); }

.erp-brand {
  height: var(--erp-topbar-h); display: flex; align-items: center; gap: .75rem;
  padding: 0 1.1rem; border-bottom: 1px solid rgba(255,255,255,.08); flex: 0 0 auto;
}
.erp-brand a { display: flex; align-items: center; gap: .75rem; color: #fff; text-decoration: none; min-width: 0; }
.erp-brand img { width: 34px; height: 34px; flex: 0 0 34px; }
.erp-brand-text { font-weight: 600; font-size: .98rem; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.erp-nav { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: .75rem .6rem 1.5rem; }
.erp-nav ul { list-style: none; margin: 0; padding: 0; }
.erp-nav-link {
  width: 100%; display: flex; align-items: center; gap: .8rem;
  padding: .62rem .75rem; border: 0; border-radius: 8px; background: transparent;
  color: inherit; text-decoration: none; text-align: left; font-size: .93rem; cursor: pointer;
}
.erp-nav-link i.ti { font-size: 1.3rem; flex: 0 0 1.3rem; }
.erp-nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.erp-nav-link.active, .erp-nav-group.open > .erp-nav-link { background: rgba(255,255,255,.1); color: #fff; }
.erp-nav-link.active { box-shadow: inset 3px 0 0 var(--erp-green); }
.erp-nav-label { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.erp-nav-caret { transition: transform .2s ease; font-size: 1rem !important; opacity: .7; }
.erp-nav-group.open > .erp-nav-link .erp-nav-caret { transform: rotate(180deg); }

.erp-subnav { display: none; padding: .15rem 0 .4rem 2.55rem; }
.erp-nav-group.open > .erp-subnav { display: block; }
.erp-sublink {
  display: block; padding: .42rem .7rem; border-radius: 6px; font-size: .88rem;
  color: #aab7d1; text-decoration: none;
}
a.erp-sublink:hover { color: #fff; background: rgba(255,255,255,.06); }
.erp-sublink.active { color: #fff; background: rgba(47,177,112,.18); }
.erp-sublink.disabled { opacity: .5; cursor: default; }
.erp-sublink small { font-size: .7rem; opacity: .8; }

body.sidebar-collapsed .erp-brand-text,
body.sidebar-collapsed .erp-nav-label,
body.sidebar-collapsed .erp-nav-caret,
body.sidebar-collapsed .erp-subnav { display: none !important; }
body.sidebar-collapsed .erp-nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .erp-brand { justify-content: center; padding: 0; }

.erp-backdrop { display: none; }

/* ---------- Barre supérieure ---------- */
.erp-topbar {
  position: sticky; top: 0; z-index: 1030; height: var(--erp-topbar-h);
  background: var(--erp-surface); border-bottom: 1px solid var(--erp-border);
  display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem;
}
.erp-icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent;
  color: var(--erp-text); font-size: 1.3rem; text-decoration: none;
}
.erp-icon-btn:hover { background: var(--erp-bg); color: var(--erp-navy-3); }
.erp-icon-btn .erp-badge {
  position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #e5484d; color: #fff; font-size: .68rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.erp-search { flex: 1 1 auto; max-width: 460px; }
.erp-search .form-control { background: var(--erp-bg); border-color: transparent; padding-left: 2.4rem; }
.erp-search .ti { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--erp-muted); }
.erp-user { display: flex; align-items: center; gap: .6rem; border: 0; background: transparent; padding: .25rem .5rem; border-radius: 10px; color: var(--erp-text); }
.erp-user:hover { background: var(--erp-bg); }
.erp-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--erp-navy-3); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .85rem;
}
.erp-user-name { font-weight: 600; font-size: .88rem; line-height: 1.1; }
.erp-user-role { font-size: .74rem; color: var(--erp-muted); }

/* ---------- Contenu ---------- */
.erp-breadcrumb { font-size: .85rem; margin-bottom: .35rem; }
.erp-breadcrumb .breadcrumb { margin: 0; }
.erp-page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.erp-page-title { font-size: 1.5rem; font-weight: 700; margin: 0; color: var(--erp-navy); }

.card { border: 1px solid var(--erp-border); border-radius: 12px; box-shadow: 0 1px 2px rgba(15,31,61,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--erp-border); }
.card-title { font-weight: 600; color: var(--erp-navy); }

.kpi-card .kpi-value { font-size: 2rem; font-weight: 700; color: var(--erp-navy); line-height: 1.1; }
.kpi-card .kpi-label { color: var(--erp-muted); font-size: .85rem; }
.kpi-card .kpi-icon {
  width: 46px; height: 46px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.5rem; background: rgba(47,177,112,.12); color: var(--erp-green-dark);
}
.kpi-card.kpi-alert .kpi-icon { background: rgba(229,72,77,.12); color: #c0343a; }
.kpi-card.kpi-navy .kpi-icon { background: rgba(23,50,94,.1); color: var(--erp-navy-3); }

.table-responsive { -webkit-overflow-scrolling: touch; }
.table thead th { font-size: .75rem; letter-spacing: .03em; text-transform: uppercase; color: var(--erp-muted); white-space: nowrap; }

.btn-primary { background: var(--erp-navy-3); border-color: var(--erp-navy-3); }
.btn-primary:hover { background: var(--erp-navy); border-color: var(--erp-navy); }
.btn-success { background: var(--erp-green); border-color: var(--erp-green); color: #fff; }
.btn-success:hover { background: var(--erp-green-dark); border-color: var(--erp-green-dark); color: #fff; }

.perm-matrix th, .perm-matrix td { vertical-align: middle; }
.perm-matrix td.cell { text-align: center; width: 120px; }
.erp-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .4rem .75rem; }

.form-label.required::after { content: " *"; color: #e5484d; }
.invalid-feedback { display: block; }

/* ---------- Authentification ---------- */
.erp-auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem;
  background: radial-gradient(1200px 600px at 10% -10%, var(--erp-navy-3), transparent 60%),
              linear-gradient(160deg, var(--erp-navy), var(--erp-navy-2));
}
.erp-auth-card { width: 100%; max-width: 420px; }
.erp-auth-card .card { border: 0; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.erp-auth-brand { text-align: center; color: #fff; margin-bottom: 1.25rem; }
.erp-auth-brand img { width: 56px; height: 56px; }

/* ---------- Chargement ---------- */
.btn.is-loading { pointer-events: none; opacity: .75; }
.btn.is-loading::after {
  content: ""; display: inline-block; width: .9em; height: .9em; margin-left: .5rem;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  vertical-align: -.1em; animation: erp-spin .7s linear infinite;
}
@keyframes erp-spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .erp-main, body.sidebar-collapsed .erp-main { margin-left: 0; }
  .erp-sidebar, body.sidebar-collapsed .erp-sidebar { width: min(86vw, var(--erp-sidebar-w)); transform: translateX(-100%); }
  body.sidebar-open .erp-sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.35); }
  /* en mobile, le mode « rétracté » ne s'applique pas : le menu est complet */
  body.sidebar-collapsed .erp-brand-text, body.sidebar-collapsed .erp-nav-label { display: initial !important; }
  body.sidebar-collapsed .erp-nav-caret { display: inline-block !important; }
  body.sidebar-collapsed .erp-nav-link { justify-content: flex-start; padding-left: .75rem; padding-right: .75rem; }
  body.sidebar-collapsed .erp-nav-group.open > .erp-subnav { display: block !important; }
  .erp-backdrop { position: fixed; inset: 0; z-index: 1035; background: rgba(8,16,33,.5); }
  body.sidebar-open .erp-backdrop { display: block; }
  body.sidebar-open { overflow: hidden; }
  .erp-content { padding: 1rem; }
  .erp-topbar { padding: 0 .75rem; }
}
@media (max-width: 575.98px) {
  .erp-page-title { font-size: 1.25rem; }
  .erp-user-meta { display: none; }
  .kpi-card .kpi-value { font-size: 1.6rem; }
}

@media print {
  .erp-sidebar, .erp-topbar, .erp-backdrop, .erp-footer, .no-print { display: none !important; }
  .erp-main { margin-left: 0 !important; }
}
