:root {
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #eef3ea;
  --ink: #20251f;
  --muted: #657061;
  --line: #d8ded3;
  --green: #27664b;
  --green-soft: #dceade;
  --amber: #c07822;
  --red: #b6423c;
  --shadow: 0 16px 38px rgba(38, 50, 34, 0.1);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.is-hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(220, 234, 222, 0.85), transparent 340px),
    var(--bg);
}

body.preview-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: rgba(39, 102, 75, 0.26);
  transition: transform 0.1s ease, filter 0.1s ease, box-shadow 0.1s ease, border-color 0.12s ease, background 0.12s ease;
}

button:active,
button.tap-feedback {
  transform: scale(0.96);
  filter: brightness(1.08) saturate(1.18);
  box-shadow: 0 0 0 4px rgba(39, 102, 75, 0.2), 0 8px 18px rgba(39, 102, 75, 0.18);
}

button.tap-feedback {
  animation: tapPulse 0.22s ease-out;
}

@keyframes tapPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(39, 102, 75, 0.36);
  }
  45% {
    transform: scale(0.94);
    box-shadow: 0 0 0 6px rgba(39, 102, 75, 0.24);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(39, 102, 75, 0);
  }
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 430px);
  gap: 18px;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.workspace,
.summary {
  min-width: 0;
}

.topbar,
.summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  padding: 8px 2px 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.55rem, 3vw, 2.35rem);
  line-height: 1.1;
}

h2 {
  font-size: 1.05rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  font-size: 1.7rem;
  line-height: 1;
}

.quote-meta,
.main-subject-panel,
.selector-grid,
.catalog-panel,
.summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.quote-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.site-picker {
  position: relative;
}

.site-picker input {
  padding-right: 46px;
}

.site-picker-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--green);
  background: var(--green-soft);
  transform: translateY(-50%);
}

.site-picker-toggle:active,
.site-picker-toggle.tap-feedback {
  transform: translateY(-50%) scale(0.94);
}

.site-suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  overflow: hidden;
  border: 1px solid rgba(39, 102, 75, 0.26);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 38px rgba(38, 50, 34, 0.18);
}

.site-suggestion-meta {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.site-suggestion-list {
  max-height: min(44vh, 360px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
}

.site-suggestion {
  display: block;
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.site-suggestion:hover,
.site-suggestion.active {
  border-color: rgba(39, 102, 75, 0.24);
  background: var(--green-soft);
}

.site-suggestion-empty {
  padding: 14px 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.main-subject-panel {
  margin-top: 14px;
  padding: 14px;
}

.subject-spec {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.custom-material {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.confirm-button {
  min-height: 42px;
  border: 1px solid var(--green);
  border-radius: 8px;
  color: #fff;
  background: var(--green);
  font-weight: 900;
}

.pressure-options,
.underwater-light-options,
.six-way-options,
.shock-ball-options,
.tile-options,
.motor-options {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.pressure-options > span,
.underwater-light-options > span,
.six-way-options > span,
.shock-ball-options > span,
.tile-options > span,
.nested-options > span,
.motor-options > span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.nested-options {
  display: grid;
  gap: 8px;
}

.motor-diameter-options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.measurement-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.tile-area-list {
  display: grid;
  gap: 10px;
}

.tile-area-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
}

.tile-area-row .remove-btn {
  grid-column: auto;
  min-height: 42px;
}

.add-area-button {
  width: 100%;
}

.tile-summary {
  min-height: 42px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1.45;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input {
  height: 42px;
  padding: 0 12px;
}

select {
  height: 42px;
  padding: 0 36px 0 12px;
  outline: none;
}

textarea {
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(39, 102, 75, 0.15);
}

.selector-grid {
  display: grid;
  grid-template-columns: 0.95fr 1.4fr;
  gap: 0;
  margin-top: 14px;
  overflow: hidden;
}

.selector-panel {
  padding: 14px;
}

.selector-panel + .selector-panel {
  border-left: 1px solid var(--line);
}

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

.panel-head > span,
.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.chip-grid,
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.diameter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
}

.chip,
.category-tab,
.item-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
}

.chip,
.category-tab {
  min-height: 40px;
  padding: 0 13px;
  font-weight: 800;
}

.chip.active,
.category-tab.active {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.catalog-panel {
  margin-top: 14px;
  padding: 14px;
}

.catalog-head {
  align-items: flex-end;
}

.catalog-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.item-card {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 12px;
  text-align: left;
}

.item-card:hover {
  border-color: var(--green);
  background: #fbfdf9;
  transform: translateY(-1px);
}

.item-card strong {
  font-size: 1rem;
  line-height: 1.25;
}

.item-card span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.reducer-panel {
  display: grid;
  grid-column: 1 / -1;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--green-soft);
}

.reducer-panel > strong {
  font-size: 0.95rem;
}

.reducer-panel > span {
  color: var(--muted);
  font-size: 0.86rem;
}

.reducer-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
}

.reducer-option {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 900;
}

.reducer-option:hover {
  border-color: var(--green);
}

.summary {
  position: sticky;
  top: 18px;
  display: grid;
  align-content: start;
  gap: 13px;
  max-height: calc(100vh - 36px);
  padding: 16px;
  overflow: auto;
}

.selected-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
}

.empty-state strong {
  color: var(--ink);
}

.selected-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.selected-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.selected-name {
  overflow-wrap: anywhere;
}

.selected-spec {
  color: var(--muted);
  font-size: 0.82rem;
}

.qty-control {
  display: block;
  height: 36px;
}

.qty-control input {
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  text-align: center;
}

.remove-btn {
  grid-column: 1 / -1;
  min-height: 36px;
  border: 1px solid rgba(182, 66, 60, 0.32);
  border-radius: 8px;
  color: var(--red);
  background: #fff7f6;
  font-weight: 800;
}

.site-conditions {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
}

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

.condition-head span,
.condition-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.small-text-button {
  min-height: 30px;
  border: 0;
  color: var(--red);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 900;
}

.condition-row {
  display: grid;
  gap: 8px;
}

.condition-grid,
.sub-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.sub-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.people-options {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.shock-ball-size-options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.condition-toggle,
.sub-option {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 900;
}

.condition-toggle.active,
.sub-option.active {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.pending-action-row {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 10px;
}

.confirm-output-button,
.clear-pending-button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 900;
}

.confirm-output-button {
  border: 1px solid var(--green);
  color: #fff;
  background: var(--green);
}

.clear-pending-button {
  border: 1px solid rgba(182, 66, 60, 0.32);
  color: var(--red);
  background: #fff7f6;
}

.time-field input {
  height: 40px;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.primary-button,
.secondary-button,
.reset-button {
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 900;
  line-height: 1.2;
  overflow-wrap: anywhere;
  white-space: normal;
}

.primary-button {
  border: 1px solid var(--green);
  color: #fff;
  background: var(--green);
}

.secondary-button {
  border: 1px solid rgba(192, 120, 34, 0.45);
  color: #5d3710;
  background: #fff4e5;
}

.reset-button {
  border: 1px solid rgba(182, 66, 60, 0.32);
  color: var(--red);
  background: #fff7f6;
}

.status {
  min-height: 20px;
  margin: 0;
  color: var(--green);
  font-size: 0.85rem;
  font-weight: 800;
}

.quote-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  background: rgba(20, 25, 20, 0.62);
}

.quote-preview-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 1080px);
  height: 100vh;
  margin: 0 auto;
  background: #eceee8;
}

.quote-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.quote-preview-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.quote-preview-actions button {
  min-height: 38px;
}

.compact-close {
  width: 38px;
  height: 38px;
  font-size: 1.45rem;
}

.quote-preview-scroll {
  overflow: auto;
  padding: 18px;
}

.company-quote-paper {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  padding: 56px 50px 36px;
  color: #111;
  background: #fff;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
  font-family: "DFKai-SB", "KaiTi", "標楷體", "Microsoft JhengHei", serif;
  font-size: 13px;
  line-height: 1.45;
}

.company-quote-paper p,
.company-quote-paper h2,
.company-quote-paper h3 {
  margin: 0;
  letter-spacing: 0;
}

.quote-letterhead {
  display: grid;
  grid-template-columns: 1fr 230px;
  gap: 24px;
  min-height: 120px;
}

.quote-letterhead h3 {
  margin-bottom: 10px;
  font-size: 18px;
  font-weight: 500;
}

.quote-title-block {
  text-align: center;
}

.quote-title-block h2 {
  margin-bottom: 10px;
  font-size: 25px;
  font-weight: 500;
  letter-spacing: 0.45em;
  text-indent: 0.45em;
}

.quote-info-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.85fr 1fr;
  gap: 14px;
  align-items: end;
  margin-top: 12px;
}

.quote-info-grid p {
  min-height: 20px;
}

.quote-info-grid span {
  display: inline-block;
  min-width: 72px;
}

.quote-valid-note {
  margin: 8px 0;
}

.quote-detail-table {
  width: 100%;
  height: 478px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.quote-detail-table th,
.quote-detail-table td {
  border: 1px solid #111;
  vertical-align: top;
}

.quote-detail-table th {
  height: 28px;
  text-align: center;
  font-weight: 500;
}

.quote-detail-table td {
  padding: 8px;
  text-align: center;
}

.quote-detail-table th:nth-child(1),
.quote-detail-table td:nth-child(1) {
  width: 38px;
}

.quote-detail-table th:nth-child(2),
.quote-detail-table td:nth-child(2) {
  width: 54px;
}

.quote-detail-table th:nth-child(3),
.quote-detail-table td:nth-child(3) {
  width: auto;
  text-align: left;
}

.quote-detail-table th:nth-child(4),
.quote-detail-table td:nth-child(4),
.quote-detail-table th:nth-child(5),
.quote-detail-table td:nth-child(5) {
  width: 34px;
}

.quote-detail-table th:nth-child(6),
.quote-detail-table td:nth-child(6),
.quote-detail-table th:nth-child(7),
.quote-detail-table td:nth-child(7) {
  width: 50px;
}

.quote-detail-table th:nth-child(8),
.quote-detail-table td:nth-child(8) {
  width: 64px;
}

.quote-item-cell {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.quote-line {
  min-height: 16px;
  text-align: left;
}

.quote-line-gap {
  min-height: 8px;
}

.quote-group {
  margin-top: 5px;
}

.quote-note {
  margin-top: 3px;
}

.quote-bottom-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 24px;
  align-items: start;
  margin-top: 12px;
}

.quote-payment {
  display: grid;
  gap: 10px;
  padding-left: 38px;
}

.quote-payment span {
  display: inline-block;
  min-width: 86px;
}

.quote-total-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.quote-total-table th,
.quote-total-table td {
  padding: 8px 6px;
  border-bottom: 1px solid #111;
  font-weight: 500;
}

.quote-total-table td {
  text-align: right;
}

.quote-terms {
  margin-top: 18px;
  padding-left: 8px;
  font-size: 11.5px;
  line-height: 1.55;
}

.quote-contact {
  margin-top: 10px !important;
}

.quote-sign-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 80px;
  margin-top: 48px;
  font-size: 14px;
}

.quote-sign-row span {
  display: inline-block;
  width: 210px;
  border-bottom: 1px solid #111;
}

.quote-page-num {
  margin-top: 72px;
  text-align: center;
  font-size: 12px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .summary {
    position: static;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .quote-meta,
  .selector-grid {
    grid-template-columns: 1fr;
  }

  .selector-panel + .selector-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .catalog-head {
    display: grid;
    align-items: start;
  }

  .item-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .condition-grid,
  .sub-options,
  .people-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .measurement-grid,
  .tile-area-row {
    grid-template-columns: 1fr;
  }

  .action-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pending-action-row {
    grid-template-columns: 1fr;
  }

  .subject-spec,
  .custom-material {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .quote-preview-toolbar {
    align-items: flex-start;
  }

  .quote-preview-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(100%, 360px);
  }

  .quote-preview-scroll {
    padding: 12px;
  }
}

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

  .selected-item {
    grid-template-columns: 1fr;
  }

  .qty-control {
    width: 140px;
  }
}

@media print {
  body,
  .quote-preview-modal,
  .quote-preview-shell,
  .quote-preview-scroll {
    display: block;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: #fff;
  }

  .app-shell,
  .quote-preview-toolbar {
    display: none !important;
  }

  .quote-preview-modal[hidden] {
    display: none !important;
  }

  .company-quote-paper {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 14mm 13mm 10mm;
    box-shadow: none;
  }
}
