:root {
  --bg: #f3f7fa;
  --surface: #ffffff;
  --ink: #16324a;
  --muted: #5a7388;
  --line: #d9e4ec;
  --brand: #0077c8;
  --brand-2: #0063a8;
  --accent: #6bb02d;
  --ok: #2f8f45;
  --warn: #b7791f;
  --danger: #b42318;
  --info: #0077c8;
  --sidebar: #004e87;
  --sidebar-text: #e7f3fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.04);
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --font-display: "IBM Plex Sans", "Source Sans 3", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 0% -10%, rgba(0, 119, 200, 0.10), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(107, 176, 45, 0.08), transparent 50%),
    var(--bg);
  min-height: 100vh;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, #0077c8 100%);
  color: var(--sidebar-text);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  color: #fff;
  padding: 0.35rem 0.35rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.brand-logo {
  width: 52px;
  height: auto;
  flex-shrink: 0;
  background: #fff;
  border-radius: 8px;
  padding: 0.2rem;
}
.brand-text { line-height: 1.2; }
.brand small { display: block; font-weight: 400; opacity: 0.75; font-size: 0.72rem; margin-top: 0.25rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  margin-bottom: 0.2rem;
  text-decoration: none;
  font-size: 0.95rem;
}
.nav-link:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.14); color: #fff; font-weight: 600; }
.nav-section { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.55; padding: 1rem 0.75rem 0.4rem; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-search { flex: 1; max-width: 360px; }
.topbar-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
.btn-menu {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.2rem;
  cursor: pointer;
}
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 24, 40, 0.45);
  z-index: 30;
}
.user-chip { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.9rem; }
.user-meta { text-align: right; }

/* Terrain mobile */
.input-lg { font-size: 1.05rem !important; padding: 0.85rem 0.9rem !important; min-height: 3rem; }
.btn-terrain {
  width: 100%;
  justify-content: center;
  padding: 1rem;
  font-size: 1.1rem;
  margin-top: 0.5rem;
  background: var(--accent);
}
.btn-terrain:hover { background: #a84c1f; }
.terrain-form .form-group { margin-bottom: 1rem; }
.terrain-recent {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.terrain-wrap { max-width: 640px; margin: 0 auto; }

.content { padding: 1.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }

.grid-kpi {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 0.85rem; }
.kpi .value {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 0.25rem;
  color: var(--brand);
}
.kpi.danger .value { color: var(--danger); }
.kpi.warn .value { color: var(--warn); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 0.75rem;
  justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.data th, table.data td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
table.data th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f8fafc;
  position: sticky; top: 0;
}
table.data tr:hover td { background: #f8fbfd; }

.badge {
  display: inline-flex; align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.badge-ok { background: #ecfdf3; color: var(--ok); border-color: #abefc6; }
.badge-warn { background: #fffaeb; color: var(--warn); border-color: #fedf89; }
.badge-danger { background: #fef3f2; color: var(--danger); border-color: #fecdca; }
.badge-info { background: #eff8ff; color: var(--info); border-color: #b2ddff; }
.badge-muted { background: #f2f4f7; color: #475467; border-color: #e4e7ec; }

.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  background: var(--brand);
  color: #fff;
}
.btn:hover { background: var(--brand-2); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: #f8fafc; color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-accent { background: var(--accent); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 0.85rem; font-weight: 600; color: #344054; }
input, select, textarea {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15, 76, 92, 0.25);
  border-color: var(--brand-2);
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert-success { background: #ecfdf3; border-color: #abefc6; color: #067647; }
.alert-error { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.alert-info { background: #eff8ff; border-color: #b2ddff; color: #175cd3; }

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    linear-gradient(135deg, rgba(0, 78, 135, 0.94), rgba(0, 119, 200, 0.88) 55%, rgba(107, 176, 45, 0.75));
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 2rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-brand { text-align: center; margin-bottom: 0.5rem; }
.login-logo {
  display: block;
  width: min(220px, 70%);
  height: auto;
  margin: 0 auto 0.85rem;
}
.login-card h1 {
  font-family: var(--font-display);
  margin: 0 0 0.35rem;
  color: var(--brand);
  font-size: 1.55rem;
}
.login-card p { color: var(--muted); margin: 0 0 1.5rem; }
.login-card .form-group { margin-bottom: 1rem; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 0.5rem; }
.login-hint {
  margin-top: 1.25rem;
  padding: 0.75rem;
  background: #f3f8fc;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.stack-sm > * + * { margin-top: 0.75rem; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.ligne-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: end;
}

@media (max-width: 1100px) {
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .topbar-search { max-width: 220px; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .btn-menu { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100vh;
    z-index: 40;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop { display: block; }
  .sidebar-backdrop[hidden] { display: none !important; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-kpi { grid-template-columns: 1fr; }
  .ligne-row { grid-template-columns: 1fr; }
  .user-meta { display: none; }
  .topbar { padding: 0.75rem 1rem; flex-wrap: wrap; }
  .topbar-search { order: 3; max-width: none; flex: 1 1 100%; }
  .content { padding: 1rem; }
}

/* Modal traitement alertes */
.modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: min(520px, 94vw);
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 40, 80, 0.28);
}
.modal::backdrop { background: rgba(10, 30, 50, 0.45); }
.modal-card { margin: 0; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.1rem; color: var(--brand); }
.modal-body { padding: 1rem 1.15rem; }
.modal-body .form-group { margin-bottom: 0.85rem; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.15rem 1.1rem;
  border-top: 1px solid var(--line);
  background: #f7fbfe;
}

/* ===== Droits d'accès ===== */
.droits-hero {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: stretch;
  margin-bottom: 1rem;
  background:
    linear-gradient(135deg, rgba(0, 119, 200, 0.08), transparent 55%),
    linear-gradient(225deg, rgba(107, 176, 45, 0.08), transparent 45%),
    var(--surface);
}
.droits-hero h2 {
  margin: 0.15rem 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--brand);
}
.droits-kicker {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
.droits-hero-text { flex: 1; min-width: 0; }
.droits-summary {
  min-width: 160px;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: #f3f8fc;
  border: 1px solid var(--line);
  align-self: center;
}
.droits-summary-count strong {
  font-size: 1.75rem;
  color: var(--brand);
  font-family: var(--font-display);
  line-height: 1;
}
.droits-summary-count span { color: var(--muted); font-size: 0.9rem; }
.droits-progress {
  height: 8px;
  background: #dde8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.55rem;
}
.droits-progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  border-radius: inherit;
}
.role-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.role-tab {
  display: block;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.role-tab:hover {
  text-decoration: none;
  border-color: #9ec9e8;
  box-shadow: var(--shadow);
}
.role-tab.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0, 119, 200, 0.15);
  background: linear-gradient(180deg, #f7fbfe, #fff);
}
.role-tab-name { display: block; font-weight: 700; color: var(--ink); }
.role-tab-desc {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}
.droits-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  padding: 0.75rem 0;
}
.droits-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.kind-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.kind-view { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }
.kind-edit { background: #ecfdf3; color: #067647; border-color: #abefc6; }
.kind-delete { background: #fef3f2; color: #b42318; border-color: #fecdca; }
.kind-action { background: #fffaeb; color: #b54708; border-color: #fedf89; }
.droits-groups { display: grid; gap: 0.75rem; padding-bottom: 5rem; }
.perm-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.perm-group > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: #f8fbfd;
  border-bottom: 1px solid var(--line);
  user-select: none;
}
.perm-group > summary::-webkit-details-marker { display: none; }
.perm-group-left { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.perm-group-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-family: var(--font-display);
  flex-shrink: 0;
}
.tone-brand { background: #e8f4fc; color: var(--brand); }
.tone-ok { background: #eaf8ef; color: var(--ok); }
.tone-warn { background: #fff6e8; color: var(--warn); }
.tone-info { background: #eef4ff; color: var(--info); }
.perm-group-count { margin-left: 0.45rem; font-size: 0.82rem; }
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.65rem;
  padding: 0.9rem;
}
.perm-card {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.perm-card:hover { border-color: #9ec9e8; }
.perm-card.is-checked {
  border-color: rgba(0, 119, 200, 0.45);
  background: linear-gradient(180deg, #f5fbff, #fff);
  box-shadow: inset 0 0 0 1px rgba(0, 119, 200, 0.08);
}
.perm-card input { margin-top: 0.2rem; accent-color: var(--brand); width: 1rem; height: 1rem; }
.perm-card-body { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.perm-code { font-size: 0.86rem; word-break: break-word; color: var(--ink); }
.perm-desc { font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.droits-sticky-actions {
  position: sticky;
  bottom: 0.75rem;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(16, 40, 70, 0.12);
}
@media (max-width: 720px) {
  .droits-hero { flex-direction: column; }
  .droits-sticky-actions { flex-direction: column; align-items: stretch; }
  .droits-sticky-actions .btn { width: 100%; justify-content: center; }
}

