:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #181b1e;
  --panel-2: #202428;
  --panel-3: #272c31;
  --line: #343a40;
  --line-strong: #495158;
  --text: #f3f4f4;
  --muted: #9ea6ad;
  --muted-2: #727b83;
  --orange: #f28a2e;
  --orange-bright: #ff9d45;
  --orange-soft: rgba(242, 138, 46, 0.14);
  --blue: #65b8ff;
  --green: #6ed49a;
  --red: #ff7b73;
  --radius: 12px;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.startup-error {
  position: fixed;
  z-index: 200;
  left: 50%;
  top: 14px;
  width: min(620px, calc(100vw - 28px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 123, 115, .6);
  border-left: 4px solid var(--red);
  border-radius: 10px;
  background: #2a2021;
  box-shadow: var(--shadow);
}
.startup-error > div { display: grid; gap: 3px; }
.startup-error strong { font-size: .84rem; }
.startup-error span { color: #d8b9b7; font-size: .72rem; }
.startup-error button { min-height: 34px; flex: 0 0 auto; border: 1px solid #89504d; border-radius: 7px; background: #3a292a; color: #fff; padding: 6px 11px; font-weight: 750; font-size: .74rem; }

button, input, select { font: inherit; }

button, select, input { color: inherit; }

button { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--orange-bright);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: -60px;
  z-index: 100;
  background: var(--orange);
  color: #161616;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 800;
  transition: top 160ms ease;
}

.skip-link:focus { top: 12px; }

.topbar {
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 480px) minmax(360px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 22, 24, 0.97);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  width: 35px;
  height: 35px;
  border: 1px solid #5c646b;
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 6px;
  transform: skewY(-8deg);
  background: linear-gradient(145deg, #343a40, #17191b);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}

.brand-mark span { background: var(--orange); border-radius: 2px; }
.brand-mark span:nth-child(2) { height: 72%; align-self: end; }
.brand-mark span:nth-child(3) { height: 43%; align-self: end; }

.brand-name { font-size: 1.4rem; font-weight: 850; letter-spacing: -0.04em; }
.brand-name span { color: var(--orange); }
.version { font-size: .67rem; color: var(--muted-2); border: 1px solid var(--line); border-radius: 5px; padding: 2px 5px; letter-spacing: .08em; }

.job-title {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.job-title input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: .96rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: normal;
}

.job-title input:hover, .job-title input:focus { background: var(--panel-2); border-color: var(--line); }

.top-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; min-width: 0; }
.save-status { font-size: .76rem; color: var(--muted-2); margin-right: 3px; white-space: nowrap; }

.button {
  border: 1px solid transparent;
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 13px;
  font-weight: 750;
  font-size: .86rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform 130ms ease, border-color 130ms ease, background 130ms ease;
}

.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button.primary { color: #171717; background: var(--orange); border-color: var(--orange); }
.button.primary:hover { background: var(--orange-bright); }
.button.secondary { background: var(--panel-3); border-color: var(--line-strong); color: var(--text); }
.button.secondary:hover, .button.ghost:hover { border-color: #646e76; background: #2a3035; }
.button.ghost { background: transparent; border-color: var(--line); color: #d7dadd; }
.button.wide { width: 100%; }
.button.compact { padding-inline: 11px; }

.menu-wrap { position: relative; }
.popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 210px;
  padding: 7px;
  background: #22262a;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 60;
}

.popover button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 7px;
  padding: 10px;
  color: #e8e9e9;
}

.popover button:hover { background: #30363b; }

.workspace {
  min-height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 355px minmax(460px, 1fr) 330px;
  background: #121416;
}

.setup-panel, .results-panel {
  background: var(--panel);
  min-width: 0;
}

.setup-panel { border-right: 1px solid var(--line); overflow-y: auto; max-height: calc(100vh - 68px); }
.results-panel { border-left: 1px solid var(--line); padding: 20px; overflow-y: auto; max-height: calc(100vh - 68px); }

.panel-section { padding: 20px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-heading > div { display: flex; align-items: center; gap: 10px; }
.section-heading h2 { font-size: .98rem; margin: 0; letter-spacing: -0.01em; }
.step-number {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--orange-soft);
  color: var(--orange-bright);
  border: 1px solid rgba(242, 138, 46, .32);
  font-size: .75rem;
  font-weight: 850;
}

.text-button { border: 0; background: transparent; color: var(--orange-bright); font-size: .8rem; font-weight: 750; padding: 4px; }
.section-count { color: var(--muted); font-size: .78rem; }

.field-grid { display: grid; gap: 9px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.optimisation-fields { margin-top: 10px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field.full { width: 100%; margin-bottom: 12px; }
.field > span, .cost-field > span:first-child { color: var(--muted); font-size: .75rem; font-weight: 700; }
.field small { color: var(--muted-2); font-size: .68rem; font-weight: 600; }

input, select {
  width: 100%;
  min-height: 39px;
  background: #111416;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .88rem;
}

input:hover, select:hover { border-color: var(--line-strong); }
input:focus, select:focus { border-color: var(--orange); }

.cost-field {
  margin-top: 12px;
  min-height: 48px;
  border-radius: 9px;
  background: var(--orange-soft);
  border: 1px solid rgba(242, 138, 46, .26);
  padding: 7px 10px 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.currency-input { display: flex; align-items: center; color: var(--orange-bright); font-weight: 850; }
.currency-input input { width: 86px; min-height: 34px; text-align: right; background: transparent; border: 0; padding: 5px; font-weight: 800; }
.material-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 9px; color: var(--muted-2); font-size: .7rem; }

.drop-zone {
  min-height: 84px;
  border: 1px dashed #555e66;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(255,255,255,.025), rgba(242,138,46,.025));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.drop-zone:hover, .drop-zone.dragging { border-color: var(--orange); background: var(--orange-soft); }
.drop-icon { width: 35px; height: 35px; border-radius: 8px; background: var(--panel-3); display: grid; place-items: center; font-size: 1.25rem; color: var(--orange); }
.drop-zone > span:nth-child(2) { display: grid; gap: 3px; font-size: .82rem; }
.drop-zone small { color: var(--muted); font-size: .72rem; }
.format-pill { border: 1px solid var(--line); color: var(--muted); border-radius: 5px; padding: 3px 5px; font-size: .6rem; font-weight: 800; }
.part-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }

.parts-list { display: grid; gap: 8px; margin-top: 13px; }
.part-card { background: #131619; border: 1px solid var(--line); border-radius: 10px; padding: 11px; display: grid; gap: 10px; }
.part-card:hover { border-color: #465059; }
.part-card-top { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.part-swatch { width: 34px; height: 34px; border-radius: 7px; display: grid; place-items: center; background: color-mix(in srgb, var(--part-color) 18%, #1e2226); border: 1px solid color-mix(in srgb, var(--part-color) 62%, #32383e); color: var(--part-color); font-size: .67rem; font-weight: 900; }
.part-title { min-width: 0; display: grid; gap: 2px; }
.part-title input { min-height: 28px; border-color: transparent; background: transparent; padding: 2px 4px; font-weight: 750; text-overflow: ellipsis; }
.part-title small { color: var(--muted-2); font-size: .67rem; padding-left: 4px; }
.remove-part { background: transparent; color: var(--muted); border: 0; font-size: 1.15rem; width: 30px; height: 30px; border-radius: 6px; }
.remove-part:hover { background: rgba(255, 123, 115, .12); color: var(--red); }
.part-card-bottom { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; }
.part-marking-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 8px; border-top: 1px solid #292e32; }
.part-marking-row > span { min-width: 0; color: var(--muted-2); font-size: .68rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.part-marking-row > span.active { color: #ffd09f; }
.marking-button { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 6px; background: #20252a; color: #e8eaeb; padding: 5px 8px; font-size: .68rem; font-weight: 750; }
.marking-button:hover { border-color: var(--orange); background: var(--orange-soft); }
.part-dimensions { color: #cad0d4; font-size: .76rem; }
.quantity-control { display: flex; align-items: center; gap: 5px; }
.quantity-control span { font-size: .67rem; color: var(--muted); margin-right: 2px; }
.quantity-control button { width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
.quantity-control input { width: 52px; min-height: 28px; height: 28px; padding: 3px; text-align: center; }
.empty-parts { text-align: center; color: var(--muted); display: grid; gap: 5px; padding: 24px 10px 10px; font-size: .77rem; }
.empty-parts strong { color: #d7dbde; font-size: .84rem; }

.forge-button { margin-top: 14px; width: 100%; min-height: 47px; background: linear-gradient(135deg, #f28a2e, #e36c17); border: 1px solid #ffab5f; color: #17130f; font-size: .92rem; justify-content: space-between; padding-inline: 16px; box-shadow: 0 8px 24px rgba(242, 138, 46, .16); }
.forge-button:hover { background: linear-gradient(135deg, #ff9d45, #f27b20); }
.forge-button:disabled { opacity: .72; cursor: wait; transform: none; }
.forge-button.is-working span:last-child { animation: working-pulse 800ms ease-in-out infinite alternate; }
@keyframes working-pulse { to { transform: translateX(5px); opacity: .45; } }

.viewer-panel { min-width: 0; display: grid; grid-template-rows: auto minmax(420px, 1fr) auto; background: #0f1113; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.viewer-head-actions { display: flex; align-items: center; gap: 9px; }
.edit-layout-button { min-height: 34px; padding: 6px 10px; font-size: .74rem; }
.edit-layout-button.active { border-color: var(--orange); background: var(--orange-soft); color: var(--orange-bright); }
.eyebrow { display: block; color: var(--orange); font-size: .66rem; line-height: 1.2; font-weight: 850; letter-spacing: .15em; margin-bottom: 5px; }
.viewer-head h1 { font-size: 1.05rem; margin: 0; letter-spacing: -.02em; }
.view-tabs { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.view-tabs button { border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 7px 11px; font-size: .75rem; font-weight: 750; }
.view-tabs button.active { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }

.viewer-stage {
  min-height: 420px;
  position: relative;
  overflow: hidden;
  background-color: #101315;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 28px 28px;
}

#nest-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
#nest-canvas.is-editing { cursor: default; }
#nest-canvas.is-editing.drag-ready { cursor: grab; }
#nest-canvas.is-editing.dragging-part { cursor: grabbing; }
.canvas-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; padding: 25px; pointer-events: none; }
.canvas-empty h2 { margin: 17px 0 5px; font-size: 1rem; }
.canvas-empty p { margin: 0; max-width: 360px; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.empty-plate { width: 150px; height: 90px; border: 1px solid #4a5259; transform: skewY(-6deg); background: rgba(255,255,255,.02); display: flex; gap: 7px; padding: 14px; box-shadow: 9px 9px 0 rgba(0,0,0,.16); }
.empty-plate span { display: block; width: 28%; border: 1px dashed #4f5961; background: rgba(242,138,46,.055); }

.viewer-controls { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 9px; background: rgba(24,27,30,.92); border: 1px solid var(--line); border-radius: 9px; padding: 4px; backdrop-filter: blur(10px); }
.viewer-controls button { width: 31px; height: 31px; border: 0; border-radius: 6px; background: var(--panel-3); color: var(--text); }
.viewer-controls button:disabled { opacity: .35; cursor: default; }
.viewer-controls span { min-width: 96px; text-align: center; color: #dce0e2; font-size: .74rem; font-weight: 700; }
.interaction-hint { position: absolute; right: 14px; bottom: 17px; color: var(--muted); font-size: .68rem; background: rgba(17,19,21,.84); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }

.layout-toolbar {
  position: absolute;
  z-index: 8;
  left: 14px;
  right: 14px;
  top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 9px 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: rgba(24, 27, 30, .94);
  box-shadow: 0 8px 26px rgba(0,0,0,.26);
  backdrop-filter: blur(12px);
}
.layout-toolbar > span { color: #d8dcde; font-size: .74rem; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout-toolbar > div { display: flex; gap: 5px; }
.layout-toolbar button { border: 1px solid var(--line); border-radius: 6px; background: var(--panel-3); color: var(--text); padding: 6px 8px; font-size: .68rem; font-weight: 700; white-space: nowrap; }
.layout-toolbar button:hover:not(:disabled) { border-color: var(--orange); }
.layout-toolbar button:disabled { opacity: .35; cursor: default; }

.overview-grid { position: absolute; inset: 0; padding: 18px 18px 72px; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; overflow: auto; align-content: start; }
.overview-card { border: 1px solid var(--line); background: rgba(24,27,30,.93); border-radius: 10px; padding: 10px; text-align: left; }
.overview-card:hover, .overview-card.active { border-color: var(--orange); }
.overview-card canvas { width: 100%; aspect-ratio: 1.5; background: #0d0f11; display: block; border-radius: 6px; }
.overview-meta { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: .72rem; }
.overview-meta strong { color: var(--text); }

.plate-strip { min-height: 97px; padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 9px; overflow-x: auto; background: #15181a; }
.plate-thumb { flex: 0 0 116px; border: 1px solid var(--line); background: #101214; border-radius: 8px; padding: 6px; text-align: left; color: var(--muted); }
.plate-thumb.active { border-color: var(--orange); box-shadow: 0 0 0 1px rgba(242,138,46,.25); }
.plate-thumb canvas { width: 100%; height: 55px; display: block; }
.plate-thumb span { font-size: .64rem; display: flex; justify-content: space-between; margin-top: 3px; }

.results-heading { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 17px; }
.result-state { color: var(--muted); font-size: .7rem; border: 1px solid var(--line); border-radius: 999px; padding: 4px 7px; }
.hero-metric { border: 1px solid var(--line); border-radius: 11px; padding: 15px; background: linear-gradient(145deg, #21262a, #181b1e); }
.hero-metric > span { display: block; color: var(--muted); font-size: .76rem; }
.hero-metric strong { display: block; font-size: 2.05rem; margin: 5px 0 10px; letter-spacing: -.055em; }
.meter { height: 5px; border-radius: 999px; background: #0e1012; overflow: hidden; }
.meter span { display: block; width: 0%; height: 100%; background: linear-gradient(90deg, var(--orange), #ffc16f); border-radius: inherit; transition: width 350ms ease; }

.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.metric-card { border: 1px solid var(--line); border-radius: 9px; padding: 11px; background: #15181a; display: grid; gap: 4px; }
.metric-card span { color: var(--muted); font-size: .7rem; }
.metric-card strong { font-size: .96rem; }

.cost-card { margin-top: 10px; border-radius: 10px; border: 1px solid rgba(242,138,46,.28); background: var(--orange-soft); padding: 14px; }
.cost-card > div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.cost-card > div span { font-size: .76rem; color: #d6b28d; }
.cost-card > div strong { font-size: 1.35rem; color: #ffc183; }
.cost-card dl { margin: 13px 0 0; border-top: 1px solid rgba(242,138,46,.2); padding-top: 9px; display: grid; gap: 6px; }
.cost-card dl div { display: flex; justify-content: space-between; font-size: .72rem; }
.cost-card dt { color: var(--muted); }
.cost-card dd { margin: 0; color: #e5e7e8; font-weight: 700; }

.plate-breakdown { margin-top: 22px; }
.subheading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.subheading h2 { margin: 0; font-size: .86rem; }
.subheading span { color: var(--muted); font-size: .68rem; }
.breakdown-list { display: grid; gap: 7px; }
.breakdown-row { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #141719; display: grid; gap: 7px; }
.breakdown-row:hover { border-color: #555f67; }
.breakdown-row-top { display: flex; justify-content: space-between; gap: 8px; font-size: .72rem; }
.breakdown-row-top strong { color: #e8eaeb; }
.breakdown-row-top span { color: var(--muted); }
.mini-meter { height: 3px; background: #0a0c0d; border-radius: 99px; overflow: hidden; }
.mini-meter span { display: block; height: 100%; background: var(--orange); }
.breakdown-empty { border: 1px dashed var(--line); color: var(--muted-2); border-radius: 8px; padding: 18px; text-align: center; font-size: .73rem; }
.warning-card { margin-top: 12px; border: 1px solid rgba(255,123,115,.3); background: rgba(255,123,115,.08); color: #ffaaa5; border-radius: 9px; padding: 11px; display: grid; gap: 4px; font-size: .73rem; }
.production-check { margin-top: 12px; border: 1px solid var(--line); border-radius: 9px; background: #15191c; padding: 11px; display: grid; gap: 9px; }
.production-check-head { display: flex; align-items: flex-start; gap: 9px; }
.production-check-head > span { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--muted); font-size: .72rem; }
.production-check-head > div { display: grid; gap: 3px; min-width: 0; }
.production-check strong { font-size: .76rem; }
.production-check-head div > span { color: var(--muted); font-size: .68rem; line-height: 1.4; }
.production-check[data-state="passed"] { border-color: rgba(110,212,154,.34); background: rgba(110,212,154,.07); }
.production-check[data-state="passed"] .production-check-head > span { color: var(--green); border-color: rgba(110,212,154,.45); }
.production-check[data-state="failed"] { border-color: rgba(255,123,115,.4); background: rgba(255,123,115,.07); }
.production-check[data-state="failed"] .production-check-head > span { color: var(--red); border-color: rgba(255,123,115,.5); }
.production-check details { border-top: 1px solid var(--line); padding-top: 8px; }
.production-check summary { color: #d7dadc; cursor: pointer; font-size: .68rem; font-weight: 750; }
.production-check ul { margin: 7px 0 0; padding-left: 18px; color: var(--muted); font-size: .67rem; line-height: 1.45; }

.dialog {
  width: min(520px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #1d2124;
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}
.dialog::backdrop { background: rgba(0,0,0,.68); backdrop-filter: blur(4px); }
.dialog form { padding: 20px; }
.wide-dialog { width: min(720px, calc(100vw - 28px)); }
.dxf-dialog { width: min(980px, calc(100vw - 28px)); }
.dialog-head { display: flex; justify-content: space-between; align-items: start; gap: 18px; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; font-size: 1.2rem; }
.dialog-head p { color: var(--muted); font-size: .78rem; margin: 7px 0 0; line-height: 1.45; }
.icon-button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 1.2rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-toolbar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.file-button { cursor: pointer; }

.dxf-repair-row { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 11px 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 9px; background: #171a1d; }
.dxf-repair-row > label:first-child { display: flex; align-items: center; gap: 8px; color: #d9dcde; font-size: .78rem; font-weight: 700; }
.dxf-repair-row input[type="checkbox"] { width: 17px; min-height: 17px; accent-color: var(--orange); }
.dxf-repair-row .field { width: 120px; }
.dxf-repair-row .field input { min-height: 34px; }
.dxf-review-list { display: grid; gap: 9px; max-height: min(58vh, 620px); overflow-y: auto; padding-right: 3px; }
.dxf-review-card { display: grid; grid-template-columns: 155px minmax(0, 1fr); border: 1px solid var(--line); border-radius: 10px; background: #15181a; overflow: hidden; }
.dxf-preview { width: 155px; min-height: 150px; background: #0e1113; border-right: 1px solid var(--line); }
.dxf-preview canvas { display: block; width: 100%; height: 100%; min-height: 150px; }
.dxf-review-body { padding: 12px; display: grid; gap: 10px; min-width: 0; }
.dxf-review-fields { display: grid; grid-template-columns: minmax(160px, 1.5fr) minmax(120px, .8fr) 90px auto; align-items: end; gap: 8px; }
.dxf-review-fields input, .dxf-review-fields select { min-height: 35px; }
.dxf-include { min-height: 35px; display: flex; align-items: center; gap: 6px; padding: 0 6px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.dxf-include input { width: 16px; min-height: 16px; accent-color: var(--orange); }
.dxf-stats { display: flex; flex-wrap: wrap; gap: 5px; }
.dxf-stats span { border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; color: var(--muted); font-size: .66rem; }
.dxf-layers { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.dxf-layers > strong { margin-right: 2px; color: var(--muted); font-size: .67rem; }
.dxf-layer-option { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; color: #cbd0d3; background: #111416; font-size: .65rem; }
.dxf-layer-option input { width: 14px; min-height: 14px; margin: 0; accent-color: var(--orange); }
.dxf-warnings { display: grid; gap: 4px; }
.dxf-warning { color: #ffc183; font-size: .7rem; line-height: 1.4; }
.dxf-ok { color: var(--green); font-size: .7rem; }
.dxf-error { border-color: rgba(255,123,115,.42); }
.dxf-error-copy { color: #ffaaa5; font-size: .74rem; line-height: 1.45; }
.marking-dialog { width: min(900px, calc(100vw - 28px)); }
.marking-layout { display: grid; grid-template-columns: minmax(320px, 1.35fr) minmax(250px, .65fr); gap: 16px; }
.marking-preview-wrap { min-height: 360px; display: grid; grid-template-rows: 1fr auto; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0e1113; }
.marking-preview-wrap canvas { display: block; width: 100%; height: 100%; min-height: 320px; touch-action: none; cursor: crosshair; }
.marking-preview-wrap > span { padding: 8px 10px; border-top: 1px solid var(--line); color: var(--muted); background: #15191c; text-align: center; font-size: .68rem; }
.marking-fields { display: grid; align-content: start; gap: 12px; }
.marking-toggle { display: flex; align-items: flex-start; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #15191c; cursor: pointer; }
.marking-toggle input { margin: 2px 0 0; accent-color: var(--orange); }
.marking-toggle span { display: grid; gap: 2px; }
.marking-toggle strong { color: var(--text); font-size: .74rem; }
.marking-toggle small { color: var(--muted); font-size: .66rem; line-height: 1.35; }
.marking-status { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; color: var(--muted); background: #111416; font-size: .7rem; line-height: 1.4; }
.marking-status[data-state="valid"] { color: var(--green); border-color: rgba(110,212,154,.35); background: rgba(110,212,154,.07); }
.marking-status[data-state="invalid"] { color: #ffaaa5; border-color: rgba(255,123,115,.4); background: rgba(255,123,115,.07); }
.marking-actions { display: grid; grid-template-columns: auto 1fr auto auto; }
.danger-button { color: #ffaaa5 !important; border-color: rgba(255,123,115,.35) !important; }

.materials-list, .jobs-list { display: grid; gap: 8px; }
.material-row { display: grid; grid-template-columns: 1.4fr .65fr .8fr .8fr .8fr auto; gap: 7px; align-items: end; border: 1px solid var(--line); padding: 10px; border-radius: 9px; background: #171a1d; }
.material-row .field span { font-size: .66rem; }
.material-row input { min-height: 34px; padding: 6px 8px; font-size: .8rem; }
.row-delete { width: 34px; height: 34px; background: transparent; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); }
.row-delete:hover { border-color: var(--red); color: var(--red); }

.job-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 15px; border: 1px solid var(--line); border-radius: 9px; background: #171a1d; padding: 11px; }
.job-row-info { min-width: 0; display: grid; gap: 4px; }
.job-row-info strong { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; font-size: .86rem; }
.job-row-info span { color: var(--muted); font-size: .68rem; }
.job-row-actions { display: flex; gap: 6px; }
.job-row-actions button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 7px; padding: 7px 9px; font-size: .72rem; }
.job-row-actions button.danger { color: var(--red); }
.jobs-empty { color: var(--muted); border: 1px dashed var(--line); border-radius: 9px; padding: 30px; text-align: center; font-size: .8rem; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 36px)); }
.toast { background: #282d31; border: 1px solid #4a535a; border-left: 3px solid var(--orange); border-radius: 9px; padding: 12px 14px; box-shadow: var(--shadow); animation: toast-in 180ms ease; display: grid; gap: 3px; }
.toast.error { border-left-color: var(--red); }
.toast strong { font-size: .82rem; }
.toast span { color: var(--muted); font-size: .74rem; line-height: 1.4; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1280px) {
  .workspace { grid-template-columns: 330px minmax(430px, 1fr) 285px; }
  .results-panel { padding: 16px; }
  .save-status { display: none; }
}

@media (max-width: 1060px) {
  .topbar { grid-template-columns: auto 1fr; }
  .job-title { grid-column: 1 / -1; grid-row: 2; }
  .top-actions { grid-column: 2; grid-row: 1; }
  .workspace { grid-template-columns: 330px minmax(0, 1fr); }
  .setup-panel { max-height: none; }
  .results-panel { grid-column: 1 / -1; max-height: none; border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .results-heading { grid-column: 1 / -1; }
  .plate-breakdown { margin-top: 0; grid-row: span 2; }
}

@media (max-width: 760px) {
  .topbar { position: static; grid-template-columns: 1fr; gap: 8px; padding: 10px 12px; }
  .brand { grid-row: 1; }
  .top-actions { grid-column: 1; grid-row: 2; justify-content: stretch; }
  .top-actions .button { flex: 1; }
  .job-title { grid-column: 1; grid-row: 3; }
  .workspace { display: block; }
  .setup-panel, .results-panel { max-height: none; border: 0; }
  .viewer-panel { min-height: 650px; border-block: 1px solid var(--line); }
  .viewer-head { align-items: start; padding: 14px; }
  .viewer-head-actions { align-items: stretch; flex-direction: column-reverse; }
  .viewer-stage { min-height: 430px; }
  .results-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .results-heading, .plate-breakdown, .warning-card { grid-column: 1 / -1; }
  .interaction-hint { display: none !important; }
  .layout-toolbar { align-items: stretch; flex-direction: column; }
  .layout-toolbar > div { overflow-x: auto; }
  .dxf-review-card { grid-template-columns: 1fr; }
  .dxf-preview { width: 100%; min-height: 180px; border-right: 0; border-bottom: 1px solid var(--line); }
  .dxf-review-fields { grid-template-columns: 1fr 1fr; }
  .marking-layout { grid-template-columns: 1fr; }
  .marking-preview-wrap { min-height: 290px; }
  .marking-preview-wrap canvas { min-height: 250px; }
}

@media (max-width: 520px) {
  .brand .version { display: none; }
  .top-actions .button.ghost { display: none; }
  .panel-section { padding: 17px 14px; }
  .field-grid.three { grid-template-columns: 1fr 1fr; }
  .field-grid.three .field:last-child { grid-column: 1 / -1; }
  .viewer-head { display: grid; }
  .view-tabs { width: 100%; }
  .view-tabs button { flex: 1; }
  .viewer-panel { grid-template-rows: auto 460px auto; }
  .results-panel { display: block; }
  .metrics-grid, .cost-card, .plate-breakdown { margin-top: 10px; }
  .material-row { grid-template-columns: 1fr 1fr; }
  .material-row .field:first-child { grid-column: 1 / -1; }
  .job-row { grid-template-columns: 1fr; }
  .job-row-actions { justify-content: flex-end; }
  .dxf-repair-row { align-items: stretch; flex-direction: column; }
  .dxf-repair-row .field { width: 100%; }
  .dxf-review-fields { grid-template-columns: 1fr; }
  .marking-actions { grid-template-columns: 1fr 1fr; }
  .marking-actions > span { display: none; }
  .marking-actions button { width: 100%; }
}

@media print {
  body { background: white; color: #111; }
  .topbar, .setup-panel, .viewer-head, .viewer-controls, .plate-strip, .results-panel { display: none !important; }
  .workspace, .viewer-panel { display: block; min-height: 0; }
  .viewer-stage { background: white; height: 700px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
