/* ==========================================================================
   PLAN PRÉLIMINAIRE — SUIVI PNS (Calculateur Stratégique Multi-Unités)
   Espace 100% pratique : calcul automatique par cours et multi-unités
   (Minutes, Heures, Jours, Semaines) avec saisie manuelle du nombre de cours
   ========================================================================== */

:root {
  --plan-gradient-head: linear-gradient(135deg, rgba(37, 99, 235, 0.1) 0%, rgba(6, 182, 212, 0.06) 100%);
  --plan-card-bg: rgba(255, 255, 255, 0.85);
  --plan-card-border: rgba(148, 163, 184, 0.2);
  --plan-subcard-bg: rgba(248, 250, 252, 0.9);
  --plan-input-bg: #ffffff;
  --plan-highlight: #2563eb;
  --plan-accent: #06b6d4;
  --plan-success: #10b981;
  --plan-warning: #f59e0b;
  --plan-danger: #ef4444;
}

[data-theme="dark"],
html.dark,
body.dark {
  --plan-gradient-head: linear-gradient(135deg, rgba(37, 99, 235, 0.16) 0%, rgba(6, 182, 212, 0.08) 100%);
  --plan-card-bg: rgba(22, 28, 45, 0.85);
  --plan-card-border: rgba(148, 163, 184, 0.14);
  --plan-subcard-bg: rgba(15, 23, 42, 0.7);
  --plan-input-bg: rgba(15, 23, 42, 0.85);
  --plan-highlight: #38bdf8;
  --plan-accent: #22d3ee;
}

/* Container */
#modulePreliminaryPlanContainer {
  margin-bottom: 12px;
  width: 100%;
}

.preliminary-plan-wrap {
  background: var(--bg2);
  border: 1px solid var(--plan-card-border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.preliminary-plan-wrap:hover {
  border-color: rgba(37, 99, 235, 0.35);
}

/* Slim Accordion Header */
.preliminary-plan-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--plan-gradient-head);
  border-bottom: 1px solid var(--plan-card-border);
  cursor: pointer;
  user-select: none;
}

.preliminary-plan-header:hover {
  filter: brightness(1.02);
}

.preliminary-plan-header .group-toggle {
  font-size: 13px;
  color: var(--text2);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.preliminary-plan-header .group-toggle.open {
  transform: rotate(90deg);
  color: var(--plan-highlight);
}

.preliminary-plan-title-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.plan-title-icon-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.plan-main-title {
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.plan-series-tag {
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 12px;
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.25);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Compact Header Stats */
.preliminary-plan-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.plan-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--plan-subcard-bg);
  border: 1px solid var(--plan-card-border);
  color: var(--text2);
  white-space: nowrap;
}

.plan-stat-pill i { font-size: 10px; }

.plan-stat-pill.pill-time {
  color: #3b82f6;
  border-color: rgba(59, 130, 246, 0.25);
  background: rgba(59, 130, 246, 0.08);
}

.plan-stat-pill.pill-courses {
  color: #06b6d4;
  border-color: rgba(6, 182, 212, 0.25);
  background: rgba(6, 182, 212, 0.08);
}

.plan-stat-pill.pill-diag-safe {
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.25);
  background: rgba(16, 185, 129, 0.08);
}

.plan-stat-pill.pill-diag-warning {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.25);
  background: rgba(245, 158, 11, 0.08);
}

.plan-stat-pill.pill-diag-danger {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.25);
  background: rgba(239, 68, 68, 0.08);
}

.plan-stat-pill.pill-diag-neutral {
  color: var(--text3, #64748b);
  border-color: rgba(148, 163, 184, 0.2);
}

.plan-header-action-btn {
  background: var(--plan-subcard-bg);
  border: 1px solid var(--plan-card-border);
  color: var(--text2);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.plan-header-action-btn:hover {
  background: var(--plan-highlight);
  color: #fff;
  border-color: var(--plan-highlight);
}

/* Compact Accordion Body */
.preliminary-plan-body {
  padding: 10px 14px 14px 14px;
  background: var(--bg2);
}

/* Compact Tabs Bar */
.plan-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--plan-card-border);
  padding-bottom: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.plan-tabs-list {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.plan-tab-btn {
  background: var(--plan-subcard-bg);
  border: 1px solid var(--plan-card-border);
  color: var(--text2);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.plan-tab-btn i { font-size: 10px; }

.plan-tab-btn:hover {
  background: var(--item-bg-hover, rgba(148, 163, 184, 0.1));
  color: var(--text);
}

.plan-tab-btn.active {
  background: var(--plan-highlight);
  color: #fff;
  border-color: var(--plan-highlight);
}

.plan-save-indicator,
.plan-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 6px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  background: rgba(16, 185, 129, 0.08);
  color: #059669;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.plan-save-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(16, 185, 129, 0.2);
}

.plan-save-btn.saved {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.35);
  color: #059669;
}

.plan-save-btn.has-changes {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: #1d4ed8;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.plan-save-btn.has-changes:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

[data-theme="dark"] .plan-save-btn.saved {
  color: #34d399;
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(52, 211, 153, 0.3);
}

/* Generic Form Inputs - Ultra Compact */
.plan-input,
.plan-select,
.plan-textarea {
  width: 100%;
  height: 28px;
  background: var(--plan-input-bg);
  border: 1px solid var(--plan-card-border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11.5px;
  color: var(--text);
  font-family: var(--font-main);
  box-sizing: border-box;
  transition: border-color 0.15s ease;
}

.plan-textarea {
  height: auto;
  min-height: 70px;
  padding: 6px 8px;
  resize: vertical;
  line-height: 1.4;
}

.plan-input:focus,
.plan-select:focus,
.plan-textarea:focus {
  outline: none;
  border-color: var(--plan-highlight);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.plan-field-compact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}

.plan-field-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text3, #64748b);
  display: block;
  white-space: nowrap;
}

/* Grand Total Multi-Unit Hero Banner */
.plan-grand-total-banner {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.09) 0%, rgba(6, 182, 212, 0.07) 100%);
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.plan-grand-total-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.plan-grand-total-label {
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.plan-grand-total-per-course {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
}

.plan-multi-units-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.plan-unit-card {
  background: var(--plan-card-bg);
  border: 1px solid var(--plan-card-border);
  border-radius: 6px;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}

.plan-unit-val {
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.plan-unit-lbl {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--text3, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Multi-Units Comparison Table */
.plan-table-wrapper {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--plan-card-border);
  background: var(--bg2);
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.plan-units-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11.5px;
  text-align: center;
}

.plan-units-table th {
  background: var(--plan-subcard-bg);
  padding: 9px 12px;
  font-weight: 700;
  color: var(--text2);
  border-bottom: 1px solid var(--plan-card-border);
  white-space: nowrap;
}

.plan-units-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--plan-card-border);
  color: var(--text);
  vertical-align: middle;
}

.plan-units-table td.col-couche-name {
  padding-left: 14px;
  padding-right: 14px;
  text-align: left;
  white-space: nowrap;
}

.plan-units-table tr:hover td {
  background: var(--item-bg-hover, rgba(148, 163, 184, 0.05));
}

.plan-units-table tr.total-row td {
  background: rgba(37, 99, 235, 0.05);
  font-weight: 800;
  color: var(--text);
  border-top: 2px solid rgba(37, 99, 235, 0.25);
  border-bottom: none;
  font-size: 12px;
  padding: 10px 10px;
}

/* Couche Pill Badges (First Column) */
.plan-couche-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 5px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 11.5px;
  line-height: 1;
}

.plan-couche-pill .pill-token {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.plan-couche-pill .pill-title {
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  letter-spacing: 0.2px;
}

/* Couche 1 */
.plan-couche-pill.couche-1 {
  background: rgba(37, 99, 235, 0.08);
  color: #2563eb;
  border: 1px solid rgba(37, 99, 235, 0.2);
}
.plan-couche-pill.couche-1 .pill-token {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
}

/* Couche 2 */
.plan-couche-pill.couche-2 {
  background: rgba(6, 182, 212, 0.08);
  color: #0891b2;
  border: 1px solid rgba(6, 182, 212, 0.2);
}
.plan-couche-pill.couche-2 .pill-token {
  background: linear-gradient(135deg, #0891b2, #06b6d4);
}

/* Couche 3 */
.plan-couche-pill.couche-3 {
  background: rgba(16, 185, 129, 0.08);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.2);
}
.plan-couche-pill.couche-3 .pill-token {
  background: linear-gradient(135deg, #059669, #10b981);
}

/* Couche 4 */
.plan-couche-pill.couche-4 {
  background: rgba(245, 158, 11, 0.08);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.2);
}
.plan-couche-pill.couche-4 .pill-token {
  background: linear-gradient(135deg, #d97706, #f59e0b);
}

/* Couche Total */
.plan-couche-pill.couche-total {
  background: rgba(79, 70, 229, 0.09);
  color: #4f46e5;
  border: 1px solid rgba(79, 70, 229, 0.25);
}
.plan-couche-pill.couche-total .pill-token {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
}

[data-theme="dark"] .plan-couche-pill.couche-1, html.dark .plan-couche-pill.couche-1 {
  background: rgba(59, 130, 246, 0.16); color: #60a5fa; border-color: rgba(59, 130, 246, 0.3);
}
[data-theme="dark"] .plan-couche-pill.couche-2, html.dark .plan-couche-pill.couche-2 {
  background: rgba(6, 182, 212, 0.16); color: #38bdf8; border-color: rgba(6, 182, 212, 0.3);
}
[data-theme="dark"] .plan-couche-pill.couche-3, html.dark .plan-couche-pill.couche-3 {
  background: rgba(16, 185, 129, 0.16); color: #34d399; border-color: rgba(16, 185, 129, 0.3);
}
[data-theme="dark"] .plan-couche-pill.couche-4, html.dark .plan-couche-pill.couche-4 {
  background: rgba(245, 158, 11, 0.16); color: #fbbf24; border-color: rgba(245, 158, 11, 0.3);
}
[data-theme="dark"] .plan-couche-pill.couche-total, html.dark .plan-couche-pill.couche-total {
  background: rgba(99, 102, 241, 0.18); color: #818cf8; border-color: rgba(99, 102, 241, 0.35);
}

.plan-units-badge {
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
}

.badge-min { background: rgba(6, 182, 212, 0.1); color: #06b6d4; }
.badge-hrs { background: rgba(37, 99, 235, 0.1); color: #3b82f6; }
.badge-day { background: rgba(16, 185, 129, 0.1); color: #10b981; }
.badge-sem { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }

/* Parameters Bar (Row 1: 3 Inputs) */
.plan-params-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--plan-subcard-bg);
  border: 1px solid var(--plan-card-border);
  border-radius: 8px;
  padding: 8px 14px;
  flex-wrap: wrap;
}

.plan-param-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.plan-param-item label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  white-space: nowrap;
}

.plan-param-item input {
  height: 26px;
  font-size: 11.5px;
  text-align: center;
  font-weight: 700;
}

/* Feasibility Diagnosis Banner (Row 2: Dedicated row, clearly separated stats) */
.plan-feasibility-banner {
  margin-top: 8px;
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid transparent;
  transition: all 0.25s ease;
}

.plan-feasibility-banner.safe {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
}

.plan-feasibility-banner.warning {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.25);
}

.plan-feasibility-banner.danger {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.25);
}

.plan-feasibility-banner.neutral {
  background: var(--plan-subcard-bg);
  border-color: var(--plan-card-border);
}

/* Status Badge inside banner */
.feasibility-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 800;
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.plan-feasibility-banner.safe .feasibility-status-badge {
  background: rgba(16, 185, 129, 0.16);
  color: #10b981;
}

.plan-feasibility-banner.warning .feasibility-status-badge {
  background: rgba(245, 158, 11, 0.16);
  color: #f59e0b;
}

.plan-feasibility-banner.danger .feasibility-status-badge {
  background: rgba(239, 68, 68, 0.16);
  color: #ef4444;
}

.plan-feasibility-banner.neutral .feasibility-status-badge {
  background: rgba(148, 163, 184, 0.14);
  color: var(--text3, #64748b);
}

/* Items wrapper */
.feasibility-items-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.feasibility-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
}

.feasibility-item-label {
  color: var(--text2);
  font-weight: 600;
  font-size: 11px;
}

.feasibility-item-label i {
  color: var(--text3);
  margin-right: 2px;
}

.feasibility-item-value {
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  font-weight: 800;
  color: var(--text);
  font-size: 12px;
}

.feasibility-item-value.highlight {
  color: var(--plan-highlight);
}

.feasibility-item-value.val-safe {
  color: #10b981;
}

.feasibility-item-value.val-warning {
  color: #f59e0b;
}

.feasibility-item-value.val-danger {
  color: #ef4444;
}

.feasibility-divider {
  width: 1px;
  height: 16px;
  background: var(--plan-card-border);
  opacity: 0.7;
}

/* Compact Sources List */
.plan-sources-actions-bar {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.btn-add-source-quick {
  background: var(--plan-subcard-bg);
  border: 1px solid var(--plan-card-border);
  color: var(--text);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.btn-add-source-quick:hover {
  background: var(--plan-highlight);
  color: #fff;
  border-color: var(--plan-highlight);
}

.plan-source-compact-row {
  display: grid;
  grid-template-columns: 115px 1.4fr 1.2fr 1.6fr 30px;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--plan-card-bg);
  border: 1px solid var(--plan-card-border);
  margin-bottom: 6px;
  transition: all 0.2s ease;
}

.plan-source-compact-row:hover {
  border-color: rgba(37, 99, 235, 0.3);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.plan-source-type-pill {
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-heading, 'Manrope'), sans-serif;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.plan-source-type-pill i {
  font-size: 11.5px;
  width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.plan-source-type-pill.poly {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border-color: rgba(37, 99, 235, 0.25);
}

.plan-source-type-pill.youtube {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.25);
}

.plan-source-type-pill.livre {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.25);
}

.plan-source-type-pill.drive {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
  border-color: rgba(245, 158, 11, 0.25);
}

.plan-source-type-pill.web {
  background: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
  border-color: rgba(139, 92, 246, 0.25);
}

.plan-source-type-pill.qcms {
  background: rgba(6, 182, 212, 0.1);
  color: #0891b2;
  border-color: rgba(6, 182, 212, 0.25);
}

[data-theme="dark"] .plan-source-type-pill.poly, html.dark .plan-source-type-pill.poly {
  background: rgba(59, 130, 246, 0.18); color: #60a5fa; border-color: rgba(59, 130, 246, 0.35);
}
[data-theme="dark"] .plan-source-type-pill.youtube, html.dark .plan-source-type-pill.youtube {
  background: rgba(239, 68, 68, 0.18); color: #f87171; border-color: rgba(239, 68, 68, 0.35);
}
[data-theme="dark"] .plan-source-type-pill.livre, html.dark .plan-source-type-pill.livre {
  background: rgba(16, 185, 129, 0.18); color: #34d399; border-color: rgba(16, 185, 129, 0.35);
}
[data-theme="dark"] .plan-source-type-pill.drive, html.dark .plan-source-type-pill.drive {
  background: rgba(245, 158, 11, 0.18); color: #fbbf24; border-color: rgba(245, 158, 11, 0.35);
}
[data-theme="dark"] .plan-source-type-pill.web, html.dark .plan-source-type-pill.web {
  background: rgba(139, 92, 246, 0.18); color: #a78bfa; border-color: rgba(139, 92, 246, 0.35);
}
[data-theme="dark"] .plan-source-type-pill.qcms, html.dark .plan-source-type-pill.qcms {
  background: rgba(6, 182, 212, 0.18); color: #38bdf8; border-color: rgba(6, 182, 212, 0.35);
}

/* 2 Columns Compact Layout */
.plan-compact-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.plan-compact-card {
  background: var(--plan-card-bg);
  border: 1px solid var(--plan-card-border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}

.plan-compact-card-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--plan-card-border);
  padding-bottom: 4px;
}

/* Prerequisites Compact Items */
.plan-prereq-compact-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  background: var(--plan-subcard-bg);
  border: 1px solid var(--plan-card-border);
  border-radius: 6px;
  margin-bottom: 4px;
}

.plan-prereq-checkbox {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--plan-success);
}

/* Sliders Compact */
.plan-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.plan-slider-row label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  min-width: 140px;
}

.plan-slider-row input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: var(--plan-highlight);
  cursor: pointer;
}

.plan-slider-row span.val-badge {
  font-size: 11px;
  font-weight: 800;
  color: var(--plan-highlight);
  min-width: 45px;
  text-align: right;
}

.plan-btn-group-toggle {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--plan-card-border);
}

.plan-btn-option {
  flex: 1;
  height: 26px;
  background: var(--plan-subcard-bg);
  border: none;
  border-right: 1px solid var(--plan-card-border);
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0 6px;
  white-space: nowrap;
}

.plan-btn-option:last-child {
  border-right: none;
}

.plan-btn-option.selected {
  background: var(--plan-highlight);
  color: #fff;
}

/* Exam Options Compact Row */
.plan-exam-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--plan-subcard-bg);
  border: 1px solid var(--plan-card-border);
  border-radius: 6px;
}

.plan-exam-bar label {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

/* Toast */
.plan-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg2);
  border: 1px solid var(--plan-card-border);
  border-left: 3px solid var(--plan-highlight);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 999999;
  transform: translateY(60px);
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.plan-toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Print */
@media print {
  body * { visibility: hidden; }
  #preliminaryPlanWrap, #preliminaryPlanWrap * { visibility: visible; }
  #preliminaryPlanWrap { position: absolute; left: 0; top: 0; width: 100%; border: none !important; }
  .preliminary-plan-actions, .plan-tabs-bar, .plan-sources-actions-bar { display: none !important; }
  .plan-section-panel { display: block !important; margin-bottom: 15px; }
}

@media (max-width: 900px) {
  .plan-compact-2col { grid-template-columns: 1fr; }
  .plan-source-compact-row { grid-template-columns: 1fr; gap: 4px; padding: 6px; }
}

/* ==========================================================================
   PLAN PRÉLIMINAIRE — MOBILE
   Tout doit tenir dans la largeur de l'écran : aucun défilement horizontal,
   aucun chevauchement, et les espaces libres sont mis à profit.
   ========================================================================== */
@media (max-width: 768px) {
  /* --- 1. En-tête : titre / stats / actions sur des lignes distinctes --- */
  .preliminary-plan-header {
    flex-wrap: wrap !important;
    row-gap: 8px !important;
    column-gap: 8px !important;
    padding: 10px 12px !important;
    align-items: center !important;
  }

  .preliminary-plan-header .group-toggle {
    order: 1;
  }

  .preliminary-plan-title-box {
    order: 2;
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }

  .plan-main-title {
    font-size: 12.5px !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  .plan-main-title > span:first-child {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  .plan-series-tag {
    font-size: 9px !important;
    padding: 2px 6px !important;
    white-space: nowrap !important;
  }

  /* Les pastilles de statistiques passent sur une ligne dédiée (largeur pleine) */
  .preliminary-plan-stats {
    order: 3;
    flex: 1 1 100% !important;
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    margin: 0 !important;
  }

  .plan-stat-pill {
    flex: 1 1 calc(50% - 3px) !important;
    min-width: 0 !important;
    justify-content: center !important;
    font-size: 10.5px !important;
    padding: 5px 8px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
  }

  .preliminary-plan-actions {
    order: 4;
    margin-left: auto !important;
  }

  /* --- 2. Onglets : défilement interne fluide, jamais la page entière --- */
  .plan-tabs-bar {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .plan-tabs-bar::-webkit-scrollbar { display: none; }

  .plan-tab-btn {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    font-size: 11px !important;
    padding: 8px 10px !important;
  }

  /* --- 3. TOTAL GLOBAL : grille 2×2 (au lieu de 3+1) --- */
  .plan-grand-total-banner {
    padding: 10px !important;
  }

  .plan-grand-total-head {
    flex-wrap: wrap !important;
    row-gap: 4px !important;
  }

  .plan-grand-total-label {
    font-size: 11px !important;
    white-space: normal !important;
  }

  .plan-grand-total-grid,
  .plan-grand-total-cards,
  .plan-total-grid,
  .plan-multi-units-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .plan-grand-total-cell,
  .plan-total-cell,
  .plan-unit-card {
    min-width: 0 !important;
    padding: 8px !important;
  }

  .plan-grand-total-cell .plan-stat-value,
  .plan-total-cell .plan-stat-value,
  .plan-unit-card .plan-unit-val {
    font-size: 17px !important;
  }

  .plan-grand-total-cell .plan-stat-label,
  .plan-total-cell .plan-stat-label,
  .plan-unit-card .plan-unit-lbl {
    font-size: 8.5px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* --- 4. Tableau : colonnes ajustées, pas de débordement --- */
  .plan-table-wrapper {
    overflow-x: visible !important;
  }

  .plan-table-wrapper table {
    width: 100% !important;
    table-layout: fixed !important;
    min-width: 0 !important;
  }

  .plan-table-wrapper th,
  .plan-table-wrapper td {
    padding: 8px 6px !important;
    font-size: 10.5px !important;
  }

  .plan-table-wrapper th {
    font-size: 9px !important;
    letter-spacing: 0 !important;
    white-space: normal !important;
    line-height: 1.25 !important;
  }

  .plan-table-wrapper th:first-child,
  .plan-table-wrapper td.col-couche-name {
    width: 32% !important;
    min-width: 0 !important;
  }

  .plan-table-wrapper th:nth-child(2),
  .plan-table-wrapper td:nth-child(2) { width: 22% !important; }
  .plan-table-wrapper th:nth-child(3),
  .plan-table-wrapper td:nth-child(3) { width: 16% !important; }
  .plan-table-wrapper th:nth-child(4),
  .plan-table-wrapper td:nth-child(4) { width: 15% !important; }
  .plan-table-wrapper th:nth-child(5),
  .plan-table-wrapper td:nth-child(5) { width: 15% !important; }

  /* Colonnes secondaires masquées sur téléphone (Heures / Semaines) */
  .plan-table-wrapper th:nth-child(4),
  .plan-table-wrapper td:nth-child(4) { display: none !important; }
  .plan-table-wrapper th:nth-child(6),
  .plan-table-wrapper td:nth-child(6) { display: none !important; }

  .plan-table-wrapper th:nth-child(2) { width: 28% !important; }
  .plan-table-wrapper th:nth-child(3) { width: 20% !important; }
  .plan-table-wrapper th:nth-child(5) { width: 20% !important; }

  .plan-units-badge {
    font-size: 9.5px !important;
    padding: 3px 6px !important;
    white-space: nowrap !important;
  }

  .col-couche-name {
    min-width: 0 !important;
  }

  .plan-input {
    min-width: 0 !important;
    width: 100% !important;
    font-size: 12px !important;
  }

  .plan-row-actions {
    gap: 4px !important;
  }
}

@media (max-width: 420px) {
  .plan-stat-pill {
    flex: 1 1 100% !important;
  }

  .plan-main-title {
    font-size: 11.5px !important;
  }
}
