/* ============================================================
   Impact Matrices Module — Styles
   Layout 2 colonnes, cartes, grille éditable, responsive
   ============================================================ */

/* ---------- Layout 2 colonnes ---------- */
.imx-layout {
  display: flex;
  gap: var(--spacing-lg, 1.5rem);
  align-items: flex-start;
  min-height: 400px;
}

.imx-list-panel {
  width: 320px;
  min-width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm, 0.5rem);
}

.imx-editor-panel {
  flex: 1;
  min-width: 0;
}

/* ---------- Toolbar ---------- */
.imx-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm, 0.5rem);
}

.imx-toolbar__title {
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: 600;
  color: var(--color-text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Cartes matrice (liste) ---------- */
.imx-card {
  background: var(--color-surface, #fff);
  border: 2px solid var(--color-border, #e5e7eb);
  border-radius: var(--border-radius, 0.5rem);
  padding: var(--spacing-md, 1rem);
  cursor: pointer;
  transition: border-color var(--transition-duration, 0.2s) var(--transition-timing, ease), box-shadow var(--transition-duration, 0.2s) var(--transition-timing, ease);
  position: relative;
}

.imx-card:hover {
  border-color: var(--color-primary-light, #93c5fd);
}

.imx-card--selected {
  border-color: var(--color-primary, #3b82f6);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.1));
}

.imx-card__name {
  font-weight: 600;
  font-size: var(--font-size-md, 1rem);
  color: var(--color-text, #111827);
  margin-bottom: var(--spacing-xs, 0.25rem);
  padding-right: 60px;
}

.imx-card__date {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-light, #9ca3af);
}

.imx-card__stats {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-light, #9ca3af);
  margin-top: var(--spacing-xs, 0.25rem);
}

.imx-card__colorbar {
  display: flex;
  height: 4px;
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  margin-top: var(--spacing-sm, 0.5rem);
  gap: 1px;
}

.imx-card__colorbar-seg {
  flex: 1;
  min-width: 0;
}
.imx-card__colorbar-seg[data-severity="1"] { background: #86efac; }
.imx-card__colorbar-seg[data-severity="2"] { background: #fde68a; }
.imx-card__colorbar-seg[data-severity="3"] { background: #fed7aa; }
.imx-card__colorbar-seg[data-severity="4"] { background: #fca5a5; }
.imx-card__colorbar-seg[data-severity="5"] { background: #f87171; }
.imx-card__colorbar-seg[data-severity="6"] { background: #ef4444; }
.imx-card__colorbar-seg[data-severity="7"] { background: #b91c1c; }

.imx-card__actions {
  display: flex;
  gap: var(--spacing-xs, 0.25rem);
  margin-top: var(--spacing-sm, 0.5rem);
}

.imx-card__actions .btn {
  font-size: var(--font-size-xs, 0.75rem);
  padding: var(--spacing-xs) var(--spacing-sm);
}

/* ---------- Badge Active ---------- */
.imx-badge-active {
  display: inline-block;
  background: var(--color-success, #22c55e);
  color: var(--color-surface, #fff);
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--border-radius-full);
  position: absolute;
  top: var(--spacing-md, 1rem);
  right: var(--spacing-md, 1rem);
}

/* ---------- Empty state ---------- */
.imx-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl, 2rem);
  text-align: center;
  color: var(--color-text-light, #9ca3af);
}

.imx-empty i {
  font-size: 2.5rem;
  margin-bottom: var(--spacing-md, 1rem);
  opacity: 0.4;
}

/* ---------- Editor sections ---------- */
.imx-editor-section {
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--border-radius, 0.5rem);
  padding: var(--spacing-lg, 1.5rem);
  margin-bottom: var(--spacing-md, 1rem);
}

.imx-editor-section__title {
  font-size: var(--font-size-md, 1rem);
  font-weight: 600;
  color: var(--color-text, #111827);
  margin-bottom: var(--spacing-md, 1rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.imx-editor-section__title .imx-chevron {
  transition: transform 0.2s ease;
  font-size: var(--font-size-xs);
  color: var(--color-text-light, #9ca3af);
  margin-right: var(--spacing-sm, 0.5rem);
}

.imx-editor-section--collapsed .imx-chevron {
  transform: rotate(-90deg);
}

.imx-editor-section--collapsed .imx-editor-section__title {
  margin-bottom: 0;
}

.imx-editor-section__body {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  max-height: 5000px;
  opacity: 1;
}

.imx-editor-section--collapsed .imx-editor-section__body {
  max-height: 0;
  opacity: 0;
}

/* ---------- Form fields ---------- */
.imx-field {
  margin-bottom: var(--spacing-md, 1rem);
}

.imx-field label {
  display: block;
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: 500;
  color: var(--color-text-secondary, #6b7280);
  margin-bottom: var(--spacing-xs, 0.25rem);
}

.imx-field input,
.imx-field textarea,
.imx-field select {
  width: 100%;
  padding: var(--spacing-sm, 0.5rem);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--border-radius-sm, 0.25rem);
  background: var(--color-surface, #fff);
  color: var(--color-text, #111827);
  font-family: inherit;
  font-size: var(--font-size-sm, 0.875rem);
  box-sizing: border-box;
}

.imx-field textarea {
  resize: vertical;
  min-height: 60px;
}

/* ---------- Levels table ---------- */
.imx-levels-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm, 0.875rem);
}

.imx-levels-table th {
  text-align: left;
  padding: var(--spacing-sm, 0.5rem);
  font-weight: 600;
  color: var(--color-text-secondary, #6b7280);
  border-bottom: 2px solid var(--color-border, #e5e7eb);
  white-space: nowrap;
}

/* Colonne « # » : centrée comme ses cellules */
.imx-levels-table th:first-child {
  text-align: center;
}

.imx-levels-table td {
  padding: var(--spacing-xs, 0.25rem) var(--spacing-sm, 0.5rem);
  vertical-align: top;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
}

.imx-levels-table input,
.imx-levels-table textarea,
.imx-levels-table select {
  width: 100%;
  padding: var(--spacing-xs) var(--spacing-xs);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--border-radius-sm, 0.25rem);
  background: var(--color-surface, #fff);
  color: var(--color-text, #111827);
  font-family: inherit;
  font-size: var(--font-size-xs, 0.75rem);
  box-sizing: border-box;
}

.imx-levels-table textarea {
  resize: vertical;
  min-height: 40px;
}

.imx-levels-table .imx-level-num {
  width: 36px;
  text-align: center;
  font-weight: 700;
  color: var(--color-primary, #3b82f6);
}

.imx-levels-table .imx-col-actions {
  white-space: nowrap;
  width: 80px;
}

.imx-levels-table .imx-col-actions .btn {
  padding: var(--spacing-xs) var(--spacing-xs);
  font-size: var(--font-size-xs);
}

/* ---------- Dimensions list ---------- */
.imx-dim-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm, 0.5rem);
}

.imx-dim-chip {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  background: var(--color-surface-secondary, #f3f4f6);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--border-radius, 0.5rem);
  padding: var(--spacing-xs) 10px;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text, #111827);
  cursor: default;
}

.imx-dim-chip input {
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
  min-width: 100px;
  width: auto;
}

.imx-dim-chip .imx-dim-remove {
  cursor: pointer;
  color: var(--color-text-light, #9ca3af);
  font-size: var(--font-size-xs);
  padding: var(--spacing-xs);
}

.imx-dim-chip .imx-dim-remove:hover {
  color: var(--color-danger, #ef4444);
}

/* ---------- Impact grid (dimension x level) ---------- */
.imx-grid-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.imx-grid {
  border-collapse: collapse;
  width: 100%;
  min-width: 600px;
  font-size: var(--font-size-sm, 0.875rem);
}

.imx-grid th {
  position: sticky;
  top: 0;
  background: var(--color-surface-secondary, #f3f4f6);
  padding: var(--spacing-sm, 0.5rem);
  font-weight: 600;
  color: var(--color-text-secondary, #6b7280);
  border: 1px solid var(--color-border, #e5e7eb);
  white-space: nowrap;
  font-size: var(--font-size-xs, 0.75rem);
  z-index: 1;
}

.imx-grid th.imx-grid__dim-header {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 140px;
}

.imx-grid td {
  padding: var(--spacing-xs, 0.25rem) var(--spacing-sm, 0.5rem);
  border: 1px solid var(--color-border, #e5e7eb);
  vertical-align: top;
  position: relative;
}

.imx-grid td.imx-grid__dim-label {
  position: sticky;
  left: 0;
  background: var(--color-surface-secondary, #f3f4f6);
  font-weight: 500;
  color: var(--color-text, #111827);
  font-size: var(--font-size-xs, 0.75rem);
  min-width: 140px;
  z-index: 1;
  padding: var(--spacing-sm, 0.5rem);
}

.imx-grid textarea {
  width: 100%;
  min-height: 54px;
  max-height: 54px;
  padding: var(--spacing-xs) var(--spacing-xs);
  border: 1px solid transparent;
  border-radius: var(--border-radius-sm, 0.25rem);
  background: transparent;
  color: var(--color-text, #111827);
  font-family: inherit;
  font-size: var(--font-size-xs, 0.75rem);
  line-height: 1.4;
  resize: none;
  overflow: hidden;
  box-sizing: border-box;
  transition: border-color var(--transition-duration, 0.2s) var(--transition-timing, ease), min-height var(--transition-duration, 0.2s) var(--transition-timing, ease), max-height var(--transition-duration, 0.2s) var(--transition-timing, ease);
}

.imx-grid textarea:focus {
  border-color: var(--color-primary, #3b82f6);
  background: var(--color-surface, #fff);
  outline: none;
  min-height: 120px;
  max-height: 400px;
  overflow-y: auto;
  resize: vertical;
}

/* ---------- Aggregation selector ---------- */
.imx-aggregation {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm, 0.5rem);
  flex-wrap: wrap;
}

.imx-aggregation label {
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: 500;
  color: var(--color-text-secondary, #6b7280);
}

.imx-aggregation select {
  padding: var(--spacing-xs) var(--spacing-sm);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--border-radius-sm, 0.25rem);
  background: var(--color-surface, #fff);
  color: var(--color-text, #111827);
  font-family: inherit;
  font-size: var(--font-size-sm, 0.875rem);
}

/* ---------- Severity column coloring (grid) ---------- */
.imx-grid th[data-severity="1"] { background: #86efac; color: #14532d; border-color: #22c55e; }
.imx-grid th[data-severity="2"] { background: #fde68a; color: #713f12; border-color: #eab308; }
.imx-grid th[data-severity="3"] { background: #fed7aa; color: #7c2d12; border-color: #f97316; }
.imx-grid th[data-severity="4"] { background: #fca5a5; color: #7f1d1d; border-color: #ef4444; }
.imx-grid th[data-severity="5"] { background: #f87171; color: #fff;    border-color: #dc2626; }
.imx-grid th[data-severity="6"] { background: #ef4444; color: #fff;    border-color: #b91c1c; }
.imx-grid th[data-severity="7"] { background: #b91c1c; color: #fff;    border-color: #7f1d1d; }

.imx-grid td[data-severity="1"] { background: rgba(134, 239, 172, 0.12); }
.imx-grid td[data-severity="2"] { background: rgba(253, 230, 138, 0.15); }
.imx-grid td[data-severity="3"] { background: rgba(254, 215, 170, 0.18); }
.imx-grid td[data-severity="4"] { background: rgba(252, 165, 165, 0.18); }
.imx-grid td[data-severity="5"] { background: rgba(248, 113, 113, 0.18); }
.imx-grid td[data-severity="6"] { background: rgba(239, 68, 68, 0.18); }
.imx-grid td[data-severity="7"] { background: rgba(185, 28, 28, 0.18); }

.imx-grid td[data-severity="1"]:focus-within { background: rgba(134, 239, 172, 0.25); }
.imx-grid td[data-severity="2"]:focus-within { background: rgba(253, 230, 138, 0.28); }
.imx-grid td[data-severity="3"]:focus-within { background: rgba(254, 215, 170, 0.30); }
.imx-grid td[data-severity="4"]:focus-within { background: rgba(252, 165, 165, 0.30); }
.imx-grid td[data-severity="5"]:focus-within { background: rgba(248, 113, 113, 0.30); }
.imx-grid td[data-severity="6"]:focus-within { background: rgba(239, 68, 68, 0.30); }
.imx-grid td[data-severity="7"]:focus-within { background: rgba(185, 28, 28, 0.30); }

/* ---------- Severity dot in levels table ---------- */
.imx-level-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: var(--border-radius-full);
  margin-right: var(--spacing-xs);
  vertical-align: middle;
}
.imx-level-dot[data-severity="1"] { background: #22c55e; }
.imx-level-dot[data-severity="2"] { background: #eab308; }
.imx-level-dot[data-severity="3"] { background: #f97316; }
.imx-level-dot[data-severity="4"] { background: #ef4444; }
.imx-level-dot[data-severity="5"] { background: #dc2626; }
.imx-level-dot[data-severity="6"] { background: #b91c1c; }
.imx-level-dot[data-severity="7"] { background: #7f1d1d; }

.imx-levels-table tr[data-severity="1"] { background: rgba(134, 239, 172, 0.06); }
.imx-levels-table tr[data-severity="2"] { background: rgba(253, 230, 138, 0.08); }
.imx-levels-table tr[data-severity="3"] { background: rgba(254, 215, 170, 0.08); }
.imx-levels-table tr[data-severity="4"] { background: rgba(252, 165, 165, 0.08); }
.imx-levels-table tr[data-severity="5"] { background: rgba(248, 113, 113, 0.08); }
.imx-levels-table tr[data-severity="6"] { background: rgba(239, 68, 68, 0.08); }
.imx-levels-table tr[data-severity="7"] { background: rgba(185, 28, 28, 0.08); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .imx-layout {
    flex-direction: column;
  }

  .imx-list-panel {
    width: 100%;
    min-width: 0;
  }

  .imx-grid {
    min-width: 500px;
  }
}
