:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687386;
  --line: #d9e0ea;
  --accent: #d62728;
  --accent-dark: #9d1d1f;
  --good: #146c43;
  --warn: #9a6700;
  --bad: #b42318;
  --shadow: 0 14px 35px rgba(24, 37, 56, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hero {
  padding: 30px clamp(18px, 4vw, 56px);
  background: linear-gradient(135deg, #111827, #2d3340 60%, #171717);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 18px; }
.logo { width: 72px; height: 72px; object-fit: contain; border-radius: 50%; }
.eyebrow { margin: 0 0 6px; color: #ffd6d6; text-transform: uppercase; letter-spacing: .12em; font-size: 12px; }
h1 { margin: 0; font-size: clamp(26px, 4vw, 42px); line-height: 1.05; }
.subtitle { margin: 9px 0 0; color: #d7dce6; }
.hero-note {
  max-width: 430px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 16px;
  line-height: 1.45;
}

.layout { padding: 26px clamp(16px, 4vw, 56px); display: grid; gap: 22px; }
.grid { display: grid; gap: 22px; }
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.input-sections { align-items: start; }
.wide { grid-column: 1 / -1; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 16px; font-size: 20px; }
.panel h3 { margin: 24px 0 12px; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #5d3440;
  background: #fff0f0;
  border: 1px solid #ffd5d5;
}
.pill.good { color: var(--good); background: #eaf7ef; border-color: #b9e4c8; }
.pill.warn { color: var(--warn); background: #fff7df; border-color: #f3d98b; }
.pill.bad { color: var(--bad); background: #fff1f0; border-color: #ffccc7; }

.controls-panel { display: grid; gap: 14px; }
.button-grid, .tools-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.tools-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: end; }
button, .file-label {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
button:hover, .file-label:hover { background: var(--accent-dark); }
button.ghost { background: #e9edf4; color: #1c2738; }
button.ghost:hover { background: #d9e0ea; }
.file-label input { display: none; }

.warning-panel { border-left: 6px solid var(--warn); }
.small { font-size: 13px; }
.muted { color: var(--muted); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid.five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: #354052; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input[readonly] { background: #f2f5f9; color: var(--muted); }
.toggle-row { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.kpi {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: #fbfcff;
}
.kpi span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.kpi strong { display: block; font-size: clamp(20px, 2.5vw, 30px); }
.kpi.highlight { border-color: #ffb7b7; background: #fff6f6; }

.bar-list { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 190px 1fr 130px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 18px; background: #edf1f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #c42126, #f16b6d); border-radius: 999px; min-width: 2px; }
.bar-value { text-align: right; font-weight: 700; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { text-align: left; }
thead th { background: #f2f5f9; color: #354052; }
tbody tr:last-child td { border-bottom: 0; }
.negative { color: var(--bad); font-weight: 700; }
.positive { color: var(--good); font-weight: 700; }

textarea { resize: vertical; line-height: 1.5; min-height: 160px; }
.mini-card {
  margin-top: 14px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fbfcff;
  line-height: 1.45;
}
footer { padding: 18px clamp(16px, 4vw, 56px) 40px; color: var(--muted); }

@media (max-width: 1000px) {
  .hero { flex-direction: column; align-items: flex-start; }
  .two-col, .form-grid.five { grid-template-columns: 1fr; }
  .button-grid, .tools-grid, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bar-row { grid-template-columns: 1fr; }
  .bar-value { text-align: left; }
}
@media (max-width: 620px) {
  .brand { align-items: flex-start; }
  .logo { width: 54px; height: 54px; }
  .form-grid, .button-grid, .tools-grid, .kpi-grid { grid-template-columns: 1fr; }
}

@media print {
  .controls-panel, .warning-panel, footer, button, .file-label { display: none !important; }
  body { background: white; }
  .panel { box-shadow: none; break-inside: avoid; }
  .hero { color: black; background: white; border-bottom: 1px solid #ccc; }
  .hero-note { border-color: #ccc; background: white; }
}

.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.panel > h3 { font-size: 15px; color: #1d2b43; border-top: 1px solid var(--line); padding-top: 14px; }
.panel > h3:first-of-type { border-top: 0; padding-top: 0; }
#workpieceCostTable td:nth-child(2), #workpieceCostTable th:nth-child(2) { min-width: 150px; }
#workpieceCostTable td:nth-child(3), #workpieceCostTable th:nth-child(3) { min-width: 320px; }
.total-row td { background: #f6fff9; font-weight: 800; }
@media (max-width: 1200px) {
  .form-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .form-grid.four { grid-template-columns: 1fr; }
}
