/* songyang-docs — Design System (Dark Theme, consistent with BOQ) */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117; --surface: #161b22; --surface2: #21262d; --surface3: #2d333b;
  --border: #30363d; --accent: #58a6ff; --accent2: #79c0ff;
  --orange: #f0883e; --green: #3fb950; --teal: #39d0c8; --purple: #a371f7; --red: #f85149;
  --text: #e6edf3; --text2: #8b949e; --text3: #6e7681;
  --radius: 14px; --radius-sm: 10px;
}

body {
  font-family: 'Sarabun', sans-serif; background: var(--bg); color: var(--text);
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 0; line-height: 1.5;
}

/* Password Gate */
.gate-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate-overlay.hidden { display: none; }
.gate-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 48px 36px; max-width: 420px; width: 100%; text-align: center; animation: fadeIn 0.5s ease; }
.gate-logo { font-size: 4rem; margin-bottom: 16px; filter: drop-shadow(0 0 24px rgba(88,166,255,0.5)); animation: float 3s ease-in-out infinite; }
.gate-card h1 { font-size: 1.8rem; font-weight: 800; background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 8px; }
.gate-card p { color: var(--text2); font-size: 0.95rem; margin-bottom: 28px; }
.gate-input { width: 100%; background: var(--surface2); border: 1.5px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: 'Sarabun', sans-serif; font-size: 1.1rem; font-weight: 600; padding: 14px 18px; outline: none; text-align: center; letter-spacing: 4px; transition: border-color 0.2s, box-shadow 0.2s; margin-bottom: 18px; }
.gate-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,0.15); }
.gate-input.error { border-color: var(--red); animation: shake 0.4s ease; }
.gate-btn { width: 100%; padding: 14px; border: none; border-radius: var(--radius-sm); background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-family: 'Sarabun', sans-serif; font-size: 1.05rem; font-weight: 800; cursor: pointer; box-shadow: 0 4px 18px rgba(88,166,255,0.35); transition: all 0.25s; }
.gate-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.gate-error { color: var(--red); font-size: 0.85rem; font-weight: 600; margin-top: 12px; min-height: 1.2em; }

/* Main App */
.app-container { display: none; width: 100%; max-width: 720px; padding: 24px 16px 60px; flex-direction: column; align-items: center; }
.app-container.visible { display: flex; animation: fadeIn 0.5s ease; }

/* Header */
header { text-align: center; margin-bottom: 28px; margin-top: 12px; width: 100%; }
.back-link { display: inline-block; color: var(--text2); font-size: 0.85rem; font-weight: 600; text-decoration: none; margin-bottom: 12px; padding: 6px 14px; border-radius: 8px; background: var(--surface2); border: 1px solid var(--border); transition: all 0.25s; }
.back-link:hover { color: var(--accent); border-color: var(--accent); }
header h1 { font-size: 2rem; font-weight: 800; background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; line-height: 1.5; }
header .subtitle { color: var(--text2); font-size: 1rem; margin-top: 6px; }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: 100%; margin-bottom: 20px; animation: fadeIn 0.3s ease; }
.card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; color: var(--text2); display: flex; align-items: center; gap: 8px; }
.card h2 span { font-size: 1.3em; }

/* Document Type Selector */
.doc-type-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.doc-type-option { cursor: pointer; }
.doc-type-option input { display: none; }
.doc-type-card { background: var(--surface2); border: 2px solid var(--border); border-radius: 12px; padding: 20px 12px; text-align: center; transition: all 0.25s ease; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.doc-type-card:hover { border-color: var(--accent); background: rgba(88,166,255,0.05); }
.doc-type-option input:checked + .doc-type-card { border-color: var(--accent); background: rgba(88,166,255,0.1); box-shadow: 0 4px 16px rgba(88,166,255,0.25); }
.doc-type-icon { font-size: 2rem; }
.doc-type-name { font-size: 0.88rem; font-weight: 700; color: var(--text); }

/* Form Fields */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.88rem; color: var(--text2); margin-bottom: 8px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; background: var(--surface2); border: 1.5px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: 'Sarabun', sans-serif; font-size: 1rem; font-weight: 600; padding: 13px 14px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; appearance: none; }
.field textarea { resize: vertical; min-height: 120px; line-height: 1.8; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,0.15); }
.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.input-wrap { position: relative; }
.unit-badge { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--accent); font-size: 0.85rem; font-weight: 700; pointer-events: none; }
.field-hint { font-size: 0.78rem; color: var(--text3); margin-top: 4px; }

/* Dynamic form sections */
.form-section { display: none; animation: fadeIn 0.3s ease; }
.form-section.active { display: block; }

/* Buttons */
.btn-primary { width: 100%; padding: 16px; border: none; border-radius: var(--radius); background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-family: 'Sarabun', sans-serif; font-size: 1.1rem; font-weight: 800; cursor: pointer; box-shadow: 0 4px 20px rgba(88,166,255,0.35); transition: all 0.25s; }
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { width: 100%; padding: 14px; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface2); color: var(--text2); font-family: 'Sarabun', sans-serif; font-size: 1rem; font-weight: 700; cursor: pointer; transition: all 0.25s; }
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }
.btn-green { background: linear-gradient(135deg, #2ea043, #3fb950); box-shadow: 0 4px 20px rgba(63,185,80,0.35); }
.btn-row { display: flex; gap: 12px; margin-top: 20px; }
.btn-row > * { flex: 1; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Document Preview Frame */
.preview-frame { background: #fff; border-radius: var(--radius); padding: 40px 48px; color: #111; overflow-x: auto; min-height: 400px; font-family: 'Sarabun', 'TH Sarabun New', sans-serif; font-size: 14px; line-height: 1.8; }

/* Document Styles (inside preview) */
.doc-page { max-width: 600px; margin: 0 auto; }
.doc-garuda { text-align: center; margin-bottom: 8px; }
.garuda-img { margin: 0 auto; display: block; object-fit: contain; }
/* Preview sizing (on-screen) */
.garuda-large { width: 90px; height: 90px; }
.garuda-small { width: 50px; height: 50px; }
.garuda-placeholder { width: 80px; height: 80px; margin: 0 auto; border: 2px dashed #ccc; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; color: #999; }
@media print {
  /* Per ระเบียบสำนักนายกรัฐมนตรีว่าด้วยงานสารบรรณ:
     - หนังสือภายนอก (ตราครุฑ) = 3 cm
     - บันทึกข้อความภายใน (ครุฑเล็ก) = 1.5 cm */
  .garuda-large { width: 3cm; height: 3cm; }
  .garuda-small { width: 1.5cm; height: 1.5cm; }
  .garuda-img { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.doc-header-line { text-align: center; border-bottom: 2px solid #333; padding-bottom: 8px; margin-bottom: 16px; }
.doc-header-title { font-size: 18px; font-weight: 800; }
.doc-info-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-info-table td { padding: 4px 8px; vertical-align: top; font-size: 14px; }
.doc-label { width: 120px; font-weight: 700; white-space: nowrap; }
.doc-right-align { text-align: right; font-size: 14px; margin-bottom: 2px; }
.doc-date-line { text-align: right; font-size: 14px; margin-bottom: 16px; }

/* Letter (หนังสือภายนอก) — 2-column header for ที่ + department block */
.doc-header-2col { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.doc-header-2col td { font-size: 14px; vertical-align: top; padding: 2px 0; }
.doc-header-left { width: 40%; }
.doc-header-right { text-align: right; }
.doc-header-right p { margin: 0; line-height: 1.6; }
.letter-closing { text-align: center; margin-bottom: 12px; font-size: 14px; }
.letter-signature { margin-top: 28px; text-align: center; }
.doc-contact-block { margin-top: 36px; font-size: 13px; line-height: 1.6; }
.doc-contact-block p { margin: 0; }

/* Memo — ที่ + วันที่ in one row */
.memo-info-table .memo-date-label { padding-left: 40px; }
.memo-info-table td:nth-child(2) { width: 35%; }
.doc-to-line { font-size: 14px; margin: 8px 0 4px; }
.memo-signature { margin-top: 28px; text-align: center; }

.doc-content { margin: 16px 0; }
.doc-para { text-indent: 0; margin-bottom: 8px; font-size: 14px; text-align: justify; }
.doc-indent { text-indent: 48px; }
.doc-signature { margin-top: 32px; text-align: center; }
.sig-block { display: inline-block; text-align: center; min-width: 200px; margin: 12px 20px; }
.sig-line { width: 180px; border-bottom: 1px dotted #333; margin: 40px auto 8px; }
.sig-row { text-align: center; margin-bottom: 16px; }
.sig-row-2 { display: flex; justify-content: center; gap: 40px; flex-wrap: wrap; }

/* Voucher table (ฎีกา) */
.voucher-table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.voucher-table th { background: #f0f0f0; padding: 8px; border: 1px solid #bbb; font-weight: 700; font-size: 12px; text-align: center; }
.voucher-table td { padding: 8px; border: 1px solid #bbb; font-size: 13px; vertical-align: top; }
.voucher-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.voucher-table .total-row td { font-weight: 800; background: #fafafa; }
.voucher-detail { font-size: 12px; color: #666; }

/* Footer */
footer { color: var(--text2); font-size: 0.82rem; text-align: center; margin-top: 12px; padding-bottom: 24px; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* Responsive */
@media (max-width: 480px) {
  header h1 { font-size: 1.5rem; }
  .input-grid { grid-template-columns: 1fr; }
  .doc-type-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 20px 16px; }
  .preview-frame { padding: 24px 16px; }
  .btn-row { flex-direction: column; }
  .sig-row-2 { flex-direction: column; align-items: center; }
}

/* Print */
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .gate-overlay, header, .btn-primary, .btn-secondary, .btn-row, footer, .card { display: none !important; }
  .preview-frame { border: none; padding: 0; }
}
