:root {
  --bg: #0f172a;
  --panel: #111827;
  --card: #00040c;
  --muted: #6b7280;
  --text: #e5e7eb;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --border: #1f2937;
  --danger: #ef4444;
  --danger-dark: #7f1d1d;
  --ok: #10b981;
  --ok-dark: #064e3b;
  --warning: #f59e0b;
  --shadow: rgba(0, 0, 0, 0.35);
}

/* ------------------------------------------------------------
   RESET / BASE
------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.4 system-ui, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: #0b1220;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}

input[readonly] {
  opacity: 0.9;
  background: #0b1220;
  color: #cbd5e1;
  cursor: not-allowed;
}

textarea {
  resize: vertical;
}

label {
  display: block;
  margin: 0.5rem 0 0.25rem;
  color: #cbd5e1;
}

button {
  cursor: pointer;
}

button:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

code {
  color: #c4b5fd;
  font-size: 0.92em;
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------
   UTILITAIRES
------------------------------------------------------------- */

.w-100 {
  width: 100%;
}

.mt-1 {
  margin-top: 0.5rem;
}

.mt-2 {
  margin-top: 1rem;
}

.center {
  text-align: center;
}

.muted {
  color: var(--muted);
}

.alert {
  padding: 0.7rem 0.85rem;
  border-radius: 0.7rem;
  margin: 0.6rem 0;
}

.alert-error {
  background: #220e12;
  border: 1px solid #3f1a1f;
  color: #fecaca;
}

.alert-success {
  background: #052e24;
  border: 1px solid #14532d;
  color: #bbf7d0;
}

/* ------------------------------------------------------------
   BOUTONS
------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: #0b1220;
  color: var(--text);
  line-height: 1.2;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: #0f1627;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-600);
}

.btn-ghost {
  background: transparent;
}

.btn-login {
  margin-top: 20px;
}

.btn-logout:hover:not(:disabled) {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}

.btn.btn-icon {
  padding: 4px 8px;
  line-height: 1;
}

/* Bouton menu mobile */
.btn-mobile-menu {
  display: none;
  min-width: 40px;
}

/* ------------------------------------------------------------
   PAGE CONNEXION
------------------------------------------------------------- */

body.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  padding: 2rem;

  background: linear-gradient(-45deg, #0f172a, #1a1035, #001f3f, #190033);
  background-size: 400% 400%;
  animation: gradientAnim 15s ease infinite;
}

body.login-body::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../img/bg-login.svg") no-repeat center center;
  background-size: cover;
  opacity: 0.75;
  pointer-events: none;
  z-index: 0;
}

@keyframes gradientAnim {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  background: rgba(0, 4, 12, 0.92);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow:
    0 0 25px rgba(79, 70, 229, 0.45),
    0 0 60px rgba(180, 0, 255, 0.25);
}

.logo {
  display: block;
  height: 200px;
  max-width: 100%;
  margin: 0.25rem auto 1rem;
}

/* ------------------------------------------------------------
   FORMULAIRES
------------------------------------------------------------- */

.form .modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 0.9rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------
   LAYOUT APP
------------------------------------------------------------- */

.app-body {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 80;
}

.brand {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 36px;
  height: 36px;
}

.brand-title {
  font-weight: 700;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  gap: 0.3rem;
}

.nav-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-radius: 0.6rem;
  border: 1px solid transparent;
  background: transparent;
  color: #cbd5e1;
}

.nav-link:hover {
  background: #0b1220;
  border-color: var(--border);
}

.nav-link.active {
  background: #1a2236;
  border-color: #243049;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.8rem;
  min-width: 0;
}

.avatar {
  display: inline-grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #1f2937;
  color: #fff;
  font-weight: 700;
}

.chip-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-role {
  font-size: 12px;
  color: var(--muted);
}

.content {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(#0f172a, #0f172a 78%, rgba(15, 23, 42, 0.94));
}

.input.search,
.search {
  max-width: 520px;
}

/* ------------------------------------------------------------
   DROPDOWN + NOUVEAU
------------------------------------------------------------- */

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown .menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 0;
  min-width: 180px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  list-style: none;
}

.dropdown .menu li {
  margin: 0;
}

.dropdown .menu button {
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  color: #e8eefc;
  border-radius: 6px;
  cursor: pointer;
}

.dropdown .menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* ------------------------------------------------------------
   PANELS / SECTIONS
------------------------------------------------------------- */

.section {
  display: none;
  padding: 1rem;
}

.section.visible {
  display: block;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
}

.card-title {
  color: #cbd5e1;
}

.card-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 0.25rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  margin-top: 1rem;
  overflow: visible;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
}

.panel-tools {
  display: flex;
  gap: 0.6rem;
}

.list {
  padding: 0.4rem 1rem 1rem;
}

.list-striped > div:nth-child(odd) {
  background: #0b1220;
  border-radius: 0.6rem;
  padding: 0.5rem;
}

/* ------------------------------------------------------------
   TABLES
------------------------------------------------------------- */

.table {
  overflow: auto;
}

#appsTable,
#versionsTable,
#usersTable {
  overflow: visible;
}

.table table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 0.65rem;
  text-align: left;
  vertical-align: middle;
}

.table th {
  color: #cbd5e1;
  font-weight: 600;
  background: #0b1220;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table tr:hover td {
  background: rgba(255, 255, 255, 0.018);
}

.row-actions {
  gap: 0.35rem;
}

/* ------------------------------------------------------------
   TAGS
------------------------------------------------------------- */

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  font-size: 12px;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.03);
}

.tag-success {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.12);
  color: #86efac;
}

.tag-muted {
  border-color: rgba(148, 163, 184, 0.22);
  background: rgba(148, 163, 184, 0.08);
  color: #cbd5e1;
}

.tag-danger {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

/* ------------------------------------------------------------
   PAGINATION
------------------------------------------------------------- */

.pagination {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
  padding: 1rem;
}

.pagination button {
  min-width: 34px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #0b1220;
  color: var(--text);
}

.pagination button:hover:not(:disabled) {
  background: #111827;
}

.pagination span {
  color: var(--muted);
}

/* ------------------------------------------------------------
   MODALES
------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 100;
}

.modal.visible {
  display: flex;
}

.modal-card {
  width: min(560px, 92vw);
  max-height: min(86vh, 820px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.45);
}

.modal-card h3 {
  margin: 0 0 0.8rem;
}

/* ------------------------------------------------------------
   TOAST
------------------------------------------------------------- */

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(360px, calc(100vw - 32px));
  display: none;
  padding: 0.75rem 0.9rem;
  border-radius: 0.7rem;
  background: #10261f;
  border: 1px solid #1a3a2e;
  color: #bbf7d0;
  z-index: 150;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.toast.show {
  display: block;
}

.toast-ok {
  background: #10261f;
  border-color: #1a3a2e;
  color: #bbf7d0;
}

.toast-error {
  background: #2b1111;
  border-color: #3a1a1a;
  color: #fecaca;
}

/* ------------------------------------------------------------
   ACTIVITÉ RÉCENTE
------------------------------------------------------------- */

.activity {
  list-style: none;
  padding: 0;
  margin: 0;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
  border-bottom: 0;
}

.activity-item .ico {
  width: 1.5rem;
  text-align: center;
  opacity: 0.9;
}

.activity-body {
  flex: 1;
  min-width: 0;
}

.activity-body .title {
  font-weight: 600;
}

.activity-body .sub {
  font-size: 0.9rem;
  opacity: 0.8;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.activity-body .when {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

/* ------------------------------------------------------------
   BOUTONS D’ACTION / MENUS DE TABLEAU
------------------------------------------------------------- */

.row-actions,
.actions {
  position: relative;
  overflow: visible;
}

.actions {
  display: inline-block;
}

.actions .menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  min-width: 170px;
  background: #1f2530;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  list-style: none;
}

.actions .menu li {
  list-style: none;
}

.actions .menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
  border: 0;
  color: #e8eefc;
  border-radius: 6px;
  cursor: pointer;
}

.actions .menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.actions .menu button.danger {
  color: #ffb3b3;
}

.actions .menu button.danger:hover {
  background: rgba(255, 0, 0, 0.12);
}

/* ------------------------------------------------------------
   RESPONSIVE
------------------------------------------------------------- */

@media (max-width: 980px) {
  .app-body {
    display: block;
  }

  .btn-mobile-menu {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35);
  }

  .sidebar.open {
    transform: none;
  }

  .content {
    width: 100%;
    margin-left: 0;
  }

  .topbar {
    align-items: center;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-tools {
    width: 100%;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
  }

  .input.search,
  .search {
    max-width: none;
    width: 100%;
  }

  .modal-card {
    width: 96vw;
  }

  .pagination {
    justify-content: center;
  }
}