* {
  box-sizing: border-box;
}

:root {
  --bg: #f2f4f8;
  --panel: #ffffff;
  --line: #d5deea;
  --muted: #5f6f85;
  --text: #112031;
  --accent: #1f6feb;
  --accent-2: #00a991;
  --bad: #dc2626;
  --ok: #1f9d55;
  --warn: #c27803;
  --hour-h: 58px;
  --radius: 14px;
  --shadow: 0 14px 38px rgba(17, 32, 49, 0.09);
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font: 'Manrope', 'Segoe UI', sans-serif;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.bg-layer {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1100px 520px at -14% -8%, rgba(31, 111, 235, 0.2), transparent 72%),
    radial-gradient(900px 420px at 110% 105%, rgba(0, 169, 145, 0.14), transparent 76%),
    linear-gradient(145deg, #f8fbff 0%, #eff4fb 43%, #f4f8fd 100%);
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 290px 1fr 430px;
  gap: 16px;
  height: 100dvh;
  padding: 14px;
}

.sidebar,
.workspace,
.inspector {
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-head h1 svg {
  flex-shrink: 0;
}

.panel-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 11px 10px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: color 0.15s, border-color 0.15s;
}

.sidebar-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.sidebar-tab:hover:not(.active) {
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
}

#optimizer-sidebar-panel,
#history-sidebar-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.sidebar-controls {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.sidebar-controls label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

.sidebar-controls input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.18s ease;
}

.sidebar-controls input:focus {
  border-color: var(--accent);
}

.group-list {
  overflow: auto;
  padding: 10px;
}

.history-panel-head {
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.history-panel-head button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-family: var(--font);
  font-size: 0.74rem;
  font-weight: 700;
  background: #f6f9ff;
  cursor: pointer;
}

.history-list {
  overflow: auto;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.history-row {
  border: 1px solid #d2deed;
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px;
  cursor: pointer;
}

.history-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.16);
}

.history-row.is-favorite {
  border-left: 4px solid #f1c40f;
  background: rgba(241, 196, 15, 0.05);
}

.history-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.favorite-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.3;
  transition: opacity 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.favorite-toggle:hover {
  opacity: 0.8;
  transform: scale(1.1);
}

.is-favorite .favorite-toggle {
  opacity: 1;
  color: #f1c40f;
}

.history-title {
  font-size: 0.8rem;
  font-weight: 800;
  color: #1a3e61;
  line-height: 1.25;
}

.history-meta {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: #4c627c;
}

.history-depth-control {
  margin-top: 6px;
  display: grid;
  gap: 4px;
}

.history-depth-range {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

.history-depth-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.64rem;
  color: #4c627c;
}

.history-actions {
  margin-top: 7px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.history-actions button {
  border: 1px solid #c8d7eb;
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 700;
  color: #20486f;
  cursor: pointer;
}

.history-actions button[data-history-delete] {
  border-color: #efc2c2;
  color: #9d1f1f;
  background: #fff5f5;
}

.history-actions button[data-history-delete].confirm-armed {
  border-color: #dc2626;
  color: #fff;
  background: #dc2626;
}

.history-actions button[data-history-delete].confirm-armed:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.resource-section {
  margin-bottom: 10px;
}

.resource-section-title {
  font-size: 0.69rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6f7f94;
  margin: 2px 2px 7px;
}

.resource-items {
  display: block;
}

.group-item {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  margin-bottom: 7px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  background: #f7faff;
}

.group-item:hover {
  transform: translateY(-1px);
  border-color: #bfd4f4;
}

.group-item.active {
  border-color: var(--accent);
  background: #eaf2ff;
}

.group-name {
  font-size: 0.93rem;
  font-weight: 700;
}

.group-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.76rem;
}

.workspace {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toolbar,
.calendar-shell,
.inspector .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar {
  padding: 14px;
}

.toolbar-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.title-wrap h2 {
  margin: 0;
  font-size: 1.18rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.week-nav {
  display: flex;
  gap: 8px;
}

.week-nav button {
  border: 1px solid var(--line);
  background: #f7faff;
  border-radius: 8px;
  font-family: var(--font);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
  color: #1f3550;
}

.week-nav button:hover {
  border-color: var(--accent);
}

.score-strip {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.score-chip {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: white;
}

.score-chip-btn {
  border: 1px solid rgba(255, 255, 255, 0.36);
  font-family: var(--font);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}

.score-chip-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.score-chip-btn.active {
  box-shadow: 0 0 0 2px rgba(17, 32, 49, 0.2);
}

.score-chip-btn:focus-visible {
  outline: 2px solid #123a62;
  outline-offset: 2px;
}

.score-detail {
  margin-top: 10px;
  border: 1px solid #d2deed;
  border-radius: 10px;
  background: #f8fbff;
  padding: 10px 11px;
}

.score-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.score-detail-title {
  font-size: 0.84rem;
  font-weight: 800;
  color: #1a3e61;
}

.score-detail-close {
  border: 1px solid #c8d7eb;
  border-radius: 8px;
  padding: 5px 8px;
  background: #ffffff;
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 700;
  color: #1f4b76;
  cursor: pointer;
}

.score-detail-sub {
  margin-top: 5px;
  font-size: 0.7rem;
  color: #4b6280;
}

.score-detail-meta {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: #3f5d7c;
}

.score-penalty-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.score-penalty-item {
  border: 1px solid #dde7f4;
  border-radius: 8px;
  background: #ffffff;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.74rem;
  color: #173655;
}

.score-penalty-item strong {
  font-family: var(--mono);
  color: #9d1f1f;
}

.score-detail-empty {
  margin-top: 8px;
  font-size: 0.74rem;
  color: #4b6280;
}

.calendar-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.calendar-head {
  display: grid;
  grid-template-columns: 62px repeat(5, 1fr);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f9fcff 0%, #f2f7ff 100%);
}

.corner {
  border-right: 1px solid var(--line);
}

.day-head {
  min-width: 0;
  padding: 10px 9px;
  border-right: 1px solid var(--line);
}

.day-head:last-child {
  border-right: 0;
}

.day-label {
  font-size: 0.73rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.day-date {
  margin-top: 3px;
  font-size: 0.92rem;
  font-weight: 700;
}

.calendar-scroll {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
}

.calendar-grid {
  display: grid;
  grid-template-columns: 62px repeat(5, 1fr);
  min-height: 0;
  height: 100%;
  width: 100%;
}

.time-col,
.day-col {
  position: relative;
}

.time-col {
  border-right: 1px solid var(--line);
  background: #fbfdff;
}

.time-mark {
  height: var(--hour-h);
  border-bottom: 1px dashed #e1e8f3;
  font-size: 0.68rem;
  color: var(--muted);
  padding: 3px 5px;
  font-weight: 700;
}

.day-col {
  border-right: 1px solid var(--line);
}

.day-col:last-child {
  border-right: 0;
}

.hour-line {
  height: var(--hour-h);
  border-bottom: 1px dashed #e6edf8;
}

.event {
  position: absolute;
  left: 7px;
  right: 7px;
  border-radius: 10px;
  border: 1px solid #bfd3f2;
  background: linear-gradient(180deg, #f4f8ff 0%, #e9f1ff 100%);
  padding: 7px 8px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.event:hover {
  transform: translateY(-1px);
  border-color: #8eb4f1;
}

.event.selected {
  border-color: #0f67f4;
  box-shadow: 0 0 0 2px rgba(15, 103, 244, 0.2);
}

.event.moved {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, #e9fff7 0%, #ddfcef 100%);
}

.event.moved-over-old {
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.38), 0 8px 20px rgba(220, 38, 38, 0.18);
}

.event.moved-over-old:hover {
  opacity: 0 !important;
}

.event-old-ghost {
  pointer-events: none;
  border-color: rgba(220, 38, 38, 0.55);
  border-style: dashed;
  background: rgba(220, 38, 38, 0.16);
  color: #7f1d1d;
  box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.14);
}

.event-old-ghost .ev-time,
.event-old-ghost .ev-room {
  color: rgba(127, 29, 29, 0.88);
}

.ev-title {
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.2;
}

.ev-time {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 0.67rem;
  color: #3a5c7e;
}

.ev-room {
  margin-top: 4px;
  color: #4c627c;
  font-size: 0.65rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inspector {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  min-height: 0;
}

.inspector .card {
  padding: 14px;
}

.inspector h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.selected-event {
  font-size: 0.83rem;
  line-height: 1.45;
  color: #173655;
}

.selected-event.empty {
  color: var(--muted);
}

.selected-event .uid {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: #486682;
}

.hidden {
  display: none !important;
}

.new-simulation-card {
  display: flex;
  align-items: center;
  justify-content: center;
}

.new-simulation-btn {
  width: 100%;
  border: 1px solid #b6cbe9;
  border-radius: 10px;
  padding: 11px 10px;
  background: #f3f8ff;
  color: #194772;
  font-family: var(--font);
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}

.new-simulation-btn:hover {
  border-color: var(--accent);
}

#params-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.params-card {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.params-card.results-mode {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.results-section {
  margin-top: 4px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Footer temps de run final ── */
.results-footer {
  flex-shrink: 0;
  padding: 7px 0 2px;
  border-top: 1px solid var(--line);
  font-size: 0.74rem;
  color: var(--muted);
  text-align: center;
}

/* ── Barre de progression dans l'onglet résultats ── */
.results-progress-bar {
  flex-shrink: 0;
  padding: 8px 0 4px;
  border-top: 1px solid var(--line);
  margin-top: 6px;
}

.results-progress-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.results-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

.results-progress-label {
  margin-top: 5px;
  font-size: 0.74rem;
  color: var(--muted);
  text-align: center;
}

/* ── Accordion tabs (Paramètres / Résultats) ── */
.accordion-tabs {
  display: flex;
  margin: -14px -14px 10px -14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.accordion-tab {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  text-align: center;
}

.accordion-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.accordion-tab:hover:not(.active) {
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  align-items: center;
}

.form-grid label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.form-grid input,
.form-grid select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-family: var(--font);
  font-size: 0.82rem;
}

.run-btn {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(135deg, #1f6feb 0%, #0e56c9 100%);
  color: white;
  font-family: var(--font);
  font-weight: 800;
  cursor: pointer;
}

.run-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.algo-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 108px;
  gap: 8px;
}

.stop-btn {
  border: 1px solid #efb5b5;
  border-radius: 10px;
  padding: 10px;
  background: #fff1f1;
  color: #9d1f1f;
  font-family: var(--font);
  font-weight: 800;
  cursor: pointer;
}

.stop-btn:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.run-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.75rem;
}

.progress-panel {
  margin-top: 12px;
  border: 1px solid #d8e3f3;
  border-radius: 10px;
  background: #f8fbff;
  padding: 10px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.progress-panel.hidden {
  display: none;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.progress-head strong {
  font-size: 0.79rem;
}

.progress-head span {
  font-size: 0.7rem;
  color: var(--muted);
}

.progress-track {
  height: 9px;
  border-radius: 999px;
  background: #dce7f6;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #1f6feb 0%, #00a991 100%);
  transition: width 0.2s ease;
}

.progress-line {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: #1f4166;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workers-list {
  margin-top: 8px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-top: 1px dashed #d3deed;
  padding-top: 6px;
}

.worker-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 7px;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.67rem;
  padding: 4px 0;
  border-bottom: 1px dotted #e3ebf6;
}

.worker-row:last-child {
  border-bottom: 0;
}

.worker-id {
  color: #2f4f73;
  font-weight: 700;
}

.worker-slot {
  color: #32587f;
}

.worker-evals {
  color: #173f69;
  font-weight: 700;
}

.results-head {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
}

#results-meta {
  font-size: 0.72rem;
  color: var(--muted);
}

.results-list {
  margin-top: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-gutter: stable;
}

.result-empty {
  color: var(--muted);
  font-size: 0.82rem;
  padding-top: 6px;
}

.schedule-warning {
  border: 1px solid #e4b65b;
  border-radius: 10px;
  background: #fff7df;
  color: #734b00;
  padding: 9px 10px;
  display: grid;
  gap: 4px;
  font-size: 0.78rem;
}

.schedule-warning strong {
  font-size: 0.82rem;
}

.solution {
  border: 1px solid #cfdae9;
  border-radius: 12px;
  padding: 8px;
  background: #f8fbff;
  min-width: 0;
  overflow: hidden;
  flex: 0 0 auto;
}

.solution.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(0, 169, 145, 0.15);
}

.solution.expanded {
  border-color: #b9cce7;
}

.solution-line {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
}

.solution-line-main {
  min-width: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.sol-move-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1c3f63;
}

.solution-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1c3f63;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.solution-line-side {
  flex: 0 0 auto;
}

.solution-body {
  margin-top: 8px;
  border-top: 1px dashed #cfdae9;
  padding-top: 8px;
}

.solution-tail {
  margin-top: 8px;
  display: block;
}

.details-btn {
  border: 1px solid #b7cbe7;
  border-radius: 8px;
  padding: 5px 9px;
  width: 100%;
  background: #edf4ff;
  cursor: pointer;
  font-size: 0.74rem;
  font-family: var(--font);
  font-weight: 700;
  color: #214b76;
}

.detail-moves {
  margin-top: 8px;
}

.sol-delta {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.sol-rank {
  font-weight: 800;
  font-size: 0.88rem;
}

.sol-delta.good {
  color: var(--ok);
}

.sol-delta.bad {
  color: var(--bad);
}

.moves {
  margin-top: 8px;
  display: grid;
  gap: 7px;
}

.move {
  font-size: 0.75rem;
  background: #fff;
  border: 1px solid #deebff;
  border-radius: 8px;
  padding: 7px;
}

.move-time {
  margin-top: 4px;
  color: #365879;
  font-family: var(--mono);
  font-size: 0.68rem;
  white-space: normal;
  overflow-wrap: anywhere;
}

.impact {
  margin-top: 2px;
  border-top: 1px dashed #cfdae9;
  padding-top: 8px;
}

.impact-headline {
  font-size: 0.74rem;
  font-weight: 800;
  color: #244568;
}

.impact-list {
  margin-top: 8px;
  display: grid;
  gap: 7px;
}

.impact-row {
  border: 1px solid #c9d8ec;
  border-radius: 8px;
  padding: 8px 9px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
  box-shadow: 0 1px 0 rgba(17, 32, 49, 0.04);
}

.impact-row-clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.impact-row-clickable:hover {
  border-color: #8bb3e8;
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.12);
  transform: translateY(-1px);
}

.impact-row-active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(0, 169, 145, 0.16);
  background: #f1fffb;
}

.impact-hint {
  margin-top: 4px;
  font-size: 0.66rem;
  color: #3d6389;
}

.impact-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.73rem;
}

.impact-title > div {
  min-width: 0;
}

.tag {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 800;
}

.week-score-delta {
  display: grid;
  gap: 2px;
  min-width: 74px;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--muted);
  line-height: 1.1;
}

.week-score-delta span {
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.week-score-delta strong {
  font-size: 0.82rem;
  font-weight: 900;
}

.week-score-delta.good {
  color: #15803d;
}

.week-score-delta.bad {
  color: #dc2626;
}

.days-mini {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
}

.day-mini {
  border: 1px solid #e0e7f1;
  border-radius: 6px;
  padding: 4px;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.62rem;
}

@media (max-width: 1480px) {
  .app-shell {
    grid-template-columns: 255px 1fr 380px;
  }
}

@media (max-width: 1220px) {
  .app-shell {
    grid-template-columns: 255px 1fr;
    grid-template-rows: auto auto;
  }

  .inspector {
    grid-column: 1 / -1;
    grid-template-columns: minmax(220px, 320px) 1fr;
    grid-template-rows: auto;
  }
}

@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
  }

  .sidebar,
  .workspace,
  .inspector {
    min-height: unset;
  }

  .inspector {
    grid-template-columns: 1fr;
  }

  .calendar-head,
  .calendar-grid {
    min-width: 0;
  }
}

/* --------------------------------------------------------------------------
   Refonte graphique optimiseur - 2026-07-01
   Layout centre sur l'emploi du temps, sidebar retractable et popups.
   -------------------------------------------------------------------------- */
:root {
  --sidebar-w: 318px;
  --sidebar-collapsed-w: 0px;
  --toolbar-h: auto;
  --radius: 8px;
  --shadow: 0 10px 26px rgba(17, 32, 49, 0.08);
}

.bg-layer {
  display: none;
}

body {
  background: #eef2f7;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 0;
  height: 100dvh;
  padding: 0;
  background: #eef2f7;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  background: #ffffff;
  min-width: 0;
  width: var(--sidebar-w);
  overflow: hidden;
  z-index: 4;
}

.app-shell.sidebar-collapsed .sidebar {
  width: 0;
  border-right: 0;
}

.sidebar-top {
  height: 56px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.brand-lockup svg {
  color: var(--accent-2);
  flex-shrink: 0;
}

.icon-btn,
.sidebar-toggle,
.sidebar-open-btn,
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}

.icon-btn:hover,
.sidebar-toggle:hover,
.sidebar-open-btn:hover,
.modal-close:hover {
  background: #f5f8fc;
  border-color: #b9c8db;
}

.sidebar-toggle {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  font-size: 22px;
  line-height: 1;
}

.sidebar-open-btn {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 8;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(17, 32, 49, 0.12);
}

.new-simulation-btn {
  margin: 14px 14px 10px;
  width: calc(100% - 28px);
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(31, 111, 235, .2);
}

.new-simulation-btn:hover {
  background: #185dc7;
}

.sidebar-current {
  margin: 0 14px 12px;
  padding: 10px 11px;
  border: 1px solid #dbe5f1;
  border-radius: 8px;
  background: #f8fbff;
  display: grid;
  gap: 3px;
}

.sidebar-current.sidebar-current-clickable {
  cursor: pointer;
  transition: all 0.2s ease;
  border-color: #72a1e7;
  background: #ebf3ff;
}

.sidebar-current.sidebar-current-clickable:hover {
  background: #dae8ff;
  border-color: #2b70d5;
  box-shadow: 0 3px 8px rgba(43, 112, 213, 0.12);
  transform: translateY(-1px);
}

.sidebar-current.sidebar-current-clickable .eyebrow {
  color: #2b70d5;
}

.sidebar-current .eyebrow,
.sidebar-section-head {
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

#sidebar-current-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .86rem;
  color: var(--text);
}

#sidebar-current-week {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .76rem;
  color: var(--muted);
}

.sidebar-results {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 10px 10px;
}

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  flex-shrink: 0;
}

.sidebar-results .results-list {
  margin-top: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 4px 4px;
}

.sidebar-results .solution {
  border-radius: 8px;
  box-shadow: none;
}

.sidebar-results .solution-line {
  min-height: 42px;
}

.sidebar-results .solution-body {
  padding: 8px;
}

.sidebar-tabs,
.panel-head,
.legacy-resource-panel {
  display: none !important;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: #eef2f7;
}

.toolbar {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  padding: 10px 14px;
  flex-shrink: 0;
  z-index: 2;
}

.toolbar-main {
  gap: 14px;
}

.title-wrap h2 {
  font-size: 1rem;
  letter-spacing: 0;
}

.subtitle {
  font-size: .78rem;
}

.week-nav {
  gap: 6px;
}

.week-nav .icon-btn {
  width: 34px;
  height: 32px;
  border-radius: 7px;
  font-size: 20px;
  font-weight: 800;
}

.week-nav button:not(.icon-btn) {
  height: 32px;
  border-radius: 7px;
}

.calendar-shell {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  min-height: 0;
  background: #fff;
}

.calendar-scroll {
  overflow: auto;
}

.calendar-head,
.calendar-grid {
  grid-template-columns: 62px repeat(5, minmax(160px, 1fr));
}

.inspector {
  display: none !important;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, .34);
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: min(720px, calc(100vw - 36px));
  max-height: calc(100dvh - 36px);
  background: #fff;
  border: 1px solid #d9e4f1;
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.resource-modal-card {
  width: min(760px, calc(100vw - 36px));
}

.optimizer-modal-card {
  width: min(560px, calc(100vw - 36px));
}

.plan-browser-card {
  width: min(620px, calc(100vw - 36px));
}

.plan-browser-body {
  padding: 18px;
}

.plan-browser-month-nav {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}

.plan-browser-month-nav strong {
  text-align: center;
  text-transform: capitalize;
  font-size: 1rem;
  color: #173655;
}

.plan-browser-month-nav button {
  width: 38px;
  height: 34px;
  border: 1px solid #cfdae7;
  border-radius: 9px;
  background: #f8fbff;
  color: #1f4b76;
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}

.plan-browser-month-nav button:hover {
  border-color: var(--accent);
  background: #eef5ff;
}

.plan-browser-grid {
  display: grid;
  gap: 8px;
}

.plan-browser-month-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
}

.plan-browser-month-name {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid #e0e7ef;
  border-radius: 8px;
  background: #f8fbff;
  color: #405772;
  font-size: 14.4px;
  font-weight: 850;
  line-height: 1.25;
  text-transform: capitalize;
}

.plan-browser-weeks {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.plan-browser-week {
  min-height: 48px;
  border: 1px solid #e0e7ef;
  border-radius: 8px;
  background: #fff;
  color: #31435a;
  font: inherit;
  font-size: 12.8px;
  font-weight: 750;
  line-height: 1.2;
}

.plan-browser-week.available {
  border-color: #16a34a;
  background: #16a34a;
  color: #fff;
  cursor: pointer;
}

.plan-browser-week.available:hover,
.plan-browser-week.available:focus-visible {
  border-color: #15803d;
  background: #15803d;
  box-shadow: 0 0 0 2px rgba(25, 135, 84, .16);
  outline: 0;
}

.plan-browser-week.current {
  box-shadow: inset 0 0 0 2px #176338;
}

.plan-browser-legend {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 14px;
  color: #55708a;
  font-size: 12px;
}

.plan-browser-legend span {
  width: 14px;
  height: 14px;
  border: 1px solid #8bd0a5;
  border-radius: 4px;
  background: #d7f4df;
}

@media (max-width: 520px) {
  .plan-browser-body { padding: 14px; }
  .plan-browser-month-row { grid-template-columns: 78px minmax(0, 1fr); gap: 5px; }
  .plan-browser-month-name { padding: 7px; font-size: 12px; }
  .plan-browser-weeks { gap: 3px; }
  .plan-browser-week { min-height: 43px; font-size: 11.2px; }
}

.modal-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: 0;
}

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .82rem;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.resource-search-wrap {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.resource-search-wrap label {
  display: block;
  margin-bottom: 6px;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.resource-search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font-family: var(--font);
  font-size: .94rem;
  outline: none;
}

.resource-search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}

.resource-modal-results {
  min-height: 260px;
  overflow: auto;
  padding: 10px 12px 14px;
}

.resource-modal-results .resource-section {
  margin-bottom: 12px;
}

.resource-modal-results .resource-section-title {
  padding: 7px 4px;
}

.resource-modal-results .resource-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.resource-modal-results .group-item {
  margin: 0;
}

.optimizer-modal-card .selected-card,
.optimizer-modal-card .params-card {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #fff;
}

.optimizer-modal-card .selected-card {
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
}

.optimizer-modal-card .selected-card h3,
.optimizer-modal-card .params-card h3 {
  margin: 0 0 8px;
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}

.optimizer-modal-card .params-card {
  padding: 14px 18px 18px;
  overflow: auto;
}

.params-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.advanced-toggle {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-family: var(--font);
  font-size: .78rem;
  font-weight: 800;
  cursor: pointer;
  padding: 4px 0;
}

.advanced-settings {
  display: none;
  margin-top: 6px;
}

.optimizer-modal-card.show-advanced .advanced-settings {
  display: grid;
}

.algo-actions {
  grid-template-columns: minmax(0, 1fr) 112px;
}

.run-btn,
.stop-btn {
  border-radius: 8px;
}

.run-hint {
  min-height: 20px;
}

.progress-panel {
  border-radius: 8px;
}

.results-progress-bar {
  padding: 8px 4px 10px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 330px);
    max-width: 330px;
    transform: translateX(0);
    transition: transform .18s ease;
    box-shadow: 12px 0 34px rgba(15, 23, 42, .22);
    z-index: 50;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 49;
    background: rgba(15, 23, 42, .34);
  }

  .app-shell.sidebar-collapsed .sidebar-backdrop { display: none; }

  .app-shell.sidebar-collapsed .sidebar {
    width: min(86vw, 330px);
    border-right: 1px solid var(--line);
    transform: translateX(-102%);
  }

  .toolbar {
    padding-left: 58px;
  }

  .toolbar-main {
    align-items: stretch;
  }

  .calendar-head,
  .calendar-grid {
    min-width: 880px;
  }

  .resource-modal-results .resource-items {
    grid-template-columns: 1fr;
  }
}


/* Toolbar inline scores */
.toolbar-main {
  align-items: center;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.toolbar-actions .score-strip {
  margin-top: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  min-width: 0;
  scrollbar-width: thin;
}

.toolbar-actions .score-chip {
  white-space: nowrap;
  flex: 0 0 auto;
  padding: 5px 9px;
}

@media (max-width: 900px) {
  .toolbar-main {
    flex-wrap: wrap;
    align-items: center;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
}


/* Toolbar centered week controls */
.toolbar-main {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  gap: 12px;
}

/* Colonne centrale de la barre d'outils : les deux pastilles segmentées
   (Vue semaine / preset) côte à côte, empilées si l'espace manque. */
.toolbar-toggles {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Navigation de semaine (barre d'outils) : flèches ◀ ▶ encadrant le titre,
   sautent d'un plan enregistré à l'adjacent. */
.title-wrap { display: flex; align-items: center; gap: 8px; }
.title-wrap .title-text { min-width: 0; }
.week-arrow { flex: 0 0 auto; }
.week-arrow:disabled { opacity: .4; cursor: default; }

.toolbar-main .title-wrap {
  min-width: 0;
  justify-self: start;
}

.toolbar-main .week-nav {
  justify-self: center;
}

.toolbar-main > .score-strip {
  justify-self: end;
  margin-top: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  scrollbar-width: thin;
}

.toolbar-main > .score-strip .score-chip {
  flex: 0 0 auto;
  white-space: nowrap;
}

.toolbar-actions {
  display: contents;
}

@media (max-width: 900px) {
  .toolbar-main {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .toolbar-main .title-wrap,
  .toolbar-main .week-nav,
  .toolbar-main > .score-strip {
    justify-self: stretch;
  }

  .toolbar-main .week-nav {
    justify-content: center;
  }

  .toolbar-main > .score-strip {
    justify-content: flex-start;
  }
}

/* Day-header score chips and Willow-like events */
.day-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.day-head .score-chip-btn {
  border: 0;
  min-width: 62px;
  justify-content: center;
  padding: 4px 9px;
  font-size: .72rem;
  line-height: 1.1;
  box-shadow: inset 0 0 0 1px currentColor;
}

.day-head .score-chip-btn.active {
  box-shadow: inset 0 0 0 1px currentColor, 0 0 0 2px rgba(17, 32, 49, .18);
}

.day-date {
  margin-top: 0;
}

.score-detail {
  position: fixed;
  inset: 0;
  z-index: 42;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 18px;
  border: 0;
  border-radius: 0;
  background: rgba(15, 23, 42, .42);
}

.score-detail-card {
  width: min(460px, calc(100vw - 36px));
  max-height: calc(100dvh - 36px);
  overflow: auto;
  border: 1px solid #d9e4f1;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
  padding: 16px 18px 18px;
}

.score-detail-kicker {
  font-size: .7rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: .07em;
  text-transform: uppercase;
}

.score-detail-score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 32px;
  margin-top: 12px;
  border-radius: 7px;
  font-weight: 800;
}

.event {
  left: 3px;
  right: 3px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 6px;
  padding: 4px 7px;
  min-height: 20px;
  transition: transform .1s ease, box-shadow .1s ease, opacity .1s;
}

.event:hover {
  transform: translateY(-1px) scale(1.01);
  box-shadow: var(--shadow-md) !important;
  z-index: 5;
}

.event.selected {
  outline: 2px solid rgba(15, 103, 244, .32);
  outline-offset: 1px;
}

.event.moved {
  outline: 2px solid rgba(34, 197, 94, .34);
  outline-offset: 1px;
  border-left-color: #16a34a !important;
}

.event .ev-type {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .8;
  line-height: 1;
  margin-bottom: 2px;
}

.event .ev-title {
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
  overflow: hidden;
}

.event .ev-title.compact {
  font-size: 10.5px;
}

.event .ev-loc {
  font-size: 10.5px;
  opacity: .75;
  word-break: break-word;
  overflow: hidden;
  margin-top: 1px;
}

.event.moved-over-old {
  opacity: .9;
}

.event.moved-over-old .ev-type,
.event.moved-over-old .ev-title,
.event.moved-over-old .ev-loc {
  opacity: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
}

.event.moved:not(.moved-over-old) {
  outline-color: rgba(34, 197, 94, .28);
}

/* Section avancée + slider préférence étudiants/enseignants (popup nouveau plan) */
.advanced-section { margin-top: 12px; border-top: 1px solid var(--border, #e5e7eb); padding-top: 10px; }
.advanced-section > summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--text-muted, #6b7280); user-select: none; }
.advanced-section[open] > summary { margin-bottom: 10px; }
.pref-block { padding: 4px 2px; }
.pref-labels { display: flex; justify-content: space-between; font-size: 0.8rem; font-weight: 600; color: var(--text, #374151); margin-bottom: 4px; }
.pref-block input[type="range"] { width: 100%; accent-color: var(--accent, #22c55e); cursor: pointer; }
.pref-readout { margin-top: 6px; font-size: 0.8rem; color: var(--text-muted, #6b7280); text-align: center; }
