/* ============================================================================
   PW SMART PLC — Clean & Accessible Design System (v3.0)
   โรงเรียนปทุมวิไล (Pathumwilai School)
   ปรับปรุงตามข้อกำหนด PLC_DEVELOPMENT_REVIEW.md:
   - ฟอนต์พื้นฐาน 16px (1rem) อ่านง่าย สบายตาสำหรับภาษาไทย
   - พื้นหลังสว่างสบายตา ลดเงาซ้อนและกรอบซ้อนที่ไม่จำเป็น
   - ปุ่มกดขนาดไม่น้อยกว่า 44x44px พร้อมกรอบ Focus สำหรับคีย์บอร์ด
   - รองรับหน้าจอมือถือ 360px แบบคอลัมน์เดียว
   - แก้ปัญหา @media print ตัดข้อความด้วย overflow: hidden (D15)
   ============================================================================ */

:root {
  --primary: #1e3a8a;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --border-subtle: #e2e8f0;
  --text-main: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --status-success-bg: #ecfdf5;
  --status-success-text: #065f46;
  --status-success-border: #a7f3d0;
  --status-warn-bg: #fffbeb;
  --status-warn-text: #92400e;
  --status-warn-border: #fde68a;
  --status-danger-bg: #fef2f2;
  --status-danger-text: #991b1b;
  --status-danger-border: #fecaca;
  --status-info-bg: #eff6ff;
  --status-info-text: #1e40af;
  --status-info-border: #bfdbfe;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1rem;
  line-height: 1.65;
  background-color: var(--bg-page);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

/* Keyboard Accessibility & Focus States (Section 3.7) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #2563eb !important;
  outline-offset: 2px !important;
}

/* Minimum Touch Target 44x44px (Section 3.7) */
.touch-target,
.btn-primary,
.btn-secondary,
.btn-danger,
.nav-menu-btn {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Form Elements (Section 3.5 & 3.7) */
.form-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.form-hint {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  font-size: 1rem;
  line-height: 1.5;
  padding: 0.625rem 0.875rem;
  border-radius: 0.625rem;
  border: 1.5px solid #cbd5e1;
  background-color: #ffffff;
  color: var(--text-main);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-input.input-error,
.form-select.input-error,
.form-textarea.input-error {
  border-color: #dc2626 !important;
  background-color: #fef2f2;
}

.field-error-msg {
  color: #dc2626;
  font-size: 0.875rem;
  font-weight: 600;
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Status Badges with Icon + Text (Section 3.1) */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.4;
  border: 1px solid transparent;
}
.status-badge-success {
  background-color: var(--status-success-bg);
  color: var(--status-success-text);
  border-color: var(--status-success-border);
}
.status-badge-warn {
  background-color: var(--status-warn-bg);
  color: var(--status-warn-text);
  border-color: var(--status-warn-border);
}
.status-badge-danger {
  background-color: var(--status-danger-bg);
  color: var(--status-danger-text);
  border-color: var(--status-danger-border);
}
.status-badge-info {
  background-color: var(--status-info-bg);
  color: var(--status-info-text);
  border-color: var(--status-info-border);
}
.status-badge-neutral {
  background-color: #f1f5f9;
  color: #475569;
  border-color: #cbd5e1;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

/* ============================================================================
   A4 Booklet Preview & Print Layout (Fixes D15)
   ============================================================================ */
.a4-page {
  width: 210mm;
  min-height: 297mm;
  padding: 16mm 18mm;
  margin: 0 auto 24px auto;
  background: #ffffff;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  border: 1px solid #cbd5e1;
  position: relative;
  box-sizing: border-box;
  font-family: 'Sarabun', sans-serif;
  color: #0f172a;
  line-height: 1.55;
  overflow: visible;
}

.a4-page.page-overflow-warning {
  border: 2px dashed #d97706;
}

.a4-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-32deg);
  font-size: 3.5rem;
  font-weight: 800;
  color: rgba(30, 58, 138, 0.035);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

.a4-content {
  position: relative;
  z-index: 1;
}

.a4-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.a4-table th,
.a4-table td {
  border: 1px solid #334155;
  padding: 5px 8px;
  vertical-align: top;
}

.a4-table th {
  background-color: #f1f5f9;
  font-weight: 700;
  text-align: center;
}

.a4-table tr {
  break-inside: avoid;
  page-break-inside: avoid;
}

.sig-box {
  border: 1px dashed #64748b;
  background-color: #f8fafc;
  border-radius: 6px;
  padding: 8px 10px;
  text-align: center;
  min-height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  break-inside: avoid;
  page-break-inside: avoid;
}

.sig-box.signed {
  border: 1px solid #059669;
  background-color: #ecfdf5;
}

.handwriting-sig {
  font-family: 'Charm', 'Sarabun', cursive;
  font-size: 1.15rem;
  color: #1e3a8a;
  transform: rotate(-1.5deg);
  display: inline-block;
}

/* Sticky Action Bar for Forms */
.sticky-form-footer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--border-subtle);
  padding: 0.875rem 1.25rem;
}

/* Mobile Responsive Adjustments (360px and up - Section 3.7) */
@media (max-width: 768px) {
  html {
    font-size: 15.5px;
  }

  .a4-preview-wrapper {
    overflow-x: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .a4-page {
    width: 100%;
    min-width: 320px;
    min-height: auto;
    padding: 16px;
    margin-bottom: 16px;
  }

  .mobile-single-col {
    grid-template-columns: 1fr !important;
  }

  .sticky-form-footer {
    padding: 0.75rem 1rem;
  }
}

/* ============================================================================
   Print Stylesheet (Fixes D15: Never clip overflow or truncate pages)
   ============================================================================ */
@page {
  size: A4 portrait;
  margin: 12mm 14mm;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 12pt;
  }

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

  #appRoot {
    display: none !important;
  }

  #printContainer {
    display: block !important;
    width: 100% !important;
  }

  /* แก้ไข D15: ป้องกันการตัดเนื้อหาที่ยาวเกินหน้ากระดาษ */
  .a4-page {
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
    width: 100% !important;
    min-height: auto !important;
    max-height: none !important;
    height: auto !important;
    padding: 4mm 2mm !important;
    overflow: visible !important;
    page-break-after: always;
    break-after: page;
  }

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

  .a4-table tr,
  .sig-box {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
