/* Board Beaver optimizer — the /optimizer app: input tables + settings + the
   rendered cut layouts + print. Self-contained; pairs with theme.css. All
   same-origin to satisfy the strict CSP (style-src 'self'). */

.opt-app {
  max-width: var(--maxw);
  margin: 1.4rem auto;
  padding: 0 clamp(1rem, 4vw, 1.5rem) 3rem;
}
.opt-intro { color: var(--muted); max-width: 60ch; margin: 0.2rem 0 1.4rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem clamp(1rem, 3vw, 1.4rem) 1.3rem;
  margin-bottom: 1.3rem;
}
.panel h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin: 0 0 0.8rem; }

/* settings row */
.settings { display: flex; flex-wrap: wrap; gap: 0.9rem 1.2rem; align-items: end; }
.field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8rem; font-weight: 600; color: var(--text); }
.field input[type="number"], .field select {
  font: inherit; font-size: 0.9rem; color: var(--text);
  padding: 0.42rem 0.55rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); width: 7rem;
}
.field.check { flex-direction: row; align-items: center; gap: 0.45rem; }
.field.check input { width: auto; accent-color: var(--brand); }
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }

/* input tables (stock / parts) */
.table-wrap { overflow-x: auto; }
table.io { width: 100%; border-collapse: collapse; min-width: 460px; }
table.io th {
  text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 700; padding: 0 0.4rem 0.45rem; border-bottom: 1px solid var(--border);
}
table.io td { padding: 0.3rem 0.4rem; }
table.io input[type="text"], table.io input[type="number"] {
  font: inherit; font-size: 0.9rem; color: var(--text); width: 100%; min-width: 4.5rem;
  padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
table.io input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
table.io input[type="checkbox"] { width: auto; accent-color: var(--brand); }
.col-num input { text-align: right; }
.row-del {
  border: none; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1;
  cursor: pointer; padding: 0.2rem 0.35rem; border-radius: 6px;
}
.row-del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

.row-add {
  margin-top: 0.7rem; border: 1px dashed color-mix(in srgb, var(--brand) 45%, var(--border));
  background: none; color: var(--brand-ink); font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 0.45rem 0.9rem; border-radius: var(--radius-sm); cursor: pointer;
}
.row-add:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }
@media (prefers-color-scheme: dark) { .row-add { color: var(--brand); } }

.run-row { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; margin-top: 0.4rem; }
.run-note { margin: 0; color: var(--muted); font-size: 0.85rem; }

/* results */
.results { margin-top: 0.4rem; }
.results:empty { display: none; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.8rem; margin-bottom: 1.2rem; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.7rem 0.9rem; }
.stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat .v { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.stat .v small { font-size: 0.85rem; font-weight: 600; color: var(--muted); }

.notice { border-radius: var(--radius-sm); padding: 0.7rem 0.9rem; margin-bottom: 1.1rem; font-size: 0.9rem; }
.notice.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-ink); }

.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.1rem; }
.sheet-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.8rem; background: var(--surface); }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.5rem; }
.sheet-head .t { font-weight: 700; font-size: 0.9rem; }
.sheet-head .w { font-size: 0.78rem; color: var(--muted); }
.sheet-card svg { width: 100%; height: auto; display: block; background: var(--surface-2); border-radius: 6px; }

.bb-sheet { fill: var(--surface-2); stroke: var(--border); stroke-width: 1; }
.bb-part { stroke: var(--surface); stroke-width: 1.5; }
.bb-plabel { font: 600 11px var(--font); fill: #0b1220; }
.bb-pdim { font: 500 9px var(--font); fill: #0b1220; opacity: 0.75; }
.bb-seq { fill: var(--brand-ink); opacity: 0.92; }
.bb-seqn { font: 700 10px var(--font); fill: #ffffff; }

/* cut list */
.cutlist { width: 100%; border-collapse: collapse; margin-top: 1.4rem; }
.cutlist th, .cutlist td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.cutlist th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.cutlist .num { text-align: right; white-space: nowrap; }
.swatch { display: inline-block; width: 0.85rem; height: 0.85rem; border-radius: 3px; vertical-align: -1px; margin-right: 0.45rem; }

.action-btn {
  display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.6rem 0.95rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: transform 0.08s, border-color 0.15s, box-shadow 0.15s;
}
.action-btn:hover { border-color: var(--brand); box-shadow: 0 2px 8px color-mix(in srgb, var(--brand) 14%, transparent); transform: translateY(-1px); }

@media print {
  .site-header, .site-footer, .panel.inputs, .run-row, .ad-slot, .action-btn, .opt-intro { display: none !important; }
  .opt-app { margin: 0; padding: 0; max-width: none; }
  .sheet-grid { grid-template-columns: repeat(2, 1fr); }
  .panel { border: none; box-shadow: none; padding: 0; }
}
