:root {
  --paper: #fffaf0;
  --surface: #ffffff;
  --ink: #25211b;
  --muted: #6d6256;
  --line: #ded4c4;
  --gold: #b88918;
  --red: #9d1b2f;
  --green: #12634e;
  --focus: #1f6f8b;
  --shadow: 0 12px 34px rgba(64, 45, 18, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Microsoft JhengHei", "PingFang TC", Arial, sans-serif;
  line-height: 1.55;
}

.site-header {
  padding: 24px clamp(18px, 4vw, 48px) 18px;
  background: linear-gradient(180deg, #fff7df, #fffaf0);
  border-bottom: 1px solid var(--line);
}

.brand-strip {
  display: grid;
  grid-template-columns: 86px minmax(0, 560px);
  gap: 20px;
  align-items: center;
  max-width: 1180px;
  margin: 0 auto;
}

.seal-logo {
  width: 76px;
  height: 76px;
  object-fit: contain;
}

.word-logo {
  width: min(100%, 560px);
  height: 92px;
  object-fit: contain;
  object-position: left center;
  mix-blend-mode: multiply;
}

.header-copy {
  max-width: 1180px;
  margin: 18px auto 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
}

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

h1 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.24rem;
}

.header-copy p:last-child {
  max-width: 760px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 22px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 32px) 48px;
}

.side-panel {
  position: sticky;
  top: 12px;
  align-self: start;
  display: grid;
  gap: 14px;
}

.tool-section,
.form-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-section {
  padding: 16px;
}

.tool-section h2 {
  margin-bottom: 12px;
  font-size: 1rem;
}

label,
legend {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fffefb;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(31, 111, 139, 0.14);
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf8;
  color: var(--ink);
  cursor: pointer;
  min-height: 40px;
}

button:hover {
  border-color: var(--gold);
}

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

.danger {
  color: var(--red);
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 8px;
}

.full-btn {
  width: 100%;
  margin-top: 8px;
}

.small-btn {
  padding: 0 14px;
  font-weight: 700;
}

.icon-btn {
  width: 34px;
  min-height: 34px;
  color: var(--red);
  font-size: 1.1rem;
  line-height: 1;
}

.status-text {
  min-height: 38px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.summary-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.summary-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #eee6da;
}

.summary-list div:last-child {
  border-bottom: 0;
}

.summary-list dt,
.summary-list dd {
  margin: 0;
}

.summary-list dd {
  font-weight: 800;
  color: var(--green);
}

.form-shell {
  display: grid;
  gap: 18px;
}

.form-section {
  padding: clamp(16px, 3vw, 24px);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.required-note {
  color: var(--red);
  font-weight: 700;
  white-space: nowrap;
}

.field-grid {
  display: grid;
  gap: 14px;
}

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

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.full-field {
  display: block;
  margin-top: 14px;
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  margin: 16px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.choice-group label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
}

.choice-group input {
  width: auto;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th {
  background: #f8f1e3;
  color: #4d3d2b;
  text-align: left;
  font-size: 0.88rem;
}

th,
td {
  padding: 8px;
  border: 1px solid var(--line);
  vertical-align: top;
}

td input,
td select {
  margin: 0;
}

.print-preview {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: #fffefb;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.print-preview h3 {
  margin: 0 0 6px;
}

.print-preview p {
  margin: 0;
}

.preview-table {
  width: 100%;
  min-width: 0;
  font-size: 0.92rem;
}

.mobile-action-bar {
  display: none;
}

.mobile-action-bar button {
  width: 100%;
}

.submit-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 16px;
  color: #fff;
  background: var(--green);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(18, 99, 78, 0.24);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.submit-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.submit-toast[data-type="pending"] {
  background: var(--gold);
}

.submit-toast[data-type="warning"] {
  background: var(--red);
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(220px, 280px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 32px) 48px;
}

.admin-header h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.admin-search-panel,
.admin-actions-panel {
  align-self: start;
}

.admin-result-panel {
  grid-row: span 2;
}

.admin-lookup {
  grid-template-columns: minmax(0, 1fr) 88px;
}

.admin-link {
  display: block;
  margin-top: 14px;
  color: var(--green);
  font-weight: 800;
  text-decoration: none;
}

.admin-link:hover {
  text-decoration: underline;
}

.admin-result {
  display: grid;
  gap: 18px;
}

.admin-result.empty-state {
  min-height: 220px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.admin-result h2,
.admin-result h3 {
  margin: 0 0 8px;
}

.admin-result p {
  margin: 0;
}

.admin-print-head {
  padding-bottom: 12px;
  border-bottom: 2px solid var(--line);
}

.admin-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 20px;
}

@media (max-width: 920px) {
  body {
    padding-bottom: 86px;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px 12px 28px;
  }

  .side-panel {
    order: 2;
    position: static;
  }

  .form-shell {
    order: 1;
    gap: 14px;
  }

  .brand-strip {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 12px;
  }

  .seal-logo {
    width: 58px;
    height: 58px;
  }

  .word-logo {
    height: 66px;
  }

  .field-grid.two,
  .field-grid.three {
    grid-template-columns: 1fr;
  }

  .site-header {
    padding: 18px 14px 14px;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.12rem;
  }

  .header-copy p:last-child {
    font-size: 0.94rem;
  }

  .form-section,
  .tool-section {
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(64, 45, 18, 0.1);
  }

  .section-heading {
    align-items: flex-start;
    margin-bottom: 14px;
  }

  .small-btn {
    min-width: 112px;
    min-height: 44px;
  }

  input,
  select,
  textarea,
  button {
    font-size: 16px;
  }

  input,
  select,
  textarea {
    min-height: 46px;
    padding: 11px 12px;
  }

  .choice-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .choice-group label {
    min-height: 44px;
  }

  .table-wrap {
    overflow: visible;
  }

  .table-wrap table:not(.preview-table) {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 12px;
  }

  .table-wrap table:not(.preview-table) thead {
    display: none;
  }

  .table-wrap table:not(.preview-table) tbody,
  .table-wrap table:not(.preview-table) tr,
  .table-wrap table:not(.preview-table) td {
    display: block;
    width: 100%;
  }

  .table-wrap table:not(.preview-table) tr {
    padding: 12px;
    background: #fffefb;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .table-wrap table:not(.preview-table) td {
    padding: 0;
    border: 0;
  }

  .table-wrap table:not(.preview-table) td + td {
    margin-top: 10px;
  }

  .table-wrap table:not(.preview-table) td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
  }

  .table-wrap table:not(.preview-table) td[data-label="操作"] {
    display: flex;
    justify-content: flex-end;
  }

  .table-wrap table:not(.preview-table) td[data-label="操作"]::before {
    display: none;
  }

  .icon-btn {
    width: 44px;
    min-height: 44px;
  }

  .mobile-action-bar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: block;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 250, 240, 0.96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(64, 45, 18, 0.14);
  }

  .mobile-action-bar button {
    min-height: 52px;
    font-weight: 800;
  }

  .submit-toast {
    right: 12px;
    bottom: 78px;
    left: 12px;
    max-width: none;
    text-align: center;
  }

  .admin-layout {
    grid-template-columns: 1fr;
    padding: 16px 12px 28px;
  }

  .admin-result-panel {
    grid-row: auto;
  }

  .admin-totals {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .site-header,
  .side-panel,
  .admin-search-panel,
  .admin-actions-panel,
  .form-section:not(.print-section) {
    display: none;
  }

  .layout,
  .admin-layout {
    display: block;
    padding: 0;
  }

  .form-section {
    border: 0;
    box-shadow: none;
  }
}
