/* --- 1. ตัวแปรและค่าเริ่มต้น --- */
:root {
    --primary-color: #4A90E2;
    --background-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-color: #333;
    --light-gray: #e0e0e0;
    --font-family: 'Sarabun', sans-serif;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start; /* เปลี่ยนเป็น flex-start เพื่อให้เริ่มจากด้านบน */
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

/* --- 2. Layout หลัก --- */
.container {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 600px;
    text-align: center;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.header-icon {
    width: 70px;
    height: 80px;
}

.subtitle {
    margin-bottom: 30px;
    color: #666;
}

.separator {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 30px 0;
}

/* --- 3. สไตล์ฟอร์ม --- */
.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.form-group input[type="text"],
.form-group input[type="file"],
select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--light-gray);
    border-radius: 8px;
    box-sizing: border-box;
    font-family: var(--font-family);
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input[type="text"]:focus,
select:focus {
    border-color: var(--primary-color);
    outline: none;
}

.form-row {
    display: flex;
    gap: 20px;
}

.form-row .form-group {
    flex: 1;
}

input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    height: 45px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--light-gray);
    cursor: pointer;
    background-color: transparent;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 5px;
}
input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}
input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}


.options-title {
    margin-bottom: 20px;
    font-size: 1.2rem;
    color: var(--text-color);
}

.generate-btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 8px;
    background-color: var(--primary-color);
    color: white;
    font-family: var(--font-family);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.3s;
}

.generate-btn:hover {
    background-color: #357ABD;
}

/* --- 4. ส่วนแสดงผลลัพธ์ --- */
.qr-result {
    margin-bottom: 30px;
    padding: 20px;
    border: 2px dashed var(--light-gray);
    border-radius: 8px;
}

.qr-result h3 {
    margin-top: 0;
}

.qr-result img {
    max-width: 80%;
    margin-top: 10px;
    margin-bottom: 20px;
    border-radius: 8px;
    border: 1px solid var(--light-gray);
}

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 25px;
    border-radius: 8px;
    background-color: #28a745;
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.3s;
    gap: 8px;
}

.download-btn:hover {
    background-color: #218838;
}


/* --- 5. ส่วนแสดงประวัติ --- */
.history-section {
    margin-top: 30px;
    text-align: left;
}

.history-section h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-color);
}

.history-grid {
    display: grid;
    grid-template-columns: 1fr; /* 1 คอลัมน์บนมือถือ */
    gap: 20px;
}

/* สำหรับจอใหญ่ขึ้น ให้แสดง 2 คอลัมน์ */
@media (min-width: 768px) {
    .history-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.history-item {
    background: #f9f9f9;
    border: 1px solid #e9e9e9;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: box-shadow 0.3s;
}

.history-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.history-item img {
    width:50px;
    height: 50px;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
}

.history-info {
    flex: 1;
    overflow: hidden; /* ป้องกันข้อความยาวเกิน */
}

.history-info p {
    margin: 0 0 5px 0;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* แสดง ... เมื่อข้อความยาว */
}

.history-download {
    display: inline-block;
    margin-top: 5px;
    font-size: 0.9rem;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.history-download:hover {
    text-decoration: underline;
}