:root {
  color-scheme: light;
  --ink: #17231d;
  --muted: #68736d;
  --paper: #fff;
  --canvas: #f2f5f0;
  --line: #dce4de;
  --accent: #147957;
  --accent-dark: #0d543d;
  --accent-soft: #dcf2e7;
  --warm: #eb7047;
  --danger: #bd3b32;
  --shadow: 0 20px 60px rgba(24, 54, 39, .1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 4% 5%, rgba(255, 255, 255, .9), transparent 27rem),
    radial-gradient(circle at 96% 14%, rgba(193, 229, 211, .5), transparent 31rem),
    var(--canvas);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(20, 121, 87, .22);
  outline-offset: 2px;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 64px; }

.app-tabs {
  position: sticky;
  top: 12px;
  z-index: 30;
  width: max-content;
  display: flex;
  gap: 5px;
  margin: 0 auto 42px;
  padding: 5px;
  background: rgba(23, 35, 29, .94);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 16px;
  box-shadow: 0 12px 34px rgba(20, 38, 29, .18);
  backdrop-filter: blur(16px);
}
.app-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 17px;
  color: #b8c7bf;
  background: transparent;
  border: 0;
  border-radius: 11px;
  font-size: .85rem;
  font-weight: 850;
}
.app-tab:hover { color: #fff; }
.app-tab.is-active { color: var(--accent-dark); background: #fff; box-shadow: 0 4px 12px rgba(0, 0, 0, .15); }
.tab-icon { font: 900 1.05rem/1 ui-monospace, monospace; }
.tab-view[hidden] { display: none; }

.hero, .helper-hero { display: grid; grid-template-columns: 1fr auto; gap: 28px; align-items: end; margin-bottom: 30px; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: .76rem; font-weight: 900; letter-spacing: .2em; }
h1 { margin: 0; font-size: clamp(2.15rem, 6vw, 4.7rem); line-height: .98; letter-spacing: -.065em; }
.subtitle { max-width: 700px; margin: 16px 0 0; color: var(--muted); font-size: .95rem; line-height: 1.7; }
.summary, .contact-summary {
  min-width: 190px;
  padding: 20px 22px;
  color: #fff;
  background: var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.summary strong, .contact-summary strong { display: block; font: 800 2.3rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.06em; }
.summary span, .contact-summary span { display: block; margin-top: 7px; color: #b8c7bf; font-size: .75rem; font-weight: 700; letter-spacing: .08em; }

/* Historical records */
.control-panel { position: sticky; top: 78px; z-index: 20; padding: 18px; background: rgba(255, 255, 255, .9); border: 1px solid rgba(255, 255, 255, .95); border-radius: 24px; box-shadow: 0 12px 38px rgba(24, 54, 39, .09); backdrop-filter: blur(18px); }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; top: 50%; left: 17px; width: 20px; height: 20px; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
#history-search { width: 100%; height: 52px; padding: 0 50px 0 48px; color: var(--ink); background: #f5f7f4; border: 1px solid transparent; border-radius: 15px; outline: none; transition: border-color .16s ease, box-shadow .16s ease, background .16s ease; }
#history-search:focus { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(20, 121, 87, .1); }
#clear-history-search { position: absolute; top: 50%; right: 10px; width: 34px; height: 34px; display: none; place-items: center; padding: 0; color: var(--muted); background: transparent; border: 0; border-radius: 50%; transform: translateY(-50%); }
#clear-history-search:hover { background: var(--line); }
.filters { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(130px, .65fr) minmax(150px, .7fr) auto; gap: 10px; margin-top: 10px; }
select, .bulk-copy { min-width: 0; height: 44px; padding: 0 13px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 12px; font-size: .86rem; font-weight: 700; }
.results-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 26px 4px 16px; }
.results-bar p { margin: 0; color: var(--muted); font-size: .86rem; }
.results-bar strong { color: var(--ink); }
.active-query { max-width: 52%; overflow: hidden; color: var(--accent) !important; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.records { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.record-card { min-width: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--paper); border: 1px solid rgba(219, 228, 221, .9); border-radius: 21px; box-shadow: 0 12px 34px rgba(24, 54, 39, .055); animation: reveal .3s ease both; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 22px 22px 17px; }
.company { margin: 0; font-size: 1.25rem; line-height: 1.3; letter-spacing: -.025em; }
.source { margin: 6px 0 0; color: var(--muted); font-size: .73rem; line-height: 1.5; }
.quantity { flex: 0 0 auto; min-width: 66px; padding: 10px 9px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 14px; text-align: center; }
.quantity strong { display: block; font: 800 1.35rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.quantity small { display: block; margin-top: 5px; font-size: .66rem; font-weight: 800; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 22px; border-top: 1px solid var(--line); }
.field { min-width: 0; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.field:nth-child(odd) { padding-right: 16px; }
.field:nth-child(even) { padding-left: 16px; border-left: 1px solid var(--line); }
.field.wide { grid-column: 1/-1; padding-inline: 4px; border-left: 0; }
dt { margin: 0 0 5px; color: var(--muted); font-size: .69rem; font-weight: 800; letter-spacing: .08em; }
dd { min-height: 1.45em; margin: 0; font-size: .89rem; font-weight: 750; line-height: 1.5; overflow-wrap: anywhere; }
.missing { color: #b5bdb8; font-weight: 500; }
dd a { color: inherit; text-decoration: none; }
dd a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding: 17px 22px 21px; }
.history-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--warm); font-size: .7rem; font-weight: 900; letter-spacing: .06em; }
.history-badge::before { content: ""; width: 7px; height: 7px; background: var(--warm); border-radius: 50%; }
.copy-one { display: inline-flex; align-items: center; gap: 7px; padding: 9px 13px; color: var(--accent-dark); background: var(--accent-soft); border: 0; border-radius: 10px; font-size: .78rem; font-weight: 900; }
.copy-one:hover { color: #fff; background: var(--accent); }
.copy-one svg, .bulk-copy svg { width: 16px; height: 16px; }
.load-more { width: 100%; margin-top: 18px; padding: 14px 20px; color: var(--accent-dark); background: transparent; border: 1px solid #b8cec2; border-radius: 14px; font-weight: 850; }
.load-more:hover { background: var(--accent-soft); }
.empty { display: none; padding: 62px 20px; background: rgba(255, 255, 255, .75); border: 1px dashed #bdcbc3; border-radius: 20px; text-align: center; }
.empty strong { display: block; font-size: 1.2rem; }
.empty span { display: block; margin-top: 8px; color: var(--muted); font-size: .86rem; }

/* Dispatch helper */
.helper-grid { display: grid; grid-template-columns: minmax(0, 1.13fr) minmax(360px, .87fr); gap: 18px; align-items: start; }
.helper-column { display: grid; gap: 18px; min-width: 0; }
.output-column { position: sticky; top: 82px; }
.panel { background: rgba(255, 255, 255, .94); border: 1px solid rgba(219, 228, 221, .95); border-radius: 22px; box-shadow: 0 12px 36px rgba(24, 54, 39, .06); }
.upload-panel, .settings-panel, .output-panel { padding: 22px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.panel-heading > div { display: flex; align-items: center; gap: 10px; }
.panel-heading h2 { margin: 0; font-size: 1.04rem; letter-spacing: -.02em; }
.step { width: 27px; height: 27px; display: grid; place-items: center; color: var(--accent-dark); background: var(--accent-soft); border-radius: 50%; font: 800 .77rem/1 ui-monospace, monospace; }
.privacy-pill { padding: 6px 9px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 999px; font-size: .67rem; font-weight: 850; }
.upload-zone { min-height: 126px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; color: var(--muted); background: #f7f9f6; border: 2px dashed #bed0c6; border-radius: 16px; text-align: center; cursor: pointer; transition: border-color .15s ease, background .15s ease, transform .15s ease; }
.upload-zone:hover, .upload-zone.is-dragging { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); transform: translateY(-1px); }
.upload-zone svg { width: 27px; height: 27px; margin-bottom: 8px; }
.upload-zone strong { color: var(--accent); font-size: .9rem; }
.upload-zone span { margin-top: 5px; font-size: .72rem; }
.upload-status { margin-top: 12px; padding: 10px 12px; color: var(--muted); background: #f7f9f6; border-radius: 11px; font-size: .76rem; line-height: 1.5; }
.upload-status.success { color: var(--accent-dark); background: var(--accent-soft); }
.upload-status.error { color: var(--danger); background: #fff0ee; }
.text-button { margin-top: 10px; padding: 0; color: var(--danger); background: transparent; border: 0; font-size: .73rem; font-weight: 750; }
.form-grid { display: grid; grid-template-columns: 1fr 135px; gap: 12px; }
.field-group { position: relative; margin-bottom: 15px; }
.field-group > label { display: block; margin-bottom: 7px; color: #445149; font-size: .76rem; font-weight: 800; }
.field-group input, #bedding-count, #generated-text { width: 100%; color: var(--ink); background: #f8faf8; border: 1px solid var(--line); border-radius: 12px; outline: none; }
.field-group input, #bedding-count { height: 44px; padding: 0 12px; }
.field-group input:focus, #bedding-count:focus, #generated-text:focus { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(20, 121, 87, .08); }
.field-group input:disabled { color: #99a39d; cursor: not-allowed; }
#bedding-count { text-align: center; font-weight: 850; }
.suggestions { position: absolute; top: calc(100% - 9px); left: 0; right: 0; z-index: 25; max-height: 244px; overflow-y: auto; padding: 5px; background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 18px 44px rgba(24, 54, 39, .16); }
.suggestion { width: 100%; display: block; padding: 10px 11px; color: var(--ink); background: transparent; border: 0; border-radius: 9px; text-align: left; }
.suggestion:hover { background: var(--accent-soft); }
.suggestion strong { display: block; font-size: .82rem; }
.suggestion span { display: block; margin-top: 3px; color: var(--muted); font-size: .68rem; line-height: 1.35; }
.check-row { display: flex; align-items: center; gap: 9px; margin-top: 3px; color: #445149; font-size: .77rem; font-weight: 700; cursor: pointer; }
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); }
#generated-text { min-height: 156px; padding: 15px; resize: vertical; font-size: .9rem; font-weight: 650; line-height: 1.75; }
.output-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.primary-button, .secondary-button { min-height: 43px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border-radius: 11px; font-size: .8rem; font-weight: 850; }
.primary-button { color: #fff; background: var(--accent); border: 1px solid var(--accent); }
.primary-button:hover { background: var(--accent-dark); }
.secondary-button { color: var(--accent-dark); background: #fff; border: 1px solid #b8cec2; }
.secondary-button:hover { background: var(--accent-soft); }
.primary-button:disabled, .secondary-button:disabled { opacity: .46; cursor: not-allowed; }
.helper-history-panel { overflow: hidden; }
.helper-history-panel .panel-heading { margin: 0; padding: 17px 20px; background: #f8faf8; border-bottom: 1px solid var(--line); }
.history-mark { color: var(--accent); font-size: 1.1rem; font-weight: 900; }
.history-count { color: var(--muted); font-size: .7rem; font-weight: 750; }
.helper-history { max-height: 390px; overflow-y: auto; padding: 12px; }
.helper-history-empty { padding: 38px 12px; color: #98a29d; text-align: center; font-size: .76rem; }
.helper-history-item { position: relative; padding: 13px 78px 13px 13px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.helper-history-item + .helper-history-item { margin-top: 8px; }
.helper-history-item p { margin: 0; font-size: .73rem; line-height: 1.55; }
.helper-history-item time { display: block; margin-top: 6px; color: #98a29d; font-size: .63rem; }
.history-actions { position: absolute; top: 10px; right: 9px; display: flex; gap: 5px; }
.mini-button { padding: 6px 7px; color: var(--accent-dark); background: var(--accent-soft); border: 0; border-radius: 8px; font-size: .65rem; font-weight: 800; }
.mini-button.danger { color: var(--danger); background: #fff0ee; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; max-width: calc(100% - 32px); padding: 11px 17px; color: #fff; background: var(--ink); border-radius: 999px; box-shadow: 0 14px 35px rgba(0, 0, 0, .2); font-size: .83rem; font-weight: 800; opacity: 0; transform: translate(-50%, 14px); transition: opacity .18s ease, transform .18s ease; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 900px) {
  .helper-grid { grid-template-columns: 1fr; }
  .output-column { position: static; }
}
@media (max-width: 780px) {
  .app-shell { width: min(100% - 26px, 620px); padding-top: 14px; }
  .app-tabs { top: 8px; margin-bottom: 30px; }
  .hero, .helper-hero { grid-template-columns: 1fr; gap: 18px; align-items: start; }
  .summary, .contact-summary { min-width: 0; width: 100%; display: flex; align-items: baseline; gap: 12px; padding: 15px 18px; }
  .summary strong, .contact-summary strong { font-size: 1.8rem; }
  .summary span, .contact-summary span { margin: 0; }
  .control-panel { position: relative; top: auto; padding: 12px; border-radius: 18px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .bulk-copy { grid-column: 1/-1; }
  .records { grid-template-columns: 1fr; }
}
@media (max-width: 430px) {
  .app-shell { width: calc(100% - 20px); }
  .app-tabs { width: 100%; }
  .app-tab { flex: 1; justify-content: center; padding-inline: 9px; }
  .subtitle { font-size: .87rem; }
  .filters, .form-grid, .output-actions { grid-template-columns: 1fr; }
  .bulk-copy { grid-column: auto; }
  .results-bar { align-items: flex-start; flex-direction: column; gap: 6px; }
  .active-query { max-width: 100%; }
  .card-head, .card-actions { padding-inline: 17px; }
  .fields { margin-inline: 17px; }
  .upload-panel, .settings-panel, .output-panel { padding: 17px; }
  .privacy-pill { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
