:root {
  color-scheme: light;
  --ink: #12151c;
  --ink-2: #3a404c;
  --muted: #6b7280;
  --line: #e4e2dc;
  --bg: #f5f4f0;
  --card: #ffffff;
  --orange: #ff5c39;
  --orange-ink: #d9431f;
  --orange-soft: #fff1ec;
  --steel: #dfe5ee;
  --steel-ink: #2f3a4c;
  --ideal: #eef0f4;
  --wood: #e8b45f;
  --ok: #1f8a4c;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(18, 21, 28, 0.04), 0 8px 24px rgba(18, 21, 28, 0.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Inter Tight", "Inter", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a {
  color: inherit;
}
h1,
h2,
h3 {
  font-family: var(--display);
  letter-spacing: -0.02em;
  margin: 0;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
[hidden] {
  display: none !important;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 40px);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-logo {
  height: 34px;
  width: auto;
  display: block;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}
.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.install-btn svg {
  width: 16px;
  height: 16px;
}
@media (max-width: 480px) {
  .hide-sm {
    display: none;
  }
}
.by-ibi {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-size: 13px;
  color: var(--muted);
}
.by-ibi strong {
  font-family: var(--display);
  font-weight: 800;
  color: var(--ink);
  font-size: 17px;
  letter-spacing: -0.03em;
}
.pill {
  background: var(--orange);
  color: #fff;
  border-radius: 999px;
  padding: 1px 9px 2px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
}

/* Layout */
.layout {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  padding: 24px clamp(16px, 4vw, 40px);
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 16px;
  }
}
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.results {
  display: grid;
  gap: 20px;
  min-width: 0;
}
#result {
  display: grid;
  gap: 20px;
  min-width: 0;
}
.inputs {
  position: sticky;
  top: 86px;
}
@media (max-width: 1000px) {
  .inputs {
    position: static;
  }
}

.hero-title {
  font-size: clamp(26px, 3vw, 32px);
  font-weight: 800;
  line-height: 1.08;
}
.hero-title span {
  color: var(--orange);
}
.hero-sub {
  color: var(--ink-2);
  margin: 10px 0 18px;
}

/* Fields */
form {
  display: grid;
  gap: 14px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.grid-3 .field:last-child {
  grid-column: 1 / -1;
}
.field {
  display: grid;
  gap: 6px;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}
.field > span,
.field > legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  padding: 0;
  margin-bottom: 6px;
}
fieldset.field > legend {
  margin-bottom: 8px;
}
.unit-input {
  position: relative;
}
.unit-input em {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-style: normal;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}
input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfaf8;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  outline: none;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.unit-input input {
  padding-right: 38px;
  font-weight: 600;
  font-size: 16px;
}
textarea {
  resize: vertical;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(255, 92, 57, 0.18);
  background: #fff;
}
input.invalid {
  border-color: var(--orange-ink);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  gap: 4px;
}
.segmented label {
  position: relative;
}
.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
}
.segmented span {
  display: block;
  text-align: center;
  padding: 9px 8px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-2);
  cursor: pointer;
}
.segmented input:checked + span {
  background: var(--ink);
  color: #fff;
}
.segmented input:focus-visible + span {
  outline: 2px solid var(--orange);
}
.segmented.small span {
  padding: 6px 12px;
  font-size: 13px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  position: relative;
}
.chip input {
  position: absolute;
  opacity: 0;
}
.chip span {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  background: #fff;
}
.chip input:checked + span {
  background: var(--orange-soft);
  border-color: var(--orange);
  color: var(--orange-ink);
}
.chip input:focus-visible + span {
  outline: 2px solid var(--orange);
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.switch input {
  position: absolute;
  opacity: 0;
}
.switch .track {
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: #cfd3da;
  position: relative;
  flex: none;
  transition: background 0.15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch input:checked + .track {
  background: var(--ink);
}
.switch input:checked + .track::after {
  transform: translateX(16px);
}
.switch input:focus-visible + .track {
  outline: 2px solid var(--orange);
}

/* Buttons */
.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 700;
  font-family: var(--display);
  letter-spacing: -0.01em;
  font-size: 15px;
  transition:
    transform 0.05s,
    background 0.15s;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--orange);
  color: #fff;
}
.btn-primary:hover {
  background: var(--orange-ink);
}
.btn-primary:disabled {
  background: #f3a693;
  cursor: progress;
}
.btn-ghost {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover {
  background: #ecebe6;
}
.btn-link {
  background: none;
  color: var(--muted);
  padding: 6px 0;
  font-weight: 500;
  font-family: var(--font);
  font-size: 13px;
  text-decoration: underline;
}
.btn-block {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}
.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}

/* Stock */
.stock {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.stock summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  list-style: none;
}
.stock summary::-webkit-details-marker {
  display: none;
}
.stock summary::after {
  content: "+";
  font-size: 22px;
  color: var(--muted);
  margin-left: auto;
  padding-left: 10px;
}
.stock[open] summary::after {
  content: "–";
}
.badge {
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  padding: 2px 9px;
  margin-left: 8px;
  font-family: var(--font);
}
.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 12px;
}
.stock-group {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.stock-group h3 {
  font-size: 14px;
  padding: 9px 12px;
  background: var(--bg);
  display: flex;
  justify-content: space-between;
}
.stock-group h3 small {
  color: var(--muted);
  font-family: var(--font);
  font-weight: 500;
}
.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 1px;
  background: var(--line);
}
.stock-item {
  background: #fff;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.stock-item label {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.stock-item input {
  width: 54px;
  padding: 6px 6px;
  text-align: center;
  font-weight: 600;
}
.stock-item input:not(:placeholder-shown) {
  border-color: var(--ink);
  background: #fff;
}
.stock-item .del {
  border: 0;
  background: none;
  color: var(--orange-ink);
  cursor: pointer;
  font-size: 16px;
  padding: 0 2px;
}
.custom-form {
  margin-top: 14px;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  gap: 10px;
}
.custom-form h3 {
  font-size: 14px;
}

/* Results */
.empty {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  gap: 6px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.section-head h2 {
  font-size: 20px;
  font-weight: 800;
}
.section-head select {
  width: auto;
  padding: 7px 10px;
  font-size: 13px;
}

.notice {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--ink-2);
  margin: -4px 0 14px;
}
.compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.sys-card {
  text-align: left;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 14px;
  cursor: pointer;
  display: grid;
  gap: 8px;
  position: relative;
}
.sys-card:hover {
  border-color: #c9c6be;
}
.sys-card.selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(18, 21, 28, 0.08);
}
.sys-card h3 {
  font-size: 16px;
  font-weight: 800;
}
.sys-card .big {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}
.sys-card .big small {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0;
}
.sys-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 3px;
  font-size: 13px;
  color: var(--ink-2);
}
.sys-card .warn {
  color: var(--orange-ink);
  font-weight: 600;
}
.sys-card .good {
  color: var(--ok);
  font-weight: 600;
}
.tag {
  position: absolute;
  top: -10px;
  right: 12px;
  background: var(--orange);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--display);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.sys-card.na {
  cursor: default;
  color: var(--muted);
}

.drawing {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  background: #fafaf7;
  border: 1px solid var(--line);
  padding: 8px;
}
.drawing svg {
  display: block;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-2);
  margin: 10px 0 14px;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sw {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
  border: 1.5px solid var(--steel-ink);
}
.sw-stock {
  background: var(--steel);
}
.sw-ideal {
  background: var(--ideal);
}
.sw-missing {
  background: repeating-linear-gradient(45deg, var(--orange-soft) 0 3px, #ffc9b8 3px 6px);
  border-color: var(--orange-ink);
}
.sw-filler {
  background: var(--wood);
  border-color: #9a6a1c;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.stat b {
  display: block;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.stat span {
  font-size: 12px;
  color: var(--muted);
}
.stat.alert {
  background: var(--orange-soft);
}
.stat.alert b {
  color: var(--orange-ink);
}

.table-wrap {
  overflow-x: auto;
}
.parts {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.parts th,
.parts td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.parts th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.parts td.num,
.parts th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.parts td.miss {
  color: var(--orange-ink);
  font-weight: 700;
}
.parts tfoot td {
  font-weight: 700;
  border-bottom: 0;
}

/* AI */
.ai {
  display: grid;
  gap: 12px;
}
.ai .section-head {
  margin-bottom: 0;
}
.spark {
  color: var(--orange);
}
.ai-out:empty {
  display: none;
}
.ai-out {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.ai-headline {
  font-family: var(--display);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
}
.ai-block h4 {
  margin: 0 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.ai-block ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}
.ai-block.warn {
  background: var(--orange-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.ai-block.warn h4 {
  color: var(--orange-ink);
}
.ai-answer {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  white-space: pre-wrap;
}
.ai-meta {
  font-size: 12px;
  color: var(--muted);
}
.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-2);
}
.dots {
  display: inline-flex;
  gap: 4px;
}
.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
  animation: blink 1s infinite ease-in-out;
}
.dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}
.error {
  color: var(--orange-ink);
  background: var(--orange-soft);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.footer {
  padding: 10px clamp(16px, 4vw, 40px) 40px;
  max-width: 1440px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 13px;
}
.footer .small {
  font-size: 12px;
  max-width: 900px;
}

@media (max-width: 520px) {
  .brand-logo {
    height: 28px;
  }
  .panel {
    padding: 16px;
  }
}

/* Install pop-up */
.install-sheet {
  border: 0;
  padding: 22px;
  width: min(440px, calc(100% - 32px));
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(18, 21, 28, 0.25);
}
.install-sheet[open] {
  animation: sheet-in 0.22s ease-out;
}
.install-sheet::backdrop {
  background: rgba(18, 21, 28, 0.45);
}
@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}
@media (max-width: 600px) {
  .install-sheet {
    margin: auto 0 0;
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
}
@media (prefers-reduced-motion: reduce) {
  .install-sheet[open] {
    animation: none;
  }
}
.install-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.install-head img {
  border-radius: 14px;
  flex: none;
}
.install-head h2 {
  font-size: 20px;
}
.install-head p {
  margin: 4px 0 0;
  color: var(--ink-2);
}
.install-steps {
  margin: 16px 0 0;
  padding: 14px 14px 14px 34px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.install-steps li + li {
  margin-top: 6px;
}
.install-steps svg {
  width: 18px;
  height: 18px;
  vertical-align: -3px;
  color: #0a84ff;
}
.install-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.install-sheet[data-mode="ios"] [data-for="prompt"],
.install-sheet[data-mode="prompt"] [data-for="ios"] {
  display: none;
}

@media print {
  .install-btn,
  .install-sheet,
  .inputs,
  .by-ibi,
  .ai button,
  .ai select,
  .ai label,
  #print,
  #face-tabs {
    display: none !important;
  }
  .topbar {
    position: static;
    border: 0;
    padding: 0 0 12px;
  }
  body {
    background: #fff;
  }
  .layout {
    display: block;
    padding: 0;
  }
  .panel {
    box-shadow: none;
    border: 0;
    padding: 0 0 16px;
  }
  .drawing {
    overflow: visible;
  }
}
