:root {
  color-scheme: light;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --ink: #17211d;
  --muted: #63716b;
  --line: #d9e0dc;
  --surface: #ffffff;
  --surface-soft: #f5f7f5;
  --green: #175c47;
  --green-dark: #0f4636;
  --green-soft: #e6f1ec;
  --warning: #9a5a0b;
  --shadow: 0 14px 36px rgba(32, 54, 45, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: #eef2ef;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(20px, 4vw, 60px);
  color: #fff;
  background: var(--green-dark);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.5rem, 3vw, 2rem); }
h2 { margin-bottom: 0; font-size: 1.35rem; }
h3 { margin-bottom: 0; }

.eyebrow {
  margin-bottom: 4px;
  color: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.74;
}

.header-actions, .paste-help, .editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-badge {
  padding: 7px 10px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  font-size: .82rem;
}

main {
  display: grid;
  gap: 22px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 30px clamp(16px, 3vw, 34px) 60px;
}

.panel {
  padding: clamp(20px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.section-heading > p {
  max-width: 540px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: .9rem;
  text-align: right;
}

.quote-list { display: grid; gap: 10px; }
.quote-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.quote-card time, .quote-card span, .item-summary { color: var(--muted); font-size: .82rem; }
.quote-card h3 { margin: 3px 0; font-size: 1rem; }
.item-summary { margin-bottom: 0; }
.quote-card-side { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.quote-card-side strong { color: var(--green-dark); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 700;
  text-decoration: none;
}
.button-primary { border: 1px solid var(--green); color: #fff; background: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border: 1px solid #a9bbb3; color: var(--green-dark); background: #fff; }
.button-quiet { border: 1px solid rgba(255,255,255,.35); color: #fff; background: transparent; }
.button-ai-disabled { margin-top: 12px; border: 1px solid #d7c8b3; color: #704d1e; background: #fff8ed; }

.testing-banner {
  padding: 12px 16px;
  border: 1px solid #d7c8b3;
  border-radius: 12px;
  color: #704d1e;
  background: #fff8ed;
  font-size: .86rem;
}

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background: #eef2ef;
}
.login-card {
  width: min(420px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}
.login-card .eyebrow { color: var(--green-dark); }
.login-card h1 { color: var(--green-dark); }
.login-card [role="alert"] { color: #a12f25; }
.test-warning { margin: 12px 0 22px; color: #704d1e; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 7px; font-size: .88rem; font-weight: 700; }
.login-form input { min-height: 44px; padding: 8px 10px; border: 1px solid #b9c5bf; border-radius: 8px; }
.login-form button { min-height: 44px; border: 0; border-radius: 9px; color: #fff; background: var(--green); font-weight: 700; }

.input-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, .8fr);
  gap: 22px;
}

.field-label { display: block; margin-bottom: 7px; font-size: .88rem; font-weight: 700; }
textarea, input[type="text"], input[type="date"], input[type="email"], input[type="tel"], .items-table input {
  width: 100%;
  border: 1px solid #b9c5bf;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}
textarea { min-height: 210px; padding: 13px; resize: vertical; line-height: 1.55; }
input[type="text"], input[type="date"], input[type="email"], input[type="tel"] { min-height: 42px; padding: 8px 10px; }
textarea:focus, input:focus { outline: 3px solid rgba(23, 92, 71, .15); border-color: var(--green); }

.paste-help { margin-top: 12px; color: var(--muted); font-size: .86rem; }
kbd { padding: 2px 6px; border: 1px solid #bdc7c2; border-bottom-width: 2px; border-radius: 5px; background: #fff; }
.field-note { margin: 10px 0 0; color: var(--muted); font-size: .78rem; }
.input-message { min-height: 24px; margin-top: 8px; font-size: .82rem; }
.input-message[data-state="success"] { color: var(--green); }
.input-message[data-state="warning"] { color: var(--warning); }

.preview-panel {
  min-height: 296px;
  padding: 14px;
  border: 1px dashed #adbbb4;
  border-radius: 12px;
  background: var(--surface-soft);
}
.preview-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.preview-heading h3 { font-size: .95rem; }
.preview-heading span { color: var(--muted); font-size: .8rem; }
.empty-state { display: grid; place-items: center; align-content: center; min-height: 220px; color: var(--muted); }
.empty-state[hidden] { display: none; }
.empty-icon { font-size: 2rem; }
.empty-state p { margin: 6px 0 0; }
.image-previews { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.image-card { position: relative; margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.image-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #eef1ef; }
.image-card figcaption { display: grid; padding: 8px; font-size: .72rem; }
.image-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.image-size { color: var(--muted); }
.remove-image { position: absolute; top: 6px; right: 6px; padding: 5px 8px; border: 0; border-radius: 7px; color: #fff; background: rgba(23, 33, 29, .78); font-size: .72rem; }

.form-divider { height: 1px; margin: 28px 0; background: var(--line); }
.quote-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.field-company { grid-column: span 2; }
.field-address { grid-column: span 2; }
.customer-check, .items-heading, .items-table-wrapper, .editor-actions { grid-column: 1 / -1; }
.customer-check {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid #b7c8c0;
  border-radius: 12px;
  background: var(--green-soft);
}
.customer-check-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.customer-check-heading h3 { font-size: 1rem; }
.customer-check-heading p { margin: 4px 0 0; color: var(--muted); font-size: .8rem; }
.customer-check-status { margin: 0; color: var(--muted); font-size: .86rem; }
.customer-check-status[data-state="success"] { color: var(--green-dark); }
.customer-check-status[data-state="warning"] { color: #7a4206; font-weight: 700; }
.customer-candidates { display: grid; gap: 8px; }
.customer-candidates[hidden], .confirm-different[hidden] { display: none; }
.customer-candidate {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid #bdcac4;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.customer-candidate:has(input:checked) { border-color: var(--green); box-shadow: 0 0 0 2px rgba(23, 92, 71, .12); }
.customer-candidate input { margin-top: 3px; }
.customer-candidate-content { display: grid; gap: 4px; }
.customer-candidate-heading { display: flex; align-items: center; gap: 8px; }
.customer-candidate-metadata, .customer-candidate-reasons { color: var(--muted); font-size: .8rem; }
.match-badge { padding: 2px 7px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.match-badge-high { color: #7a4206; background: #fff1d9; }
.match-badge-medium { color: #175c47; background: #e6f1ec; }
.match-badge-low { color: #53615b; background: #edf1ef; }
.customer-candidate-empty { margin: 0; color: var(--muted); font-size: .84rem; }
.confirm-different { display: flex; align-items: center; gap: 8px; font-size: .84rem; font-weight: 700; }
.items-heading { display: flex; align-items: center; justify-content: space-between; }
.items-heading h3 { font-size: 1rem; }
.items-heading span { color: var(--muted); font-size: .8rem; }
.items-table-wrapper { overflow-x: auto; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { padding: 8px; color: var(--muted); background: var(--surface-soft); font-size: .78rem; text-align: left; }
.items-table td { padding: 5px; border-bottom: 1px solid var(--line); }
.items-table input { min-width: 90px; padding: 8px; }
.items-table th:nth-child(1), .items-table th:nth-child(2) { min-width: 170px; }
.items-table th:nth-child(6) { min-width: 90px; text-align: right; }
.line-total { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; white-space: nowrap; }
.remove-row { border: 0; color: #8b382e; background: transparent; font-size: .78rem; }
.editor-actions { justify-content: space-between; margin-top: 4px; }
.copy-status { margin: 0; color: var(--green); font-size: .86rem; }
.total-actions { display: flex; align-items: center; gap: 18px; margin-left: auto; }
.quote-total { margin: 0; color: var(--muted); font-size: .82rem; }
.quote-total strong { display: block; color: var(--green-dark); font-size: 1.15rem; }

@media (max-width: 800px) {
  .site-header, .section-heading, .quote-card { align-items: stretch; flex-direction: column; }
  .header-actions, .quote-card-side { justify-content: space-between; }
  .section-heading > p { text-align: left; }
  .input-grid, .quote-form { grid-template-columns: 1fr; }
  .quote-form > * { grid-column: 1; }
  .customer-check-heading { align-items: stretch; flex-direction: column; }
  .editor-actions, .total-actions { align-items: stretch; flex-direction: column; }
}
