/* ========== DATASHEET LAYOUT EDITOR STYLES ========== */

/* Back Link */
.back-link {
    color: #E87722;
    text-decoration: none;
    font-weight: 600;
    padding: 8px 16px;
    border: 1px solid #E87722;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.back-link:hover {
    background: #E87722;
    color: #fff;
}

/* Editor Main Layout */
.editor-main {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    gap: 16px;
    max-width: 100vw;
    margin: 16px auto;
    padding: 0 16px;
    min-height: calc(100vh - 160px);
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Controls Panel */
.editor-controls {
    background: #111;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 14px;
}

.editor-controls h2 {
    margin: 0 0 14px 0;
    font-size: 16px;
    color: #E87722;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

/* Control Sections */
.control-section {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}

.control-header {
    padding: 10px 12px;
    background: #222;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: background 0.2s;
    position: relative;
}

.control-header:hover {
    background: #2a2a2a;
}

/* Collapse indicator arrow */
.control-header::before {
    content: '▼';
    position: absolute;
    right: 12px;
    font-size: 8px;
    color: #666;
    transition: transform 0.3s ease;
}

.control-section.collapsed .control-header::before {
    transform: rotate(-90deg);
}

.control-section.collapsed .control-header {
    border-bottom: none;
}

/* Collapsible body animation */
.control-body {
    padding: 14px;
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.control-section.collapsed .control-body {
    max-height: 0;
    padding: 0 14px;
    opacity: 0;
}

/* Element reorder buttons */
.element-reorder-btns {
    display: flex;
    gap: 4px;
}

.element-reorder-btn {
    background: #333;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.element-reorder-btn:hover {
    background: #E87722;
    border-color: #E87722;
}

/* Missing field warning - red border for fields not found in Excel */
.field-missing {
    border-color: #ff4444 !important;
    background: rgba(255, 68, 68, 0.1) !important;
    box-shadow: 0 0 4px rgba(255, 68, 68, 0.5);
}

.field-missing::placeholder {
    color: #ff6666;
}

/* Lock button */
.element-lock-btn {
    background: #333;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.element-lock-btn:hover {
    background: #555;
}

.element-lock-btn.locked {
    background: #E87722;
    border-color: #E87722;
}

/* Disabled reorder buttons when locked */
.control-section.locked .element-reorder-btn {
    opacity: 0.3;
    pointer-events: none;
}

.element-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
}

.element-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #E87722;
}

.control-body {
    padding: 14px;
}

.control-body.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-row label {
    flex: 0 0 70px;
    font-size: 12px;
    color: #999;
}

.title-text-input {
    font-size: 11px !important;
    cursor: text;
    width: 100%;
}

/* Full width input for footer text etc */
.full-width-input {
    width: 100% !important;
    flex: 1 !important;
    font-size: 11px;
    padding: 8px 10px;
    background: #222;
    border: 1px solid #444;
    border-radius: 4px;
    color: #fff;
}

.control-row select,
.control-row input[type="text"],
.control-row input[type="number"] {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #444;
    border-radius: 6px;
    background: #222;
    color: #fff;
    font-size: 13px;
}

.control-row select:focus,
.control-row input:focus {
    outline: none;
    border-color: #E87722;
}

/* Radio Group */
.radio-group {
    display: flex;
    gap: 16px;
}

.radio-group label {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #ccc;
    cursor: pointer;
}

.radio-group input[type="radio"] {
    accent-color: #E87722;
}

/* Value Editor */
.value-editor {
    margin-top: 12px;
    padding: 12px;
    background: #151515;
    border-radius: 8px;
    border: 1px dashed #444;
}

.value-editor.hidden {
    display: none;
}

.value-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #333;
}

.value-row:last-child {
    border-bottom: none;
}

.value-row span {
    font-size: 12px;
    color: #999;
}

.value-row input {
    width: 60px;
    padding: 4px 8px;
    text-align: right;
}

/* CLS Border Controls */
.border-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 6px;
    padding: 10px;
    background: #151515;
    border-radius: 6px;
    border: 1px solid #333;
}

/* Plus/Minus Size Controls */
.plusminus-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

.plusminus-control input {
    width: 50px;
    padding: 4px 6px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #222;
    color: #fff;
    font-size: 12px;
    text-align: center;
}

.pm-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #666;
    border-radius: 4px;
    background: #333;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s;
}

.pm-btn:hover {
    background: #555;
    border-color: #f77f00;
}

.border-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.border-row label {
    flex: 0 0 50px;
    font-size: 11px;
    color: #999;
}

.border-row input {
    width: 50px;
    padding: 4px 6px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #222;
    color: #fff;
    font-size: 12px;
    text-align: center;
}

.border-row input:focus {
    outline: none;
    border-color: #E87722;
}

/* Parameters List for Pie Chart */
.params-list {
    background: #151515;
    border-radius: 6px;
    padding: 8px;
    margin-top: 8px;
    border: 1px solid #333;
}

.param-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
    border-bottom: 1px solid #333;
}

.param-row:last-child {
    border-bottom: none;
}

.param-row .param-name {
    flex: 1;
    min-width: 80px;
    padding: 4px 6px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #222;
    color: #fff;
    font-size: 11px;
}

.param-row .param-minmax {
    width: 52px;
    padding: 4px 2px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #222;
    color: #999;
    font-size: 10px;
}

.param-row .param-value {
    width: 45px;
    padding: 4px 4px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #222;
    color: #fff;
    font-size: 11px;
    text-align: center;
}

.param-row input:focus,
.param-row select:focus {
    outline: none;
    border-color: #E87722;
}

.delete-param-btn {
    padding: 2px 6px;
    border: none;
    background: transparent;
    color: #ff6666;
    font-size: 12px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.delete-param-btn:hover {
    opacity: 1;
}

/* Excel Data Source Section */
.excel-source {
    border-left: 3px solid #4CAF50;
}

.excel-source select {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #222;
    color: #fff;
    font-size: 12px;
}

.btn-secondary {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #E87722;
    border-radius: 6px;
    background: transparent;
    color: #E87722;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #E87722;
    color: #fff;
}

/* Column Preview Panel */
.column-preview {
    background: #1a1a1a;
    border-radius: 6px;
    padding: 8px;
    margin-top: 8px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 11px;
    color: #aaa;
}

.badge {
    background: #E87722;
    color: #fff;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: bold;
}

.badge.warning {
    background: #ff6b6b;
}

.column-list {
    max-height: 200px;
    overflow-y: auto;
}

.column-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 6px;
    margin: 2px 0;
    background: #252525;
    border-radius: 4px;
    font-size: 11px;
}

.column-item .col-name {
    color: #ccc;
}

.column-item .col-value {
    color: #E87722;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* File name display */
.file-name-display {
    font-size: 11px;
    color: #aaa;
    padding: 4px 8px;
    background: #1a1a1a;
    border-radius: 4px;
    margin: 6px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Data Row (Excel data display in content areas) */
.data-row {
    display: flex;
    justify-content: space-between;
    padding: 2mm 3mm;
    border-bottom: 0.5px solid #ddd;
    font-size: 9px;
}

.data-row:last-child {
    border-bottom: none;
}

.data-label {
    color: #333;
    font-weight: 500;
}

.data-value {
    color: #333;
    text-align: right;
    max-width: 60%;
    word-wrap: break-word;
}

/* Upload Areas */
.upload-area {
    background: #1a1a1a;
    border: 2px dashed #444;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    text-align: center;
}

.upload-preview {
    width: 80px;
    height: 80px;
    margin: 0 auto 10px auto;
    background: #222;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.upload-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.upload-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.upload-btn {
    display: inline-block;
    padding: 8px 14px;
    background: #E87722;
    color: #fff;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.upload-btn:hover {
    background: #d66b1c;
}

/* Section List */
.section-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.section-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: #222;
    border-radius: 6px;
    font-size: 12px;
    cursor: grab;
    transition: background 0.2s;
}

.section-item:hover {
    background: #2a2a2a;
}

.section-item input[type="checkbox"] {
    accent-color: #E87722;
}

.section-item.dragging {
    opacity: 0.5;
    background: #333;
}

/* Template Actions */
.template-actions h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #ccc;
}

.button-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.button-row button {
    flex: 1;
}

button.small {
    padding: 6px 10px;
    font-size: 11px;
}

/* Saved Templates List */
.saved-templates {
    margin-top: 12px;
    max-height: 150px;
    overflow-y: auto;
}

.saved-template-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: #222;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 12px;
}

.saved-template-item:hover {
    background: #2a2a2a;
}

.saved-template-item .template-name {
    flex: 1;
    cursor: pointer;
    color: #ccc;
}

.saved-template-item .delete-btn {
    background: transparent;
    border: none;
    color: #c0392b;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
}

/* Preview Section */
.editor-preview {
    background: #0a0a0a;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    max-width: calc(100vw - 640px);
    overflow: hidden;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.preview-header h2 {
    margin: 0;
    font-size: 16px;
    color: #ccc;
}

.preview-actions {
    display: flex;
    gap: 8px;
}

/* Preview Canvas Wrapper */
.preview-canvas-wrapper {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 12px;
    background: #151515;
    border-radius: 6px;
}

/* Preview Canvas */
.preview-canvas {
    padding: 20px;
    overflow: auto;
}

/* 4-Page Grid Layout (2x2) */
.pages-container {
    display: grid;
    grid-template-columns: repeat(2, 105mm);
    grid-template-rows: repeat(2, 297mm);
    column-gap: 0;
    row-gap: 10mm;
    background: #333;
}

.datasheet-page {
    width: 105mm;
    height: 297mm;
    background: white;
    color: #000;
    padding: 3mm;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 9px;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    border: 1px solid #ccc;
}

/* P1.1 - Pie Chart Panel (60mm = P2.1 + P2.2) */
.p1-chart-panel {
    width: 100%;
    height: auto;
    min-height: 50mm;
    background: white;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    overflow: hidden;
    box-sizing: border-box;
    padding: 2mm;
    margin: 0;
    /* border-bottom: 1px dashed #ccc; - Guide line hidden */
}

.p1-chart-panel canvas {
    max-width: 100%;
    max-height: 60mm;
}

/* Pie Chart with Labels Layout */
.pie-with-labels {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 3mm;
    padding: 2mm;
}

.pie-labels {
    display: flex;
    flex-direction: column;
    gap: 1mm;
    padding-top: 2mm;
}

.pie-label-row {
    /* font-size and font-weight are set dynamically by JS */
    color: #333;
    text-align: left;
    white-space: nowrap;
}

/* P1.1 - Ingredient Info Panel (auto height, shrinks to fit content) */
.p1-ingredient-panel {
    width: 100%;
    height: auto;
    min-height: 30mm;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    /* border-bottom: 1px dashed #ccc; - Guide line hidden */
}

.p1-ingredient-panel .ingredient-header {
    width: 100%;
    background: #000;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 3mm;
    box-sizing: border-box;
}

.p1-ingredient-panel .ingredient-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9px;
}

.p1-ingredient-panel .ingredient-table tr {
    border-bottom: 1px solid #ddd;
}

.p1-ingredient-panel .ingredient-table tr:last-child {
    border-bottom: none;
}

.p1-ingredient-panel .ingredient-table td {
    padding: 1mm 3mm;
}

.p1-ingredient-panel .ingredient-table td.label {
    width: 50%;
    color: #333;
}

.p1-ingredient-panel .ingredient-table td.value {
    width: 50%;
    text-align: right;
    color: #000;
    font-weight: 500;
}

/* P1.3 - Content Area (fills remaining space using flex) */
.p1-content-area {
    width: 100%;
    flex: 1;
    min-height: 100mm;
    background: white;
    padding: 3mm;
    padding-bottom: 20mm;
    /* 15mm footer + 3mm buffer */
    overflow: hidden;
    box-sizing: border-box;
}

/* Page 1 specific layout */
#page1 {
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* P2.1 - Fixed Image Panel at top of Page 2 */
.p2-image-panel {
    width: 100%;
    height: 50mm;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    /* border-bottom: 1px dashed #ccc; - Guide line hidden */
}

.p2-image-panel img {
    width: 105mm;
    height: auto;
    max-height: 50mm;
    object-fit: contain;
    background: white;
    border: none;
    display: block;
}

/* P2.2 - Heading Strip (20mm height) */
.p2-heading-strip {
    width: 100%;
    height: 10mm;
    background: #fff;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-sizing: border-box;
    padding: 0 3mm;
    /* border-bottom: 1px dashed #ccc; - Guide line hidden */
}

/* P2.3 - Content Area (remaining space after image + heading) */
.p2-content-area {
    width: 100%;
    height: calc(297mm - 50mm - 10mm - 6mm);
    background: white;
    padding: 3mm;
    padding-bottom: 20mm;
    /* 15mm footer + 3mm buffer */
    overflow: hidden;
    box-sizing: border-box;
}

/* ── A4 Footer Layer System ──────────────────────────────
   Each footer lives inside its own transparent A4-sized layer
   (297mm tall × 210mm wide) that overlays a row of pages.
   The footer bar is pinned to bottom:0 of this layer,
   so it can ONLY appear at the bottom of the A4 page. */

/* The transparent A4 layer */
.a4-footer-layer {
    position: absolute;
    left: 0;
    width: 210mm;
    /* Full A4 width */
    height: 297mm;
    /* Full A4 height */
    pointer-events: none;
    /* Don't block clicks on page content */
    z-index: 100;
}

/* Layer 1: covers page row 1 (pages 1+2) */
.a4-footer-layer-row1 {
    top: 0;
}

/* Layer 2: covers page row 2 (pages 3+4), after 10mm gap */
.a4-footer-layer-row2 {
    top: 307mm;
    /* 297mm + 10mm row-gap */
}

/* The footer bar itself — always at the bottom of its A4 layer */
.a4-footer-overlay {
    position: absolute;
    bottom: 0;
    /* Locked to bottom of A4 layer */
    left: 0;
    width: 100%;
    /* Inherits 210mm from layer */
    height: 15mm;
    background: #ffffff;
    color: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 400;
    letter-spacing: 0.3px;
    text-align: center;
    box-sizing: border-box;
    padding: 0 5mm;
    border-top: 0.5px solid #ccc;
    pointer-events: auto;
    /* Re-enable clicks on footer itself */
}

.a4-footer-overlay .footer-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* pages-container must be position:relative for the footer layers */
.pages-container {
    position: relative;
}

/* P3/P4 Content Areas */
.p3-content-area,
.p4-content-area {
    width: 100%;
    height: calc(297mm - 15mm);
    /* Full height minus footer */
    background: white;
    padding: 3mm;
    padding-bottom: 20mm;
    /* 15mm footer + 3mm buffer */
    overflow: hidden;
    box-sizing: border-box;
}

/* Overflow content area for dynamic pages (p5, p6, etc.) */
.overflow-content-area {
    width: 100%;
    height: calc(297mm - 15mm);
    background: white;
    padding: 3mm;
    padding-bottom: 20mm;
    /* 15mm footer + 3mm buffer */
    overflow: hidden;
    box-sizing: border-box;
}

/* Page 2 specific layout - no padding to allow P2.1 full width */
#page2 {
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Locked elements at page tops */
.locked-element {
    width: 100%;
    margin-bottom: 3mm;
    text-align: center;
}

.page-chart {
    width: 100%;
    max-width: 45mm;
    height: auto;
}

.locked-image img {
    width: 100%;
    height: auto;
    max-height: 60mm;
    object-fit: contain;
}

/* Black strip section headings */
.section-heading {
    background: #000;
    color: #fff;
    padding: 2mm 3mm;
    font-weight: bold;
    font-size: 8px;
    margin-bottom: 1mm;
}

.section-data {
    padding: 1mm 0;
    font-size: 8px;
    line-height: 1.4;
}

/* Legacy a4-page class - kept for backwards compatibility */
.a4-page {
    width: 105mm;
    min-height: 297mm;
    background: white;
    color: #000;
    padding: 5mm;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 9px;
    position: relative;
    box-sizing: border-box;
}

/* A4 Page Elements */
.a4-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: flex-start;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.a4-header:empty {
    display: none;
}

.a4-header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.a4-logo {
    object-fit: contain;
}

.a4-logo.small {
    width: 40px;
}

.a4-logo.medium {
    width: 60px;
}

.a4-logo.large {
    width: 80px;
}

.a4-title {
    font-size: 16px;
    font-weight: bold;
    margin: 0;
}

.a4-subtitle {
    font-size: 12px;
    color: #555;
    margin: 4px 0 0 0;
}

.a4-header-right {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.a4-stacked-element {
    width: 100%;
    text-align: right;
}

.a4-product-img {
    max-width: 100px;
    max-height: 80px;
    object-fit: contain;
}

.a4-product-img.small {
    max-width: 60px;
    max-height: 60px;
}

.a4-product-img.medium {
    max-width: 100px;
    max-height: 100px;
}

.a4-product-img.large {
    max-width: 140px;
    max-height: 140px;
}

.a4-product-img.xlarge {
    max-width: 180px;
    max-height: 180px;
}

.a4-product-img.xxxl {
    width: 100%;
    max-width: 100%;
    max-height: none;
    height: auto;
}

.a4-logo.xlarge {
    width: 100px;
}

/* Title Sizes */
.a4-title.small {
    font-size: 12px;
}

.a4-title.medium {
    font-size: 16px;
}

.a4-title.large {
    font-size: 20px;
}

/* Title Section (in data grid) */
.a4-title-section {
    margin-bottom: 8px;
}

/* Product Image Section (in data grid) */
.a4-product-image-section {
    margin-bottom: 10px;
    text-align: center;
}

.a4-title-section .a4-section-title {
    font-weight: bold;
    text-transform: uppercase;
    padding: 4px 0;
}

.a4-title-section.small .a4-section-title {
    font-size: 12px;
}

.a4-title-section.medium .a4-section-title {
    font-size: 16px;
}

.a4-title-section.large .a4-section-title {
    font-size: 20px;
}

/* Title Bar (for top-center position) */
.a4-title-bar {
    text-align: center;
    padding: 8px 0;
    border-bottom: 2px solid #000;
    margin-bottom: 10px;
}


/* Absolute Top Right - Product image at very top right with nothing above */
.a4-top-right-absolute {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 10;
}

/* Above Title Image */
.a4-above-title-image {
    text-align: center;
    margin-bottom: 10px;
}

/* Header Center */
.a4-header-center {
    flex: 1;
    text-align: center;
}

/* Section Reorder Buttons */
.section-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: #222;
    border-radius: 6px;
    font-size: 12px;
    transition: background 0.2s;
}

.section-item .section-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-item .reorder-btns {
    display: flex;
    gap: 2px;
}

.section-item .reorder-btn {
    background: #333;
    border: none;
    color: #999;
    padding: 2px 5px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s;
}

.section-item .reorder-btn:hover {
    background: #E87722;
    color: #fff;
}

/* Pie Chart Toggle */
.pie-toggle {
    margin-left: auto;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #444;
    border: 1px solid #666;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 14px;
    transition: all 0.2s;
}

.pie-toggle:hover {
    background: #555;
    border-color: #E87722;
}

.pie-toggle:has(input:checked) {
    background: #E87722;
    border-color: #E87722;
    color: #fff;
}

.pie-toggle input {
    display: none;
}

/* Content Grid */
.a4-content {
    display: grid;
    gap: 15px;
}

.a4-content.cols-1 {
    grid-template-columns: 1fr;
}

.a4-content.cols-2 {
    grid-template-columns: 1fr 1fr;
}

/* Chart Area */
.a4-chart-area {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
}

.a4-chart-img {
    object-fit: contain;
}

.a4-chart-img.small {
    width: 80px;
    height: 80px;
}

.a4-chart-img.medium {
    width: 120px;
    height: 120px;
}

.a4-chart-img.large {
    width: 160px;
    height: 160px;
}

/* Data Sections */
.a4-section {
    margin-bottom: 10px;
}

.a4-section-header {
    background: #000;
    color: #fff;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.a4-section-content {
    font-size: 10px;
    line-height: 1.4;
}

.a4-data-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 0.5px solid #ddd;
}

.a4-data-key {
    color: #333;
}

.a4-data-val {
    font-weight: 500;
    text-align: right;
}

/* Footer */
.a4-footer {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 8px;
    color: #666;
    border-top: 1px solid #ccc;
    padding-top: 8px;
    margin-top: 15px;
}

.a4-footer-content {
    font-size: 8px;
    color: #666;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* ========== FIELD MANAGER PANEL ========== */
.field-manager {
    background: #111;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 14px;
}

.field-manager-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.field-manager-header h2 {
    margin: 0;
    font-size: 16px;
    color: #E87722;
}

.field-manager-actions {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.fm-btn {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #444;
    border-radius: 6px;
    background: #222;
    color: #ccc;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.fm-btn:hover {
    background: #333;
    border-color: #E87722;
    color: #fff;
}

.field-manager-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fm-empty-state {
    text-align: center;
    color: #666;
    font-size: 12px;
    padding: 40px 10px;
    border: 2px dashed #333;
    border-radius: 8px;
}

/* Individual Field Item */
.fm-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    transition: all 0.2s;
    cursor: grab;
}

.fm-item:hover {
    background: #222;
    border-color: #555;
}

.fm-item.dragging {
    opacity: 0.4;
    background: #333;
    border-color: #E87722;
}

.fm-item.drag-over {
    border-color: #E87722;
    box-shadow: 0 0 0 1px #E87722;
}

.fm-item.disabled {
    opacity: 0.4;
}

.fm-item.disabled .fm-header-input,
.fm-item.disabled .fm-value-input {
    color: #666;
}

.fm-drag-handle {
    cursor: grab;
    color: #555;
    font-size: 10px;
    flex-shrink: 0;
    padding: 0 2px;
    -webkit-user-select: none;
    user-select: none;
}

.fm-item:active .fm-drag-handle {
    cursor: grabbing;
}

.fm-checkbox {
    width: 16px;
    height: 16px;
    accent-color: #E87722;
    flex-shrink: 0;
    cursor: pointer;
}

.fm-fields {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.fm-header-input {
    border: none;
    background: transparent;
    color: #ccc;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 4px;
    border-radius: 3px;
    width: 100%;
    box-sizing: border-box;
}

.fm-header-input:focus {
    outline: none;
    background: #222;
    border: 1px solid #E87722;
}

.fm-value-input {
    border: none;
    background: transparent;
    color: #E87722;
    font-size: 10px;
    padding: 2px 4px;
    border-radius: 3px;
    width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fm-value-input:focus {
    outline: none;
    background: #222;
    border: 1px solid #E87722;
    white-space: normal;
}

.fm-reorder-btns {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex-shrink: 0;
}

.fm-reorder-btn {
    background: transparent;
    border: none;
    color: #666;
    font-size: 10px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    transition: color 0.2s;
}

.fm-reorder-btn:hover {
    color: #E87722;
}

/* Field index number */
.fm-index {
    color: #555;
    font-size: 9px;
    font-weight: 600;
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

/* Responsive */
@media (max-width: 1400px) {
    .editor-main {
        grid-template-columns: 240px 1fr 220px;
    }
}

@media (max-width: 1100px) {
    .editor-main {
        grid-template-columns: 220px 1fr 200px;
    }
}

@media (max-width: 900px) {
    .editor-main {
        grid-template-columns: 1fr;
    }

    .field-manager {
        display: none;
    }

    .editor-controls {
        position: static;
        max-height: none;
    }

    .preview-canvas-wrapper {
        min-height: 500px;
    }

    .a4-page {
        transform: scale(0.5);
        transform-origin: top center;
    }
}

/* ========== STRIP-BASED LAYOUT SYSTEM ========== */
/* Horizontal strips that stack vertically for easy reordering */

.a4-strips-container {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.a4-strip {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #ccc;
    padding: 10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 5px;
    background: rgba(0, 0, 0, 0.02);
}

.a4-strip:last-child {
    border-bottom: none;
}

/* Strip heights */
.a4-strip.height-small {
    min-height: 30mm;
}

.a4-strip.height-medium {
    min-height: 55mm;
}

.a4-strip.height-large {
    min-height: 80mm;
}

.a4-strip.height-auto {
    min-height: auto;
}

/* Strip content alignment */
.a4-strip.align-left {
    justify-content: flex-start;
}

.a4-strip.align-center {
    justify-content: center;
}

.a4-strip.align-right {
    justify-content: flex-end;
}

/* Strip element types */
.a4-strip-title {
    width: 100%;
    text-align: center;
}

.a4-strip-image {
    max-width: 100%;
}

.a4-strip-chart {
    display: flex;
    justify-content: center;
}

.a4-strip-data {
    width: 100%;
}

/* Visual indicator for strip reordering */
.a4-strip.dragging {
    opacity: 0.5;
    background: #f0f0f0;
}

.a4-strip.drop-target {
    border-top: 3px solid #E87722;
}

/* ========== USER MANUAL BUTTON & MODAL ========== */

/* User Manual Button in Header */
.user-manual-btn {
    background: linear-gradient(135deg, #4a5568, #2d3748);
    border: 1px solid #4a5568;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-manual-btn:hover {
    background: linear-gradient(135deg, #E87722, #d66b1c);
    border-color: #E87722;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(232, 119, 34, 0.3);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Modal Content */
.modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
    transform: scale(1) translateY(0);
}

/* Modal Header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(232, 119, 34, 0.1);
    border-radius: 16px 16px 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
    color: #fff;
    font-weight: 600;
}

.modal-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close-btn:hover {
    background: #E87722;
    transform: rotate(90deg);
}

/* Modal Body */
.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 25px;
    color: #ccc;
}

.manual-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.manual-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.manual-section h3 {
    color: #E87722;
    font-size: 1.1rem;
    margin: 0 0 12px 0;
    font-weight: 600;
}

.manual-section p {
    margin: 0 0 10px 0;
    line-height: 1.6;
    font-size: 14px;
}

.manual-section ul,
.manual-section ol {
    margin: 0;
    padding-left: 20px;
}

.manual-section li {
    margin-bottom: 8px;
    line-height: 1.5;
    font-size: 14px;
}

.manual-section strong {
    color: #fff;
}

.manual-section.tips {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
    border-radius: 10px;
    padding: 16px;
    margin-top: 20px;
}

.manual-section.tips h3 {
    color: #4CAF50;
}

/* Modal Footer */
.modal-footer {
    padding: 16px 25px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: right;
}

.modal-footer .primary {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    border: none;
    color: #fff;
    padding: 12px 30px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-footer .primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(76, 175, 80, 0.3);
}

/* Scrollbar styling for modal */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========== LAYOUT FUNCTION BUTTONS ========== */

/* Layout insertion button row in Field Manager */
.field-manager-layout-btns {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}

.fm-layout-btn {
    flex: 1;
    padding: 5px 6px;
    border: 1px dashed #555;
    border-radius: 5px;
    background: #1a1a1a;
    color: #aaa;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.fm-layout-btn:hover {
    background: #222;
    border-color: #E87722;
    color: #E87722;
}

/* Layout items in Field Manager list */
.fm-item.layout-heading {
    background: #1a1a1a;
    border-left: 3px solid #000;
}

.fm-item.layout-heading .fm-heading-text {
    background: #000;
    color: #fff;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 11px;
}

.fm-item.layout-heading .fm-heading-text:focus {
    background: #222;
    color: #fff;
    border: 1px solid #E87722;
}

.fm-item.layout-whitespace {
    background: #1a1a1a;
    border-left: 3px solid #666;
    min-height: 24px;
}

.fm-item.layout-line {
    background: #1a1a1a;
    border-left: 3px solid #444;
    min-height: 24px;
}

.fm-layout-label {
    flex: 1;
    font-size: 10px;
    color: #777;
    font-style: italic;
    padding: 2px 4px;
}

/* Delete button for layout items */
.fm-delete-btn {
    background: transparent;
    border: none;
    color: #666;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    flex-shrink: 0;
    transition: color 0.2s;
}

.fm-delete-btn:hover {
    color: #e74c3c;
}

/* Selected row for insert-before */
.fm-item.fm-selected {
    border-color: #E87722;
    background: rgba(232, 119, 34, 0.12);
    box-shadow: 0 0 0 1px rgba(232, 119, 34, 0.4);
}

/* ========== PREVIEW: Layout Elements ========== */

/* Heading strip — black bar with white bold text */
.data-heading-strip {
    background: #000;
    color: #fff;
    font-weight: 700;
    font-size: 9px;
    text-transform: uppercase;
    padding: 3px 6px;
    margin: 2px 0;
    letter-spacing: 0.5px;
    width: 100%;
    box-sizing: border-box;
}

/* Whitespace — blank spacer line */
.data-whitespace {
    height: 10px;
    width: 100%;
}

/* Thin black line */
.data-thin-line {
    border-top: 1px solid #000;
    width: 100%;
    margin: 3px 0;
    height: 0;
}

/* ============================
   DATA SHEET LIBRARY MODAL
   ============================ */
.library-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9000;
    align-items: center;
    justify-content: center;
}

.library-modal-overlay.show {
    display: flex;
}

.library-modal {
    background: #1e1e1e;
    border-radius: 12px;
    width: 640px;
    max-width: 92vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
    overflow: hidden;
}

.library-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #333;
    background: #252525;
}

.library-modal-header h2 {
    color: #f0f0f0;
    font-size: 18px;
    margin: 0;
}

.library-header-actions {
    display: flex;
    gap: 8px;
}

.library-btn {
    padding: 6px 14px;
    border: 1px solid #444;
    border-radius: 6px;
    background: #2a2a2a;
    color: #ccc;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.library-btn:hover {
    background: #3a3a3a;
    color: #fff;
}

.library-btn.close-btn {
    font-size: 16px;
    padding: 4px 10px;
    border: none;
    background: none;
    color: #888;
}

.library-btn.close-btn:hover {
    color: #ff5555;
}

.library-btn.su-toggle {
    background: #2d2520;
    border-color: #8b6914;
    color: #daa520;
}

.library-btn.su-toggle:hover {
    background: #3d3520;
}

/* Super User Bar */
.library-su-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background: #2a2010;
    border-bottom: 1px solid #6b4b00;
}

.su-badge {
    color: #ffc107;
    font-size: 13px;
    font-weight: 600;
}

.library-btn.su-logout {
    font-size: 11px;
    padding: 3px 10px;
    border-color: #6b4b00;
    color: #daa520;
}

/* Super User Login Form */
.library-su-login {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: #1a1810;
    border-bottom: 1px solid #6b4b00;
    flex-wrap: wrap;
}

.su-login-label {
    color: #daa520;
    font-size: 13px;
    font-weight: 600;
}

.su-password-input {
    padding: 6px 10px;
    border: 1px solid #6b4b00;
    border-radius: 5px;
    background: #2a2510;
    color: #f0e6c0;
    font-size: 13px;
    outline: none;
    width: 160px;
}

.su-password-input:focus {
    border-color: #daa520;
    box-shadow: 0 0 4px rgba(218, 165, 32, 0.3);
}

.library-btn.su-login-btn {
    background: #3d3010;
    border-color: #8b6914;
    color: #ffc107;
    font-weight: 600;
}

.library-btn.su-login-btn:hover {
    background: #4d4020;
}

.library-btn.su-cancel-btn {
    border-color: #555;
    color: #999;
}

.su-login-error {
    color: #ef5350;
    font-size: 12px;
}

/* Sheet List */
.library-sheet-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.library-empty {
    color: #666;
    text-align: center;
    padding: 40px 20px;
    font-size: 14px;
}

/* Sheet Card */
.library-sheet-card {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    background: #252525;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid #333;
    gap: 12px;
    transition: background 0.15s;
}

.library-sheet-card:hover {
    background: #2d2d2d;
}

.sheet-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.sheet-info {
    flex: 1;
    min-width: 0;
}

.sheet-name {
    color: #f0f0f0;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-meta {
    color: #888;
    font-size: 11px;
    margin-top: 2px;
}

.sheet-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
}

.sheet-status.approved {
    background: #1a3a1a;
    color: #4caf50;
    border: 1px solid #2e7d32;
}

.sheet-status.pending {
    background: #3a3a1a;
    color: #ffc107;
    border: 1px solid #8b6914;
}

.sheet-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.sheet-action-btn {
    padding: 5px 10px;
    border-radius: 5px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: #ccc;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.sheet-action-btn:hover {
    background: #3a3a3a;
    color: #fff;
}

.sheet-action-btn.approve-btn {
    border-color: #2e7d32;
    color: #4caf50;
}

.sheet-action-btn.approve-btn:hover {
    background: #1a3a1a;
}

.sheet-action-btn.delete-btn {
    border-color: #c62828;
    color: #ef5350;
}

.sheet-action-btn.delete-btn:hover {
    background: #3a1a1a;
}