:root {
  --brand: #3f742c;
  --brand-dark: #2d5d24;
  --blue: #5aa7d5;
  --orange: #ec8a00;
  --red: #b84436;
  --page: #f5f8fb;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #334155;
  --line: rgba(31, 41, 51, 0.12);
  --shadow: 0 14px 32px rgba(35, 55, 74, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, rgba(90, 167, 213, 0.16), transparent 28%),
    linear-gradient(180deg, #fbfdff 0%, var(--page) 48%, #ffffff 100%);
  line-height: 1.55;
}

body,
input,
textarea,
select,
button {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

a {
  color: var(--brand-dark);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(236, 138, 0, 0.42);
  outline-offset: 3px;
}

.dashboard,
.app-shell {
  min-height: 100vh;
  background: transparent !important;
}

.sidebar {
  background: rgba(255, 255, 255, 0.88) !important;
  border-right: 1px solid var(--line) !important;
  box-shadow: 10px 0 28px rgba(35, 55, 74, 0.08) !important;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.sidebar h1,
.sidebar h2 {
  color: var(--brand-dark) !important;
  line-height: 1.15;
}

.sidebar ul,
.sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar li {
  margin: 0 !important;
}

.sidebar ul {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar a,
.sidebar nav a,
.sidebar button.switch-theme,
#theme-toggle {
  display: flex !important;
  align-items: center;
  width: 100% !important;
  min-height: 44px;
  height: 44px;
  padding: 0 14px !important;
  line-height: 1.1 !important;
  border-radius: 8px !important;
  border: 1px solid rgba(31, 41, 51, 0.18) !important;
  color: var(--text) !important;
  text-decoration: none !important;
  font-weight: 750;
  position: relative;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.sidebar li:nth-child(1) a,
.sidebar nav a:nth-child(1) {
  background: #d8f3dc !important;
  border-color: #95d5b2 !important;
}

.sidebar li:nth-child(2) a,
.sidebar nav a:nth-child(2) {
  background: #d7ecfb !important;
  border-color: #8ecae6 !important;
}

.sidebar li:nth-child(3) a,
.sidebar nav a:nth-child(3) {
  background: #d8f3f0 !important;
  border-color: #7dd3c7 !important;
}

.sidebar li:nth-child(4) a,
.sidebar nav a:nth-child(4) {
  background: #ffe8b8 !important;
  border-color: #f5bd55 !important;
}

.sidebar li:nth-child(5) a,
.sidebar nav a:nth-child(5) {
  background: #e7ddff !important;
  border-color: #b7a4f4 !important;
}

.sidebar li:nth-child(6) a,
.sidebar nav a:nth-child(6) {
  background: #ffd9e8 !important;
  border-color: #f3a6c4 !important;
}

.sidebar li:nth-child(7) a,
.sidebar nav a:nth-child(7) {
  background: #d9eef7 !important;
  border-color: #8fc7df !important;
}

.sidebar li:nth-child(8) a,
.sidebar nav a:nth-child(8) {
  background: #ffe1c2 !important;
  border-color: #f0ad72 !important;
}

.sidebar li:nth-child(9) a,
.sidebar nav a:nth-child(9) {
  background: #ffd6d6 !important;
  border-color: #ee9b9b !important;
}

.sidebar a:hover,
.sidebar a.active,
.sidebar nav a:hover,
.sidebar nav a.active {
  color: #ffffff !important;
  box-shadow:
    inset 4px 0 0 rgba(255, 255, 255, 0.72),
    inset 0 0 0 1px rgba(255, 255, 255, 0.36);
  transform: none;
}

.sidebar li:nth-child(1) a:hover,
.sidebar li:nth-child(1) a.active,
.sidebar nav a:nth-child(1):hover,
.sidebar nav a:nth-child(1).active {
  background: #2f7d52 !important;
  border-color: #23623f !important;
}

.sidebar li:nth-child(2) a:hover,
.sidebar li:nth-child(2) a.active,
.sidebar nav a:nth-child(2):hover,
.sidebar nav a:nth-child(2).active {
  background: #2f6fa3 !important;
  border-color: #24577f !important;
}

.sidebar li:nth-child(3) a:hover,
.sidebar li:nth-child(3) a.active,
.sidebar nav a:nth-child(3):hover,
.sidebar nav a:nth-child(3).active {
  background: #277b78 !important;
  border-color: #1f625f !important;
}

.sidebar li:nth-child(4) a:hover,
.sidebar li:nth-child(4) a.active,
.sidebar nav a:nth-child(4):hover,
.sidebar nav a:nth-child(4).active {
  background: #8a6a23 !important;
  border-color: #6c521b !important;
}

.sidebar li:nth-child(5) a:hover,
.sidebar li:nth-child(5) a.active,
.sidebar nav a:nth-child(5):hover,
.sidebar nav a:nth-child(5).active {
  background: #6b5ca5 !important;
  border-color: #544884 !important;
}

.sidebar li:nth-child(6) a:hover,
.sidebar li:nth-child(6) a.active,
.sidebar nav a:nth-child(6):hover,
.sidebar nav a:nth-child(6).active {
  background: #9a4f78 !important;
  border-color: #7b3f61 !important;
}

.sidebar li:nth-child(7) a:hover,
.sidebar li:nth-child(7) a.active,
.sidebar nav a:nth-child(7):hover,
.sidebar nav a:nth-child(7).active {
  background: #3a7898 !important;
  border-color: #2d5f78 !important;
}

.sidebar li:nth-child(8) a:hover,
.sidebar li:nth-child(8) a.active,
.sidebar nav a:nth-child(8):hover,
.sidebar nav a:nth-child(8).active {
  background: #9a6437 !important;
  border-color: #7c4f2b !important;
}

.sidebar li:nth-child(9) a:hover,
.sidebar li:nth-child(9) a.active,
.sidebar nav a:nth-child(9):hover,
.sidebar nav a:nth-child(9).active,
.sidebar li:nth-child(10) a:hover,
.sidebar li:nth-child(10) a.active,
.sidebar nav a:nth-child(10):hover,
.sidebar nav a:nth-child(10).active {
  background: #9a4b4b !important;
  border-color: #7a3939 !important;
}

.sidebar li.theme-item {
  margin-bottom: 14px;
}

.sidebar li.theme-item #theme-toggle {
  width: 100%;
  justify-content: center;
  background: #e2e8f0 !important;
  border-color: #94a3b8 !important;
  color: #172033 !important;
  cursor: pointer;
}

.sidebar li.theme-item #theme-toggle:hover {
  background: #475569 !important;
  border-color: #334155 !important;
  color: #ffffff !important;
}

.sidebar a.active::after,
.sidebar nav a.active::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
  transform: translateY(-50%);
}

.main,
.main-content {
  width: 100%;
  min-width: 0;
  background: transparent !important;
}

.main h1,
.main-content h1,
.main h2,
.main-content h2 {
  color: var(--text) !important;
  line-height: 1.15;
  letter-spacing: 0;
}

.page-intro {
  max-width: 760px;
  color: var(--muted);
  margin: -10px 0 24px;
}

.muted,
.form-help,
.empty-state,
.resource-card p,
.card p,
.panel-card p,
.category-card p {
  color: var(--muted) !important;
}

form,
.form-panel,
.card,
.resource-card,
.category-card,
.content-block,
.panel-card,
table {
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow) !important;
}

form form,
.resource-actions form,
.chapter-row,
.delete-row,
.delete-category,
.category-header,
.inline-form,
.add-chapter-form {
  border: 0 !important;
  box-shadow: none !important;
}

input,
textarea,
select {
  min-height: 44px;
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  background: #fff !important;
  color: var(--text) !important;
}

textarea {
  min-height: 140px;
}

button,
.btn,
.action-button,
.expand-button,
.back-button,
.buttons a,
.panel-card a {
  border-radius: 8px !important;
  border: 0;
  font-weight: 700;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:hover,
.btn:hover,
.action-button:hover,
.expand-button:hover,
.back-button:hover,
.buttons a:hover,
.panel-card a:hover {
  transform: translateY(-2px);
}

.notice,
.message,
.error {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
}

.notice,
.message {
  color: var(--brand-dark);
  background: rgba(63, 116, 44, 0.1);
  border: 1px solid rgba(63, 116, 44, 0.18);
}

.error {
  color: #9e2f25 !important;
  background: rgba(184, 68, 54, 0.1);
  border: 1px solid rgba(184, 68, 54, 0.18);
}

.form-help {
  margin: -6px 0 18px;
  color: var(--muted);
  font-size: 0.95rem;
}

.search-bar,
.search-container form,
.inline-form,
.category-header,
.add-chapter-form,
.chapter-row {
  display: grid !important;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
}

.search-bar,
.search-container form {
  background: var(--panel) !important;
  padding: 14px !important;
}

.category-list {
  display: grid;
  gap: 18px;
}

.form-panel,
.category-card {
  background: var(--panel);
  padding: 20px;
  margin-bottom: 18px;
}

.category-card {
  display: grid;
  gap: 14px;
}

.category-header {
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 160px) auto;
}

.add-chapter-form,
.chapter-row {
  grid-template-columns: minmax(180px, 1fr) auto;
}

.chapter-list {
  display: grid;
  gap: 8px;
}

.delete-row,
.delete-category {
  display: flex;
  justify-content: flex-end;
  margin: -6px 0 2px;
}

.delete-row button,
.delete-category button,
button.danger {
  background: var(--red) !important;
  color: #fff !important;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
}

.resource-grid,
.resources-container {
  gap: 18px !important;
}

.resource-card,
.card {
  background: var(--panel) !important;
}

table {
  width: 100%;
  overflow: hidden;
  border-collapse: separate !important;
  border-spacing: 0 !important;
  background: var(--panel);
}

th {
  background: rgba(63, 116, 44, 0.1) !important;
  color: var(--brand-dark) !important;
}

td,
th {
  border-bottom: 1px solid var(--line) !important;
  vertical-align: top;
}

.user-panel-container {
  border: 1px solid var(--line) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.86) !important;
  box-shadow: var(--shadow) !important;
}

.user-panel-container.compact {
  position: static;
  width: fit-content;
  margin-left: auto;
  margin-bottom: 18px;
}

body.dark-mode {
  --page: #101820;
  --panel: #17212b;
  --text: #eef4f8;
  --muted: #b3c1cb;
  --line: rgba(238, 244, 248, 0.14);
  background: #101820 !important;
  color: var(--text) !important;
}

body.dark-mode .sidebar,
body.dark-mode .resource-card,
body.dark-mode .card,
body.dark-mode form,
body.dark-mode .form-panel,
body.dark-mode .category-card,
body.dark-mode table,
body.dark-mode .user-panel-container {
  background: var(--panel) !important;
  color: var(--text) !important;
}

body.dark-mode .sidebar h1,
body.dark-mode .sidebar h2 {
  color: #86efac !important;
}

body.dark-mode .sidebar a,
body.dark-mode .sidebar nav a {
  border: 1px solid rgba(255, 255, 255, 0.28) !important;
  color: #f8fafc !important;
  font-weight: 750;
  position: relative;
}

body.dark-mode .sidebar li:nth-child(1) a,
body.dark-mode .sidebar nav a:nth-child(1) {
  background: #2f7d52 !important;
}

body.dark-mode .sidebar li:nth-child(2) a,
body.dark-mode .sidebar nav a:nth-child(2) {
  background: #2f6fa3 !important;
}

body.dark-mode .sidebar li:nth-child(3) a,
body.dark-mode .sidebar nav a:nth-child(3) {
  background: #277b78 !important;
}

body.dark-mode .sidebar li:nth-child(4) a,
body.dark-mode .sidebar nav a:nth-child(4) {
  background: #8a6a23 !important;
}

body.dark-mode .sidebar li:nth-child(5) a,
body.dark-mode .sidebar nav a:nth-child(5) {
  background: #6b5ca5 !important;
}

body.dark-mode .sidebar li:nth-child(6) a,
body.dark-mode .sidebar nav a:nth-child(6) {
  background: #9a4f78 !important;
}

body.dark-mode .sidebar li:nth-child(7) a,
body.dark-mode .sidebar nav a:nth-child(7) {
  background: #3a7898 !important;
}

body.dark-mode .sidebar li:nth-child(8) a,
body.dark-mode .sidebar nav a:nth-child(8) {
  background: #9a6437 !important;
}

body.dark-mode .sidebar li:nth-child(9) a,
body.dark-mode .sidebar nav a:nth-child(9) {
  background: #9a4b4b !important;
}

body.dark-mode .sidebar li:nth-child(10) a,
body.dark-mode .sidebar nav a:nth-child(10) {
  background: #9a4b4b !important;
}

body.dark-mode .sidebar a:hover,
body.dark-mode .sidebar a.active,
body.dark-mode .sidebar nav a:hover,
body.dark-mode .sidebar nav a.active {
  background: #4c956c !important;
  color: #ffffff !important;
  border-color: #d9f99d !important;
  box-shadow:
    inset 4px 0 0 #d9f99d,
    inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

body.dark-mode .sidebar a.active,
body.dark-mode .sidebar nav a.active {
  transform: none;
}

body.dark-mode .sidebar a.active::after,
body.dark-mode .sidebar nav a.active::after {
  content: "";
  position: absolute;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d9f99d;
  box-shadow: 0 0 10px rgba(217, 249, 157, 0.9);
}

body.dark-mode #theme-toggle,
body.dark-mode .sidebar button.switch-theme {
  background: #bbf7d0 !important;
  color: #123524 !important;
  justify-content: center;
}

body.dark-mode .sidebar li.theme-item #theme-toggle {
  background: #334155 !important;
  border-color: rgba(255, 255, 255, 0.28) !important;
  color: #f8fafc !important;
}

body.dark-mode .sidebar li.theme-item #theme-toggle:hover {
  background: #475569 !important;
  color: #ffffff !important;
}

body.dark-mode input,
body.dark-mode textarea,
body.dark-mode select {
  background: #101820 !important;
  color: var(--text) !important;
}

@media (max-width: 900px) {
  body {
    overflow-x: hidden;
  }

  .dashboard,
  .app-shell {
    display: block !important;
    min-height: 100vh;
  }

  .sidebar {
    position: sticky !important;
    top: 0;
    z-index: 50;
    width: 100% !important;
    min-height: auto !important;
    padding: 12px !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--line) !important;
  }

  .sidebar h1,
  .sidebar h2 {
    margin: 0 0 10px !important;
    font-size: 1.05rem !important;
    text-align: left !important;
  }

  .sidebar ul,
  .sidebar nav ul {
    display: flex !important;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .sidebar li {
    flex: 0 0 auto;
    margin: 0 !important;
  }

  .sidebar a,
  .sidebar nav a {
    min-height: 38px;
    padding: 9px 12px !important;
    white-space: nowrap;
    font-size: 0.92rem !important;
  }

  #theme-toggle,
  .sidebar button.switch-theme {
    margin-top: 10px !important;
    width: 100% !important;
  }

  .main,
  .main-content {
    width: 100% !important;
    margin: 0 !important;
    padding: 22px 14px !important;
  }

  .user-panel-container {
    position: static !important;
    width: 100%;
    margin: 0 0 18px !important;
    justify-content: center;
    padding: 10px 14px !important;
  }

  .user-panel-container span {
    font-size: 1rem !important;
  }

  .search-bar,
  .search-container form,
  .inline-form,
  .category-header,
  .add-chapter-form,
  .chapter-row {
    grid-template-columns: 1fr !important;
  }

  .resource-grid,
  .resources-container,
  .panel-cards,
  .content-section {
    display: grid !important;
    grid-template-columns: 1fr !important;
    width: 100% !important;
  }

  .resource-card,
  .card,
  .form-panel,
  .category-card {
    width: 100% !important;
    max-width: none !important;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 520px) {
  .main h1,
  .main-content h1,
  .main h2,
  .main-content h2 {
    font-size: 1.55rem !important;
  }

  input,
  textarea,
  select,
  button,
  .btn {
    width: 100% !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Menu professeur stable : aucune variation de taille entre les pages */
.sidebar ul,
.sidebar nav ul {
  display: flex !important;
  flex-direction: column !important;
  gap: 8px !important;
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
}
.sidebar li,
.sidebar li.theme-item {
  margin: 0 !important;
  padding: 0 !important;
}
.sidebar a,
.sidebar nav a,
.sidebar #theme-toggle,
.sidebar .theme-toggle,
#theme-toggle {
  box-sizing: border-box !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  width: 100% !important;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  padding: 0 14px !important;
  margin: 0 !important;
  line-height: 1.1 !important;
  border-width: 1px !important;
  border-style: solid !important;
  transform: none !important;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease !important;
}
.sidebar a:hover,
.sidebar a.active,
.sidebar nav a:hover,
.sidebar nav a.active {
  transform: none !important;
  box-shadow: inset 4px 0 0 rgba(255,255,255,0.72), inset 0 0 0 1px rgba(255,255,255,0.36) !important;
}