/* --- Variables --- */
:root{
  --bg: #f7f7f7;
  --card: #fff;
  --border: #e7e7e7;
  --border-2: #ddd;
  --text: #111;
  --muted: #555;
  --danger: #b00;
  --focus: rgba(0, 120, 212, 0.35);
}

body {
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  max-width: 980px;
  margin: 2rem auto;
  padding: 0 1rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.card {
  margin-top: 1.2rem;
  padding: 1rem;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
@media (max-width: 480px) {
  .card { padding: 0.75rem; }
  body { padding: 0 0.75rem; }
}

h1 { margin: 0 0 0.5rem 0; font-size: 1.6rem; }
h2 { margin: 1rem 0 0.8rem 0; font-size: 1.15rem; }

/* Titre de section avec infobulle à droite */
.section-title {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.section-title .info-tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border-2);
  border-radius: 50%;
  cursor: help;
  flex-shrink: 0;
}
.section-title .info-tooltip:hover {
  color: #333;
  border-color: #999;
  background: #f5f5f5;
}

label { display: block; margin-top: 0.8rem; font-weight: 600; }

input, textarea, select {
  margin-top: 0.25rem;
  padding: 0.5rem 0.65rem;
  font-size: 1rem;
  line-height: 1.4;
  min-height: 2.75rem;
  width: 100%;
  max-width: 520px;
  box-sizing: border-box;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
}
input, select { height: 2.75rem; }
textarea {
  height: auto;
  min-height: 3.2rem;
  resize: vertical;
  padding: 0.5rem 0.65rem;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23555' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}
input:hover, textarea:hover, select:hover { border-color: #c7c7c7; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #6aa7e8;
  box-shadow: 0 0 0 4px var(--focus);
}
input[required]:invalid { border-color: #d6a3a3; }

button {
  padding: 0.6rem 1.05rem;
  border: 1px solid #cfcfcf;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 650;
}
button:hover { background:#f1f1f1; }
button:focus{ outline:none; box-shadow: 0 0 0 4px var(--focus); }

/* Primary action: compute */
#computeBtn{
  border-color: #6aa7e8;
  background: #eaf3ff;
}
#computeBtn:hover{ background:#dbeaff; }

.btnrow {
  display:flex;
  gap:0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.btn-icon {
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.4rem;
  line-height: 1;
}
.btn-icon svg {
  vertical-align: middle;
}

.error {
  color: var(--danger);
  margin-top: 0.8rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  background: #fff3f3;
  border: 1px solid #f0c0c0;
}
.error:empty {
  display: none;
}

.hint { color: var(--muted); font-size: 0.92rem; margin: 0.35rem 0 0; }
ul.hint{
  padding-left: 1.1rem;
  margin: 0.35rem 0 0;
}
ul.hint li{ margin: 0.2rem 0; }

.row-check{
  display:flex;
  align-items:center;
  gap:0.5rem;
  margin-top:0.7rem;
}

.row-2{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  align-items: end;
  margin-top: 0.2rem;
}
.row-2 > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.row-2 label { margin-top: 0; }
.row-2 input,
.row-2 select {
  max-width: none;
}
@media (max-width: 640px){
  .row-2 { grid-template-columns: 1fr; }
}

.row-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.8rem;
  align-items: end;
  margin-top: 0.2rem;
}
.row-4 > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.row-4 label { margin-top: 0; }
.row-4 input,
.row-4 select {
  max-width: none;
}
@media (max-width: 720px) {
  .row-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 420px) {
  .row-4 { grid-template-columns: 1fr; }
}

.inline-label{
  display:inline;
  font-weight:600;
  margin:0;
}

.group{
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 0.9rem 0.95rem;
  margin-top: 0.9rem;
  background: #fcfcfc;
}
.group legend{
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0 0.4rem;
}

.advanced{
  margin-top: 0.8rem;
  padding-top: 0.2rem;
}
.advanced > summary{
  cursor: pointer;
  font-weight: 700;
  color: #333;
  list-style: none;
}
.advanced > summary::-webkit-details-marker{ display:none; }
.advanced > summary:before{
  content: "▸";
  display:inline-block;
  margin-right: 0.35rem;
  transform: translateY(-1px);
}
details[open].advanced > summary:before{ content: "▾"; }

.tag {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 0.8rem;
  background:#fafafa;
  margin-left: 0.25rem;
}
.tag-ok { border-color:#3a9b4b; color:#2f7b3b; background:#e7f7ea; }
.tag-warn { border-color:#b37a00; color:#8a5f00; background:#fff4d7; }

table {
  border-collapse: collapse;
  margin-top: 0.8rem;
  width: 100%;
  max-width: 700px;
}
th, td {
  border: 1px solid #ddd;
  padding: 0.35rem 0.5rem;
  text-align: right;
}
th { background:#f0f0f0; }

/* --- 1D bar --- */
.visual-wrapper { margin-top: 1rem; }
.visual-bar {
  display:flex;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #ddd;
  background:#fdfdfd;
}
.module-block {
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 0.75rem;
  white-space: nowrap;
  padding: 0 4px;
  border-right: 1px solid rgba(255,255,255,0.7);
  box-sizing: border-box;
}
.module-block:last-child { border-right: none; }

.module-color-0 { background:#dfe9ff; }
.module-color-1 { background:#ffe4d9; }
.module-color-2 { background:#e6f7e8; }
.module-color-3 { background:#fff7cc; }
.module-color-4 { background:#f3e5ff; }
.module-color-5 { background:#ffebf2; }
.module-color-6 { background:#e0f0f5; }

.visual-caption { margin-top:0.35rem; color:#555; font-size:0.85rem; }

/* --- Scale --- */
.scale-wrapper { margin-top: 1rem; }
.scale-title { font-size:0.9rem; color:#555; margin-bottom:0.3rem; }
.scale-bar {
  position: relative;
  display:flex;
  width:100%;
  height: 28px;
  border: 1px solid #ddd;
  background:#fafafa;
  border-radius: 6px;
  overflow:hidden;
}
.scale-origin {
  position:absolute;
  bottom:-1.1rem;
  left:0;
  font-size:0.7rem;
  color:#555;
}
.scale-segment {
  flex-grow: 1;
  border-right: 1px dashed #ccc;
  position:relative;
}
.scale-segment:last-child { border-right:none; }
.scale-tick {
  position:absolute;
  top:0; left:0;
  border-left: 1px solid #999;
  height:50%;
}
.scale-label {
  position:absolute;
  bottom:-1.1rem;
  right:2px;
  font-size:0.7rem;
  color:#555;
  transform: translateX(50%);
}

/* --- 2D view --- */
.view2d-wrapper { margin-top: 1.2rem; }
.view2d-title { font-size:0.9rem; color:#555; margin-bottom:0.3rem; }
.view2d-container {
  position: relative;
  border: 1px solid #ccc;
  border-radius: 8px;
  background:#fdfdfd;
  overflow:hidden;
  max-width: 650px;
}
.view2d-module {
  position:absolute;
  top:0; bottom:0;
  border-right: 1px solid rgba(255,255,255,0.7);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:0.75rem;
  white-space: nowrap;
  padding:0 4px;
  box-sizing:border-box;
}
.view2d-border {
  position:absolute; inset:0;
  border: 2px solid rgba(0,0,0,0.25);
  pointer-events:none;
}
.view2d-caption { margin-top:0.35rem; color:#555; font-size:0.8rem; }

/* --- Exploded view --- */
.exploded-wrapper {
  margin-top: 1.4rem;
  padding-top: 0.6rem;
  border-top: 1px dashed #ccc;
}
.exploded-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.exploded-row { margin-bottom: 0.8rem; }
.exploded-row-header { font-size: 0.82rem; color:#555; margin-bottom: 0.2rem; }
.exploded-row-bar {
  display:flex;
  height: 40px;
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow:hidden;
  background:#fafafa;
}
.exploded-module {
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 0.7rem;
  white-space: nowrap;
  padding: 0 4px;
  border-right: 1px solid rgba(255,255,255,0.7);
}
.exploded-module:last-child { border-right:none; }

.projects {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.6rem;
}
.project-item {
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 0.6rem;
  background:#fcfcfc;
}
.project-item .title { font-weight: 700; }
.project-item .meta {
  font-size: 0.85rem;
  color:#555;
  margin-top: 0.15rem;
}
.project-item .actions {
  margin-top: 0.5rem;
  display:flex;
  gap:0.5rem;
  flex-wrap: wrap;
}

.table-wrap{ overflow:auto; -webkit-overflow-scrolling: touch; }

/* --- Pièces à débiter --- */
.pieces-container { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }

.piece-row {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) 150px 150px 150px 85px 40px;
  gap: 0.6rem;
  align-items: stretch;
  min-height: 2.75rem;
}
.piece-row-header {
  font-weight: 700;
  font-size: 0.8rem;
  color: #555;
  align-items: center;
  min-height: auto;
  padding: 0.25rem 0;
}
.piece-row-header .piece-preview { font-weight: 700; }

@media (max-width: 768px) {
  .piece-row-header {
    grid-template-columns: 1fr 1fr 56px 64px 40px;
    grid-template-rows: auto;
  }
  .piece-row-header .piece-name { grid-column: 1; }
  .piece-row-header .piece-qty { grid-column: 2; }
  .piece-row-header .piece-length { grid-column: 1; grid-row: 2; }
  .piece-row-header .piece-width { grid-column: 2; grid-row: 2; }
  .piece-row-header .piece-preview { grid-column: 3; grid-row: 1 / span 2; }
  .piece-row-header .piece-actions { grid-column: 4; grid-row: 1 / span 2; }
}
@media (max-width: 480px) {
  .piece-row-header {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
  }
  .piece-row-header .piece-name { grid-column: 1; grid-row: 1; }
  .piece-row-header .piece-qty { grid-column: 2; grid-row: 1; }
  .piece-row-header .piece-length { grid-column: 1; grid-row: 2; }
  .piece-row-header .piece-width { grid-column: 2; grid-row: 2; }
  .piece-row-header .piece-preview { grid-column: 1; grid-row: 3; }
  .piece-row-header .piece-actions { grid-column: 2; grid-row: 3; }
}

.piece-row .piece-name,
.piece-row .piece-length,
.piece-row .piece-width,
.piece-row .piece-qty {
  min-width: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  height: 2.5rem;
  min-height: 2.5rem;
  padding: 0 0.5rem;
  font-size: 0.95rem;
}
.piece-row select.piece-name,
.piece-row select.piece-qty {
  cursor: pointer;
  padding-right: 1.75rem;
}
.piece-row select.piece-qty {
  padding-right: 1.5rem;
}

.piece-preview-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.piece-preview-svg {
  display: block;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fafafa;
  flex-shrink: 0;
  width: 60px;
  height: 44px;
}
.piece-preview-svg .edge { cursor: pointer; }
.piece-preview-svg .edge:hover { stroke-width: 2.5; }

.piece-row .btn-remove-piece {
  padding: 0.25rem 0.4rem;
  font-size: 1.25rem;
  line-height: 1;
  height: 2.5rem;
  align-self: center;
  min-width: 2.5rem;
  border: none;
  color: #b00;
}

@media (max-width: 768px) {
  .piece-row {
    grid-template-columns: 1fr 1fr 56px 64px 40px;
    grid-template-rows: auto auto;
    gap: 0.5rem;
  }
  .piece-row .piece-name { grid-column: 1; grid-row: 1; }
  .piece-row .piece-qty { grid-column: 2; grid-row: 1; }
  .piece-row .piece-length { grid-column: 1; grid-row: 2; }
  .piece-row .piece-width { grid-column: 2; grid-row: 2; }
  .piece-row .piece-preview-wrap { grid-column: 3; grid-row: 1 / span 2; align-self: center; }
  .piece-row .btn-remove-piece { grid-column: 4; grid-row: 1 / span 2; align-self: center; }
}

@media (max-width: 480px) {
  .piece-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
  }
  .piece-row .piece-name { grid-column: 1; grid-row: 1; }
  .piece-row .piece-qty { grid-column: 2; grid-row: 1; }
  .piece-row .piece-length { grid-column: 1; grid-row: 2; }
  .piece-row .piece-width { grid-column: 2; grid-row: 2; }
  .piece-row .piece-preview-wrap { grid-column: 1 / -1; grid-row: 3; justify-content: flex-start; }
  .piece-row .btn-remove-piece { grid-column: 2; grid-row: 3; justify-self: end; }
}

/* Liste de débit : occurences multiples en gras */
.cut-list-table .cut-list-multi { font-weight: 700; font-size: 1.05em; }
.cut-list-table .cut-list-multi td { background: #f0f4ff; }

/* Calpinage 2D */
.calpinage-panel-title { font-size: 0.9rem; color: #555; margin-bottom: 0.35rem; }
.calpinage-svg { display: block; background: #fafafa; }
