/* Design System & Root Variables */
:root {
  --bg-primary: #F4F5F0;
  --bg-secondary: #ffffff;
  --bg-input: #ffffff;
  --text-primary: #000080;
  --text-secondary: #000000;
  --accent-color: #000080;
  --accent-hover: #0000b3;
  --success-color: #10b981;
  --danger-color: #590016;
  --border-color: #ccd1d9;
  --font-sans: 'Inter', 'Noto Sans Thai', 'Noto Sans SC', sans-serif;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Global Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
}

/* Web Application Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-logo {
  height: 55px;
  width: auto;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-size: 24px;
  font-weight: 700;
  color: #000080;
  line-height: 1.1;
}

.logo-subtitle {
  font-size: 16px;
  font-weight: 500;
  color: #000000;
  line-height: 1.1;
  margin-top: 3px;
}

/* Language Selector */
.lang-selector {
  display: flex;
  gap: 0.5rem;
  background-color: var(--bg-primary);
  padding: 0.25rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
}

.lang-btn {
  background: transparent;
  border: none;
  padding: 0.35rem 0.65rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lang-btn.active, .lang-btn:hover {
  background-color: var(--accent-color);
}

.flag-icon {
  width: 24px;
  height: 16px;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  display: block;
}

/* Main Area Grid Layout */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.left-panel {
  width: 45%;
  min-width: 450px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  background-color: var(--bg-primary);
}

/* Storage Note Banner */
.storage-note {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background-color: rgba(89, 0, 22, 0.05);
  border-bottom: 1px solid rgba(89, 0, 22, 0.12);
  padding: 0.75rem 1.25rem;
  flex-shrink: 0;
}

.storage-note-icon {
  font-size: 1.1rem;
  color: var(--danger-color);
}

.storage-note-text {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--danger-color);
  line-height: 1.4;
}

.right-panel {
  width: 55%;
  background-color: #0f172a;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
}

/* Tabs Navigation */
.tabs {
  display: flex;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.85rem 0.5rem;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 2px solid transparent;
  text-align: center;
}

.tab-btn.active {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
  background-color: rgba(0, 0, 128, 0.05);
}

/* Form Inputs Panel */
.form-inputs-container {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  color: var(--accent-color);
}

.instruction-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="tel"],
.form-group input[type="email"] {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: #000000;
  padding: 0.6rem 0.8rem;
  border-radius: 0.375rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent-color);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--accent-color);
  color: white;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-input);
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

.btn-success:hover {
  filter: brightness(1.1);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.tab-nav-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Custom Checkbox Design */
.custom-checkbox-container {
  display: flex;
  position: relative;
  padding-left: 2rem;
  cursor: pointer;
  font-size: 0.875rem;
  user-select: none;
  color: var(--text-primary);
  line-height: 1.4;
}

.custom-checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 2px;
  left: 0;
  height: 1.25rem;
  width: 1.25rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  transition: all 0.2s;
}

.custom-checkbox-container:hover input ~ .checkmark {
  background-color: #475569;
}

.custom-checkbox-container input:checked ~ .checkmark {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.custom-checkbox-container input:checked ~ .checkmark:after {
  display: block;
}

.custom-checkbox-container .checkmark:after {
  left: 6px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.reason-block {
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: 0.5rem;
  background-color: var(--bg-secondary);
  transition: all 0.2s;
}

.reason-block:focus-within, .reason-block:hover {
  border-color: var(--accent-color);
}

/* Sub Options Container */
.sub-options {
  margin-top: 0.75rem;
  margin-left: 1rem;
  padding-left: 1rem;
  border-left: 2px solid var(--accent-color);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: slideDown 0.25s ease-out;
}

.sub-sub-options {
  margin-top: 0.5rem;
  padding-left: 1.5rem;
  display: flex;
  flex-direction: column;
  animation: slideDown 0.25s ease-out;
}

.sub-options-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-color);
}

.flex-col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; overflow: hidden; }
  to { opacity: 1; max-height: 500px; }
}

.hidden {
  display: none !important;
}

/* Radio Buttons UI */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.radio-container {
  display: flex;
  position: relative;
  padding-left: 1.75rem;
  cursor: pointer;
  font-size: 0.8rem;
  user-select: none;
  color: var(--text-secondary);
}

.radio-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.radio-mark {
  position: absolute;
  top: 2px;
  left: 0;
  height: 1rem;
  width: 1rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 50%;
}

.radio-container:hover input ~ .radio-mark {
  background-color: #475569;
}

.radio-container input:checked ~ .radio-mark {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
}

.radio-mark:after {
  content: "";
  position: absolute;
  display: none;
}

.radio-container input:checked ~ .radio-mark:after {
  display: block;
}

.radio-container .radio-mark:after {
  top: 3px;
  left: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: white;
}

/* Red Warning in UI */
.ui-warning-text {
  color: var(--danger-color);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
  margin-top: 0.25rem;
}

/* Checklist Cards */
.checklist-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.checklist-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.35rem;
}

.checklist-items {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.4;
  cursor: pointer;
}

.checklist-item input[type="checkbox"] {
  margin-top: 0.2rem;
  accent-color: var(--accent-color);
  cursor: pointer;
}

.card-important-note {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.375rem;
  background-color: rgba(89, 0, 22, 0.05);
  border-left: 3px solid var(--danger-color);
  font-size: 0.8rem;
  color: var(--danger-color);
  line-height: 1.4;
}

.screenshot-advice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background-color: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--success-color);
  padding: 1rem;
  border-radius: 0.5rem;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
}

.advice-icon {
  font-size: 1.5rem;
}

.advice-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: #6ee7b7;
}

/* Document Live Preview Panel (Right Side) */
.preview-header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.preview-header span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-page-outer {
  padding: 2rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  flex-grow: 1;
}

/* High Fidelity Paper Form */
.form-page {
  width: 210mm;
  min-height: 297mm;
  background-color: white;
  color: black;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  padding: 15mm 15mm;
  font-family: 'Inter', 'Noto Sans Thai', sans-serif;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Page styles when viewing inside the UI (scalable container) */
.right-panel {
  perspective: 1000px;
}

.form-page-outer {
  overflow-y: auto;
  max-height: calc(100vh - 120px);
}

/* Replicated PDF Styles */
.page-top-right {
  position: absolute;
  top: 10mm;
  right: 15mm;
  font-size: 14px;
  font-weight: bold;
}

.form-title-section {
  text-align: center;
  margin-top: 5mm;
}

.form-main-title {
  font-size: 11.5px;
  font-weight: bold;
  letter-spacing: 0.2px;
}

.form-sub-title {
  font-size: 12.5px;
  font-weight: normal;
  margin-top: 2px;
}

.form-row {
  display: flex;
  align-items: flex-end;
  font-size: 11px;
  margin-bottom: 4px;
}

.text-right {
  justify-content: flex-end;
}

.text-center {
  text-align: center;
}

.font-bold {
  font-weight: bold;
}

.align-center {
  align-items: center;
}

.flex-row {
  display: flex;
}

.label-hint {
  font-size: 9px;
  color: #333;
}

/* Blanks filled out dynamically */
.filled-field {
  border-bottom: 1px solid black;
  min-height: 16px;
  padding: 0 4px;
  margin: 0 3px;
  font-size: 11.5px;
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.form-divider {
  width: 100%;
  margin: 6px 0;
}

/* Custom visual checkbox on the paper preview */
.preview-checkbox {
  width: 12px;
  height: 12px;
  border: 1.5px solid black;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
  margin-top: 2px;
  flex-shrink: 0;
  position: relative;
  background-color: white;
}

.preview-checkbox.checked::after {
  content: "✔";
  font-size: 10px;
  font-weight: bold;
  position: absolute;
  top: -3px;
  left: 0.5px;
}

.preview-reason-row {
  display: flex;
  margin-bottom: 4px;
  align-items: flex-start;
}

.signature-section {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: 100%;
}

.signature-line-row {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  align-items: flex-end;
}

/* Media Printing Styles */
@media print {
  body, html {
    background-color: white !important;
    color: black !important;
    height: auto !important;
    overflow: visible !important;
  }

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

  .app-container {
    height: auto !important;
    display: block !important;
    overflow: visible !important;
  }

  .main-content {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .right-panel {
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    display: block !important;
    position: static !important;
  }

  .form-page-outer {
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    max-height: none !important;
    display: flex !important;
    justify-content: center !important;
    align-items: flex-start !important;
  }

  .form-page {
    width: 210mm !important;
    height: 297mm !important;
    box-shadow: none !important;
    padding: 15mm 15mm !important;
    margin: 0 !important;
    border: none !important;
    box-sizing: border-box !important;
  }

  @page {
    size: A4;
    margin: 0;
  }
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.25s ease-out;
}

.modal-overlay.hidden {
  display: none !important;
}

/* Modal Card */
.modal-card {
  background-color: #ffffff;
  border-radius: 1rem;
  width: 90%;
  max-width: 650px;
  max-height: 85vh;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1.5rem;
  text-align: center;
}

.modal-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.modal-header h2 {
  font-size: 1.5rem;
  color: var(--accent-color);
  font-weight: 700;
}

.modal-header p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.info-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.info-block h3 {
  font-size: 1rem;
  color: var(--accent-color);
  font-weight: 700;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.25rem;
}

.info-block p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Bullet list in summary modal */
.summary-doc-list {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.summary-doc-list li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
  background-color: #f8fafc;
}
