/* General Styling */
html {
    box-sizing: border-box;
}

*,
*::before,
*::after {
    box-sizing: inherit;
}

body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
        background-color: hsl(160, 16%, 96%);
        margin: 0;
        padding: 0;
        color: #333;
        /* --- V127: START FIX - Set global full height --- */
        width: 100%;
        min-height: 100vh;
        /* Use vh (viewport height) for robust full height */
        /* --- V127: END FIX --- */
    }
    
    .container {
    width: 90%;
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

h1,
h2,
h3 {
    color: #0056b3;
    margin-top: 0;
}

/* Navigation */
nav {
    background-color: #0056b3;
    padding: 10px 0;
    margin-bottom: 20px;
    border-radius: 8px 8px 0 0;
}

nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
}

nav ul li {
    margin: 0 15px;
}

nav ul li a {
    color: white;
    text-decoration: none;
    font-weight: bold;
    padding: 10px 15px;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

nav ul li a:hover,
nav ul li a.active {
    background-color: #004085;
}

nav ul li.logout {
    margin-left: auto;
    margin-right: 30px;
}

nav ul li.logout a {
    background-color: #c82333;
}

nav ul li.logout a:hover {
    background-color: #a71d2a;
}

/* Login Form */
.login-container {
    width: 100%;
    max-width: 400px;
    margin: 100px auto;
    padding: 30px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 25px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

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

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-sizing: border-box;
    /* สำคัญมากสำหรับ padding */
    font-size: 1rem;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

button,
.btn {
    display: inline-block;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background-color: #007bff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background-color 0.3s ease;
}

button:hover,
.btn:hover {
    background-color: #0056b3;
}

button.btn-success {
    background-color: #28a745;
}

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

.btn-edit {
    background-color: #ffc107;
    color: #333;
    padding: 8px 12px;
    font-size: 0.9rem;
}

.btn-edit:hover {
    background-color: #e0a800;
}

.btn-danger {
    background-color: #dc3545;
    padding: 8px 12px;
    font-size: 0.9rem;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-secondary {
    background-color: #6c757d;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.form-container {
    padding: 20px;
    background-color: #f9f9f9;
    border-radius: 8px;
    margin-bottom: 20px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

table th,
table td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
}

table th {
    background-color: #0056b3;
    color: white;
}

table tr:nth-child(even) {
    background-color: #f9f9f9;
}

table tr:hover {
    background-color: #f1f1f1;
}

table td.actions {
    display: flex;
    gap: 10px;
}

/* Utilities */
.alert {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 5px;
}

.alert-danger,
.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

/* ======================================================================
START: CSS From entity_crud.php
======================================================================
*/

/* --- START: V19.1 Button Styles (from master_view.php) --- */
.btn-sm {
    padding: 5px 8px;
    font-size: 12px;
    margin-right: 4px;
    border-radius: 4px;
    color: white !important;
    text-decoration: none;
    /* display: inline-block; (REMOVED) */
    display: inline-flex;
    /* (ADDED) */
    align-items: center;
    /* (ADDED) */
    line-height: 1.2;
    vertical-align: middle;
    gap: 4px;
    /* (ADDED) */
}

.btn-warning {
    background-color: #f0ad4e;
    border: 1px solid #eea236;
}

.btn-warning:hover {
    background-color: #ec971f;
}

.btn-info {
    background-color: #5bc0de;
    border: 1px solid #46b8da;
}

.btn-info:hover {
    background-color: #31b0d5;
}

.btn-danger {
    background-color: #d9534f;
    border: 1px solid #d43f3a;
}

.btn-danger:hover {
    background-color: #c9302c;
}

.btn-secondary {
    background-color: #6c757d;
    border: 1px solid #5a6268;
    color: white !important;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-sm i {
    font-size: 14px;
    /* NEW: Set standard icon size */
    line-height: 1;
    /* NEW: Prevent extra line height */
    vertical-align: middle;
    text-align: center;
    /* height/width removed to let font-size control size */
}

/* --- END: V19.1 Button Styles --- */

.child-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.child-table th,
.child-table td {
    border: 1px solid #ddd;
    padding: 8px;
}

.child-table th {
    background-color: #34495e;
    color: white;
}

.child-table .form-group {
    margin-bottom: 0;
}

.child-table .form-group label {
    display: none;
}

.child-table .form-control {
    width: 100%;
    box-sizing: border-box;
}

.remove-child-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}

.remove-child-btn:hover {
    background: #c0392b;
}

.child-template {
    display: none;
}

/* --- NEW: Child Group Tab Styles --- */
.child-tab-links {
    list-style: none;
    padding: 0;
    margin: 30px 0 0 0;
    display: flex;
    border-bottom: 2px solid #dee2e6;
}

.child-tab-link {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: #495057;
    border: 2px solid transparent;
    border-bottom: 0;
    margin-bottom: -2px;
    border-radius: 5px 5px 0 0;
    font-weight: 600;
}

.child-tab-link:hover {
    background-color: #f8f9fa;
    border-color: #e9ecef #e9ecef transparent;
}

.child-tab-link.active {
    color: #0056b3;
    background-color: #ffffff;
    border-color: #dee2e6 #dee2e6 #ffffff;
}

.child-tab-pane {
    display: none;
    border: 1px solid #dee2e6;
    border-top: 0;
    padding: 20px;
    border-radius: 0 0 5px 5px;
}

.child-tab-pane.active {
    display: block;
}

.child-tab-pane .card {
    margin-top: 0 !important;
    border: none;
    box-shadow: none;
}

.child-tab-pane .card-header {
    padding: 0 0 15px 0;
    background: none;
    border-bottom: 1px solid #eee;
}

.child-tab-pane .card-body {
    padding: 15px 0 0 0;
}

/* --- END Child Group Tab Styles --- */

/* --- NEW: Select2 Custom Styles --- */
.select2-container .select2-selection--single {
    height: 38px;
    border: 1px solid #ced4da;
    border-radius: 4px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px;
    padding-left: 12px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #3498db;
}

/* --- END Select2 Styles --- */

/* --- NEW: jQuery Drag & Drop Styles --- */
.custom-dropzone {
    border: 2px dashed #ccc;
    border-radius: 5px;
    background: #f9f9f9;
    padding: 25px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.custom-dropzone:hover,
.custom-dropzone.dragover {
    border-color: #3498db;
    background: #f0f8ff;
}

.custom-dropzone i {
    font-size: 2em;
    color: #888;
}

.custom-dropzone p {
    margin: 10px 0 0 0;
    font-size: 1.1em;
    color: #555;
}

.dropzone-preview-container {
    margin-top: 10px;
}

.dropzone-preview-container .file-preview-item {
    display: inline-block;
    padding: 8px 12px;
    background: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.95em;
    color: #333;
}

/* NEW: Remove bg/border for link/icon modes */
.dropzone-preview-container .file-preview-item.file-preview-link-mode,
.dropzone-preview-container .file-preview-item.file-preview-icon-mode {
    background: none;
    border: none;
    padding: 0;
    vertical-align: middle;
    /* Align buttons */
}

.dropzone-preview-container .file-preview-item.upload-progress {
    background: #fff8e1;
    border-color: #ffeeba;
    color: #856404;
}

.dropzone-preview-container .file-preview-item.upload-error {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
    font-weight: bold;
}

.dropzone-preview-container .remove-file-btn {
    /* Base style for ALL remove buttons */
    cursor: pointer;
    font-weight: bold;
    margin-left: 8px;
    font-size: 1.2em;
    vertical-align: middle;
}

/* Styles for the default 'X' button ONLY */
.dropzone-preview-container .remove-file-btn:not(.btn-sm) {
    background: none;
    border: none;
    color: #e74c3c;
}

/* FIX: Override base styles when it's a styled button */
.dropzone-preview-container .remove-file-btn.btn-sm {
    /* Reset conflicting base styles - REMOVED */

    /* Set specific overrides */
    font-size: 12px;
    font-weight: normal;
    line-height: 1.2;
    padding: 5px 8px;
    margin-left: 8px;
    vertical-align: middle;
}

/* --- END jQuery Drag & Drop Styles --- */

/* --- NEW: V14 File Preview Link Style --- */
.file-preview-item a {
    color: #0056b3;
    text-decoration: none;
    font-weight: 600;
}

/* NEW: Add flex properties to center link-buttons (MOVED to .btn-sm) */
/* .file-preview-item a.btn-info { ... } */

.file-preview-item a:hover {
    text-decoration: none;
    /* Already none for buttons, but good to be sure */
}

.file-preview-item a i {
    /* font-size: 0.8em; (REMOVED: Let .btn-sm i control it) */
    margin-left: 0;
    /* REMOVED: Using 'gap' on parent */
}

/* --- END V14 --- */

/* --- START: NEW V20 (Mock File Upload) --- */
.mock-file-upload {
    border: 2px dashed #ccc;
    border-radius: 5px;
    background: #f9f9f9;
    padding: 25px;
    text-align: center;
}

.mock-file-placeholder {
    color: #555;
}

.mock-file-placeholder i {
    font-size: 2em;
    color: #888;
}

.mock-file-placeholder p {
    margin: 10px 0;
    font-size: 1.1em;
}

.mock-file-placeholder .mock-storage-label {
    color: #0056b3;
    font-weight: bold;
}

.mock-save-file-btn {
    background-color: #28a745;
    border-color: #218838;
    color: white;
}

.mock-save-file-btn:hover {
    background-color: #218838;
}

/* --- END: NEW VZ-Index Controls20 --- */

/* --- START: NEW V24 Loading Overlay --- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    z-index: 9998;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    /* NEW */
}

#loading-spinner {
    border: 8px solid #f3f3f3;
    border-top: 8px solid #3498db;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    z-index: 9999;
    text-align: center;
}

#loading-text {
    /* position: absolute; */
    /* REMOVED */
    /* top: 58%; */
    /* REMOVED */
    margin-top: 20px;
    /* NEW */
    font-size: 1.1em;
    color: #333;
    font-weight: bold;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- END: NEW V24 Loading Overlay --- */

/* ======================================================================
END: CSS From entity_crud.php
======================================================================
*/

/* ======================================================================
START: CSS From module_manager.php
======================================================================
*/

/* --- V12: CodeMirror Syntax Highlighting Styles --- */
.CodeMirror {
    border: 1px solid #ccc;
    border-radius: 4px;
    height: 250px;
    /* ความสูงเริ่มต้น */
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    /* อนุญาตให้ยืด-หดได้ */
    overflow: auto !important;
}

.CodeMirror-scroll {
    min-height: 250px;
    /* ความสูงขั้นต่ำ */
}

/* V16: Set height for all editors */
#autoid_format_virtual.CodeMirror,
#upload_path_template_editor.CodeMirror,
#upload_filename_template_editor.CodeMirror {
    height: 200px;
    /* Default height */
}

#autoid_format_virtual.CodeMirror .CodeMirror-scroll,
#upload_path_template_editor.CodeMirror .CodeMirror-scroll,
#upload_filename_template_editor.CodeMirror .CodeMirror-scroll {
    min-height: 200px;
}

/* V78: Remove taller print editor, no longer using CM for print */

/* ใช้ฟอนต์โค้ด และกำหนดสี */
.cm-s-eclipse.CodeMirror {
    font-family: Consolas, "Courier New", monospace;
}

.cm-s-eclipse .cm-formula-function {
    color: #7A00A0;
    font-weight: bold;
}

/* SQL(), IF() */
.cm-s-eclipse .cm-formula-master-var {
    color: #0070C1;
}

/* master.f_... */
.cm-s-eclipse .cm-formula-child-var {
    color: #5B9D00;
}

/* child.f_... */
.cm-s-eclipse .cm-formula-sql-var {
    color: #0070C1;
    font-style: italic;
}

/* @MASTER_ID */
.cm-s-eclipse .cm-string {
    color: #A31515;
}

/* 'strings' */
.cm-s-eclipse .cm-number {
    color: #098658;
}

/* 89, 90, 67 */
.cm-s-eclipse .cm-operator {
    color: #AA5D00;
}

/* = / */
.cm-s-eclipse .cm-comment {
    color: #888;
    font-style: italic;
}

/* -- comments */
/* --- END CodeMirror --- */


/* --- Custom Number Spinner --- */
.quantity {
    position: relative;
    display: inline-block;
    width: 100%;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

.quantity input[type="number"].form-control {
    display: block;
    height: 38px;
    line-height: 1.65;
    padding: 6px 12px;
    padding-right: 40px;
    margin: 0;
    border: 1px solid #ccc;
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
}

.quantity input:focus {
    outline: 0;
    border-color: #3498db;
}

.quantity-nav {
    position: absolute;
    right: 1px;
    top: 1px;
    height: calc(100% - 2px);
    width: 30px;
    border-left: 1px solid #ccc;
}

.quantity-button {
    position: absolute;
    width: 100%;
    height: 50%;
    cursor: pointer;
    text-align: center;
    color: #333;
    font-size: 14px;
    font-family: "Trebuchet MS", Helvetica, sans-serif !important;
    line-height: 1.2;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    background: #f9f9f9;
}

.quantity-button:hover {
    background: #f1f1f1;
}

.quantity-button.quantity-up {
    top: 0;
    border-bottom: 1px solid #ccc;
    line-height: 1.4;
    border-radius: 0 4px 0 0;
}

.quantity-button.quantity-down {
    bottom: 0;
    border-radius: 0 0 4px 0;
}

/* --- End Spinner --- */

/* --- Tab Styles --- */
.tabs {
    margin-top: 20px;
    border-bottom: 2px solid #ccc;
}

.tab-links {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
}

.tab-links li {
    margin-right: 5px;
}

.tab-link {
    display: block;
    padding: 10px 15px;
    background: #f4f4f4;
    color: #333;
    text-decoration: none;
    border: 1px solid #ccc;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    transition: background 0.3s;
}

.tab-link:hover {
    background: #eaeaea;
}

.tab-link.active {
    background: #fff;
    color: #34495e;
    border-color: #ccc;
    border-bottom: 2px solid #fff;
    font-weight: bold;
}

.tab-content {
    padding: 20px 0;
    border-top: none;
}

/* --- V47: .tab-pane is no longer needed, but we keep .active for visibility --- */
.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* --- End Tabs --- */

.field-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.field-table th,
.field-table td {
    padding: 10px;
    border: 1px solid #eee;
    text-align: left;
}

.field-table th {
    background-color: #34495e;
    color: white;
    font-weight: bold;
}

.field-table tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.form-grid>.form-group {
    grid-column: span 1;
}

.lookup-fields,
.advanced-fields {
    border: 1px solid #ccc;
    padding: 10px;
    border-radius: 5px;
    background: #fafafa;
    margin-bottom: 15px;
}

.lookup-info {
    font-size: 0.9em;
    color: #555;
}

.table-active-row {
    background-color: #e6f7ff;
    border-left: 5px solid #3498db;
}

.module-table .btn {
    padding: 5px 8px;
    font-size: 0.85em;
}

.config-detail {
    font-size: 0.85em;
    background: #ecf0f1;
    padding: 2px 5px;
    border-radius: 3px;
    display: inline-block;
    margin-top: 5px;
}

.lookup-helper-select {
    width: auto;
    display: inline-block;
    font-size: 0.9em;
    height: 30px;
    padding: 2px 8px;
}

.formula-helper-bar {
    margin-top: 5px;
    margin-bottom: 5px;
}

.formula-helper-bar .btn-helper {
    padding: 2px 8px;
    font-size: 0.85em;
    margin-right: 4px;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 4px;
    cursor: pointer;
}

.formula-helper-bar .btn-helper:hover {
    background-color: #dadddf;
}

.formula-helper-group {
    border: 1px solid #dde;
    background: #fdfdff;
    padding: 10px;
    border-radius: 4px;
    margin-top: 10px;
}

.formula-helper-group h6 {
    margin: 0 0 5px 0;
    font-size: 0.95em;
    color: #34495e;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.formula-helper-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.formula-helper-grid .form-group {
    margin-bottom: 0;
}

.formula-helper-grid label {
    font-size: 0.9em;
    font-weight: bold;
    display: block;
    margin-bottom: 3px;
}

/* --- Language Inputs --- */
.lang-input-group {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 10px;
    background: #f9f9f9;
}

.lang-input-group label {
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
}

.lang-input-grid {
    display: grid;
    grid-template-columns: 50px 1fr;
    gap: 5px 10px;
    align-items: center;
}

.lang-input-grid .lang-badge {
    font-weight: bold;
    text-transform: uppercase;
    text-align: right;
    color: #555;
}

/* --- NEW: Sub-group styling --- */
.sub-group-header {
    padding: 10px 20px;
    background: #f4f4f4;
    margin: 0 -20px 0 -20px;
    border-bottom: 1px solid #eee;
    border-top: 1px solid #eee;
    font-size: 1.05em;
    font-weight: bold;
    color: #34495e;
}

.card-body .sub-group-header:first-child {
    border-top: none;
}

.card-body.no-padding {
    padding: 0;
}

.sub-group-content {
    padding: 20px;
}


.formula-helper-group.query-helper {
    border-color: #c3e6cb;
    background: #f0fff4;
}

.formula-helper-group.query-helper h6 {
    color: #155724;
}

/* V16: Specific style for file upload helper bar */
#file-upload-group .formula-helper-bar .btn-helper,
#file-upload-filename-group .formula-helper-bar .btn-helper {
    padding: 2px 8px;
    font-size: 0.85em;
    margin-right: 4px;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 4px;
    cursor: pointer;
}

#file-upload-group .formula-helper-bar .btn-helper:hover,
#file-upload-filename-group .formula-helper-bar .btn-helper:hover {
    background-color: #dadddf;
}

/* --- START: NEW V20 Storage Options --- */
.storage-options-group {
    border-top: 1px solid #e0e0e0;
    margin-top: 15px;
    padding-top: 15px;
}

.storage-options-group h5 {
    margin-top: 0;
    font-size: 1.1em;
    color: #333;
}

.storage-options-list label {
    display: block;
    font-weight: normal;
    margin-bottom: 5px;
}

.storage-options-list label input {
    margin-right: 8px;
}

/* --- END: NEW V20 Storage Options --- */

/* --- START: NEW V54 Layout Manager Styles --- */
.layout-manager-container {
    display: flex;
    gap: 20px;
}

.layout-sidebar {
    width: 300px;
    flex-shrink: 0;
}

.layout-editor {
    flex-grow: 1;
}

.layout-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

.layout-list-item {
    padding: 8px 12px;
    margin-bottom: 5px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: grab;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.layout-list-item:hover {
    background-color: #f9f9f9;
}

.layout-list-item .field-label {
    font-weight: 500;
}

.layout-list-item .field-type {
    font-size: 0.85em;
    color: #555;
    background-color: #eee;
    padding: 2px 6px;
    border-radius: 3px;
}

.layout-list-item.sortable-ghost {
    background-color: #e6f7ff;
    opacity: 0.7;
}

.layout-list-item.sortable-chosen {
    cursor: grabbing;
    background-color: #dbeeff;
}

.unused-fields-list {
    min-height: 100px;
    background: #fdfdfd;
    border: 1px dashed #ccc;
    padding: 10px;
    border-radius: 4px;
}

.layout-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 10px;
    background-color: #f9f9f9;
    border: 1px dashed #ccc;
    padding: 10px;
    min-height: 200px;
    border-radius: 4px;
}

.layout-grid .layout-list-item {
    /* Default to full width (12 columns) */
    grid-column: span 12;
    background-color: #fff;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Column Span Controls */
.field-controls {
    display: flex;
    align-items: center;
    gap: 5px;
}

.field-controls .col-span-label {
    font-size: 0.8em;
    color: #333;
}

.field-controls .col-span-select {
    width: 60px;
    padding: 2px;
    font-size: 0.85em;
    border-radius: 3px;
}

/* Responsive Device Tabs */
.device-tabs {
    display: flex;
    margin-bottom: -1px;
    /* V54: Overlap border */
    border-bottom: 1px solid #ccc;
}

.device-tab-link {
    padding: 8px 15px;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    margin-bottom: -1px;
    background-color: #f1f1f1;
    color: #555;
    text-decoration: none;
    border-radius: 4px 4px 0 0;
    /* V54 */
}

.device-tab-link.active {
    background-color: #fff;
    border-color: #ccc;
    border-bottom: 1px solid #fff;
    font-weight: bold;
    color: #333;
}

.layout-tab-pane {
    display: none;
}

.layout-tab-pane.active {
    display: block;
}

/* --- END V54 Layout Manager Styles --- */

/* --- V89: Module Settings Form Layout --- */
.module-settings-form {
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
    background: #fdfdfd;
    padding: 15px;
    border: 1px solid #eee;
    border-radius: 5px;
}

.module-selector-grid {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 15px;
    align-items: flex-end;
}

.module-selector-grid .form-group {
    margin-bottom: 0;
}

/* --- END V89 --- */

/* ======================================================================
START: V92 - New Print Designer Styles
======================================================================
*/

/* V92: Style for toolbox groups */
.toolbox-group {
    margin-bottom: 15px;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px;
}

/* V92: Hide property groups by default */
.prop-group {
    display: none;
    /* V104: Removed border-top, margin-top, padding-top. Handled by <details> */
}

/* V94: Keep Page Properties group border cleaner */
#prop-group-page {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}

/* V92: Style for color input */
.designer-properties input[type="color"] {
    padding: 2px;
    height: 30px;
    /* V92.1 Fix: Make color input fill width */
    width: 100%;
    box-sizing: border-box;
}

.designer-properties .grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

/* V92: New item type styles */
.designer-item-content.is-url-designer {
    color: #0056b3;
    text-decoration: underline;
    cursor: default;
}

.designer-item-content.is-image-designer {
    padding: 0;
}

.designer-item-content.is-image-designer img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Show the whole image */
    /* V92.1 Fix: Prevent dragging image */
    pointer-events: none;
}

.designer-item-content.is-shape-designer {
    padding: 0;
    /* Styles applied by JS */
}

/* V92.2: Z-Index Controls */
.z-index-controls {
    display: flex;
    gap: 5px;
    margin-top: 10px;
}

.z-index-controls .btn {
    flex-grow: 1;
    /* Make buttons fill space */
    font-size: 0.9em;
}


/* ======================================================================
END: V92 - New Print Designer Styles
======================================================================
*/

/* ======================================================================
START: V93 - Resizable Sections & New Items
======================================================================
*/
/* V93 Section Resize Handle */
.section-resize-handle {
    position: absolute;
    bottom: -5px;
    /* Sits on the border */
    left: 0;
    width: 100%;
    height: 10px;
    cursor: ns-resize;
    z-index: 5;
}

.section-resize-handle::after {
    /* Visual indicator */
    content: '...';
    font-size: 20px;
    color: #a0c0e0;
    line-height: 0;
    font-weight: bold;
    letter-spacing: 2px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.section-resize-handle:hover::after {
    color: #e74c3c;
}

/* Handle for Footer (at bottom of Content) needs to be on top of Footer's border */
#canvas-content .section-resize-handle {
    z-index: 3;
    /* Above footer's ::before pseudo-element */
}

/* V93 Section Selection */
.designer-section.selected {
    /* Just a visual cue, a subtle glow */
    box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
}

/* V93 New Item Placeholders */
.designer-item-content.is-signature-designer,
.designer-item-content.is-stamp-designer {
    background: #fdfdfd;
    border: 2px dashed #b0c4de;
    color: #6a85ad;
    font-style: italic;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    pointer-events: none;
}

/* ======================================================================
END: V93
======================================================================
*/

/* ======================================================================
START: V94 - Page Settings
======================================================================
*/
/* V94: Page Overlays (Grid/Dots) */
#designer-page-grid-overlay,
#designer-page-dots-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

#designer-page-grid-overlay {
    background-size: 10mm 10mm;
    /* Default, will be updated by JS */
}

#designer-page-dots-overlay {
    background-size: 1mm 1mm;
    /* Default, will be updated by JS */
}

/* V94: Custom Page Size Inputs */
.custom-page-size-group {
    display: none;
    /* Hidden by default */
    border-top: 1px dashed #ccc;
    margin-top: 8px;
    padding-top: 8px;
}

/* V94: Close button for properties panel */
.properties-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    width: 24px;
    height: 24px;
    border: none;
    background: #f1f1f1;
    color: #888;
    border-radius: 50%;
    font-weight: bold;
    font-size: 16px;
    line-height: 22px;
    text-align: center;
    cursor: pointer;
    padding: 0;
}

.properties-close-btn:hover {
    background: #e0e0e0;
    color: #333;
}

/* V94: Checkbox grid */
.grid-checkbox-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.grid-checkbox-group .form-group {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 5px;
}

.grid-checkbox-group label {
    font-size: 0.9em;
    font-weight: normal;
    margin-bottom: 0;
}

.grid-checkbox-group input[type="checkbox"] {
    width: auto;
    height: auto;
}

/* ======================================================================
END: V94
======================================================================
*/


/* ======================================================================
START: V99 - Loop Table Designer
======================================================================
*/

/* V99: Loop Item Placeholder */
.designer-item-content.is-child-loop {
    background: #f0f8ff;
    /* V105: Removed border, handled by JS */
    color: #557;
    font-style: italic;
    font-size: 0.9em;
    padding: 0;
    /* Remove padding to allow table to fill */
    overflow: hidden;
    /* V99.1: Hide overflow */
}

/* V99: Loop Item Designer Table */
.loop-designer-table {
    width: 100%;
    height: 100%;
    border-collapse: separate;
    /* V105: Use separate for border-radius */
    border-spacing: 0;
    table-layout: fixed;
    /* Important for width control */
}

.loop-designer-table th,
.loop-designer-table td {
    /* V105: Border is now applied by JS */
    padding: 2px 4px;
    font-size: 10px;
    /* Small font for designer */
    line-height: 1.2;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.loop-designer-table th {
    /* background-color: #e6f2ff; V105: Applied by JS */
    text-align: left;
    font-weight: bold;
}

.loop-designer-table td {
    /* background-color: #fff; V105: Applied by JS */
}

/* V99: Column Manager UI */
.column-manager-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.column-manager-item {
    display: grid;
    /* V105: Updated grid for new width controls */
    grid-template-columns: 20px 20px 1fr 1fr 120px;
    gap: 5px;
    align-items: center;
    padding: 5px;
    background: #fff;
    border-bottom: 1px solid #eee;
}

.column-manager-item:last-child {
    border-bottom: none;
}

.column-manager-item.sortable-ghost {
    background: #e6f7ff;
    opacity: 0.7;
}

.column-manager-handle {
    cursor: grab;
    color: #aaa;
    text-align: center;
}

.column-manager-handle:hover {
    color: #333;
}

.column-manager-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
}

.column-manager-item .col-name {
    font-size: 0.9em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #555;
}

.column-manager-item .form-control {
    font-size: 0.8em;
    height: 24px;
    padding: 2px 4px;
}

.column-manager-desc {
    font-size: 0.8em;
    color: #666;
    margin-bottom: 5px;
}

/* V99: Loop Font Settings */
.font-settings-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 8px;
}

.font-settings-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

/* ======================================================================
END: V99
======================================================================
*/

/* ======================================================================
START: V104 - Properties Panel Cleanup
======================================================================
*/
.designer-properties details {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    margin-bottom: 8px;
    background: #fafafa;
}

.designer-properties details summary {
    font-weight: bold;
    font-size: 0.9em;
    padding: 8px 12px;
    cursor: pointer;
    background: #f1f1f1;
    border-radius: 3px;
    /* V104.1: Fix radius when open */
    transition: border-radius 0.1s;
}

.designer-properties details[open] summary {
    border-bottom: 1px solid #e0e0e0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.designer-properties .details-content {
    padding: 12px;
    background: #fff;
    border-radius: 0 0 3px 3px;
}

.designer-properties .details-content .form-group:last-child {
    margin-bottom: 0;
}

.designer-properties .details-content label {
    font-size: 0.85em;
    /* V104.1: Make labels slightly larger */
}

/* ======================================================================
END: V104
======================================================================
*/

/* ======================================================================
START: V105 - Column Width Group
======================================================================
*/
.column-width-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.column-width-group .loop-col-width-mode {
    width: 100%;
}

.column-width-group .loop-col-width-custom {
    width: 100%;
    box-sizing: border-box;
    /* Ensure padding doesn't break layout */
    display: none;
    /* Hidden by default */
}

/* V105: Tweak column manager grid to give width group more space */
.column-manager-item {
    grid-template-columns: 20px 20px 1fr 1fr 120px;
    /* More space for width */
}

/* ======================================================================
END: V105
======================================================================
*/

/* ======================================================================
START: V106 - Print Designer Additions
======================================================================
*/
/* V106: Checkbox in details content */
.details-content .form-group-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.details-content .form-group-checkbox input[type="checkbox"] {
    width: auto;
    height: auto;
}

.details-content .form-group-checkbox label {
    font-weight: normal;
    margin: 0;
    font-size: 0.85em;
}

/* V106: Transposed table preview */
.loop-designer-table.transposed {
    display: flex;
    height: 100%;
}

.loop-designer-table.transposed tbody {
    display: flex;
    flex-grow: 1;
}

.loop-designer-table.transposed tr {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.loop-designer-table.transposed th,
.loop-designer-table.transposed td {
    display: block;
    width: auto !important;
    /* Override width */
}

.loop-designer-table.transposed th {
    flex-shrink: 0;
}

.loop-designer-table.transposed td {
    flex-grow: 1;
}

/* ======================================================================
END: V106
======================================================================
*/

/* +++ NEW: Styles for Reordering and Font Style Controls (V113) +++ */
.column-settings-table th.sort-col,
.column-settings-table td.sort-col {
    width: 40px;
    text-align: center;
    padding-left: 8px;
    padding-right: 8px;
}

.sort-handle {
    cursor: grab;
    color: #aaa;
    font-size: 1.2em;
}

.sort-handle:hover {
    color: #333;
}

tr.sortable-ghost {
    background: #e6f7ff;
    opacity: 0.7;
}

tr.sortable-chosen {
    cursor: grabbing;
}

.column-settings-table th.align-col,
.column-settings-table td.align-col {
    width: 120px;
}

.column-settings-table th.style-col,
.column-settings-table td.style-col {
    width: 160px;
}

.font-style-controls {
    display: flex;
    gap: 4px;
}

.font-style-btn {
    background: #f0f0f0;
    border: 1px solid #ccc;
    padding: 4px 8px;
    font-size: 0.9em;
    border-radius: 4px;
    cursor: pointer;
    width: 28px;
    text-align: center;
}

.font-style-btn.active {
    background: #3498db;
    color: white;
    border-color: #2980b9;
}

.font-style-btn .fa-strikethrough {
    font-size: 0.9em;
    /* Strikethrough icon is often taller */
}

/* +++ NEW: CSS classes for table cell styling (V113) +++ */
.cell-align-left {
    text-align: left;
}

.cell-align-center {
    text-align: center;
}

.cell-align-right {
    text-align: right;
}

.cell-style-bold {
    font-weight: bold;
}

.cell-style-italic {
    font-style: italic;
}

.cell-style-underline {
    text-decoration: underline;
}

.cell-style-strike {
    text-decoration: line-through;
}


/* Dropdown Menu - Sub-menu on Desktop should have light background */
.nav-menu .dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    /* FIX: ทำให้ dropdown ย่อยเป็นสีขาวตามปกติ */
    background-color: #ffffff;
    border-radius: 0 0 5px 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    z-index: 1000;
    padding: 5px 0;
}

.nav-menu .dropdown-menu a {
    color: #333;
    /* FIX: ทำให้ link ใน dropdown เป็นสีเข้ม */
    padding: 10px 20px;
    font-weight: normal;
}

/* Hide mobile-only menu items by default */
.nav-dropdown-mobile {
    display: none !important;
}

/* Hide desktop-only menu items by default */
.nav-dropdown-desktop {
    display: block;
    /* Show on desktop */
}

/* Mobile Toggler */
.nav-toggler {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    /* REMOVED padding: 15px; Handled by nav-left/nav-toggler in media query */
    /* NEW: ทำให้ Toggler อยู่ชิดซ้ายสุด (ใช้คู่กับ order:-1 ใน JS) */
    order: -1;
    padding: 15px 0;
    margin-right: 15px;
}


/* Responsive */
@media (max-width: 992px) {

    /* FIX: ให้ nav-left กินพื้นที่เต็มและจัดเรียง */
    .nav-left {
        width: 100%;
        justify-content: flex-start;
    }

    /* Show Toggler on Mobile */
    .nav-toggler {
        display: block;
    }

    /* Hide desktop-only menu item on Mobile */
    .nav-dropdown-desktop {
        display: none !important;
    }

    /* Show mobile-only menu item on Mobile */
    .nav-dropdown-mobile {
        display: block !important;
    }

    /* FIX: Mobile Menu Display */
    .nav-left .nav-menu {
        display: none;
        flex-direction: column;
        width: 100%;
        position: absolute;
        top: 60px;
        /* Adjust based on navbar height */
        left: 0;
        /* Use CSS Variables to ensure correct theme color */
        background-color: var(--nav-bg-color, #34495e);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }

    .nav-left .nav-menu.active {
        display: flex;
    }

    .nav-left .nav-menu a {
        color: white;
        /* Text color for main menu links on mobile */
        padding: 15px 20px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* FIX: Make top-level links match hover style */
    .nav-left .nav-menu a:hover {
        background-color: var(--nav-hover-color, #2c3e50);
    }

    /* FIX: Dropdown Menu (Sub-menus) in Mobile */
    .nav-menu .dropdown-menu {
        position: static;
        width: 100%;
        box-shadow: none;
        border-radius: 0;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        background-color: inherit;
        /* Inherit nav theme color for sub-menus */
        padding: 0;
    }

    .nav-menu .dropdown-menu a {
        /* FIX: Adjust color/padding for sub-menu links */
        color: white;
        padding: 10px 40px;
        /* Indent sub-links */
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .nav-menu .dropdown-menu a:hover {
        background-color: var(--nav-hover-color, #2c3e50);
        color: white;
    }


    /* Hide Language on mobile, keep profile button */
    .nav-right .nav-menu>li:not(.nav-profile) {
        display: none;
    }

    .nav-right {
        /* Ensure profile button is always visible */
        justify-content: flex-end;
    }
}