/* Printable Template Creator Scoped Styles v5 - Final with Side Margins */

/* The wrapper div for the entire tool application. */
#printable-template-creator-app {
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --secondary: #7209b7;
    --light: #f8f9fa;
    --dark: #212529;
    --gray: #6c757d;
    --success: #4cc9f0;
    --border: #dee2e6;
    --page-bg: #ffffff;
    --toolbar-bg: #f1f3f9;
    --sidebar-width: 280px;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    color: var(--dark);
    max-width: 100%;
    /* --- FINAL FIX: Added 20px margin on left and right --- */
    margin: 20px 20px; 
}

#printable-template-creator-app * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}

#printable-template-creator-app .fas,
#printable-template-creator-app .far,
#printable-template-creator-app .fab {
    font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Brands' !important;
    font-weight: 900;
}

#printable-template-creator-app .main-container {
    display: flex;
    position: relative;
    min-height: 85vh;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

#printable-template-creator-app .sidebar {
    width: var(--sidebar-width);
    background-color: var(--toolbar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

#printable-template-creator-app .sidebar-tabs {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    padding-bottom: 5px;
}

#printable-template-creator-app .sidebar-tab {
    padding: 0.8rem 1rem;
    text-align: left;
    cursor: pointer;
    font-weight: 500;
    color: var(--gray);
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

#printable-template-creator-app .sidebar-tab.active {
    color: var(--primary);
    background-color: rgba(67, 97, 238, 0.05);
    border-left: 3px solid var(--primary);
}

#printable-template-creator-app .sidebar-tab:hover {
    background-color: rgba(67, 97, 238, 0.03);
}

#printable-template-creator-app .sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

#printable-template-creator-app .tab-content {
    display: none;
}

#printable-template-creator-app .elements-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 1.5rem;
}

#printable-template-creator-app .element-card {
    background: none;
    border-radius: 8px;
    padding: 0.5rem;
    text-align: center;
    cursor: grab;
    box-shadow: none;
    transition: all 0.2s ease;
    border: none;
}

#printable-template-creator-app .element-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
}

#printable-template-creator-app .element-icon {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

#printable-template-creator-app .element-title {
    font-size: 0.85rem;
    font-weight: 500;
}

#printable-template-creator-app .settings-group {
    margin-bottom: 1.5rem;
}

#printable-template-creator-app .settings-group h3 {
    font-size: 1rem;
    margin-bottom: 0.8rem;
    color: var(--dark);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: none;
    justify-content: flex-start;
}

#printable-template-creator-app .settings-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.8rem;
}

#printable-template-creator-app .settings-row label {
    width: 120px;
    font-size: 0.9rem;
    color: var(--gray);
    flex-shrink: 0;
}

#printable-template-creator-app select,
#printable-template-creator-app input[type="text"],
#printable-template-creator-app input[type="number"],
#printable-template-creator-app textarea {
    flex: 1;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: white;
    min-width: 0;
}

#printable-template-creator-app textarea {
    resize: vertical;
    min-height: 60px;
}

#printable-template-creator-app .color-preview {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    border: 1px solid #ddd;
    margin-left: 10px;
    cursor: pointer;
    flex-shrink: 0;
}

#printable-template-creator-app .custom-size-inputs {
    display: flex;
    gap: 10px;
    margin-top: 0.5rem;
}

#printable-template-creator-app .custom-size-inputs input {
    flex: 1;
}

#printable-template-creator-app .canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #e2e8f0;
    padding: 1rem;
    position: relative;
}

#printable-template-creator-app .canvas-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    background: white;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    gap: 10px;
}

#printable-template-creator-app .toolbar-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

#printable-template-creator-app .tool-btn {
    padding: 0.5rem;
    min-width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--toolbar-bg);
    color: var(--gray);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    border: none;
}

#printable-template-creator-app .tool-btn:hover {
    background: var(--primary);
    color: white;
}

#printable-template-creator-app .tool-btn.active {
    background: var(--primary);
    color: white;
}

#printable-template-creator-app .page-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
    padding: 1rem;
}

#printable-template-creator-app .page {
    background-color: var(--page-bg);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    position: relative;
    margin: auto;
    transform-origin: top left;
}

#printable-template-creator-app .page-a3 { width: 297mm; height: 420mm; }
#printable-template-creator-app .page-a3.landscape { width: 420mm; height: 297mm; }
#printable-template-creator-app .page-a4 { width: 210mm; height: 297mm; }
#printable-template-creator-app .page-a4.landscape { width: 297mm; height: 210mm; }
#printable-template-creator-app .page-a5 { width: 148mm; height: 210mm; }
#printable-template-creator-app .page-a5.landscape { width: 210mm; height: 148mm; }
#printable-template-creator-app .page-b5 { width: 176mm; height: 250mm; }
#printable-template-creator-app .page-b5.landscape { width: 250mm; height: 176mm; }
#printable-template-creator-app .page-letter { width: 215.9mm; height: 279.4mm; }
#printable-template-creator-app .page-letter.landscape { width: 279.4mm; height: 215.9mm; }
#printable-template-creator-app .page-legal { width: 215.9mm; height: 355.6mm; }
#printable-template-creator-app .page-legal.landscape { width: 355.6mm; height: 215.9mm; }

#printable-template-creator-app .element {
    position: absolute;
    border: 1px dashed transparent;
    transition: border 0.2s ease;
    cursor: grab;
    min-width: 50px;
    min-height: 20px;
    box-sizing: border-box;
}

#printable-template-creator-app .element.selected {
    border: 1px dashed var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
    cursor: grabbing;
}

#printable-template-creator-app .element:hover {
    border: 1px dashed var(--gray);
}

#printable-template-creator-app .resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
    z-index: 10;
    cursor: nwse-resize;
    bottom: -5px;
    right: -5px;
}

/* All other specific element styles remain the same */
#printable-template-creator-app .text-element { padding: 10px; width: 100%; height: 100%; outline: none; overflow: hidden; word-wrap: break-word; }
#printable-template-creator-app .text-element:focus { outline: none; border: 1px solid var(--primary); }
#printable-template-creator-app .table-element { border-collapse: collapse; width: 100%; height: 100%; }
#printable-template-creator-app .table-element th { font-weight: bold; background-color: #f2f2f2; }
#printable-template-creator-app .table-element td, #printable-template-creator-app .table-element th { border: 1px solid #ddd; padding: 8px; min-width: 50px; min-height: 30px; vertical-align: top; outline: none; }
#printable-template-creator-app .table-element.striped-rows tbody tr:nth-child(odd) { background-color: #f8f8f8; }
#printable-template-creator-app .table-element.striped-rows tbody tr:nth-child(even) { background-color: #ffffff; }
#printable-template-creator-app .checklist-element { padding: 10px; width: 100%; height: 100%; overflow-y: auto; }
#printable-template-creator-app .checklist-item { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#printable-template-creator-app .checklist-item input[type="checkbox"] { cursor: pointer; width: 18px; height: 18px; flex-shrink: 0; }
#printable-template-creator-app .checklist-item input[type="text"] { border: none; border-bottom: 1px dashed #ddd; padding: 5px; flex: 1; background: transparent; font-size: 0.9rem; color: inherit; font-family: inherit; }
#printable-template-creator-app .checklist-item input[type="text"]:focus { outline: none; border-bottom: 1px solid var(--primary); }
#printable-template-creator-app .checklist-element.style-bullets { list-style: disc; padding-left: 20px; }
#printable-template-creator-app .checklist-element.style-numbers { list-style: decimal; padding-left: 20px; }
#printable-template-creator-app .checklist-element.style-bullets .checklist-item, #printable-template-creator-app .checklist-element.style-numbers .checklist-item { display: list-item; margin-left: 1em; }
#printable-template-creator-app .checklist-element.style-bullets .checklist-item input[type="checkbox"], #printable-template-creator-app .checklist-element.style-numbers .checklist-item input[type="checkbox"] { display: none; }
#printable-template-creator-app .shape-element { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
#printable-template-creator-app .circle { border-radius: 50%; }
#printable-template-creator-app .line-grid-element { width: 100%; height: 100%; position: relative; }
#printable-template-creator-app .line-grid-element .actual-line-wrapper { position: absolute; left: 0; right: 0; display: flex; flex-direction: column; align-items: flex-start; }
#printable-template-creator-app .line-grid-element .actual-line { height: 0; width: 100%; flex-shrink: 0; }
#printable-template-creator-app .line-grid-element .line-text { white-space: nowrap; overflow: hidden; text-overflow: clip; padding: 0 5px; min-width: 30px; outline: none; border: 1px dashed transparent; border-radius: 4px; background-color: transparent; line-height: 1.2; box-sizing: border-box; }
#printable-template-creator-app .line-grid-element .line-text:focus { border: 1.5px dashed var(--primary); background-color: rgba(67, 97, 238, 0.05); }
#printable-template-creator-app .line-grid-element.vertical .actual-line { position: absolute; width: 0; top: 0; bottom: 0; }
#printable-template-creator-app .sticker-element { display: inline-block; background: #ffeb3b; color: #333; padding: 8px 12px; border-radius: 4px; font-weight: bold; text-align: center; white-space: nowrap; }
#printable-template-creator-app .calendar-element { width: 100%; height: 100%; display: flex; flex-direction: column; padding: 10px; font-size: 0.8rem; overflow: hidden; }
#printable-template-creator-app .calendar-header { text-align: center; font-weight: bold; margin-bottom: 5px; font-size: 1.1rem; }
#printable-template-creator-app .calendar-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-weight: bold; margin-bottom: 5px; background-color: #f0f0f0; padding: 5px 0; border-radius: 4px; }
#printable-template-creator-app .calendar-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; flex-grow: 1; }
#printable-template-creator-app .calendar-day { text-align: center; padding: 5px 0; border: 1px solid #eee; border-radius: 4px; min-height: 25px; display: flex; align-items: center; justify-content: center; }
#printable-template-creator-app .calendar-day.empty { background-color: #f8f8f8; }
#printable-template-creator-app .qrcode-element { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
#printable-template-creator-app .qrcode-element canvas { max-width: 100%; max-height: 100%; }
#printable-template-creator-app .image-element { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; overflow: hidden; }
#printable-template-creator-app .image-element img { max-width: 100%; max-height: 100%; object-fit: contain; }
#printable-template-creator-app .image-element .placeholder { width: 100%; height: 100%; background-color: #f0f0f0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #ccc; font-size: 0.9rem; text-align: center; cursor: pointer; }
#printable-template-creator-app .image-element .placeholder i { font-size: 2rem; margin-bottom: 5px; }
#printable-template-creator-app .currency-element { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-weight: bold; }
#printable-template-creator-app .icon-element { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
#printable-template-creator-app .icon-element i { display: block; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
#printable-template-creator-app .datetime-element { padding: 10px; width: 100%; height: 100%; display: flex; align-items: center; justify-content: flex-start; overflow: hidden; word-wrap: break-word; }
#printable-template-creator-app .property-panel { background: white; padding: 1rem; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); margin-top: 1rem; }
#printable-template-creator-app .property-panel h3 { margin-bottom: 1rem; color: var(--primary); border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
#printable-template-creator-app .prop-group { margin-bottom: 1rem; }
#printable-template-creator-app .prop-row { display: flex; margin-bottom: 0.5rem; align-items: center; gap: 10px; }
#printable-template-creator-app .prop-row label { width: 80px; font-size: 0.9rem; flex-shrink: 0; }
#printable-template-creator-app .delete-btn { background: #ff6b6b; color: white; padding: 0.5rem 1rem; border-radius: 4px; border: none; cursor: pointer; display: block; width: 100%; margin-top: 1rem; transition: background 0.2s ease; }
#printable-template-creator-app .delete-btn:hover { background: #ff5252; }
#printable-template-creator-app .margin-guide { position: absolute; border: 1px dashed rgba(67, 97, 238, 0.3); pointer-events: none; }
#printable-template-creator-app .page.grid-pattern { background-image: linear-gradient(to right, #eee 1px, transparent 1px), linear-gradient(to bottom, #eee 1px, transparent 1px); }
#printable-template-creator-app .page.dots-pattern { background-image: radial-gradient(circle, #eee 1px, transparent 1px); background-size: 15px 15px; }
#printable-template-creator-app .page.lines-pattern { background-image: linear-gradient(to bottom, #eee 1px, transparent 1px); background-size: 100% 20px; }
#printable-template-creator-app .toggle-sidebar { display: none; position: absolute; top: 12px; left: 12px; z-index: 101; background: white; border-radius: 6px; padding: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); cursor: pointer; }

#printable-template-creator-app .message-box-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
#printable-template-creator-app .message-box-overlay.visible { opacity: 1; visibility: visible; }
#printable-template-creator-app .message-box { background-color: white; padding: 25px; border-radius: 10px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); text-align: center; max-width: 400px; width: 90%; }
#printable-template-creator-app .message-box h4 { margin-bottom: 15px; font-size: 1.2rem; color: var(--dark); }
#printable-template-creator-app .message-box-buttons { display: flex; justify-content: center; gap: 15px; margin-top: 20px; }
#printable-template-creator-app .message-box-buttons .btn { padding: 0.6rem 1.5rem; font-size: 1rem; border: none; border-radius: 6px; cursor: pointer; transition: background-color 0.2s ease; }
#printable-template-creator-app .message-box-buttons .btn-confirm { background-color: var(--primary); color: white; }
#printable-template-creator-app .message-box-buttons .btn-confirm:hover { background-color: var(--primary-dark); }
#printable-template-creator-app .message-box-buttons .btn-cancel { background-color: var(--gray); color: white; }
#printable-template-creator-app .message-box-buttons .btn-cancel:hover { background-color: #5a6268; }

#printable-template-creator-app .layers-list { list-style: none; padding: 0; }
#printable-template-creator-app .layer-item { background: #f8f9fa; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 8px; padding: 10px; display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; cursor: grab; transition: all 0.2s ease; }
#printable-template-creator-app .layer-item:hover { background: #f0f4ff; border-color: var(--primary); }
#printable-template-creator-app .layer-item.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.3); background-color: rgba(67, 97, 238, 0.05); }
#printable-template-creator-app .layer-item.dragging { opacity: 0.5; border: 1px dashed var(--primary); }
#printable-template-creator-app .layer-item-info { display: flex; align-items: center; gap: 10px; flex-grow: 1; }
#printable-template-creator-app .layer-item-info i { color: var(--primary); font-size: 1.1rem; }
#printable-template-creator-app .layer-name { flex-grow: 1; padding: 2px 5px; border-radius: 4px; outline: none; cursor: text; min-width: 50px; }
#printable-template-creator-app .layer-name:focus { background-color: #fff; border: 1px solid var(--primary); }
#printable-template-creator-app .layer-item-actions { display: flex; gap: 5px; }
#printable-template-creator-app .layer-action-btn { width: 28px; height: 28px; border-radius: 4px; display: flex; align-items: center; justify-content: center; background: white; border: 1px solid var(--border); color: var(--gray); cursor: pointer; transition: all 0.2s ease; }
#printable-template-creator-app .layer-action-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }

@media (max-width: 992px) {
    #printable-template-creator-app .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; transform: translateX(-100%); transition: transform 0.3s ease-in-out; }
    #printable-template-creator-app .sidebar.open { transform: translateX(0); }
    #printable-template-creator-app .toggle-sidebar { display: flex; }
}

@media (max-width: 768px) {
    #printable-template-creator-app { margin: 10px; } /* Reduce margins on smaller screens */
    #printable-template-creator-app .elements-grid { grid-template-columns: 1fr; }
    #printable-template-creator-app .page { transform: scale(0.7); margin-top: 50px; }
    #printable-template-creator-app .canvas-toolbar { flex-wrap: wrap; justify-content: center; gap: 5px; }
}