body { font-family: 'Inter', 'Sarabun', sans-serif; background-color: var(--bg-body); padding: 0; margin: 0; box-sizing: border-box; color: var(--text-primary); display: flex; flex-direction: column; height: 100vh; overflow: hidden; letter-spacing: 0.2px; }

        .top-header { position: fixed; top: 0; left: 0; right: 0; height: var(--header-height); background: var(--bg-surface); border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; padding: 0 24px; z-index: 1000; box-sizing: border-box; }
        .header-brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 500; color: var(--text-primary); width: var(--sidebar-width); }
        .header-brand img { height: 40px; margin-left: 12px; object-fit: contain; }
        .header-actions { display: flex; align-items: center; gap: 16px; }
        
        .profile-btn { display: flex; align-items: center; gap: 10px; padding: 6px 16px 6px 6px; border-radius: 24px; cursor: pointer; transition: background 0.2s; border: 1px solid transparent; }
        .profile-btn:hover { background: rgba(26,115,232,0.04); border-color: #aecbfa; }
        .profile-btn img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
        .profile-info-text { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
        .profile-info-text .user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); line-height: 1.2;}
        .profile-info-text .manage-text { font-size: 11px; font-weight: 600; color: var(--primary); display: flex; align-items: center; gap: 4px; margin-top: 2px;}
        
        .btn-outline { background: transparent; border: 1px solid var(--border-light); color: var(--text-secondary); padding: 8px 16px; border-radius: 4px; font-size: 14px; font-weight: 500; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit; }
        .btn-outline:hover { background: #f1f3f4; color: var(--text-primary); }
        .mobile-toggle { display: none; background: transparent; border: none; font-size: 24px; color: var(--text-secondary); cursor: pointer; padding: 8px; border-radius: 50%; transition: background 0.2s;}
        .mobile-toggle:hover { background: rgba(60,64,67,0.08); }

        .layout-wrapper { display: flex; flex: 1; margin-top: var(--header-height); height: calc(100vh - var(--header-height)); overflow: hidden; }

        .left-sidebar { width: var(--sidebar-width); background: var(--bg-sidebar); border-right: 1px solid var(--border-light); display: flex; flex-direction: column; overflow-y: auto; padding: 16px 0; transition: left 0.3s ease; z-index: 900; flex-shrink: 0;}
        .menu-title { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; margin: 8px 24px 12px 24px; }
        .menu-list { list-style: none; padding: 0; margin: 0 0 16px 0; }
        .menu-item { display: flex; align-items: center; gap: 16px; padding: 12px 24px; color: var(--text-primary); text-decoration: none; font-size: 14px; font-weight: 500; transition: 0.2s; position: relative; cursor: pointer; border-radius: 0 24px 24px 0; margin-right: 16px; }
        .menu-item:hover { background: #f1f3f4; }
        .menu-item.active { background: #e8f0fe; color: var(--primary); font-weight: 600; }
        .menu-item i { font-size: 20px; color: var(--text-secondary); }
        .menu-item.active i { color: var(--primary); }

        .main-content-split { flex: 1; display: flex; flex-direction: row; overflow: hidden; background: var(--bg-body); padding: 24px; gap: 24px; box-sizing: border-box;}
        
        .controls-panel { width: 480px; background: transparent; display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; border-radius: 12px; }
        .preview-panel { flex: 1; position: relative; background: #e8eaed; border-radius: 16px; overflow-y: auto; overflow-x: hidden; box-shadow: inset 0 2px 6px rgba(0,0,0,0.05); display: flex; flex-direction: column; align-items: center; padding: 40px 0; box-sizing: border-box;}

        .panel-header { margin-bottom: 16px; flex-shrink: 0;}
        .tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border-light); }
        .tab-btn { flex: 1; padding: 12px 10px; font-size: 13px; background: transparent; color: var(--text-secondary); border: none; border-bottom: 3px solid transparent; font-weight: 600; cursor: pointer; transition: all 0.2s ease; display: flex; justify-content: center; align-items: center; gap: 6px; font-family: inherit;}
        .tab-btn:hover { background: rgba(26, 115, 232, 0.04); color: var(--primary); }
        .tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

        .panel-body { flex: 1; overflow-y: auto; padding: 0 4px; padding-bottom: 24px; }
        
        label { font-weight: 500; display: block; margin-top: 16px; color: var(--text-primary); font-size: 13px; margin-bottom: 8px;}
        .app-input { width: 100%; padding: 12px 16px; border: 1px solid var(--border-light); border-radius: 8px; box-sizing: border-box; font-family: inherit; font-size: 14px; background: var(--input-bg); transition: all 0.2s ease; color: var(--text-primary); resize: vertical; box-shadow: none; }
        .app-input:hover { border-color: #b0bec5; }
        .app-input:focus, .course-tags-input-wrapper:focus-within { outline: none; border: 2px solid var(--primary); padding: 11px 15px; background: var(--bg-surface); }
        .app-input::placeholder { color: #80868b; }
        
        select.app-input { appearance: none; background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6368' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right 1rem center; background-size: 1em; padding-right: 2.5rem; cursor: pointer; }
        
        .box-card { background: var(--bg-surface); padding: 24px; border-radius: 12px; margin-bottom: 16px; box-shadow: var(--shadow-sm); border: 1px solid var(--border-light); transition: box-shadow 0.2s;}
        .box-card:hover { box-shadow: var(--shadow-md); }
        .task-box { background: var(--bg-surface); padding: 24px; border-radius: 12px; margin-top: 16px; box-shadow: 0 1px 2px rgba(60,64,67,0.1); border: 1px solid #e8eaed; }
        
        .btn-action { cursor: pointer; font-weight: 500; border: none; display: flex; align-items: center; justify-content: center; gap: 8px; transition: all 0.2s ease; font-family: inherit;}
        .btn-add-day { background: transparent; color: var(--primary); padding: 12px; border-radius: 8px; width: 100%; margin-top: 16px; font-size: 14px; border: 1px solid var(--border-light); }
        .btn-add-day:hover { background: #f8f9fa; border-color: #dadce0; box-shadow: 0 1px 2px rgba(60,64,67,0.1);}
        .btn-add-task { background: transparent; color: var(--primary); padding: 10px; border-radius: 8px; width: 100%; margin-top: 16px; font-size: 13px; border: 1px dashed #aecbfa; }
        .btn-add-task:hover { background: #f4f8fe; border-color: var(--primary); }
        .btn-delete-item { background: transparent; color: var(--text-secondary); padding: 8px; border-radius: 50%; font-size: 16px; width: 36px; height: 36px; display: flex; justify-content: center; align-items: center;}
        .btn-delete-item:hover { background: rgba(217, 48, 37, 0.08); color: var(--danger); }
        .btn-copy-item { background: transparent; color: var(--text-secondary); padding: 8px; border-radius: 50%; font-size: 16px; width: 36px; height: 36px; display: flex; justify-content: center; align-items: center;}
        .btn-copy-item:hover { background: rgba(26, 115, 232, 0.08); color: var(--primary); }
        .btn-save { background: var(--primary); color: white; padding: 12px 24px; border-radius: 24px; font-size: 14px; width: 100%; box-shadow: 0 1px 2px 0 rgba(60,64,67,0.3); cursor: pointer; font-family: inherit; margin-top: 24px; border: none; font-weight: 500; display: flex; justify-content: center; align-items: center; gap: 8px; letter-spacing: 0.25px;}
        .btn-save:hover { background: var(--primary-hover); box-shadow: 0 1px 3px 1px rgba(60,64,67,0.15), 0 2px 8px 2px rgba(60,64,67,0.15); }

        .checkbox-custom { width: 18px; height: 18px; margin-top: 2px; cursor: pointer; accent-color: var(--primary); border-radius: 4px; border: 2px solid var(--text-secondary);}

        .history-day { background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: 12px; margin-bottom: 20px; padding: 24px; box-shadow: var(--shadow-sm);}
        .history-day-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-light); padding-bottom: 12px; margin-bottom: 16px; font-weight: 500; color: var(--text-primary); font-size: 15px;}
        .history-task { background: var(--bg-body); padding: 16px; border-radius: 8px; margin-bottom: 12px; border: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 10px; transition: 0.2s;}
        
        .export-pdf { background: var(--success); color: white; padding: 12px 24px; border-radius: 24px; width: 100%; font-size: 14px; font-weight: 500; cursor: pointer; border: none; display: flex; justify-content: center; align-items: center; gap: 8px; transition: all 0.2s ease; box-shadow: 0 1px 2px 0 rgba(60,64,67,0.3); font-family: inherit; margin-top: 16px;}
        .export-pdf:hover { background: #137333; box-shadow: 0 1px 3px 1px rgba(60,64,67,0.15); }

        .autocomplete-wrapper { position: relative; width: 100%; }
        .course-tags-input-wrapper { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 48px; padding: 8px 12px; background: var(--input-bg); border: 1px solid var(--border-light); border-radius: 8px; cursor: text; transition: all 0.2s ease;}
        .course-tags-input-wrapper:hover { border-color: #b0bec5; }
        .course-chips-container { display: flex; flex-wrap: wrap; gap: 6px; }
        .course-chip { background: #e8f0fe; color: var(--primary); font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 6px; display: flex; align-items: center; gap: 8px; border: 1px solid #badef7; }
        .course-chip i { cursor: pointer; border-radius: 50%; padding: 2px; transition: 0.2s; font-size: 12px;}
        .course-chip i:hover { background: #badef7; color: var(--danger); }
        .task-course-input { border: none !important; outline: none !important; background: transparent !important; flex: 1; min-width: 150px; padding: 4px 0 !important; font-size: 14px; box-shadow: none !important; margin: 0 !important;}
        
        .autocomplete-list { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-surface); border-radius: 8px; box-shadow: var(--shadow-md); margin-top: 4px; padding: 0; list-style: none; z-index: 100; max-height: 250px; overflow-y: auto; border: 1px solid var(--border-light); display: none; }
        .autocomplete-header { padding: 8px 16px; font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; background: var(--bg-body); pointer-events: none; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border-light); border-top: 1px solid var(--border-light); margin-top: 4px;}
        .autocomplete-header:first-child { margin-top: 0; border-top: none; }
        .autocomplete-list li.autocomplete-item { padding: 10px 16px; cursor: pointer; font-size: 13px; color: var(--text-primary); transition: background 0.1s; }
        .autocomplete-list li.autocomplete-item:hover { background: rgba(26, 115, 232, 0.08); color: var(--primary); }

        .loading-screen-main { position: fixed; inset: 0; background: rgba(255, 255, 255, 0.95); display: flex; justify-content: center; align-items: center; flex-direction: column; z-index: 9999; }
        .spinner-main { border: 3px solid #f3f3f3; border-top: 3px solid var(--primary); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin-bottom: 20px; }
        @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

        .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(32, 33, 36, 0.6); backdrop-filter: blur(2px); z-index: 2000; display: none; justify-content: center; align-items: center; padding: 24px; }
        .modal-box { background: var(--bg-surface); width: 100%; max-width: 600px; max-height: 85vh; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-lg); }
        .modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; background: var(--bg-surface); }
        .modal-header h2 { margin: 0; color: var(--text-primary); font-size: 18px; font-weight: 500; display: flex; align-items: center; gap: 8px;}
        .btn-close { background: transparent; color: var(--text-secondary); border: none; padding: 8px; border-radius: 50%; cursor: pointer; font-size: 20px; transition: 0.2s; display: flex; align-items: center; justify-content: center;}
        .btn-close:hover { background: rgba(60,64,67,0.08); }
        .modal-body { padding: 24px; overflow-y: auto; flex: 1; }

        .sig-canvas-container { border: 1px dashed var(--border-light); border-radius: 8px; width: 100%; height: 160px; background: #f8f9fa; touch-action: none; position: relative; margin-bottom: 12px; overflow: hidden;}
        .sig-canvas-container canvas { width: 100%; height: 100%; }
        .btn-clear-canvas { position: absolute; top: 8px; right: 8px; background: rgba(217, 48, 37, 0.1); color: var(--danger); border: none; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
        .btn-clear-canvas:hover { background: rgba(217, 48, 37, 0.2); }

        #pdfArea { display: flex; flex-direction: column; gap: 30px; width: 100%; align-items: center; }
        .pdf-page { background: #fff; width: 210mm; min-height: 297mm; padding: 15mm 20mm; box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); color: #000; font-size: 12pt; line-height: 1.6; box-sizing: border-box; font-family: 'Sarabun', sans-serif; position: relative; }
        .page-content { width: 100%; display: flex; flex-direction: column; }
        .page-break-avoid { page-break-inside: avoid; break-inside: avoid; display: block; }
        
        .org-header { text-align: right; font-size: 11pt; font-weight: bold; margin-bottom: 8px; color: #333;}
        .page-line { border-bottom: 1px solid #000; margin-bottom: 25px; }
        .title { text-align: center; font-size: 16pt; font-weight: bold; margin-bottom: 30px; }
        .pdf-row { display: flex; align-items: flex-start; margin-bottom: 10px; page-break-inside: avoid; }
        .pdf-label { font-weight: bold; white-space: nowrap; margin-right: 10px; margin-top: 2px; }
        .pdf-value { flex: 1; border-bottom: 1px dotted #666; min-height: 24px; padding-left: 5px; white-space: pre-wrap; word-break: break-word; color: #111; padding-bottom: 4px; }
        .pdf-value-inline { border-bottom: 1px dotted #666; display: inline-block; padding: 0 10px; min-height: 24px; }
        
        .image-box { border: 1px solid #cbd5e1; width: 100%; min-height: 250px; display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 15px; padding: 15px; box-sizing: border-box; background: #f8fafc; border-radius: 8px; }
        .image-box img { max-height: 230px; object-fit: contain; border-radius: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
        
        .sig-section { margin-top: 20px; display: flex; justify-content: flex-end; width: 100%; }
        .sig-box { width: 260px; text-align: center; }
        .sig-row { display: flex; align-items: flex-end; justify-content: center; margin-bottom: 8px; }
        .sig-dot { flex: 1; border-bottom: 1px dotted #000; margin: 0 5px; position: relative; min-height: 25px; }

        .cover-page { text-align: center; height: 100%; padding-top: 40mm; box-sizing: border-box; }
        .cover-title { font-size: 34pt; font-weight: 700; margin-bottom: 10px; }
        .cover-subtitle { font-size: 22pt; margin-bottom: 40px; color: #333; }
        .cover-details-table { width: 85%; margin: 0 auto; font-size: 16pt; border-collapse: collapse; }
        .cover-details-table td { padding: 12px 15px; vertical-align: top; line-height: 1.6; border: none; }
        .cover-details-table td:first-child { width: 40%; text-align: right; font-weight: bold; white-space: nowrap; }
        .cover-details-table td:last-child { width: 60%; text-align: left; word-break: break-word; }

        .render-wrapper { position: absolute; left: -9999px; top: 0; width: 210mm; background: #fff; z-index: -10; color: #000; }


        @media (max-width: 1024px) {
            .main-content-split { flex-direction: column; overflow-y: auto; padding: 20px; gap: 20px; }
            .controls-panel { width: 100%; flex: none; height: auto; min-height: 500px; }
            .preview-panel { width: 100%; flex: none; min-height: 500px; padding: 20px 0; box-sizing: border-box; }
        }

        @media (max-width: 768px) {
            .left-sidebar { position: fixed; left: -100%; top: var(--header-height); bottom: 0; box-shadow: 4px 0 10px rgba(0,0,0,0.1); width: 260px; z-index: 1000; }
            .left-sidebar.show { left: 0; }
            .mobile-toggle { display: block; }
            .header-brand span { display: none; }
            .header-actions { gap: 10px; }
            .profile-info-text { display: none; }
            .btn-outline .hide-mobile { display: none; }
            .btn-outline { padding: 8px; width: 36px; height: 36px; display: flex; justify-content: center; align-items: center; border-radius: 50%; border: none;}
            .main-content-split { padding: 16px; gap: 16px; }
            .modal-box { max-height: 90vh; border-radius: 12px; }
        }

        @media print {
            @page { size: A4 portrait; margin: 15mm 20mm; }
            body { background: white; margin: 0; padding: 0; overflow: auto; }
            .top-header, .left-sidebar, .controls-panel, .preview-panel, #loading, .modal-overlay { display: none !important; }
            .layout-wrapper { margin-top: 0 !important; display: block !important; }
            .main-content-split { padding: 0 !important; gap: 0 !important; display: block !important; }
            .render-wrapper { position: static !important; left: 0 !important; top: 0 !important; width: 100% !important; display: block !important; z-index: 1 !important; opacity: 1 !important; visibility: visible !important; }
            #pdfArea { gap: 0 !important; padding: 0 !important; }
            .pdf-page { width: 100% !important; padding: 0 !important; margin: 0 !important; box-shadow: none !important; page-break-after: always; min-height: auto !important; background: transparent; }
            .pdf-page:last-child { page-break-after: auto; }
            .page-break-avoid { page-break-inside: avoid !important; break-inside: avoid !important; display: block; }
        }

/* Daily editor: all fields remain visible; related details and images grouped. */
#view-form .form-intro { color: var(--text-secondary); font-size: 13px; line-height: 1.7; margin: 0 4px 18px; }
#days-container > .box-card { padding: 18px; }
#days-container .task-box { padding: 18px; border-color: #dce9f5; box-shadow: none; scroll-margin-top: 16px; position: relative; }
#days-container .task-assignment-row { display: grid; grid-template-columns: minmax(0,2fr) minmax(110px,1fr); gap: 12px; margin-top: 16px; }
#days-container .task-steps { min-height: 128px; line-height: 1.7; }
#days-container .task-extra { border: 1px solid var(--border-light); border-radius: 10px; padding: 12px; margin-top: 18px; background: var(--bg-body); }
#days-container .task-extra textarea { min-height: 76px !important; }
#days-container .task-images-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; }
#days-container .image-input-block { position: relative; min-width: 0; border: 1px solid var(--border-light); border-radius: 10px; overflow: hidden; background: var(--bg-body); }
#days-container .image-thumbnail { height: 100px; display: flex; align-items: center; justify-content: center; }
#days-container .image-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
#days-container .btn-clear-img { position: absolute; right: 4px; top: 4px; background: white; width: 30px; height: 30px; box-shadow: 0 2px 8px #0002; }
#days-container .dropzone-area:focus-visible { outline: 3px solid #93c5fd; outline-offset: 3px; }
#days-container .image-upload-hint { font-size: 11px; color: var(--text-secondary); margin-top: 7px; line-height: 1.6; }
#days-container .task-current, #history-container .task-current { border-color: var(--primary); box-shadow: 0 0 0 3px #0b87e51a; }
#days-container [data-copied="true"]::before { content: 'สำเนาใหม่ · ยังไม่ได้บันทึก'; display: block; width: fit-content; padding: 5px 10px; margin-bottom: 14px; background: #e6f3ff; color: #0866ad; border-radius: 6px; font-size: 12px; font-weight: 600; }
html[lang="en"] #days-container [data-copied="true"]::before { content: 'New copy · Not saved yet'; }
#history-container .history-task { cursor: pointer; }
#history-container .history-task:hover, #history-container .history-task:focus-visible { border-color: var(--primary); }
#pdfArea .preview-current { outline: 2px solid #4fa4e7; outline-offset: 8px; }
@media (max-width: 480px) {
    #days-container > .box-card, #days-container .task-box { padding: 14px; }
    #days-container .task-assignment-row { grid-template-columns: minmax(0,1fr); }
    #days-container .task-images-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media print { #pdfArea .preview-current { outline: none; } }

#days-container .task-extra > label:first-child { margin-top: 0; }

/* Keep the save action in the same viewport dock as history printing. */
#view-form { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
.logbook-save-actions { box-sizing: border-box; }
