:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1f2933;
  background: #f0f2f5;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body {
  min-width: 320px;
  height: 100vh;
  margin: 0;
  padding: 25px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  background: #f0f2f5;
  font-size: 20px;
}
button, input, select { font: inherit; }
a { color: inherit; }

.app-wrapper {
  display: flex;
  gap: 25px;
  width: 100%;
  height: 100%;
  max-width: 1800px;
}

.sidebar,
.main {
  background: #fff;
  border-radius: 15px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, .08);
}

.sidebar {
  flex: 0 0 450px;
  width: 450px;
  padding: 25px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
}

.main {
  min-width: 0;
  flex: 1 1 auto;
  padding: 25px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

h2,
.sidebar > h1 {
  margin: 0 0 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid #eee;
  color: #1a1a1a;
  font-size: 1.25rem;
}

form { margin: 0; }
fieldset { margin: 0; padding: 0; border: 0; }
legend {
  width: 100%;
  margin: 0 0 10px;
  padding: 0;
  color: #444;
  font-size: .95rem;
  font-weight: 600;
}
.form-row { display: flex; gap: 12px; margin-bottom: 12px; }
label { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; color: #666; font-size: .8rem; font-weight: 600; }
input[type="number"], select {
  width: 100%;
  min-height: 48px;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  outline: none;
  color: #222;
  background: #fff;
  font-size: 1rem;
}
input:focus, select:focus { border-color: #0d6efd; box-shadow: 0 0 0 3px rgba(13, 110, 253, .12); }
input:invalid { border-color: #dc735d; }
.divider { margin: 20px 0; border: 0; border-top: 1px solid #eee; }

.sidebar-bottom { margin-top: auto; padding-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.status { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border-radius: 8px; color: #506172; background: #eef6ff; font-size: .7rem; line-height: 1.35; }
.status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #29845c; }
.status.loading .status-dot { animation: pulse 1s infinite; }
.status.error { color: #8d2f20; background: #fff1ed; }
.status.error .status-dot { background: #d84315; }
@keyframes pulse { 50% { opacity: .25; } }

.instructions { color: #888; font-size: .75rem; line-height: 1.4; }
.instructions summary { min-height: 38px; padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid #e2e6ea; border-radius: 8px; color: #667085; background: #f8f9fa; cursor: pointer; font-weight: 600; list-style: none; }
.instructions summary::-webkit-details-marker { display: none; }
.instructions summary::after { content: "⌄"; flex: 0 0 auto; color: #89939e; font-size: 1rem; line-height: 1; transition: transform .18s ease; }
.instructions[open] summary::after { transform: rotate(180deg); }
.instructions[open] summary { border-radius: 8px 8px 0 0; }
.instructions-content { padding: 10px 10px 2px; border: 1px solid #e2e6ea; border-top: 0; border-radius: 0 0 8px 8px; }
.instructions p { margin: 0 0 10px; }
.instructions p:last-child { margin-bottom: 0; }
.instructions strong { color: #666; }

.promo-block { padding: 18px; border: 1px solid #ffe0b2; border-radius: 10px; color: #5d4037; background: #fff4e5; font-size: .85rem; }
.promo-block strong { display: block; margin-bottom: 6px; color: #d84315; font-size: .95rem; }
.promo-block a { min-height: 44px; margin-top: 15px; padding: 10px 14px; display: flex; align-items: center; justify-content: center; border-radius: 8px; color: #fff; background: #d84315; text-decoration: none; font-size: .9rem; font-weight: 600; }
.promo-block a:hover { background: #bf360c; }
.donate-btn { min-height: 44px; padding: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #e2c7bd; border-radius: 8px; color: #7b3924; background: transparent; text-decoration: none; font-size: .85rem; font-weight: 600; }
.donate-btn span { color: #d84315; font-size: 1.1rem; }
.donate-btn:hover { border-color: #d84315; color: #4e2b20; background: #fff8f5; }

.canvas-container {
  min-height: 0;
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
canvas { width: 100%; height: 100%; min-width: 0; min-height: 0; display: block; background: #fff; object-fit: contain; }
.empty-state { position: absolute; padding: 20px; color: #667085; background: rgba(255,255,255,.92); text-align: center; }

.legend {
  position: absolute;
  z-index: 10;
  top: 15px;
  left: 15px;
  min-width: 290px;
  padding: 12px 15px;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  color: #333;
  background: rgba(255,255,255,.95);
  font-size: .8rem;
  pointer-events: none;
}
.legend-item { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; font-weight: 500; white-space: nowrap; }
.legend-item:last-child { margin-bottom: 0; }
.legend-sample { flex: 0 0 30px; width: 30px; display: block; }
.legend-sample.wood { height: 6px; border: 1px solid #333; background: #c19a6b; }
.legend-sample.niche { height: 0; border-top: 2px dashed #aaa; }
.legend-sample.rack { height: 2px; background: #26352e; }
.legend-sample.remainder { height: 0; border-top: 2px dashed #d32f2f; }

.detailing-container {
  flex: 0 0 23vh;
  height: 23vh;
  min-height: 190px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px solid #eee;
  display: flex;
  flex-direction: column;
}
.detailing-header { flex: 0 0 auto; padding-bottom: 12px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.detailing-header h2 { margin: 0; padding: 0; border: 0; }
.fact-cell { padding: 8px 16px; border-radius: 8px; color: #004481; background: #e8f4fd; font-size: 1rem; font-weight: 500; white-space: nowrap; }
.fact-cell b, .fact-cell span { font: inherit; font-weight: 700; }
.detailing-actions { justify-self: end; display: flex; align-items: center; gap: 12px; }
.parts-summary { display: none; }
#printButton { min-height: 44px; padding: 10px 20px; border: 0; border-radius: 8px; color: #fff; background: #0d6efd; cursor: pointer; font-size: .95rem; font-weight: 600; }
#printButton:hover { background: #0b5ed7; }
.table-wrapper { min-height: 0; flex: 1 1 auto; overflow: auto; border: 1px solid #ddd; border-radius: 8px 8px 0 0; }
table { width: 100%; margin: 0; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 10px; border: 1px solid #ddd; text-align: left; white-space: nowrap; }
th { position: sticky; z-index: 1; top: 0; color: #444; background: #f8f9fa; box-shadow: 0 1px 0 #ddd; }
.exact { color: #888; font-size: .85em; white-space: nowrap; }

@media (max-width: 1000px) {
  body { height: auto; min-height: 100vh; padding: 12px; overflow: auto; }
  .app-wrapper { max-width: 780px; height: auto; flex-direction: column; gap: 12px; }
  .sidebar { width: 100%; flex-basis: auto; overflow: visible; }
  .main { min-height: 900px; overflow: visible; }
  .canvas-container { flex: 0 0 640px; height: 640px; }
  .detailing-container { flex-basis: auto; height: auto; min-height: 280px; }
}

@media (max-width: 560px) {
  body { padding: 8px; font-size: 18px; }
  .sidebar, .main { padding: 16px; border-radius: 11px; }
  .form-row { flex-direction: column; }
  .canvas-container { flex-basis: 500px; height: 500px; }
  .legend { top: 8px; left: 8px; min-width: 0; max-width: calc(100% - 16px); padding: 9px 10px; font-size: .72rem; }
  .legend-item { gap: 7px; white-space: normal; }
  .detailing-header { grid-template-columns: 1fr auto; }
  .detailing-header h2 { grid-column: 1 / -1; }
  .detailing-actions { justify-self: end; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body { height: auto; padding: 0; overflow: visible; display: block; color: #000; background: #fff; font-size: 12pt; }
  .app-wrapper { max-width: none; height: auto; display: block; }
  .sidebar { display: none !important; }
  .main { padding: 0; display: block; overflow: visible; border-radius: 0; box-shadow: none; }
  .canvas-container { width: 100%; height: 145mm; min-height: 145mm; page-break-inside: avoid; }
  canvas { width: 100%; height: 145mm; }
  .legend { top: 0; left: 0; min-width: 0; padding: 5px 7px; border: 1px solid #000; box-shadow: none; font-size: 7pt; print-color-adjust: exact; }
  .legend-item { gap: 5px; margin-bottom: 3px; }
  .legend-sample { flex-basis: 18px; width: 18px; }
  .detailing-container { height: auto; min-height: 0; margin-top: 6mm; padding-top: 5mm; display: block; border-top: 1px solid #000; page-break-inside: avoid; }
  .detailing-header { grid-template-columns: 1fr auto; padding-bottom: 3mm; }
  .detailing-actions { display: none; }
  .fact-cell { border: 1px solid #777; color: #000; background: #fff; print-color-adjust: exact; }
  .table-wrapper { overflow: visible; border: 0; border-radius: 0; }
  table { border: 2px solid #000; border-collapse: collapse; font-size: 10pt; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  th, td { position: static; padding: 6px; border: 1px solid #000 !important; color: #000; }
  th { background: #eee !important; box-shadow: none; print-color-adjust: exact; }
}
