:root {
    --primary: #FF6600; /* สีส้มตามแบบ */
    --primary-dark: #E65100;
    --text-dark: #333333;
    --text-gray: #666666;
    --border: #dddddd;
    --bg-light: #f9f9f9;
}

body {
    font-family: 'Sarabun', sans-serif;
    background-color: #f0f2f5;
    color: var(--text-dark);
    line-height: 1.6;
    margin: 0;
}

.container {
    max-width: 1000px;
    margin: 20px auto;
    padding: 0 15px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.header h1 {
    color: var(--primary);
    font-size: 1.8rem;
}

/* Main Form */
.main-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px dashed var(--border);
}

section h2 {
    font-size: 1.1rem;
    color: var(--text-dark);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}
section h2 i { color: var(--primary); }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}
.grid-2-col {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 30px;
}
.span-2 { grid-column: span 2; }

.form-group { display: flex; flex-direction: column; }
.form-group label {
    font-size: 0.85rem;
    color: var(--text-gray);
    margin-bottom: 5px;
}
input, textarea, select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.95rem;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Upload Boxes */
.logo-container {
    width: 150px;
    height: 100px;
    border: 2px dashed var(--border);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    overflow: hidden;
    background: var(--bg-light);
}
.logo-container img { width: 100%; height: 100%; object-fit: contain; }
.logo-placeholder { text-align: center; color: #999; font-size: 0.8rem; }

/* Items Table */
.items-table-wrapper { overflow-x: auto; margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th {
    background: var(--bg-light);
    text-align: left;
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dark);
}
td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
td input.item-input { width: 100%; box-sizing: border-box; }
td textarea.item-input { width: 100%; resize: vertical; box-sizing: border-box; }

/* Summary */
.summary-section {
    display: flex;
    justify-content: space-between;
    gap: 30px;
    margin-top: 20px;
}
.remarks-box { flex: 1; }
.remarks-box textarea { width: 100%; height: 100px; }
.totals-box { width: 300px; }
.summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.95rem;
}
.summary-row.total {
    font-weight: bold;
    color: var(--primary);
    font-size: 1.2rem;
    border-top: 2px solid var(--primary);
    padding-top: 10px;
    margin-top: 10px;
}

/* Buttons */
.btn {
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: #28a745; color: white; }
.btn-secondary { background: #6c757d; color: white; }
.btn-outline { border: 1px solid var(--primary); color: var(--primary); background: white; }
.btn-outline:hover { background: var(--bg-light); }
.btn-text-danger { background: none; border: none; color: #dc3545; cursor: pointer; font-size: 0.85rem; margin-top: 5px; }

.actions-bar {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 40px;
}
.actions-bar .btn.large { padding: 12px 30px; font-size: 1rem; }

/* Modal & Preview Styling */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
}
.modal-content {
    background-color: #525659; /* Grey background like PDF viewer */
    margin: 20px auto;
    padding: 40px;
    width: 90%;
    max-width: 900px;
    height: 85vh;
    overflow-y: auto;
    position: relative;
    border-radius: 8px;
}
.close {
    position: absolute;
    right: 20px;
    top: 10px;
    color: white;
    font-size: 28px;
    cursor: pointer;
}

/* --- THE PREVIEW PAPER (A4 style) --- */
.preview-paper {
    background: white;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 15mm 15mm;
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
    box-sizing: border-box;
    position: relative;
    font-size: 14px; /* Base font size for A4 */
}

/* Responsive */
@media (max-width: 768px) {
    .grid-2-col { grid-template-columns: 1fr; }
    .summary-section { flex-direction: column; }
    .totals-box { width: 100%; }
    .actions-bar { flex-direction: column; }
}

/* เพิ่ม class สำหรับปุ่มขนาดเล็ก */
.btn.small {
    padding: 5px 10px;
    font-size: 0.85rem;
}

/* --- Language Switch Styles --- */
.lang-switch-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100px;  /* ความกว้างรวม */
    height: 40px;  /* ความสูงเท่าปุ่มสร้างใหม่ */
    background-color: #f0f2f5; /* สีพื้นหลังเทาอ่อน */
    border-radius: 6px; /* ความมนเท่าปุ่มอื่น */
    cursor: pointer;
    padding: 4px;
    box-sizing: border-box;
    margin-left: 10px;
    user-select: none;
    border: 1px solid #ddd;
}

/* ตัวเลื่อนสีขาว (Slider) */
.lang-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 44px; /* เกือบครึ่งหนึ่งของ container */
    height: 30px; /* height container (40) - padding บนล่าง (8) - border (2) */
    background-color: white;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1;
}

/* ตัวหนังสือ TH/EN */
.lang-option {
    position: relative;
    z-index: 2;
    flex: 1;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: #a0a0a0; /* สีเทาตอนยังไม่เลือก */
    transition: color 0.3s;
    line-height: 30px;
}

/* สีส้มเมื่อถูกเลือก */
.lang-option.active {
    color: var(--primary); /* สีส้ม */
}

/* สถานะเมื่อเป็นภาษาอังกฤษ (เลื่อน Slider ไปทางขวา) */
.lang-switch-container.en-active .lang-slider {
    transform: translateX(46px); /* เลื่อนไปขวา */
}

/* จัดสไตล์โลโก้บนหัวเว็บ */
.header-logo {
    height: 45px; /* ปรับความสูงตามต้องการ */
    width: auto;  /* ให้ความกว้างปรับอัตโนมัติ */
    object-fit: contain;
    display: inline-block;
    vertical-align: middle;
}

/* ปรับ h1 ให้รองรับรูปภาพคู่ตัวหนังสือ */
.header h1 {
    display: flex;
    align-items: center;
    gap: 15px; /* ระยะห่างระหว่างโลโก้กับตัวหนังสือ */
    color: var(--primary);
    font-size: 1.8rem;
    margin: 0;
}

/* --- Footer Credit --- */
.app-footer {
    text-align: center;
    margin-top: 20px;
    padding-bottom: 30px;
    font-size: 0.85rem;
    color: #999;
    letter-spacing: 0.5px;
}