:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --card: #fffdf8;
  --ink: #2b2620;
  --muted: #756b61;
  --line: rgba(43, 38, 32, 0.14);
  --accent: #8b5e34;
  --accent-dark: #65411f;
  --app-max-width: 1180px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #fff9ef 0, var(--bg) 42%, #ece6dc 100%);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.cover-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  width: min(var(--app-max-width), calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 22px 18px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3.5vw, 3.1rem);
  letter-spacing: -0.04em;
}

.intro { margin: 8px 0 0; color: var(--muted); }

.header-actions a {
  display: inline-flex;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255,255,255,.55);
  text-decoration: none;
  font-weight: 650;
}

.cover-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  width: min(var(--app-max-width), calc(100% - 28px));
  margin: 0 auto;
  padding: 0 22px 36px;
}

.viewer-card, .cover-panel {
  background: rgba(255, 253, 248, 0.86);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(72, 55, 35, 0.08);
}

.viewer-card {
  overflow: hidden;
  min-height: 0;
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

label { font-weight: 650; color: var(--muted); font-size: .9rem; }
select, input[type="number"], input[type="text"], button, .import-label {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffaf2;
  color: var(--ink);
  padding: 9px 11px;
  font: inherit;
}
select, input[type="number"] { margin-left: 8px; }
input[type="number"] { width: 96px; }
button, .import-label { cursor: pointer; font-weight: 700; }
button:hover, .import-label:hover { border-color: rgba(139,94,52,.45); }
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.primary:hover { background: var(--accent-dark); }
.checkbox-line { display: inline-flex; align-items: center; gap: 7px; }
.construction-control {
  display: inline-grid;
  grid-template-columns: auto minmax(150px, 220px) auto;
  gap: 10px;
  align-items: center;
}

.construction-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

#constructionStepLabel {
  min-width: 74px;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.85rem;
}



.protection-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.86);
  color: var(--ink);
  white-space: nowrap;
}

.protection-toggle input {
  accent-color: var(--accent);
}

#coverProtectionState {
  min-width: 34px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(43, 38, 32, 0.08);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.protection-toggle.is-active {
  border-color: rgba(138, 45, 36, 0.34);
  background: #fff6f4;
}

.protection-toggle.is-active #coverProtectionState {
  background: #8a2d24;
  color: #fff;
}

body.cover-protected .apply-actions button,
body.cover-protected #clearBtn,
body.cover-protected #undoBtn,
body.cover-protected #importInput + * {
  opacity: 0.6;
}

.cover-viewer {
  height: 620px;
}
.cover-viewer canvas { display: block; width: 100%; height: 100%; }

.cover-panel { padding: 16px; align-self: start; }
.panel-section + .panel-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.panel-section h2 { margin: 0 0 10px; font-size: 1.05rem; }
.label { margin: 0 0 4px; color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .12em; }
.selected-box strong { font-size: 1.5rem; }
.muted { color: var(--muted); margin: 6px 0 0; }
.material-list { display: grid; gap: 8px; margin-bottom: 12px; }
.material-option {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
}
.material-option.active { outline: 2px solid rgba(139,94,52,.35); background: #fff5e6; }
.swatch { width: 22px; height: 22px; border-radius: 999px; border: 1px solid rgba(0,0,0,.18); }

.opening-roof-window-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #eef9ff !important;
  color: #2f80c8;
  border-color: #7eb6df !important;
  opacity: 1 !important;
  overflow: hidden;
}
.opening-roof-window-swatch svg {
  width: 76%;
  height: 76%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.opening-roof-window-swatch .opening-window-pane {
  fill: rgba(47, 128, 200, 0.18);
  stroke-width: 1.35;
}

.opacity-note { color: var(--muted); font-size: .8rem; }
.action-groups { display: grid; gap: 14px; }
.action-group { display: grid; gap: 7px; }
.action-group-title {
  margin: 0;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.button-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.button-grid button,
.button-grid .import-label,
.danger-action {
  min-width: 0;
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1;
}
.action-icon-muted { color: #8f877c; }

.import-label { text-align: center; }
.import-label input { display: none; }
.action-group-danger {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.danger-action {
  width: min(78%, 240px);
  justify-self: center;
  color: #8a2d24;
  background: #fff6f4;
  border-color: #e8bbb3;
}
.danger-action:hover {
  border-color: #c56f63;
  background: #fff0ed;
}
.summary { display: grid; gap: 8px; }
.summary-row { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px dashed var(--line); }
.cover-viewer.labels-hidden .triangle-label {
  display: none !important;
}

.triangle-label {
  pointer-events: none;
  color: #1d1b18;
  background: rgba(255,255,255,.75);
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 800;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}


.custom-color-box {
  margin: 12px 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 250, 242, 0.65);
}

.custom-color-box.active {
  outline: 2px solid rgba(139,94,52,.35);
  background: #fff5e6;
}

.custom-color-box label {
  display: block;
  margin-bottom: 8px;
}

.custom-color-row {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 8px;
  align-items: center;
}

#customColorPicker,
#customColorPicker2 {
  width: 46px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffaf2;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

#customColorPicker::-webkit-color-swatch-wrapper,
#customColorPicker2::-webkit-color-swatch-wrapper {
  padding: 0;
}

#customColorPicker::-webkit-color-swatch,
#customColorPicker2::-webkit-color-swatch {
  border: 1px solid rgba(0,0,0,.15);
  border-radius: 6px;
}

#customColorHex {
  width: 100%;
  text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.custom-color-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

@media (max-width: 980px) {
  .cover-layout { grid-template-columns: 1fr; }
  .cover-panel { order: -1; }
  .viewer-card { min-height: 540px; }
  .cover-viewer { height: 500px; }
}

@media (max-width: 640px) {
  .cover-header { flex-direction: column; }
  .button-grid { grid-template-columns: 1fr; }
}

#customColorHex.invalid {
  border-color: #b42318;
  background: #fff1f0;
}

.apply-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.apply-actions button {
  width: 100%;
}

/* ===== Plan de découpe exact par toile ===== */
.cut-plan-section {
  grid-column: 1 / -1;
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(72, 55, 35, 0.08);
  padding: 18px;
}

.cut-plan-section[hidden] {
  display: none !important;
}

.cut-plan-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.cut-plan-header h2 {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 2vw, 2rem);
  letter-spacing: -0.03em;
}

.cut-plan-params {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(320px, 1.4fr);
  gap: 14px;
  margin-bottom: 16px;
}

.cut-plan-note,
.cut-plan-widths,
.cut-plan-summary,
.cut-plan-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffaf2;
}

.cut-plan-note {
  padding: 12px;
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.cut-plan-note strong {
  color: var(--ink);
}

.cut-plan-widths {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.cut-width-row {
  display: grid;
  grid-template-columns: 20px 1fr 86px;
  align-items: center;
  gap: 8px;
}

.cut-width-row input {
  width: 86px;
  margin-left: 0;
}

.cut-plan-summary {
  overflow: auto;
  margin-bottom: 16px;
}

.cut-plan-summary table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.cut-plan-summary th,
.cut-plan-summary td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.9rem;
}

.cut-plan-summary th {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

.cut-plan-output {
  display: grid;
  gap: 16px;
}

.cut-plan-card {
  padding: 14px;
  overflow: hidden;
}

.cut-plan-card h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.cut-plan-card .muted {
  margin-bottom: 10px;
}

.cut-plan-svg-wrap {
  overflow-x: auto;
  background: #fff4cc;
  border: 1px solid rgba(43,38,32,.22);
}

.cut-plan-svg {
  display: block;
  width: 100%;
  min-width: 900px;
  height: auto;
}

.cut-plan-empty {
  padding: 16px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: #fffaf2;
}

@media (max-width: 780px) {
  .cut-plan-header,
  .cut-plan-params {
    grid-template-columns: 1fr;
    flex-direction: column;
  }
}

.cut-plan-svg-wrap {
  margin-bottom: 32px;
}

.cut-plan-svg-wrap:last-child {
  margin-bottom: 0;
}

.cut-plan-svg {
  height: 230px;
  width: auto;
  max-width: none;
}
.cover-layout {
  grid-template-columns: minmax(760px, 1fr) 320px;
  align-items: start;
}

.cover-panel {
  width: 320px;
}

.viewer-card {
  min-height: calc(100vh - 70px);
}

.cover-viewer {
  height: calc(100vh - 50px);
  min-height: 820px;
}

.viewer-help,
.floor-summary,
.stage-summary,
.triangles-summary {
  transform: scale(0.9);
  transform-origin: top left;
}
/* Table de correspondance triangles / couches / matériaux */
.triangle-reference-section {
  grid-column: 1 / -1;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fffaf2;
  box-shadow: 0 12px 32px rgba(45, 35, 20, 0.08);
}

.triangle-reference-section[hidden] {
  display: none;
}

.triangle-reference-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.triangle-reference-header h2 {
  margin: 0 0 6px;
}

.triangle-reference-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.triangle-reference-summary,
.triangle-reference-layer {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
}

.triangle-reference-summary {
  margin-bottom: 14px;
}

.triangle-reference-note {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.triangle-reference-summary table,
.triangle-reference-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.triangle-reference-summary th,
.triangle-reference-summary td,
.triangle-reference-table th,
.triangle-reference-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.triangle-reference-summary th,
.triangle-reference-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: #fbf5ea;
}


.material-count-cell {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.material-count-swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  flex: 0 0 14px;
  background: var(--swatch-color, #dff7ff);
  border: 1px solid rgba(65, 54, 42, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.material-count-label {
  overflow-wrap: anywhere;
}

.material-count-value {
  white-space: nowrap;
}

.material-count-extra {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.82em;
  color: var(--muted);
}

.triangle-reference-output {
  display: grid;
  gap: 14px;
}

.triangle-reference-layer h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.triangle-reference-table-wrap {
  overflow-x: auto;
}

.triangle-reference-code {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  background: #f2eadb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
}

.triangle-reference-empty {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 760px) {
  .triangle-reference-header {
    display: grid;
  }

  .triangle-reference-actions {
    justify-content: flex-start;
  }
}

/* Outils de conception : le bouton d'étiquettes prend toute la largeur
   pour éviter un demi-bouton isolé et garder une lecture nette du panneau. */
.design-tools-grid .wide-tool-button {
  grid-column: 1 / -1;
  min-height: 52px;
}

@media (max-width: 780px) {
  .design-tools-grid {
    grid-template-columns: 1fr;
  }
}


/* Ajustement boutons outils : icônes et libellés restent dans le bouton */
.design-tools-grid .tool-button,
.button-grid .tool-button {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-inline: 8px;
  overflow: hidden;
}

.design-tools-grid .tool-button .action-icon,
.button-grid .tool-button .action-icon {
  flex: 0 0 auto;
  font-size: 1rem;
  line-height: 1;
}

.design-tools-grid .tool-button .action-label,
.button-grid .tool-button .action-label {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  line-height: 1.1;
}

.design-tools-grid .wide-tool-button {
  grid-column: 1 / -1;
  min-height: 46px;
}


/* Harmonisation largeur + responsive couverture — 2026-06 */
@media (max-width: 980px) {
  .cover-layout {
    grid-template-columns: 1fr;
  }

  .cover-panel {
    width: auto;
    order: -1;
  }

  .viewer-card {
    min-height: 540px;
  }

  .cover-viewer {
    height: 500px;
    min-height: 500px;
  }
}


.design-trace-box,
.design-trace-badge {
  border: 1px solid rgba(139, 94, 52, 0.22);
  border-radius: 18px;
  background: #fffaf2;
  color: #4f3726;
  box-shadow: 0 10px 24px rgba(58, 38, 20, 0.06);
}

.design-trace-box {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(150px, .75fr) minmax(190px, .9fr);
  gap: 10px;
  margin: 12px 0 14px;
  padding: 12px 14px;
  font-size: .88rem;
}

.design-trace-box > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.design-trace-box strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.design-trace-label {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.design-trace-box.is-dirty,
.design-trace-badge.is-stale,
.design-trace-badge.is-warning {
  border-color: rgba(217, 130, 43, .65);
  background: #fff4df;
}

.design-trace-badge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin: 0 0 12px;
  padding: 10px 12px;
  font-size: .86rem;
}

.design-trace-badge strong {
  color: var(--accent-dark);
}

.design-trace-badge span,
.design-trace-badge em {
  font-style: normal;
  color: #665f55;
}

.design-trace-stale-warning {
  flex-basis: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(217, 130, 43, .13);
  color: #8a4700;
  font-weight: 800;
}

@media (max-width: 760px) {
  .design-trace-box {
    grid-template-columns: 1fr;
  }
}


.material-label-cell .material-count-value {
  display: none;
}

.triangle-reference-table .material-count-cell {
  justify-content: flex-start;
}


.trace-accept-button {
  margin-top: 6px;
  border: 1px solid rgba(142, 92, 42, .32);
  border-radius: 999px;
  padding: 5px 10px;
  background: #fffaf1;
  color: #5f3518;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.trace-accept-button:hover {
  background: #fff2d9;
}

.viewer-display-toggles {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.viewer-display-toggles .checkbox-line {
  margin: 0;
  white-space: nowrap;
}
