/* ── CSS 變數（設計系統）────────────────────────── */
:root {
  --bg:           #f7f1e8;
  --surface:      #ffffff;
  --surface-warm: #fdf3e6;
  --ink:          #3a2e23;
  --ink-muted:    #7a6a5a;
  --border:       #ece1cd;
  --peach:        #e8a87c;
  --peach-deep:   #c97a5a;
  --sage:         #7d9b7c;
  --accent:       #B68A36;

  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   18px;
  --shadow-sm:   0 1px 4px rgba(58,46,35,0.08);
  --shadow-md:   0 4px 16px rgba(58,46,35,0.10);
  --transition:  0.2s ease;
}

/* ── 基礎重設 ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 30% 20%, #fdf3e6 0%, #f7f1e8 60%, #f0e8d8 100%);
  min-height: 100vh;
  line-height: 1.7;
}

h1, h2, h3, .brand {
  font-family: 'Noto Serif TC', serif;
}

input[type="number"] {
  font-variant-numeric: tabular-nums;
}

/* ── Layout ──────────────────────────────────── */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Topbar ──────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.topbar-nav {
  display: flex;
  gap: 16px;
  align-items: center;
}

.topbar-nav a {
  font-size: 0.88rem;
  color: var(--ink-muted);
  text-decoration: none;
  transition: color var(--transition);
}

.topbar-nav a:hover { color: var(--peach-deep); }

/* ── Step 進度條 ──────────────────────────────── */
.step-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 24px 24px 8px;
  max-width: 860px;
  margin: 0 auto;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
  position: relative;
  transition: background var(--transition), border-color var(--transition);
}

.step-item.active .step-dot {
  background: var(--peach);
  border-color: var(--peach);
  color: #fff;
}

.step-item.done .step-dot {
  background: var(--sage);
  border-color: var(--sage);
  color: #fff;
}

.step-label {
  font-size: 0.78rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.step-item.active .step-label { color: var(--ink); font-weight: 500; }

.step-connector {
  flex: 0 0 48px;
  height: 2px;
  background: var(--border);
  margin-bottom: 22px;
}

/* ── 卡片 ────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.card + .card { margin-top: 16px; }

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── 表單輸入 ─────────────────────────────────── */
.warm-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-warm);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.warm-input:focus {
  border-color: var(--peach);
  box-shadow: 0 0 0 3px rgba(232,168,124,0.18);
}

.warm-input:read-only {
  opacity: 0.65;
  cursor: not-allowed;
}

.warm-input.error {
  border-color: #c0392b;
  box-shadow: 0 0 0 3px rgba(192,57,43,0.12);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field-label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink);
}

.field-label .required { color: #c0392b; margin-left: 2px; }

.field-hint {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.field-error {
  font-size: 0.8rem;
  color: #c0392b;
  display: none;
}

.field-error.visible { display: block; }

.form-grid {
  display: grid;
  gap: 8px;
}

/* ── 按鈕 ────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 28px;
  background: var(--peach);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
}

.btn-primary:hover:not(:disabled) { background: var(--peach-deep); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  background: var(--surface);
  color: var(--ink-muted);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.btn-secondary:hover { background: var(--surface-warm); border-color: var(--peach); }

/* ── Tooltip ─────────────────────────────────── */
.tooltip-wrapper {
  position: relative;
  display: inline-flex;
}

.tooltip-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-warm);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 0.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.tooltip-body {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 200;
  pointer-events: none;
  max-width: 260px;
  white-space: normal;
}

.tooltip-wrapper:hover .tooltip-body,
.tooltip-wrapper:focus-within .tooltip-body {
  display: block;
}

/* ── 通知/提示區塊 ───────────────────────────── */
.notice {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  line-height: 1.6;
}

.notice-info { background: #e8f4fd; border-left: 3px solid #3498db; }
.notice-warn { background: #fef9e7; border-left: 3px solid var(--accent); }
.notice-success { background: #eafaf1; border-left: 3px solid var(--sage); }

/* ── Category Selector ────────────────────────── */
.category-selector {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.category-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.category-card:hover {
  border-color: var(--peach);
  background: var(--surface-warm);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.category-card.active {
  border-color: var(--peach);
  background: var(--surface-warm);
  box-shadow: 0 0 0 2px var(--peach);
}

.category-icon {
  font-size: 1.8rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 50%;
}

.category-info {
  flex: 1;
}

.category-title {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.category-desc {
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.4;
}

.category-tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  background: var(--border);
  border-radius: 4px;
  margin-top: 8px;
  color: var(--ink-muted);
}

/* Sub categories for 9A/9B */
.category-group {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-categories {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  padding-left: 16px;
  border-left: 2px solid var(--border);
  margin-left: 24px;
}

.category-group.expanded .sub-categories {
  max-height: 500px;
  margin-top: 8px;
  margin-bottom: 16px;
}

.category-group.expanded .expand-arrow {
  transform: rotate(180deg);
}

.expand-arrow {
  transition: transform 0.3s ease;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.sub-card {
  padding: 16px;
}

/* Help Section */
.help-section {
  margin-top: 32px;
}

.help-section details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.help-section summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 500;
  color: var(--ink-muted);
  outline: none;
}

.help-content {
  padding: 0 16px 16px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.help-content ul {
  padding-left: 20px;
}

.help-content li {
  margin-bottom: 8px;
}

.calc-results {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-top: 16px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.95rem;
  color: var(--ink-muted);
}

.calc-row.highlight {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-weight: 700;
  color: var(--ink);
  font-size: 1.1rem;
}

.calc-row.highlight span:last-child {
  color: var(--peach-deep);
}

/* ── ID Upload ───────────────────────────────── */
.upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface-warm);
}

.upload-dropzone:hover {
  border-color: var(--peach);
  background: var(--surface);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--ink-muted);
}

.upload-icon {
  font-size: 2rem;
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--ink-muted);
  max-width: 280px;
}

.btn-remove-img {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 24px;
  height: 24px;
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  box-shadow: var(--shadow-sm);
}

/* ── Preview & A4 ───────────────────────────── */
.preview-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.preview-container {
  display: flex;
  justify-content: center;
  overflow: auto;
  padding: 20px;
  background: #525659; /* PDF 預覽背景色 */
  border-radius: var(--radius-md);
  min-height: 600px;
}

.a4-page {
  width: 794px; /* A4 96dpi */
  height: 1123px;
  background: white;
  box-shadow: 0 0 20px rgba(0,0,0,0.3);
  padding: 60px;
  box-sizing: border-box;
  transform-origin: top center;
  color: #000;
}

.reward-form {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.form-header {
  text-align: center;
  margin-bottom: 30px;
  border-bottom: 2px solid #000;
  padding-bottom: 10px;
}

.form-header h1 {
  font-size: 2rem;
  letter-spacing: 0.5rem;
}

.form-meta {
  font-size: 0.9rem;
  margin-top: 8px;
}

.form-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.form-table th, .form-table td {
  border: 1px solid #000;
  padding: 8px 12px;
  text-align: left;
  font-size: 0.95rem;
}

.form-table th {
  background: #f5f5f5;
  width: 120px;
  font-weight: 600;
}

.table-title {
  background: #e0e0e0 !important;
  text-align: center !important;
  font-weight: 700;
}

.text-right { text-align: right !important; }
.font-bold { font-weight: 700; }

.highlight-row { background: #fffde7; }
.final-row { background: #f1f8e9; font-size: 1.1rem; }

.form-footer {
  margin-top: auto;
}

.sign-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 40px;
}

.sign-box {
  height: 150px;
  border: 1px dashed #ccc;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.sign-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sign-hint {
  color: #999;
  font-size: 0.8rem;
}

.notice-area {
  background: var(--surface-warm);
  border-left: 4px solid var(--peach);
  padding: 16px;
  border-radius: var(--radius-sm);
}

.footer-links {
  text-align: center;
  margin-top: 32px;
  color: var(--ink-muted);
}

/* ── Print Styles ────────────────────────────── */
@media print {
  body {
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .topbar,
  .step-bar,
  .preview-controls,
  .notice-area,
  .footer-links,
  .btn-primary,
  .btn-secondary {
    display: none !important;
  }

  .container {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .preview-container {
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    height: auto !important;
  }

  #previewArea {
    transform: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 20mm !important; /* 標準列印邊距 */
    width: 210mm !important;
    height: 297mm !important;
  }

  /* 移除身分證影像邊框 */
  #view-id-img {
    border: none !important;
  }
}

/* ── Section 切換 ────────────────────────────── */
.step-section { display: none; padding: 16px 0 40px; }
.step-section.active { display: block; }

/* ── @media print ────────────────────────────── */
@media print {
  .topbar,
  .step-bar,
  .btn-primary,
  .btn-secondary,
  .notice { display: none !important; }
}

/* ── RWD 手機（≤768px）──────────────────────── */
@media (max-width: 768px) {
  .container { padding: 0 16px; }

  .topbar-inner { padding: 10px 16px; }

  .step-bar { padding: 16px 16px 4px; gap: 0; }

  .step-connector { flex: 0 0 24px; }

  .step-label { font-size: 0.68rem; }

  .card { padding: 16px; }

  .btn-primary,
  .btn-secondary { width: 100%; }

  .topbar-nav { gap: 10px; }
}
