:root {
  --green: #78be20;
  --green-strong: #5aa51f;
  --green-dark: #347314;
  --green-deep: #173f18;
  --green-wash: #eff8e7;
  --orange: #f58220;
  --orange-dark: #d96211;
  --orange-wash: #fff2e5;
  --canvas: #f4f7f1;
  --surface: #ffffff;
  --ink: #17311c;
  --muted: #6a796c;
  --line: #dce6d7;
  --line-soft: #eaf0e7;
  --danger: #b83d32;
  --shadow: 0 18px 50px rgba(33, 73, 25, 0.09);
  --shadow-soft: 0 8px 24px rgba(33, 73, 25, 0.06);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Noto Sans Thai", "Segoe UI", Tahoma, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 8% 10%, rgba(120, 190, 32, 0.09), transparent 24rem),
    radial-gradient(circle at 96% 38%, rgba(245, 130, 32, 0.07), transparent 22rem),
    var(--canvas);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
svg { display: block; }
::selection { background: rgba(120, 190, 32, 0.24); color: var(--green-deep); }
button:focus-visible,
a:focus-visible { outline: 3px solid rgba(245, 130, 32, 0.42); outline-offset: 3px; }

.page-shell { min-height: 100dvh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 70px;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(220, 230, 215, 0.8);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 6px 16px rgba(33, 73, 25, 0.07);
  font-family: "Kanit", sans-serif;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
}
.brand-mark i {
  width: 1px;
  height: 1.2rem;
  transform: rotate(12deg);
  background: var(--line);
}
.brand-ais { color: var(--green-strong); }
.brand-3bb { color: var(--orange); }
.brand-copy { min-width: 0; }
.brand-copy strong,
.brand-copy small { display: block; white-space: nowrap; }
.brand-copy strong {
  font-family: "Kanit", sans-serif;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.brand-copy small {
  margin-top: 0.1rem;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.topbar-actions { display: inline-flex; align-items: center; gap: 0.5rem; }
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 40px;
  padding: 0 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--green-wash);
  color: var(--green-dark);
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-dot {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: #9daa9a;
  box-shadow: 0 0 0 4px rgba(157, 170, 154, 0.12);
}
.connection-status.is-connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(120, 190, 32, 0.16);
}
.header-export {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: 46px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 0.72rem;
  background: #fff;
  color: var(--green-dark);
  font-size: 0.7rem;
  font-weight: 800;
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.header-export svg { width: 1rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.header-export:hover { border-color: var(--orange); color: var(--orange-dark); transform: translateY(-1px); }
.brand-ribbon {
  position: relative;
  z-index: 21;
  height: 4px;
  margin-top: -4px;
  overflow: hidden;
  background: var(--green);
}
.brand-ribbon span {
  position: absolute;
  top: 0;
  right: -3rem;
  width: 42%;
  height: 100%;
  transform: skewX(-35deg);
  background: var(--orange);
}

.main-layout {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}
.hero-panel {
  position: relative;
  display: grid;
  min-height: 210px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  background: linear-gradient(135deg, rgba(23, 63, 24, 0.98), rgba(69, 141, 24, 0.98) 58%, rgba(120, 190, 32, 0.96));
  box-shadow: 0 22px 52px rgba(38, 92, 25, 0.2);
  color: #fff;
}
.hero-panel::before {
  content: "";
  position: absolute;
  top: -7rem;
  right: -8rem;
  width: 19rem;
  height: 19rem;
  border: 2.5rem solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}
.hero-panel::after {
  content: "";
  position: absolute;
  right: -12%;
  bottom: -2.9rem;
  width: 72%;
  height: 5.5rem;
  transform: rotate(-8deg);
  border-radius: 999px;
  background: var(--orange);
  opacity: 0.96;
}
.hero-copy { position: relative; z-index: 2; align-self: center; }
.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 0.6rem;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.13em;
}
.eyebrow > span { width: 1.6rem; height: 2px; border-radius: 999px; background: var(--orange); }
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 1.2rem;
  font-family: "Kanit", sans-serif;
  font-size: clamp(2.35rem, 10vw, 5.4rem);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 0.98;
}
.hero-tags { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.hero-tags span {
  padding: 0.36rem 0.58rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.57rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.signal-visual {
  position: absolute;
  right: -0.5rem;
  bottom: 1.8rem;
  z-index: 3;
  width: 8.5rem;
  height: 7rem;
  transform: rotate(-8deg);
}
.signal-orbit {
  position: absolute;
  right: 0;
  bottom: 0;
  border: 2px solid rgba(255, 255, 255, 0.34);
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
}
.orbit-one { width: 7.5rem; height: 7.5rem; }
.orbit-two { right: 1.3rem; bottom: 1.3rem; width: 4.9rem; height: 4.9rem; }
.signal-node { position: absolute; width: 0.72rem; height: 0.72rem; border: 3px solid #fff; border-radius: 50%; background: var(--orange); box-shadow: 0 4px 12px rgba(20, 55, 20, 0.25); }
.node-one { right: 0.25rem; bottom: 3.2rem; }
.node-two { right: 2.3rem; bottom: 1rem; background: #fff; border-color: var(--orange); }
.node-three { right: 4.45rem; bottom: 3.65rem; }

.repair-form { margin-top: 1rem; }
.form-section {
  position: relative;
  margin-bottom: 0.85rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}
.form-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--green) 0 76%, var(--orange) 76% 100%);
}
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.2rem;
}
.section-title-group { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.section-number {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 12px;
  background: var(--green-wash);
  color: var(--green-dark);
  font-family: "Kanit", sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
}
.section-number.is-orange { background: var(--orange-wash); color: var(--orange-dark); }
.section-index {
  margin-bottom: 0.12rem;
  color: var(--green-dark);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}
.section-index.is-orange { color: var(--orange-dark); }
.section-heading h2 {
  margin-bottom: 0;
  font-family: "Kanit", sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.required-note,
.count-label {
  flex: 0 0 auto;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}
.required-note { display: inline-flex; align-items: center; gap: 0.35rem; padding-top: 0.5rem; color: var(--muted); }
.required-note i { width: 0.42rem; height: 0.42rem; border-radius: 50%; background: var(--orange); }
.count-label { padding: 0.45rem 0.65rem; background: var(--orange-wash); color: var(--orange-dark); }
.section-help {
  margin: -0.55rem 0 1rem;
  padding-left: 3.25rem;
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.55;
}
.field-grid { display: grid; grid-template-columns: 1fr; gap: 0.9rem; }
.field-wide { grid-column: 1 / -1; }
.field,
.field-stack { display: flex; flex-direction: column; }
.field { gap: 0.43rem; }
.field > span { color: var(--ink); font-size: 0.82rem; font-weight: 700; }
.field b { color: var(--orange-dark); }
.field small { color: var(--muted); font-size: 0.69rem; }
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfdf9;
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
input,
select { min-height: 52px; padding: 0.75rem 0.85rem; }
select { cursor: pointer; }
textarea { min-height: 124px; padding: 0.85rem; resize: vertical; line-height: 1.6; }
input::placeholder,
textarea::placeholder { color: #9ba69a; }
input:hover,
select:hover,
textarea:hover { border-color: #b9c9b4; }
input:focus,
select:focus,
textarea:focus {
  border-color: var(--green-strong);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(120, 190, 32, 0.14);
}
.field.is-invalid input,
.field.is-invalid select,
.field.is-invalid textarea { border-color: var(--danger); }

.material-list { display: grid; grid-template-columns: 1fr; gap: 0.7rem; }
.material-row {
  display: grid;
  gap: 0.8rem;
  padding: 0.9rem;
  border: 1px solid var(--line-soft);
  border-radius: 15px;
  background: linear-gradient(145deg, #fbfdf9, #ffffff);
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.material-row:only-child { grid-column: 1 / -1; }
.material-row:focus-within { transform: translateY(-1px); border-color: #b9d6a8; box-shadow: 0 10px 25px rgba(65, 117, 41, 0.08); }
.material-row-header { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.material-number { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--ink); font-size: 0.75rem; font-weight: 800; }
.material-number span {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 10px;
  background: var(--orange);
  color: #fff;
  font-family: "Kanit", sans-serif;
  font-size: 0.7rem;
  box-shadow: 0 6px 14px rgba(245, 130, 32, 0.2);
}
.remove-button {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  padding: 0.45rem 0.6rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
}
.remove-button:hover { background: #fff0ed; color: var(--danger); }
.material-inputs { display: grid; grid-template-columns: 1fr; gap: 0.7rem; }
.material-inputs label { display: flex; flex-direction: column; gap: 0.38rem; color: var(--muted); font-size: 0.69rem; font-weight: 600; }
.material-inputs label small { color: var(--orange-dark); font-size: 0.65rem; font-weight: 800; }
.material-inputs select,
.material-inputs input { min-height: 50px; padding: 0.67rem 0.72rem; font-size: 0.79rem; }
.add-button { margin-top: 0.85rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 52px;
  border: 0;
  border-radius: 13px;
  padding: 0.8rem 1rem;
  font-weight: 800;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.button:active { transform: translateY(1px) scale(0.99); }
.button:disabled { cursor: not-allowed; }
.button-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--green-strong), var(--green-dark));
  color: #fff;
  box-shadow: 0 13px 28px rgba(67, 132, 28, 0.24);
}
.button-primary:hover { transform: translateY(-1px); box-shadow: 0 16px 32px rgba(67, 132, 28, 0.3); }
.button-primary svg { width: 1.35rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.1; }
.button-secondary { border: 1px dashed #b9cfae; background: var(--green-wash); color: var(--green-dark); }
.button-secondary:hover { border-color: var(--orange); background: var(--orange-wash); color: var(--orange-dark); }
.button-icon { display: grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: rgba(120, 190, 32, 0.15); font-family: "Kanit", sans-serif; font-size: 1.05rem; font-weight: 500; }
.button-secondary:hover .button-icon { background: rgba(245, 130, 32, 0.15); }
.form-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.8rem;
  align-items: stretch;
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}
.form-message { min-height: 1.2rem; color: var(--muted); font-size: 0.76rem; line-height: 1.5; }
.form-message.is-error { color: var(--danger); }
.form-message.is-success { color: var(--green-dark); font-weight: 700; }

.footer {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 0 1rem 1.5rem;
  color: var(--muted);
  font-size: 0.63rem;
  letter-spacing: 0.05em;
}
.footer b { color: var(--green-dark); }
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  max-width: min(340px, calc(100vw - 2rem));
  transform: translateY(calc(100% + 2rem));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  background: var(--green-deep);
  color: #fff;
  box-shadow: 0 18px 40px rgba(23, 63, 24, 0.24);
  font-size: 0.78rem;
  transition: transform 0.28s ease;
}
.toast.is-visible { transform: translateY(0); }
.toast:empty { display: none; }

@media (max-width: 460px) {
  .brand-copy { display: none; }
  .connection-status { max-width: 9.4rem; overflow: hidden; text-overflow: ellipsis; }
  .header-export span { display: none; }
  .hero-panel { min-height: 198px; }
  .hero-tags span:last-child { display: none; }
  .signal-visual { right: -2.3rem; opacity: 0.78; }
  .required-note { font-size: 0; }
  .required-note i { width: 0.52rem; height: 0.52rem; margin-top: 0.55rem; }
  .section-help { padding-left: 0; }
}

@media (min-width: 480px) {
  .material-inputs { grid-template-columns: minmax(0, 1fr) 7.4rem; }
  .footer { flex-direction: row; justify-content: space-between; }
}

@media (min-width: 700px) {
  .topbar { min-height: 78px; padding-inline: 1.5rem; }
  .brand-mark { min-height: 44px; padding-inline: 0.85rem; }
  .connection-status { min-height: 42px; padding-inline: 0.85rem; font-size: 0.72rem; }
  .main-layout { padding: 1.5rem 1.5rem 4rem; }
  .hero-panel { min-height: 260px; padding: 2.2rem; }
  .signal-visual { right: 2rem; bottom: 2.2rem; width: 12rem; height: 10rem; }
  .orbit-one { width: 10rem; height: 10rem; }
  .orbit-two { right: 1.7rem; bottom: 1.7rem; width: 6.6rem; height: 6.6rem; }
  .node-one { right: 0.15rem; bottom: 4.5rem; }
  .node-two { right: 3rem; bottom: 1.3rem; }
  .node-three { right: 6rem; bottom: 5rem; }
  .repair-form { margin-top: 1.25rem; }
  .form-section { margin-bottom: 1rem; padding: 1.5rem; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-actions { flex-direction: row; align-items: center; justify-content: space-between; padding: 0.8rem 0.9rem 0.8rem 1.2rem; }
  .button-primary { width: auto; min-width: 220px; }
  .form-message { flex: 1; }
  .footer { padding-inline: 1.5rem; }
}

@media (min-width: 960px) {
  .topbar { padding-inline: max(2rem, calc((100vw - 1120px) / 2)); }
  .main-layout { padding-top: 2rem; }
  .hero-panel { min-height: 295px; padding: 2.75rem; }
  .hero-panel::after { right: -6%; bottom: -3.7rem; height: 7rem; }
  .material-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-section { padding: 1.75rem; }
  .footer { padding-inline: 0; }
}

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