:root {
  --bg: #f2f5f8;
  --bg2: #e8edf2;
  --card: #ffffff;
  --ink: #16202b;
  --muted: #5f6b78;
  --line: #d5dce5;
  --brand: #1f4f78;
  --brand-2: #2b6b9f;
  --good: #2d6a4f;
  --bad: #b23b3b;
  --warn: #c47f17;
  --shadow: 0 14px 34px rgba(24, 38, 58, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-family: "Source Sans 3", "Trebuchet MS", "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  background: linear-gradient(155deg, var(--bg), var(--bg2));
}

.bg-layer {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 8% 12%, rgba(32, 79, 120, 0.08), transparent 34%),
    radial-gradient(circle at 92% 3%, rgba(43, 107, 159, 0.1), transparent 24%),
    radial-gradient(circle at 72% 84%, rgba(176, 158, 109, 0.1), transparent 26%);
  pointer-events: none;
}

.layout {
  max-width: 1180px;
  margin: 26px auto 70px;
  padding: 0 18px;
  position: relative;
  z-index: 1;
  display: grid;
  gap: 18px;
}

.site-footer {
  text-align: center;
  color: #4f5d6b;
  font-size: 0.9rem;
  margin: 0 0 20px;
  padding: 0 16px;
}

.site-footer p {
  margin: 0;
}

.card {
  background: var(--card);
  border: 1px solid #d9e2eb;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  animation: rise 0.35s ease;
}

.hero h1 {
  margin: 0;
  font-family: "Merriweather Sans", "Segoe UI Semibold", sans-serif;
  letter-spacing: 0.2px;
  font-size: clamp(1.6rem, 3vw, 2.3rem);
}

.hero p {
  margin: 10px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.8rem;
  color: var(--brand);
  font-weight: 700;
}

.mode-toggle {
  display: inline-flex;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-bottom: 14px;
}

.mode-btn {
  border: 0;
  background: #ecf1f6;
  color: #314255;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.mode-btn.active {
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
  color: #fff;
}

.form-top {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 600;
}

.field input,
td input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

input:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(43, 107, 159, 0.15);
}

input.invalid {
  border-color: var(--bad);
  box-shadow: 0 0 0 3px rgba(178, 59, 59, 0.13);
}

.message {
  margin: 14px 0;
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #f0f5fa;
  color: #2f4863;
}

.message.error {
  border-color: #f3c4c4;
  background: #fff3f3;
  color: #7f2323;
}

.message.success {
  border-color: #c6e6d6;
  background: #effaf4;
  color: #1f5d40;
}

.grid-2 {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fbfcfd;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  text-align: left;
  color: #354a5f;
  font-size: 0.88rem;
  background: #edf3f9;
}

th,
td {
  border: 1px solid var(--line);
  padding: 7px;
  vertical-align: middle;
}

td:last-child,
th:last-child {
  width: 64px;
  text-align: center;
}

.import-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--line);
  background: #f5f9fd;
  color: #23405c;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: #eef5fb;
}

.btn.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
}

.btn.ghost {
  background: #fff;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.result-head h2 {
  margin: 0;
}

.result-actions {
  display: flex;
  gap: 8px;
}

.kpi-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.kpi {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #f8fbff;
}

.kpi .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.kpi .value {
  margin-top: 4px;
  font-size: 1.1rem;
  font-weight: 700;
}

.scenarios-wrap {
  margin-top: 14px;
}

.scenario-table tr[data-feasible="false"] {
  opacity: 0.55;
}

.scenario-table tr.selected {
  background: #e8f1fb;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  border-radius: 999px;
  padding: 3px 8px;
  font-weight: 700;
  color: #fff;
  background: var(--good);
}

.scenario-details {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.pattern-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px;
  margin-top: 9px;
}

.pattern-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #324152;
  font-weight: 700;
  margin-bottom: 8px;
}

.bar {
  height: 28px;
  border-radius: 6px;
  border: 1px solid #273b4f;
  display: flex;
  overflow: hidden;
  background: #f7f9fc;
}

.segment {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  border-right: 1px solid rgba(255, 255, 255, 0.45);
  min-width: 2px;
}

.segment.cut {
  background: linear-gradient(120deg, #3e6f97, #2f5675);
}

.segment.kerf {
  background: #d04e3c;
}

.segment.offcut {
  background: #95a6b7;
  color: #1f2c39;
}

dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(540px, calc(100% - 28px));
}

dialog::backdrop {
  background: rgba(13, 20, 30, 0.45);
}

.modal-content {
  padding: 16px;
}

.scenario-options {
  display: grid;
  gap: 8px;
  margin: 10px 0 16px;
  max-height: 280px;
  overflow: auto;
}

.option {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
}

.option small {
  display: block;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: stretch;
  }

  .actions .btn {
    flex: 1;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
