* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: #121212; 
    display: flex;
    justify-content: center;
    overflow-x: auto;
}

/* Control Panel */
.control-panel {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 15px 30px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    gap: 15px;
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.6s ease-out;
}

@keyframes slideDown { from { top: -50px; opacity: 0; } to { top: 20px; opacity: 1; } }

.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-upload { background: #f8f9fa; color: #1a1a1a; }
.btn-text { background: #17a2b8; color: white; } 
.btn-text:hover { background: #138496; }
.btn-delete { background: #dc3545; color: white; } 
.btn-clear-form { background: #fd7e14; color: white; } 
.btn-history { background: #ffc107; color: #1a1a1a; } 
.btn-print { background: #007bff; color: white; }
.btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.2); }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 6px; }

/* Sheets Container */
.sheets-container {
    display: flex;
    flex-direction: column;
    gap: 60px;
    margin-top: 100px;
    margin-bottom: 60px;
    align-items: center;
}

.a3-sheet-wrapper { display: flex; flex-direction: column; gap: 15px; }

.sheet-header {
    display: flex; justify-content: space-between; align-items: center; width: 420mm; padding: 0 5mm;
}

.sheet-label {
    font-size: 22px; font-weight: 700; color: #fff; letter-spacing: 3px; text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.sheet-actions { display: flex; gap: 10px; }

/* A3 Sheet */
.a3-sheet {
    width: 420mm; height: 297mm; background: white; position: relative; padding: 10mm;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.main-border {
    width: 100%; height: 100%; border: 2px solid #000; border-radius: 2px;
    display: grid; grid-template-columns: 1fr 85mm; grid-template-rows: 1fr 20mm; position: relative;
}

.canvas-area {
    grid-column: 1 / 2; grid-row: 1 / 2; position: relative; overflow: hidden;
}

/* -------------------------------------
   Image Container
   ------------------------------------- */
.image-container {
    position: absolute; resize: both; overflow: hidden; min-width: 100px; min-height: 100px;
    border: 1px dashed transparent; transition: border 0.2s; z-index: 10;
}
.image-container:hover { border: 1px dashed #007bff; }
.image-container img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }

.drag-handle { position: absolute; top: 0; left: 0; right: 0; height: 100%; cursor: grab; z-index: 10; }
.drag-handle:active { cursor: grabbing; }

.delete-img-btn {
    position: absolute; top: 5px; right: 5px; background: rgba(220, 53, 69, 0.9); color: white;
    border: none; border-radius: 50%; width: 26px; height: 26px; font-size: 16px; line-height: 24px;
    text-align: center; cursor: pointer; z-index: 20; display: none; box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.delete-img-btn:hover { background: #c82333; }
.image-container:hover .delete-img-btn { display: block; }


/* -------------------------------------
   Free Text Container (أنيق ومرتب)
   ------------------------------------- */
.text-container {
    position: absolute;
    min-width: 150px;
    min-height: 40px;
    border: 1px dashed transparent;
    z-index: 15;
    border-radius: 4px;
}

.text-container:hover, .text-container:focus-within {
    border: 1px dashed #17a2b8;
}

.text-toolbar {
    position: absolute;
    top: -32px;
    left: -1px;
    right: -1px;
    height: 32px;
    background: #17a2b8;
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    border-radius: 6px 6px 0 0;
    z-index: 20;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.text-container:hover .text-toolbar, 
.text-container:focus-within .text-toolbar { 
    display: flex; 
}

.text-drag-handle {
    flex-grow: 1; /* مقبض عريض لسهولة السحب */
    height: 100%;
    cursor: grab;
    display: flex;
    align-items: center;
    padding-left: 5px;
    color: white;
}
.text-drag-handle:active { cursor: grabbing; }

.text-controls { display: flex; gap: 4px; margin-left: 10px; }

.text-ctrl-btn {
    background: rgba(255,255,255,0.25);
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    transition: 0.2s;
}

.text-ctrl-btn:hover { background: rgba(255,255,255,0.5); }
.text-ctrl-btn.delete:hover { background: #dc3545; }

.free-text-input {
    width: 100%;
    height: 100%;
    min-height: 40px;
    border: none;
    background: transparent;
    outline: none;
    resize: both;
    font-family: 'Inter', sans-serif;
    color: #000;
    line-height: 1.4;
    padding: 8px;
}


/* Title Block Styles (Right Side) */
.title-block {
    grid-column: 2 / 3; grid-row: 1 / 3; border-left: 2px solid #000; display: flex; flex-direction: column; background-color: #fff;
}
.header-section {
    padding: 25px 10px 20px; text-align: center; border-bottom: 2px solid #000; display: flex; flex-direction: column; justify-content: center; align-items: center;
}
.brand-logo { max-width: 160px; height: auto; margin-bottom: 12px; object-fit: contain; }
.subtitle { font-size: 10px; font-weight: 600; letter-spacing: 6px; margin-bottom: 12px; color: #000; white-space: nowrap; margin-right: -6px; }
.services { font-size: 6.5px; font-weight: 600; letter-spacing: 1.5px; color: #555; word-spacing: 2px; }

.info-row, .info-cell, .rev-row { transition: background-color 0.2s ease; }
.info-row:hover, .info-cell:hover { background-color: #f8f9fa; }
.info-row:focus-within, .info-cell:focus-within { background-color: #f0f7ff; }

.info-row { border-bottom: 1px solid #000; padding: 8px 12px; min-height: 50px; display: flex; flex-direction: column; justify-content: center; }
.info-grid-2 { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid #000; }
.info-cell { padding: 8px 12px; min-height: 50px; display: flex; flex-direction: column; justify-content: center; }
.border-left { border-left: 1px solid #000; }

label { font-size: 8px; font-weight: 700; color: #000; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; }

input, textarea.auto-expand {
    border: none; outline: none; font-size: 12px; width: 100%; background: transparent; font-weight: 600; color: #111; font-family: 'Inter', sans-serif;
}
textarea.auto-expand { resize: none; overflow: hidden; padding: 0; line-height: 1.4; min-height: 17px; display: block; }
input[type="date"] { font-size: 11px; text-transform: uppercase; cursor: pointer; font-weight: 500; }

.notes-section { padding: 15px 12px; border-bottom: 1px solid #000; flex-grow: 1; display: flex; flex-direction: column; }
.notes-section label { margin-bottom: 8px; font-size: 9px; }
.notes-section ol { padding-left: 18px; margin-top: 5px; }
.notes-section li { font-size: 7.5px; margin-bottom: 6px; color: #222; line-height: 1.4; }

.revision-table { border-bottom: 2px solid #000; }
.rev-header { display: grid; grid-template-columns: 1fr 2fr 4fr 1fr; border-bottom: 1px solid #000; padding: 6px 5px; background-color: #fafafa; }
.rev-header span { font-size: 7px; font-weight: 700; text-align: center; color: #000; letter-spacing: 0.5px; }
.rev-row { display: grid; grid-template-columns: 1fr 2fr 4fr 1fr; border-bottom: 1px solid #eaeaea; align-items: center; }
.rev-row:hover { background-color: #f8f9fa; }
.rev-row:last-child { border-bottom: none; }
.rev-row input, .rev-row textarea { text-align: center; font-size: 9px; padding: 6px 2px; font-weight: 500; }

.footer-section { padding: 15px 10px; text-align: center; font-size: 9px; font-weight: 600; letter-spacing: 3px; color: #000; display: flex; align-items: center; justify-content: center; min-height: 45px; }

/* Bottom Bar */
.bottom-bar { grid-column: 1 / 2; grid-row: 2 / 3; border-top: 1px solid #000; padding: 0 20px; display: flex; align-items: center; }
.scale-graphic { display: flex; align-items: center; }
.scale-line { margin-left: 10px; width: 250px; }
.ticks { display: flex; justify-content: space-between; font-size: 7px; margin-bottom: 2px; }
.line { width: 100%; height: 4px; border: 1px solid #000; border-top: none; position: relative; }
.line::before { content: ''; position: absolute; left: 20%; top: -4px; height: 4px; border-left: 1px solid #000; }
.line::after { content: ''; position: absolute; right: 20%; top: -4px; height: 4px; border-left: 1px solid #000; }

/* History Popup Modal */
.history-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px); display: flex; justify-content: center; align-items: center;
    z-index: 9999; opacity: 0; visibility: hidden; transition: all 0.3s ease;
}
.history-modal-overlay.active { opacity: 1; visibility: visible; }
.history-modal { background: #fff; width: 600px; max-width: 90%; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); display: flex; flex-direction: column; max-height: 80vh; }
.modal-header { padding: 20px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; background: #f8f9fa; border-radius: 12px 12px 0 0; }
.modal-header h2 { font-size: 18px; font-weight: 600; color: #333; }
.close-modal-btn { background: none; border: none; font-size: 26px; cursor: pointer; color: #555; transition: 0.2s; }
.close-modal-btn:hover { color: #dc3545; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 15px; background: #fdfdfd; border: 1px solid #eee; border-radius: 8px; transition: background 0.2s; }
.history-item:hover { background: #f1f3f5; }
.history-info strong { font-size: 15px; color: #222; }
.history-info small { font-size: 12px; color: #777; display: block; margin-top: 4px; }
.btn-restore { background: #198754; color: white; border: none; padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.btn-restore:hover { background: #157347; transform: translateY(-2px); box-shadow: 0 4px 10px rgba(25, 135, 84, 0.3); }

/* =========================================
   Print Settings
   ========================================= */
@media print {
    @page { size: A3 landscape; margin: 0; }
    body { background: white; padding: 0; margin: 0; }
    .no-print { display: none !important; }
    
    .sheets-container { margin: 0 !important; padding: 0 !important; gap: 0 !important; display: block; }
    .a3-sheet-wrapper { page-break-after: always; break-after: page; margin: 0 !important; padding: 0 !important; }
    
    .hide-on-print { display: none !important; }
    .last-visible-sheet { page-break-after: auto !important; break-after: auto !important; }
    
    .a3-sheet { box-shadow: none; animation: none; padding: 5mm; }
    
    .image-container, .text-container { border: none !important; resize: none; }
    .delete-img-btn, .text-toolbar { display: none !important; }
    
    .info-row, .info-cell, .rev-row, .rev-header { background-color: transparent !important; }
    input, textarea.auto-expand, .free-text-input { font-family: 'Inter', sans-serif; color: #000; }
}