/* ────────────────────────────────────────────────────────────────
   App Gestion BTP — CSS principal
   Variables couleurs primaires depuis le serveur (:root inline).
   ──────────────────────────────────────────────────────────────── */

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #3b82f6;
  --secondary: #1e40af;
  /* Palette dark fixe */
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #273548;
  --border:    #334155;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --text-sm:   0.8125rem;
  --danger:    #ef4444;
  --success:   #22c55e;
  --warning:   #f59e0b;
  --radius:    0.5rem;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
  --sidebar-w: 260px;
  --topbar-h:  60px;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { opacity: .85; }
svg { width: 1.1em; height: 1.1em; flex-shrink: 0; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; }
fieldset { border: none; }

/* === LAYOUT APP === */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .25s ease;
  z-index: 100;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}
.sidebar-logo {
  width: 36px; height: 36px;
  border-radius: .375rem;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-name {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-slogan {
  font-size: .72rem;
  color: var(--text-muted);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Nav */
.sidebar-nav { flex: 1; padding: .75rem .5rem; }
.nav-group { margin-bottom: 1.25rem; }
.nav-group-label {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 .625rem .375rem;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .625rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .875rem;
  transition: background .15s, color .15s;
  margin-bottom: .125rem;
  user-select: none;
}
.nav-link:hover:not(.nav-disabled) {
  background: var(--surface2);
  color: var(--text);
}
.nav-link.active {
  background: color-mix(in srgb, var(--primary) 20%, transparent);
  color: var(--primary);
  font-weight: 600;
}
.nav-link.nav-disabled {
  cursor: default;
  opacity: .45;
  font-size: .8rem;
}
.badge-lock { font-size: .7em; opacity: .7; margin-left: auto; }

/* Sidebar footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .875rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.user-info { display: flex; align-items: center; gap: .625rem; flex: 1; min-width: 0; }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}
.user-name { display: block; font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: .7rem; color: var(--text-muted); text-transform: capitalize; }
.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: .375rem;
  border-radius: var(--radius);
  display: flex;
  transition: color .15s, background .15s;
}
.btn-logout:hover { color: var(--danger); background: rgba(239,68,68,.12); }

/* === MAIN CONTENT === */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  height: var(--topbar-h);
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: .25rem;
  border-radius: .375rem;
}
.page-title {
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

/* === CARDS === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 700; }

/* === STATS === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: .625rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon-blue  { background: rgba(59,130,246,.18); color: #60a5fa; }
.stat-icon-green { background: rgba(34,197,94,.18);  color: #4ade80; }
.stat-icon-amber { background: rgba(245,158,11,.18); color: #fbbf24; }
.stat-value { display: block; font-size: 1.75rem; font-weight: 800; line-height: 1; }
.stat-label { display: block; font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

/* === TABLES === */
.table-wrapper { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.table th {
  text-align: left;
  padding: .75rem 1rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface2); }
.row-new { animation: rowFlash 2s ease; }
@keyframes rowFlash {
  0% { background: color-mix(in srgb, var(--primary) 20%, transparent); }
  100% { background: transparent; }
}

/* === BADGES === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15em .55em;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-connexion    { background: rgba(34,197,94,.18);  color: #4ade80; }
.badge-deconnexion  { background: rgba(148,163,184,.15); color: #94a3b8; }
.badge-reauth       { background: rgba(245,158,11,.18); color: #fbbf24; }
.badge-echec_connexion { background: rgba(239,68,68,.18); color: #f87171; }
.badge-creation     { background: rgba(59,130,246,.18); color: #60a5fa; }
.badge-modification { background: rgba(139,92,246,.18); color: #a78bfa; }
.badge-suppression  { background: rgba(239,68,68,.18);  color: #f87171; }
.badge-consultation { background: rgba(34,197,94,.12);  color: #6ee7b7; }
.badge-export       { background: rgba(245,158,11,.15); color: #fcd34d; }
.badge-upload       { background: rgba(59,130,246,.12); color: #93c5fd; }
.badge-lock { font-size: .7em; }
.badge-lock-inline {
  font-size: .75rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: .2em .5em;
  border-radius: .375rem;
}
.badge-sensitive { margin-left: auto; font-size: .7rem; }

/* === BUTTONS === */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: .5rem 1.125rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .875rem;
  transition: opacity .15s, transform .1s;
}
.btn-primary:hover { opacity: .88; color: #fff; }
.btn-primary:active { transform: scale(.97); }
.btn-primary.btn-block { width: 100%; justify-content: center; padding: .65rem; }
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  transition: background .15s, color .15s;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm {
  display: inline-flex;
  align-items: center;
  font-size: .8rem;
  padding: .3rem .7rem;
  border-radius: .375rem;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: color .15s;
}
.btn-sm:hover { color: var(--text); }
.btn-install {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
}

/* === FORMS === */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.form-input, .form-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .55rem .75rem;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
textarea.form-input { resize: vertical; }
.form-hint { font-size: .72rem; color: var(--text-muted); }
.checkbox-label { display:flex; align-items:center; gap:.5rem; cursor:pointer; font-size:.875rem; font-weight:500; }
.checkbox-label input[type="checkbox"] { width:1rem; height:1rem; accent-color:var(--primary); cursor:pointer; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.form-section legend {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: 0 .375rem;
}
.form-section .form-group { margin-bottom: .75rem; }
.form-grid { display: flex; flex-direction: column; gap: .5rem; }
.form-actions { display: flex; gap: .75rem; align-items: center; padding: .5rem 0; }
.input-with-toggle { position: relative; }
.input-with-toggle .form-input { padding-right: 2.5rem; }
.toggle-password {
  position: absolute; right: .6rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); padding: .2rem;
}
.color-input-wrap { display: flex; gap: .5rem; align-items: center; }
.color-input-wrap input[type="color"] {
  width: 44px; height: 38px; padding: 2px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); cursor: pointer;
}
.color-preview {
  height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 600; color: #fff;
  margin-top: .5rem;
  transition: background .3s;
}
.filters-form { padding: 1rem 1.25rem; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; margin-bottom: .75rem; }
.filters-actions { display: flex; gap: .75rem; align-items: center; }

/* === AUTH PAGES === */
.auth-page { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); padding: 1rem; }
.auth-container { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 2);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.auth-header { text-align: center; margin-bottom: 1.5rem; }
.auth-logo { width: 64px; height: 64px; border-radius: 1rem; margin-bottom: .75rem; object-fit: contain; }
.auth-title { font-size: 1.375rem; font-weight: 800; }
.auth-slogan { color: var(--text-muted); font-size: .875rem; margin-top: .25rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-back-link { display: block; text-align: center; margin-top: 1rem; font-size: .8rem; color: var(--text-muted); }
.auth-footer { margin-top: 1.25rem; font-size: .72rem; color: var(--text-muted); text-align: center; }
.reauth-icon {
  width: 56px; height: 56px;
  background: color-mix(in srgb, var(--warning) 18%, transparent);
  color: var(--warning);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto .75rem;
  font-size: 1.5rem;
}
.reauth-user {
  display: flex; align-items: center; gap: .625rem;
  padding: .625rem .875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  font-size: .875rem;
}

/* === ALERTS === */
.alert {
  display: flex; align-items: center; gap: .6rem;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 1rem;
}
.alert-error   { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.3);  color: #f87171; }
.alert-success { background: rgba(34,197,94,.12);  border: 1px solid rgba(34,197,94,.3);  color: #4ade80; }
.alert-warning { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: #fbbf24; }

/* === MODULES GRID === */
.modules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
.module-card {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: .8rem;
}
.module-active { background: color-mix(in srgb, var(--success) 8%, var(--surface)); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.module-coming { background: var(--surface); opacity: .6; }
.module-icon { font-size: 1.25rem; flex-shrink: 0; }

/* === PAGINATION === */
.pagination { display: flex; gap: .375rem; padding: .875rem 1.25rem; flex-wrap: wrap; }
.page-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 .5rem;
  border-radius: .375rem;
  font-size: .8rem;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.page-btn:hover { background: var(--primary); color: #fff; }
.page-btn.active { background: var(--primary); color: #fff; font-weight: 700; border-color: var(--primary); }

/* === LIVE INDICATOR === */
.live-indicator { display: flex; align-items: center; gap: .375rem; font-size: .75rem; color: var(--text-muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }

/* === MODAL === */
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 2);
  box-shadow: var(--shadow);
  color: var(--text);
  max-width: 480px;
  width: 90vw;
  padding: 1.5rem;
}
.modal::backdrop { background: rgba(0,0,0,.6); }
.modal-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 1.25rem; }

/* === ERROR PAGES === */
.error-card { text-align: center; }
.error-code { font-size: 4rem; font-weight: 900; color: var(--primary); line-height: 1; margin-bottom: .5rem; }
.error-title { font-size: 1.25rem; margin-bottom: .5rem; }
.error-msg { color: var(--text-muted); margin-bottom: 1.5rem; }

/* === UTILITIES === */
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.ml-auto { margin-left: auto; }
.text-sm { font-size: var(--text-sm); }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: 'Menlo', 'Consolas', monospace; }
.text-center { text-align: center; }
.section-title { font-size: 1rem; font-weight: 700; margin-bottom: .75rem; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row-2 { grid-template-columns: 1fr; }
  .filters-grid { grid-template-columns: 1fr 1fr; }
  .content-body { padding: 1rem; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .filters-grid { grid-template-columns: 1fr; }
}
