:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px -4px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans Thai', 'Inter', 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.print-only { display: none; }
.hidden-print-frame {
  position: fixed;
  width: 0;
  height: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.site-header {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-name {
  display: block;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.brand-tag {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.lang-switcher {
  display: inline-flex;
  background: var(--surface-alt);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.lang-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

/* Hero */
.main-content {
  padding-top: 28px;
  padding-bottom: 56px;
}

.hero {
  text-align: center;
  margin-bottom: 22px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 4vw, 2.05rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-sub {
  margin: 0 auto;
  max-width: 640px;
  color: var(--text-muted);
  font-size: 0.96rem;
}

/* Mode Tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.mode-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-tab:hover { border-color: #93c5fd; color: var(--text); }

.mode-tab.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.tab-icon { font-size: 1.15rem; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  background: #f8fafc;
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dropzone-icon { font-size: 2.3rem; margin-bottom: 6px; }
.dropzone-title { margin: 0 0 6px; font-weight: 700; font-size: 1.05rem; }
.dropzone-hint { margin: 0 0 16px; font-size: 0.85rem; color: var(--text-muted); }

/* Selected files list */
.selected-files {
  margin-top: 16px;
  padding: 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}

.selected-files-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.file-chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
}

.file-chip-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.file-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.file-chip-size {
  color: var(--text-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.file-chip-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.file-chip-remove:hover { background: var(--danger-soft); color: var(--danger); }

/* TTL selector */
.ttl-row {
  margin-top: 18px;
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ttl-label { font-weight: 600; font-size: 0.92rem; }

.ttl-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ttl-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ttl-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 700;
  font-size: 0.94rem;
  padding: 10px 18px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-lg { padding: 13px 22px; font-size: 1rem; }
.btn-sm { padding: 7px 12px; font-size: 0.84rem; }
.btn-block { width: 100%; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-danger-outline { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-ghost { background: var(--surface-alt); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: #e2e8f0; }

.btn-link {
  border: none;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}

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

/* Progress & Alerts */
.progress-wrap { margin-bottom: 16px; }
.progress-bar {
  height: 10px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s ease;
}
.progress-text {
  margin: 6px 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
  text-align: center;
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 14px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; }

/* Upload Result View */
.result-view { text-align: center; }

.result-badge {
  display: inline-block;
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #bbf7d0;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.result-instruction { margin: 0 0 14px; color: var(--text-muted); }

.pin-display-box {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--primary-soft);
  border: 2px solid #bfdbfe;
  border-radius: 16px;
  padding: 18px 34px;
  margin-bottom: 18px;
}

.pin-big {
  font-size: clamp(2.2rem, 8vw, 3.1rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.qr-wrap { margin-bottom: 16px; }
.qr-box {
  display: inline-block;
  background: #fff;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.qr-box svg { display: block; width: 148px; height: 148px; }
.qr-hint { margin: 6px 0 0; font-size: 0.84rem; color: var(--text-muted); }

.expiry-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #c2410c;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  margin-bottom: 16px;
}

.result-file-summary {
  list-style: none;
  padding: 0;
  margin: 0 auto 20px;
  max-width: 520px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-file-summary li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-alt);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* Receive PIN Form */
.pin-entry-view {
  text-align: center;
  padding: 16px 0;
}

.section-sm-title { margin: 0 0 16px; font-size: 1.15rem; }

.pin-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

.pin-input {
  width: 220px;
  text-align: center;
  font-family: inherit;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  padding: 11px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-variant-numeric: tabular-nums;
}

.pin-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }

/* Print Studio */
.studio-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.studio-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.pin-chip {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.expiry-chip {
  background: #fff7ed;
  color: #c2410c;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.86rem;
}

.studio-top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.studio-section { margin-bottom: 26px; }
.studio-section:last-child { margin-bottom: 0; }

.studio-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.studio-section-head h3 { margin: 0; font-size: 1.08rem; }

.print-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  background: var(--surface-alt);
  padding: 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.control-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.control-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: 0.88rem;
}

.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.img-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  transition: border-color 0.15s ease;
}

.img-card.selected { border-color: var(--primary); }

.img-thumb-wrap {
  position: relative;
  height: 170px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.img-thumb-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.img-card-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  gap: 6px;
}

.img-check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  min-width: 0;
  cursor: pointer;
}

.img-check-label span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.img-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 4px 7px;
  cursor: pointer;
  font-size: 0.85rem;
}

.icon-btn:hover { background: var(--surface-alt); }

/* Docs List */
.docs-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.doc-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.doc-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-alt);
}

.doc-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.doc-badge {
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.doc-badge.converted { background: #dcfce7; color: #15803d; }

.doc-name {
  font-weight: 600;
  font-size: 0.92rem;
  word-break: break-word;
}

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

.doc-preview-frame {
  width: 100%;
  height: 440px;
  border: 0;
  display: block;
  background: #e2e8f0;
}

/* Filter classes (preview & print) */
.filter-bw { filter: grayscale(100%) contrast(155%) brightness(108%); }
.filter-bright { filter: contrast(125%) brightness(112%); }

/* Ad Slot */
.ad-slot:empty { display: none; }
.ad-slot {
  margin: 26px 0;
  text-align: center;
  min-height: 90px;
}

/* Info & FAQ Sections */
.info-section { margin-top: 38px; }
.info-title {
  margin: 0 0 16px;
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.info-card h3 { margin: 0 0 6px; font-size: 1rem; }
.info-card p { margin: 0; font-size: 0.88rem; color: var(--text-muted); }

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.faq-item summary {
  font-weight: 700;
  font-size: 0.94rem;
  cursor: pointer;
}

.faq-item p {
  margin: 10px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.footer-links { display: flex; gap: 14px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; }
.modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 70;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

@media (max-width: 600px) {
  .card { padding: 16px; }
  .mode-tab { font-size: 0.85rem; padding: 11px 10px; }
  .doc-preview-frame { height: 320px; }
}

/* =========================================================
   PRINT STYLES — ONLY #print-sheet IS PRINTED ON A4 PAPER
   ========================================================= */
@media print {
  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .no-print { display: none !important; }
  .print-only { display: block !important; }

  .print-page {
    width: 100%;
    height: 98vh;
    page-break-after: always;
    break-after: page;
    display: grid;
    gap: 6mm;
    padding: 0;
    box-sizing: border-box;
    align-items: center;
    justify-items: center;
  }

  .print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .print-page.cols-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .print-page.cols-2 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .print-page.cols-2.landscape {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
  }

  .print-page.cols-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .print-cell {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .print-cell img {
    max-width: 100%;
    max-height: 100%;
    display: block;
  }

  .print-cell.fit-contain img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .print-cell.fit-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
