/* ============================================================
   SOREL – Thème ministériel Maroc
   Charte couleurs : rouge / vert / or / sable
   ============================================================ */

:root {
  --red-maroc:       #b22222;
  --red-maroc-hover: #d42a2a;
  --green-maroc:     #006233;
  --green-hover:     #008545;
  --gold:            #d4a84b;
  --gold-light:      #e8c97a;
  --sand:            #f8f5f0;
  --white:           #ffffff;
  --gray-50:         #f7f6f4;
  --gray-100:        #edebe7;
  --gray-200:        #d6d2cb;
  --gray-300:        #b0aba2;
  --gray-400:        #7d786f;
  --gray-500:        #5c5750;
  --gray-600:        #3d3935;
  --gray-700:        #221f1c;
  --dark-bg:         #1e1b17;

  --sidebar-width:   260px;
  --topbar-height:   56px;
  --transition:      0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: 'Segoe UI', 'Arial', 'Helvetica', sans-serif;
  background: var(--gray-50);
  color: var(--gray-600);
  display: flex;
  min-height: 100vh;
  line-height: 1.5;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* ---- Top bar Maroc ---- */
.top-bar {
  height: 4px;
  display: flex;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
}
.top-bar .stripe { flex: 1; }
.stripe-red   { background: var(--red-maroc); }
.stripe-green { background: var(--green-maroc); }
.stripe-gold  { background: var(--gold); }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 4px; left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - 4px);
  background: var(--dark-bg);
  color: var(--white);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.7rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-logo {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--white);
}

.sidebar-logo-sub {
  font-size: 0.55rem;
  font-weight: 400;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-top: 0.1rem;
  opacity: 0.8;
}

.sidebar-nav { flex: 1; padding: 0.4rem 0; }

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 1.25rem;
  color: rgba(255,255,255,0.5);
  font-size: 0.82rem;
  font-weight: 500;
  transition: var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-nav li a:hover {
  background: rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.8);
}

.sidebar-nav li a.active {
  background: rgba(255,255,255,0.06);
  color: var(--gold);
  border-left-color: var(--gold);
}

.sidebar-nav .nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-nav .nav-icon svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-footer {
  padding: 0.7rem 1.25rem;
  font-size: 0.55rem;
  color: rgba(255,255,255,0.2);
  border-top: 1px solid rgba(255,255,255,0.05);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ---- Topbar ---- */
.topbar {
  position: fixed;
  top: 4px; left: var(--sidebar-width); right: 0;
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1.25rem;
  z-index: 99;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--dark-bg);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.topbar-search {
  flex: 1;
  max-width: 380px;
  position: relative;
}

.topbar-search input {
  width: 100%;
  padding: 0.4rem 0.8rem 0.4rem 2rem;
  border: 1px solid var(--gray-200);
  font-size: 0.8rem;
  background: var(--gray-50);
  transition: var(--transition);
  outline: none;
}

.topbar-search input:focus {
  border-color: var(--red-maroc);
  background: var(--white);
}

.topbar-search .search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--gray-300);
}
.topbar-search .search-icon svg {
  width: 14px;
  height: 14px;
  display: block;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-left: auto;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 1rem;
  border: 1px solid transparent;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: inherit;
}

.btn-primary {
  background: var(--red-maroc);
  color: var(--white);
  border-color: var(--red-maroc);
}

.btn-primary:hover {
  background: var(--red-maroc-hover);
}

.btn-outline {
  background: transparent;
  color: var(--gray-500);
  border: 1px solid var(--gray-300);
}

.btn-outline:hover {
  border-color: var(--red-maroc);
  color: var(--red-maroc);
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
}

/* ---- Profil ---- */
.user-profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  transition: var(--transition);
}

.user-profile:hover { background: var(--gray-50); }

.user-avatar {
  width: 30px; height: 30px;
  background: var(--green-maroc);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
}

.user-info { line-height: 1.2; }
.user-name { font-size: 0.8rem; font-weight: 600; color: var(--gray-600); }
.user-role { font-size: 0.65rem; color: var(--gray-400); }

/* ---- Main ---- */
.main-content {
  margin-left: var(--sidebar-width);
  padding-top: calc(var(--topbar-height) + 4px);
  flex: 1;
  min-height: 100vh;
}

.page { display: none; padding: 1.5rem 2rem 2rem; max-width: 1400px; }
.page.active { display: block; }

.page-header {
  margin-bottom: 1.5rem;
  padding-bottom: 0.85rem;
  border-bottom: 2px solid var(--gray-200);
}

.page-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--dark-bg);
}

.page-header p {
  color: var(--gray-400);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

/* ---- KPI ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--white);
  padding: 1rem 1.25rem;
  border: 1px solid var(--gray-200);
  transition: var(--transition);
}

.kpi-card:hover {
  border-color: var(--gold);
}

.kpi-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
  margin-bottom: 0.2rem;
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--dark-bg);
  line-height: 1.1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.kpi-value .kpi-value-icon {
  width: 22px;
  height: 22px;
  color: var(--gray-200);
}
.kpi-value .kpi-value-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 0.25rem;
}

/* ---- Card ---- */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
}

.card-header {
  padding: 0.8rem 1.25rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--dark-bg);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--gray-50);
}

.card-body { padding: 1rem 1.25rem; }

/* ---- Dashboard grid ---- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.dashboard-grid .card:first-child {
  grid-column: 1 / -1;
}

@media (min-width: 1100px) {
  .dashboard-grid {
    grid-template-columns: 2fr 1fr 1fr;
  }
  .dashboard-grid .card:first-child {
    grid-column: 1 / 2;
  }
}

/* ---- Quick access ---- */
.quick-access-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.quick-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  background: var(--sand);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--dark-bg);
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}

.quick-item:hover {
  background: var(--white);
  border-color: var(--gold);
}

.quick-item .quick-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--red-maroc);
}
.quick-item .quick-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

/* ---- Activity ---- */
.activity-list { font-size: 0.8rem; }

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 6px; height: 6px;
  margin-top: 0.4rem;
  flex-shrink: 0;
}

.activity-dot.red   { background: var(--red-maroc); }
.activity-dot.green { background: var(--green-maroc); }
.activity-dot.gold  { background: var(--gold); }
.activity-dot.gray  { background: var(--gray-300); }

.activity-text { flex: 1; }
.activity-text strong { color: var(--dark-bg); }
.activity-time { font-size: 0.65rem; color: var(--gray-400); margin-top: 0.1rem; }

/* ---- Referentiel bars ---- */
.referentiel-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.referentiel-bar:last-child { margin-bottom: 0; }

.referentiel-bar .bar-label {
  width: 110px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray-500);
  flex-shrink: 0;
}

.referentiel-bar .bar-track {
  flex: 1;
  height: 6px;
  background: var(--gray-100);
  overflow: hidden;
}

.referentiel-bar .bar-fill {
  height: 100%;
  transition: width 0.5s ease;
}

.referentiel-bar .bar-fill.red   { background: var(--red-maroc); }
.referentiel-bar .bar-fill.green { background: var(--green-maroc); }
.referentiel-bar .bar-fill.gold  { background: var(--gold); }

.referentiel-bar .bar-value {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--dark-bg);
  min-width: 30px;
  text-align: right;
}

/* ---- Filters ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.filter-group label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
}

.filter-group select,
.filter-group input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--gray-200);
  font-size: 0.8rem;
  background: var(--white);
  color: var(--gray-600);
  min-width: 170px;
  outline: none;
  font-family: inherit;
}

.filter-group select:focus,
.filter-group input:focus {
  border-color: var(--red-maroc);
}

/* ---- Table ---- */
.table-criteres {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.table-criteres th {
  text-align: left;
  padding: 0.6rem 1rem;
  font-weight: 700;
  color: var(--gray-400);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--gray-200);
  background: var(--gray-50);
}

.table-criteres td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--gray-100);
}

.table-criteres tr:hover td {
  background: var(--sand);
}

.table-criteres .badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 600;
}

.badge-procedure { background: #f0ebe4; color: var(--red-maroc); }
.badge-classement { background: #f5efe5; color: var(--gold); }

/* ---- Status ---- */
.status {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid currentColor;
}

.status-draft    { background: var(--gray-100); color: var(--gray-400); border-color: var(--gray-300); }
.status-en-cours { background: #fdecec; color: var(--red-maroc); border-color: var(--red-maroc); }
.status-corriger { background: #f5e0d0; color: #b06000; border-color: #b06000; }
.status-conforme { background: #e7f3ed; color: var(--green-maroc); border-color: var(--green-maroc); }

/* ---- Progress ---- */
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--gray-200);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--red-maroc);
  transition: width 0.4s ease;
}

.progress-text {
  font-size: 0.65rem;
  color: var(--gray-400);
  margin-top: 0.15rem;
}

/* ---- Fiche critère ---- */
.fiche-section {
  margin-bottom: 1.25rem;
}

.fiche-section h3 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--dark-bg);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.fiche-section p,
.fiche-section ul {
  font-size: 0.82rem;
  color: var(--gray-600);
  line-height: 1.6;
}

.fiche-section ul {
  padding-left: 1.1rem;
  list-style: disc;
}

.fiche-section ul li { margin-bottom: 0.15rem; }

.fiche-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.btn-conforme {
  background: var(--green-maroc);
  color: var(--white);
  border-color: var(--green-maroc);
}

.btn-conforme:hover { opacity: 0.85; }

.btn-non-conforme {
  background: var(--red-maroc);
  color: var(--white);
  border-color: var(--red-maroc);
}

.btn-non-conforme:hover { opacity: 0.85; }

.btn-na {
  background: var(--gray-300);
  color: var(--gray-600);
  border-color: var(--gray-300);
}

.btn-na:hover { background: var(--gray-400); }

textarea {
  width: 100%;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--gray-200);
  font-size: 0.82rem;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
  outline: none;
}

textarea:focus {
  border-color: var(--red-maroc);
}

/* ---- Audit card ---- */
.audit-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  transition: var(--transition);
}

.audit-card:hover {
  border-color: var(--gold);
}

.audit-info { flex: 1; }
.audit-info h3 { font-size: 0.88rem; font-weight: 600; color: var(--dark-bg); }
.audit-info p { font-size: 0.75rem; color: var(--gray-400); margin-top: 0.15rem; }

.audit-meta {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-shrink: 0;
}

.audit-meta .progress-wrap { width: 90px; }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 2.5rem 2rem;
  color: var(--gray-400);
}

.empty-state p { font-size: 0.85rem; }
.empty-state svg {
  width: 40px;
  height: 40px;
  stroke: var(--gray-300);
  stroke-width: 1.4;
  fill: none;
  margin-bottom: 0.5rem;
}

/* ---- Table count ---- */
.table-count {
  font-size: 0.75rem;
  color: var(--gray-400);
  font-weight: 400;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .sidebar { width: 56px; }
  .sidebar-header { padding: 0.8rem 0; text-align: center; }
  .sidebar-logo { font-size: 1rem; }
  .sidebar-logo-sub,
  .sidebar-nav li a span,
  .sidebar-footer { display: none; }
  .sidebar-nav .nav-icon svg { width: 18px; height: 18px; }
  .sidebar-nav li a { justify-content: center; padding: 0.6rem 0; }
  .main-content { margin-left: 56px; }
  .topbar { left: 56px; }
}

@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-grid .card:first-child { grid-column: 1; }
  .audit-card { flex-direction: column; align-items: stretch; }
  .audit-meta { justify-content: space-between; }
}

/* ---- Transitions ---- */
.page { animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
