:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #18212b;
  --muted: #5d6b79;
  --border: #e2e8f0;
  --dark: #0f172a;
  --green: #0f766e;
  --purple: #7c3aed;
  --gray: #374151;
  --blue: #1e40af;
  --orange: #c2410c;
  --red: #dc2626;
  --sidebar-bg: #0f172a;
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

/* ========== LAYOUT PRINCIPAL ========== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

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

.sidebar-logo h1 {
  font-size: 1.1rem;
  font-weight: 800;
  color: white;
  line-height: 1.2;
}

.sidebar-logo p {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  margin-top: 0.2rem;
}

.sidebar-user {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.nav-section {
  padding: 0.6rem 1.25rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  color: rgba(255,255,255,0.3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 1.25rem;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: white;
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: white;
  font-weight: 600;
}

.nav-item .icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--orange);
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: rgba(255,255,255,0.45);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 0.4rem 0;
  transition: color 0.15s;
}

.sidebar-footer a:hover { color: white; }

/* ========== CONTENU PRINCIPAL ========== */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-content {
  padding: 1.5rem;
  flex: 1;
}

/* ========== CARDS ========== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 1px 4px rgba(15,23,42,0.04);
}

.card-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  margin-bottom: 1.5rem;
}

.card-grid-3 {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  margin-bottom: 1.5rem;
}

/* ========== METRIQUES ========== */
.metric-card {
  text-align: center;
  padding: 1.25rem 1rem;
}

.metric-card h2 {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 0.35rem;
}

.metric-card p {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-card.urgent h2 { color: var(--red); }
.metric-card.warning h2 { color: var(--orange); }
.metric-card.good h2 { color: var(--green); }

/* ========== SECTION TITLES ========== */
.section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.75rem;
  margin-top: 1.5rem;
}

/* ========== SURFACE STACK (listes items) ========== */
.surface-stack { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.75rem; }

.surface-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.surface-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.surface-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.surface-item-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.surface-item-summary {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 0.5rem;
}

.surface-item-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ========== STATUS PILLS ========== */
.status-group { display: flex; gap: 0.35rem; flex-wrap: wrap; flex-shrink: 0; }

.status-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill-green { background: #dcfce7; color: #166534; }
.pill-orange { background: #ffedd5; color: #9a3412; }
.pill-red { background: #fee2e2; color: #991b1b; }
.pill-blue { background: #dbeafe; color: #1e40af; }
.pill-purple { background: #ede9fe; color: #5b21b6; }
.pill-gray { background: #f1f5f9; color: #475569; }

/* ========== BOUTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.2;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.88; }
.btn-primary { background: var(--blue); color: white; }
.btn-green { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-outline { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary-action { background: #f1f5f9; color: var(--text); }
.btn-dark { background: var(--dark); color: white; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }

.actions-inline { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ========== PAGE HEADER ========== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.page-summary {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 0.3rem;
  line-height: 1.5;
}

/* ========== TABLES ========== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th {
  text-align: left;
  padding: 0.6rem 0.85rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}

td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ========== FORMS ========== */
.form-group { margin-bottom: 1.1rem; }

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--blue);
}

/* ========== ALERTS ========== */
.alert {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: #ffedd5; color: #9a3412; border: 1px solid #fed7aa; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ========== MOBILE ========== */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.25rem;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open { transform: translateX(0); }

  .main-wrapper { margin-left: 0; }

  .mobile-menu-toggle { display: block; }

  .page-content { padding: 1rem; }

  .card-grid { grid-template-columns: 1fr 1fr; }
  .card-grid-3 { grid-template-columns: 1fr; }

  .metric-card h2 { font-size: 1.8rem; }

  .page-header { flex-direction: column; }
  .page-header .actions-inline { width: 100%; }
  .page-header .actions-inline .btn { flex: 1; text-align: center; }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }

  .sidebar-overlay.open { display: block; }
}

@media (max-width: 480px) {
  .card-grid { grid-template-columns: 1fr; }
}

/* ========== LEGACY (compatibilité anciens templates) ========== */
.quick-list h2 { font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem; }
.quick-list p { font-size: 0.85rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.quick-list p:last-child { border-bottom: none; }

.site-header {
  background: linear-gradient(135deg, #0f172a, #1f4e79);
  color: white;
  padding: 1rem 0;
}

.site-header h1 { font-size: 1.55rem; line-height: 1.2; color: white; }
.subtitle { margin: 0.35rem 0 0 0; color: rgba(255,255,255,0.85); }

.top-nav {
  background: #15202b;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.nav-links {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  white-space: nowrap;
  padding: 0.8rem 0;
}

.nav-links a {
  flex: 0 0 auto;
  color: white;
  text-decoration: none;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 0.8rem 0.95rem;
  font-size: 0.95rem;
}
