/* Minimal CSS Reset - less aggressive approach */
html, body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Prevent pull-to-refresh on all pages */
    overscroll-behavior-y: contain;
    touch-action: pan-x pan-y;
}

*, *::before, *::after {
    box-sizing: inherit;
}

/* Base styles */
html {
    width: 100%;
    overflow-x: hidden;
}

body {
    width: 100%;
    overflow-x: hidden;
    font-family: 'Sarabun', sans-serif;
    min-height: 100vh;
    background-color: #f5f5f5; /* เปลี่ยนเป็นสีเทาอ่อนเหมือน colourful template */
    /* Additional pull-to-refresh prevention */
    overscroll-behavior: contain;
}

/* Container สำหรับจำกัดความกว้างและจัดกลาง */
.main-container {
    max-width: 480px; /* จำกัดความกว้างสูงสุดเหมือนโทรศัพท์ */
    width: 100%;
    margin: 0 auto; /* จัดกลาง */
    background-color: #f8f4db; /* พื้นหลังของเนื้อหา */
    min-height: 100vh;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); /* เพิ่มเงาเพื่อให้เห็นขอบเขต */
    position: relative;
}

/* Header styles - แบบเดียวกับ colourful template */
.header {
    padding: 0;
    text-align: center;
    background: none;
    width: 100%;
}

.header img {
    width: 100%;
    height: 100%;
    display: block;
    max-width: 100%;
    object-fit: contain;
}

/* Main content - ลบ margin-top ที่ไม่จำเป็น */
#app-container {
    padding-top: 1rem;
}

/* Form styles */
.form-container {
    background-color: #ffffff;
    border-top: 10px solid #e7c651;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    /* ยกเลิกการจำกัดความกว้างบนมือถือ */
    body {
        background-color: #f8f4db; /* กลับไปใช้สีเดิมบนมือถือ */
        padding: 0;
        margin: 0; /* ลบ margin */
    }

    .main-container {
        max-width: none;
        box-shadow: none;
        margin: 0;
    }
    
    #app-container {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
    
    .form-container {
        padding: 0.875rem;
        margin: 0 auto 6rem auto; /* เพิ่มความห่างระหว่าง form-container จาก mb-4 default */
    }
    
    /* Typography adjustments for mobile */
    h1 {
        font-size: 1.375rem;
        line-height: 1.75rem;
    }
    
    p {
        font-size: 0.8125rem;
        line-height: 1.125rem;
    }
    
    /* Form elements sizing */
    .form-input, .form-select {
        height: 2.75rem;
        font-size: 0.875rem;
        padding: 0.625rem;
    }
    
    .form-input.with-icon, .form-select.with-icon {
        padding-left: 2.5rem;
    }
    
    .btn-primary {
        height: 2.75rem;
        font-size: 0.875rem;
        padding: 0.625rem 0.875rem;
    }
    
    /* Icon positioning */
    .input-icon {
        left: 0.625rem;
    }
}

/* Desktop และ Tablet - จำกัดความกว้างให้เหมือนมือถือ */
@media (min-width: 769px) {
    body {
        background-color: #f5f5f5; /* เพิ่มพื้นหลังเพื่อให้เห็นความแตกต่าง */
        padding: 20px 0;
    }

    .main-container {
        max-width: 420px; /* ความกว้างคล้ายมือถือใหญ่ */
        margin: 0 auto;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        border-radius: 8px;
        overflow: hidden;
    }

    #app-container {
        padding-top: 1rem;
    }

    .form-container {
        margin: 0;
        padding: 0.875rem; /* ใช้ขนาดเดียวกับมือถือ */
    }
    
    /* ปรับขนาดตัวอักษรให้เล็กลงบน desktop */
    h1 {
        font-size: 1.25rem !important; /* เล็กลงจาก 1.375rem */
        line-height: 1.5rem !important;
    }
    
    h2 {
        font-size: 1rem !important; /* เล็กลงจาก 1.125rem (text-lg) */
        line-height: 1.25rem !important;
    }
    
    h3 {
        font-size: 0.875rem !important;
        line-height: 1.125rem !important;
    }
    
    /* ปรับขนาด section และ spacing */
    .bg-gray-50.rounded-lg {
        padding: 0.75rem !important; /* เล็กลงจาก 1rem (p-4) */
    }
    
    .bg-white.rounded-md,
    .bg-white.rounded-lg {
        padding: 0.625rem !important; /* เล็กลง */
    }
    
    /* ปรับขนาดตัวอักษรในเนื้อหา */
    .text-sm {
        font-size: 0.75rem !important; /* เล็กลงจาก 0.875rem */
        line-height: 1rem !important;
    }
    
    .text-xs {
        font-size: 0.6875rem !important; /* เล็กลงจาก 0.75rem */
        line-height: 0.875rem !important;
    }
    
    /* ปรับขนาด material icons */
    .material-icons {
        font-size: 16px !important; /* เล็กลงจาก 18px */
    }
    
    /* ปรับขนาดตาราง */
    table {
        font-size: 0.75rem !important;
    }
    
    th, td {
        padding: 0.375rem 0.5rem !important; /* เล็กลง */
    }
    
    /* ปรับขนาด status badge */
    .inline-block.px-3.py-1 {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.6875rem !important;
    }
    
    /* ปรับขนาดปุ่ม */
    .btn-primary {
        padding: 0.625rem 0.875rem !important;
        font-size: 0.875rem !important;
    }
    
    /* ปรับ margin และ spacing */
    section {
        margin-bottom: 1rem !important; /* เล็กลงจาก 1.5rem (mb-6) */
    }
    
    .mb-3 {
        margin-bottom: 0.5rem !important;
    }
    
    .mb-4 {
        margin-bottom: 0.75rem !important;
    }
    
    .space-x-6 > * + * {
        margin-left: 1rem !important; /* เล็กลงจาก 1.5rem */
    }
}

/* Form element styles */
.form-input, .form-select {
    background-color: #f9fafb;
    border: 1px solid #d1d5db;
    transition: all 0.3s;
    border-radius: 0.375rem;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: #9a7900;
    background-color: #ffffff;
    box-shadow: 0 0 0 2px rgba(154, 121, 0, 0.2);
}

.form-input:disabled, .form-select:disabled {
    background-color: #e5e7eb;
    cursor: not-allowed;
    color: #6b7280;
}

/* Button styles */
.btn-primary {
    background-color: #9a7900;
    color: white;
    transition: background-color 0.3s ease;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: #856b00;
}

.btn-primary:disabled {
    background-color: #9a7900;
    opacity: 0.5;
    cursor: not-allowed;
}

/* Icon positioning */
.input-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 10;
}

.material-icons {
    font-size: 18px;
}

/* Link styles */
.link-primary {
    color: #9a7900;
    transition: color 0.3s ease;
}

.link-primary:hover {
    color: #856b00;
}

/* Utility classes for spacing */
.form-section-header {
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.75rem;
    margin-bottom: 1.5rem;
}

/* Print styles */
@media print {
    .mobile-header {
        display: none !important;
    }
    
    .no-print,
    .btn-primary,
    button {
        display: none !important;
    }
    
    #app-container {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
    
    /* Hide payment section when printing */
    .form-container:nth-child(2) {
        display: none !important;
    }
    
    /* Hide action buttons section */
    section:has(button) {
        display: none !important;
    }
    
    body {
        background-color: white !important;
    }
}

/* Loading Spinner Styles */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Button Loading State */
.btn-loading {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Global Loading Overlay */
.global-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.global-loading.show {
    opacity: 1;
    visibility: visible;
}

.loading-content {
    background-color: white;
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    text-align: center;
}

.loading-spinner-large {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid #9a7900;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 1rem;
}

/* Transfer Modal Styles */
.transfer-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.transfer-modal.is-open {
    opacity: 1;
    visibility: visible;
}

.transfer-modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    width: 90%;
    max-width: 400px;
    margin: 1rem;
    position: relative;
}

/* Close Button Styles */
.modal-close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    color: #9a7900;
    border: none;
    cursor: pointer;
    transition: color 0.3s ease;
    font-size: 24px;
    padding: 0;
    width: auto;
    height: auto;
}

.modal-close-btn:hover {
    color: #856b00;
}

/* Contact Link Styles */
.contact-links {
    display: flex;
    width: 100%;
    align-items: center;
}

.contact-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    color: inherit;
    flex: 1;
    width: 50%;
}

.contact-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
    display: block;
    text-decoration: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.contact-icon:hover {
    transform: scale(1.1);
    opacity: 0.8;
}

.contact-info {
    width: 100%;
}

.contact-name {
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    display: none;
}

.contact-id {
    font-size: 0.875rem;
    color: #9a7900;
    text-decoration: none;
    transition: color 0.3s ease;
    margin-top: 0.5rem;
}

.contact-id:hover {
    color: #856b00;
}

/* Vertical divider */
.divider {
    width: 1px;
    height: 60px;
    background-color: #e5e7eb;
    flex-shrink: 0;
}

/* Secondary Button Styles */
.btn-secondary {
    background-color: #6b7280;
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-weight: 500;
}

.btn-secondary:hover {
    background-color: #4b5563;
}

/* Download specific styles */
.download-content {
    background-color: white;
    padding: 0;
    margin: 0;
    width: 100%;
    max-width: none;
    box-shadow: none;
}

.download-container {
    background-color: white;
    padding: 1.5rem;
    margin: 0;
    width: 100%;
    font-family: 'Sarabun', sans-serif;
}

/* Hide elements during download - only when generating image */
.generating-image .no-download {
    display: none !important;
}

/* Form States CSS */
.form-disabled {
    opacity: 0.6;
    pointer-events: none;
}

.input-disabled {
    background-color: #f3f4f6 !important;
    cursor: not-allowed !important;
    opacity: 0.6;
}

.toggle-disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* Loading states */
.btn-loading {
    opacity: 0.75;
    cursor: not-allowed;
}

.btn-loading .material-icons {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
