:root {
  --bg: #f8f3ec;
  --surface: #ffffff;
  --surface-soft: #fff8ef;
  --text: #1f1d1b;
  --muted: #7b746c;
  --line: #e7d8c3;
  --accent: #d88b35;
  --accent-dark: #9f5b16;
  --blue: #164deb;
  --shadow: 0 18px 50px rgba(97, 66, 29, 0.12);
  font-family: "Microsoft JhengHei", "PingFang TC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, #fffaf5 0%, var(--bg) 100%);
  color: var(--text);
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(18px, 5vw, 72px);
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.site-header .ghost-button {
  flex: 0 0 auto;
}

.hamburger-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
}

.hamburger-button span {
  display: block;
  width: 20px;
  height: 2px;
  margin: 2px 0;
  background: var(--accent-dark);
}

.admin-menu {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  display: grid;
  width: min(320px, 86vw);
  height: 100vh;
  align-content: start;
  gap: 8px;
  padding: 22px;
  border-left: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
  visibility: hidden;
  pointer-events: none;
  transform: translateX(100%);
  transition: transform 0.24s ease;
}

.admin-menu.open {
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
}

.admin-menu-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--accent-dark);
  font-size: 20px;
  font-weight: 900;
}

.admin-menu-head strong {
  white-space: nowrap;
}

.admin-menu-head button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(31, 29, 27, 0.35);
  backdrop-filter: blur(2px);
}

.admin-menu button {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-weight: 800;
}

.admin-menu button:hover,
.admin-menu button.active {
  color: var(--accent-dark);
  background: var(--surface-soft);
}

body.menu-open {
  overflow: hidden;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-dark);
  font-size: 22px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
}

.top-nav {
  display: flex;
  gap: 10px;
}

.top-nav a {
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 700;
}

.top-nav a.active,
.top-nav a:hover {
  border-color: var(--line);
  color: var(--accent-dark);
  background: var(--surface-soft);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 64px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.hero h1,
.admin-sidebar h1,
.section-title h2,
.admin-toolbar h2 {
  margin: 0;
}

.hero h1 {
  font-size: clamp(34px, 6vw, 58px);
  letter-spacing: -0.04em;
}

.hero p {
  max-width: 760px;
  color: var(--muted);
  line-height: 1.8;
}

.hero-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.hero-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 28px;
}

.hero-card span,
.eyebrow,
.hint,
.empty-state {
  color: var(--muted);
}

.hero-card strong {
  margin-top: 8px;
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: 24px;
  align-items: start;
}

.panel {
  padding: clamp(20px, 3vw, 34px);
}

.section-title {
  margin-bottom: 20px;
}

.contract-document {
  color: #36312c;
  line-height: 1.9;
}

.contract-document h3 {
  margin-top: 0;
  color: #000;
  text-align: center;
  font-size: 28px;
  font-weight: 900;
}

.contract-summary {
  position: relative;
  margin: 22px 0 30px;
  padding: 26px 0;
  border-top: 2px solid #f29a4b;
  border-bottom: 2px solid #f29a4b;
}

.contract-summary::before,
.contract-summary::after {
  position: absolute;
  left: 0;
  width: 10px;
  height: 10px;
  background: #f29a4b;
  content: "";
  transform: translate(-1px, -50%) rotate(45deg);
}

.contract-summary::before {
  top: 0;
}

.contract-summary::after {
  top: 100%;
}

.contract-parties {
  margin-bottom: 26px;
}

.contract-summary h4 {
  margin-top: 0;
}

.contract-document li {
  margin-bottom: 8px;
}

.contract-note {
  margin-top: 28px;
  padding: 16px 18px;
  border-left: 4px solid #d7d0c8;
  border-radius: 14px;
  background: #f6f3ef;
  color: #827b73;
  font-size: 13px;
  line-height: 1.75;
}

.contract-note h4 {
  margin: 0 0 8px;
  color: #6f675f;
  font-size: 14px;
}

.contract-note p,
.contract-note ul {
  margin: 6px 0;
}

.success-page {
  display: grid;
  gap: 32px;
}

.success-card {
  position: relative;
  padding: clamp(28px, 5vw, 54px);
  border: 3px solid #fb9b4a;
  background: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.success-card::before,
.success-card::after {
  position: absolute;
  width: 30px;
  height: 30px;
  border-color: #fb9b4a;
  content: "";
}

.success-card::before {
  top: -3px;
  left: -3px;
  border-top: 7px solid;
  border-left: 7px solid;
}

.success-card::after {
  right: -3px;
  bottom: -3px;
  border-right: 7px solid;
  border-bottom: 7px solid;
}

.success-icon {
  display: grid;
  width: 88px;
  height: 88px;
  margin: 0 auto 22px;
  place-items: center;
  border: 8px solid #fb9b4a;
  border-radius: 50%;
  color: #fb9b4a;
  font-size: 42px;
  font-weight: 900;
}

.success-card h1 {
  margin: 0 0 8px;
  color: #000;
  font-size: clamp(34px, 6vw, 48px);
  font-weight: 900;
}

.success-subtitle,
.success-hint,
.success-footer {
  color: var(--muted);
}

.success-subtitle {
  margin: 0;
  font-size: 18px;
}

.success-divider {
  position: relative;
  height: 2px;
  margin: 34px 0;
  background: linear-gradient(90deg, #fb9b4a, rgba(251, 155, 74, 0.08), #fb9b4a);
}

.success-divider::before,
.success-divider::after {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  background: #fb9b4a;
  content: "";
  transform: translateY(-50%) rotate(45deg);
}

.success-divider::before {
  left: 0;
}

.success-divider::after {
  right: 0;
}

.success-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  text-align: left;
}

.success-info-card {
  display: grid;
  gap: 10px;
  min-height: 132px;
  align-content: center;
  padding: 24px;
  border-left: 5px solid #fb9b4a;
  background: #fffaf5;
}

.success-info-card span {
  color: var(--muted);
  font-weight: 800;
}

.success-info-card strong {
  color: #f28b35;
  font-size: 22px;
  font-weight: 900;
}

.success-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.success-footer {
  margin: 34px 0 0;
  padding-top: 26px;
  border-top: 2px solid #fb9b4a;
  font-size: 14px;
  line-height: 1.8;
}

.success-reminder {
  padding: 26px 30px;
  border-left: 5px solid #fb9b4a;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.success-reminder h2 {
  margin: 0 0 16px;
}

.success-reminder p {
  margin: 8px 0;
  color: var(--muted);
}

.contract-form {
  display: grid;
  gap: 16px;
}

.contract-form label:not(.agreement) {
  display: grid;
  gap: 8px;
  font-weight: 800;
}

.required-mark {
  color: #d62828;
  font-style: normal;
}

.contract-form input[type="text"],
.contract-form input[type="password"],
.contract-form input[type="date"],
.contract-form input[type="number"],
.admin-actions input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.contract-form input:focus,
.admin-actions input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(216, 139, 53, 0.16);
}

.contract-form input[readonly] {
  color: #5b5147;
  background: #f6efe5;
  cursor: not-allowed;
}

.signature-block {
  display: grid;
  gap: 10px;
}

.signature-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
}

.signature-open-button {
  width: 100%;
  padding: 14px 18px;
  border: 2px dashed #d7b989;
  border-radius: 18px;
  background: #fffdf9;
  color: var(--accent-dark);
  font-weight: 800;
  cursor: pointer;
}

.signature-open-button:hover {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.signature-status {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.signature-status.is-complete {
  color: #2f7a3d;
  font-weight: 700;
}

.signature-preview-wrap {
  display: grid;
  gap: 10px;
}

.signature-preview-image {
  width: 100%;
  min-height: 120px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.signature-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
}

.signature-modal.is-hidden {
  display: none;
}

.signature-modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(31, 29, 27, 0.55);
  cursor: pointer;
}

.signature-modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 20px;
  border-radius: 22px;
  background: #fff;
  box-shadow: var(--shadow);
}

.signature-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.signature-modal-header h3 {
  margin: 0;
}

.signature-modal-close {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.signature-modal-message {
  margin: 0;
  min-height: 1.4em;
  font-size: 14px;
  color: var(--muted);
}

.signature-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.signature-modal-actions .primary-button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

body.signature-modal-open {
  overflow: hidden;
}

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

canvas {
  width: 100%;
  height: 190px;
  border: 2px dashed #d7b989;
  border-radius: 18px;
  background:
    linear-gradient(transparent 78%, rgba(216, 139, 53, 0.12) 78%),
    #fffdf9;
  touch-action: none;
}

#signatureModalCanvas {
  height: min(52vh, 320px);
}

.hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
}

.agreement {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
  color: #3a342e;
  line-height: 1.7;
}

.agreement input {
  width: 20px;
  height: 20px;
  margin-top: 3px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 12px 28px rgba(22, 77, 235, 0.22);
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--accent-dark);
  background: #fff;
}

.small-button {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.danger-button {
  color: #b42318;
}

.form-message {
  min-height: 24px;
  margin: 0;
  color: var(--accent-dark);
  font-weight: 800;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 420px);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 28px;
  color: var(--accent-dark);
  text-align: center;
  font-size: 30px;
  font-weight: 900;
}

.admin-layout {
  display: block;
}

.admin-main {
  display: grid;
  gap: 22px;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.admin-toolbar.compact {
  margin-bottom: 16px;
}

.admin-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.admin-actions input {
  width: min(420px, 42vw);
}

.page-size-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.page-size-control select {
  min-width: 96px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.admin-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 22px;
  align-items: start;
}

.admin-user-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  padding: 16px 18px;
  border-bottom: 1px solid #f0e5d6;
  text-align: left;
  white-space: nowrap;
}

th {
  color: #3f3225;
  background: #fff8ef;
  font-size: 14px;
}

td {
  color: #3b3631;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--accent-dark);
  cursor: pointer;
}

.icon-button[data-download] {
  width: auto;
  min-width: 46px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

.empty-state {
  display: none;
  margin: 0;
  padding: 24px;
  text-align: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  color: var(--muted);
  font-size: 14px;
}

.page-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.page-button {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 800;
}

.page-button.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.detail-panel {
  border-radius: 0;
  border-top: 4px solid var(--accent);
}

.contract-detail {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.detail-item {
  display: grid;
  gap: 4px;
}

.detail-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-item strong {
  font-size: 16px;
}

.signature-preview {
  width: 100%;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  object-fit: contain;
}

.admin-contract-preview {
  max-height: 420px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf9;
  color: #36312c;
  font-size: 13px;
  line-height: 1.75;
}

.admin-contract-preview h3 {
  margin-top: 0;
  text-align: center;
  font-size: 18px;
}

.admin-contract-preview .contract-summary {
  margin: 14px 0 18px;
  padding: 14px 0;
}

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

.member-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fffdf9;
}

.member-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 18px;
}

.member-card span {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  margin-top: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: #f6dfc0;
  font-size: 12px;
  font-weight: 800;
}

@media (max-width: 980px) {
  .hero,
  .page-grid,
  .admin-content,
  .admin-user-grid,
  .success-info-grid,
  .success-actions {
    grid-template-columns: 1fr;
  }

  .admin-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .admin-actions input {
    width: 100%;
  }

  .member-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .admin-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-header {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
  }

  .top-nav {
    width: 100%;
  }

  .top-nav a {
    flex: 1;
    text-align: center;
  }

  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .panel {
    padding: 20px;
  }
}
