/*
 * Thai Font Optimization
 * ปรับฟอนต์ภาษาไทยให้อ่านง่าย สวยงาม และ responsive
 */

/* Import Google Fonts - Sarabun (ฟอนต์ไทยสวย อ่านง่าย) */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700;800&display=swap');

/* Import Noto Sans Thai (Alternative font - รองรับทุก platform) */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700;900&display=swap');

/* Root font settings */
:root {
    --font-thai-primary: 'Noto Sans Thai', sans-serif;
    --font-thai-secondary: 'Sarabun', sans-serif;
    --font-english: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Font sizes - optimized for Thai characters */
    --font-size-xs: 0.875rem;    /* 14px */
    --font-size-sm: 0.9375rem;   /* 15px */
    --font-size-base: 1rem;      /* 16px */
    --font-size-lg: 1.125rem;    /* 18px */
    --font-size-xl: 1.25rem;     /* 20px */
    --font-size-2xl: 1.5rem;     /* 24px */
    --font-size-3xl: 1.875rem;   /* 30px */
    --font-size-4xl: 2.25rem;    /* 36px */

    /* Line heights - improved for Thai text readability */
    --line-height-tight: 1.3;
    --line-height-normal: 1.6;
    --line-height-relaxed: 1.8;
    --line-height-loose: 2;
}

/* Apply Thai fonts globally */
html,
body {
    font-family: var(--font-thai-primary);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Headings - เพิ่มน้ำหนักฟอนต์สำหรับภาษาไทย */
h1, .h1,
h2, .h2,
h3, .h3,
h4, .h4,
h5, .h5,
h6, .h6 {
    font-family: var(--font-thai-primary);
    font-weight: 700;
    line-height: var(--line-height-tight);
    letter-spacing: -0.01em;
}

h1, .h1 {
    font-size: var(--font-size-4xl);
    font-weight: 800;
}

h2, .h2 {
    font-size: var(--font-size-3xl);
    font-weight: 700;
}

h3, .h3 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
}

h4, .h4 {
    font-size: var(--font-size-xl);
    font-weight: 600;
}

h5, .h5 {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

h6, .h6 {
    font-size: var(--font-size-base);
    font-weight: 600;
}

/* Paragraphs and text */
p {
    line-height: var(--line-height-normal);
    margin-bottom: 1rem;
}

.text-sm {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}

.text-lg {
    font-size: var(--font-size-lg);
    line-height: var(--line-height-normal);
}

.text-xl {
    font-size: var(--font-size-xl);
    line-height: var(--line-height-normal);
}

/* Form elements - ปรับให้อ่านง่าย */
.form-label {
    font-weight: 600;
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    margin-bottom: 0.5rem;
}

.form-control,
.form-select {
    font-family: var(--font-thai-primary);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
}

.form-control::placeholder {
    font-weight: 300;
    opacity: 0.6;
}

/* Buttons - ฟอนต์ชัดเจน */
.btn {
    font-family: var(--font-thai-primary);
    font-weight: 600;
    font-size: var(--font-size-base);
    line-height: var(--line-height-tight);
    letter-spacing: 0;
}

.btn-sm {
    font-size: var(--font-size-sm);
}

.btn-lg {
    font-size: var(--font-size-lg);
}

/* Tables - ปรับให้อ่านตัวเลขและข้อความไทยง่าย */
.table {
    font-size: var(--font-size-sm);
}

.table thead th {
    font-weight: 700;
    font-size: var(--font-size-base);
    line-height: var(--line-height-tight);
}

.table tbody td {
    line-height: var(--line-height-normal);
}

/* Badges - ฟอนต์ชัด อ่านง่าย */
.badge {
    font-family: var(--font-thai-primary);
    font-weight: 600;
    font-size: var(--font-size-xs);
    line-height: var(--line-height-tight);
    padding: 0.35em 0.65em;
}

/* Alerts */
.alert {
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
}

/* Navigation */
.nav-link {
    font-weight: 500;
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
}

.nav-link:hover {
    font-weight: 600;
}

/* Cards */
.card-title {
    font-weight: 700;
    line-height: var(--line-height-tight);
}

.card-subtitle {
    font-weight: 400;
    line-height: var(--line-height-normal);
}

.card-text {
    line-height: var(--line-height-normal);
}

/* Modals */
.modal-title {
    font-weight: 700;
    line-height: var(--line-height-tight);
}

.modal-body {
    line-height: var(--line-height-normal);
}

/* Breadcrumbs */
.breadcrumb {
    font-size: var(--font-size-sm);
}

/* List groups */
.list-group-item {
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
}

/* Tooltips and Popovers */
.tooltip,
.popover {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}

/* Utility classes for Thai text */
.thai-text-tight {
    line-height: var(--line-height-tight) !important;
}

.thai-text-normal {
    line-height: var(--line-height-normal) !important;
}

.thai-text-relaxed {
    line-height: var(--line-height-relaxed) !important;
}

.thai-text-loose {
    line-height: var(--line-height-loose) !important;
}

.thai-font-light {
    font-weight: 300 !important;
}

.thai-font-regular {
    font-weight: 400 !important;
}

.thai-font-medium {
    font-weight: 500 !important;
}

.thai-font-semibold {
    font-weight: 600 !important;
}

.thai-font-bold {
    font-weight: 700 !important;
}

.thai-font-extrabold {
    font-weight: 800 !important;
}

/* Numbers and English text in Thai context */
.number-display {
    font-family: var(--font-english);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

/* Code and monospace (for Bundle Code, QR Code, etc.) */
code,
.code-text,
.bundle-code,
.qr-code-text {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.95em;
    font-weight: 500;
    letter-spacing: 0.02em;
}

/* Mobile optimization */
@media (max-width: 768px) {
    html,
    body {
        font-size: 15px; /* ลดขนาดเล็กน้อยบนมือถือ */
    }

    h1, .h1 {
        font-size: var(--font-size-3xl);
    }

    h2, .h2 {
        font-size: var(--font-size-2xl);
    }

    h3, .h3 {
        font-size: var(--font-size-xl);
    }

    .table {
        font-size: var(--font-size-xs);
    }

    .btn {
        font-size: var(--font-size-sm);
        padding: 0.5rem 1rem;
    }

    .btn-lg {
        font-size: var(--font-size-base);
    }
}

/* Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) {
    html,
    body {
        font-size: 15.5px;
    }
}

/* Large screen optimization */
@media (min-width: 1920px) {
    html,
    body {
        font-size: 17px; /* เพิ่มขนาดเล็กน้อยบนจอใหญ่ */
    }
}

/* Print optimization */
@media print {
    html,
    body {
        font-family: var(--font-thai-primary);
        font-size: 12pt;
        line-height: 1.5;
    }

    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
}

/* Accessibility - เพิ่มความคมชัดสำหรับผู้มีปัญหาการมองเห็น */
@media (prefers-contrast: high) {
    html,
    body {
        font-weight: 500;
    }

    .btn,
    .badge,
    .alert {
        font-weight: 700;
    }
}

/* Reduced motion - สำหรับผู้ที่ไม่ต้องการ animation */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
