* {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            font-family: Arial, Helvetica, sans-serif;
            height: 100vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        /* CABECERA */

        header {
            background-color: #333;
            color: #fff;
            padding: 8px 16px;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        header h1 {
            margin: 0;
            font-size: 18px;
            font-weight: normal;
        }

        .spacer {
            flex: 1;
        }

        .btn {
            background-color: #ff9800;
            color: #fff;
            border: none;
            border-radius: 18px;
            padding: 6px 14px;
            cursor: pointer;
            font-size: 14px;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            transition: opacity 0.15s ease, transform 0.05s ease;
            white-space: nowrap;
        }

        .btn:active {
            transform: scale(0.97);
        }

        .btn:disabled {
            opacity: 0.4;
            cursor: default;
        }

        header label {
            font-size: 14px;
        }

        header select {
            padding: 4px 8px;
            border-radius: 4px;
            border: 1px solid #777;
            font-size: 14px;
        }

        /* LAYOUT PRINCIPAL */

        .main {
            flex: 1;
            display: flex;
            min-height: 0;
        }

        /* BARRA LATERAL */

        .sidebar {
            width: 280px;
            background-color: #555;
            color: #fff;
            padding: 10px;
            display: flex;
            flex-direction: column;
            gap: 10px;
            overflow-y: auto;
        }

        .sidebar h2 {
            font-size: 14px;
            margin: 4px 0;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            opacity: 0.9;
        }

        .tool-button {
            width: 100%;
            background-color: #ff9800;
            color: #fff;
            border: none;
            border-radius: 12px;
            padding: 10px;
            margin-bottom: 6px;
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
            font-size: 14px;
            transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
        }

        .tool-button i {
            font-size: 20px;
            width: 24px;
            text-align: center;
        }

        .tool-button span {
            flex: 1;
            text-align: left;
        }

        .tool-button:hover:not(:disabled) {
            background-color: #ffa726;
            box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
        }

        .tool-button:active:not(:disabled) {
            transform: scale(0.97);
        }

        .tool-button:disabled {
            opacity: 0.5;
            cursor: default;
            box-shadow: none;
        }

        .color-row {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            margin-bottom: 8px;
        }

        .color-circle {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            border: 2px solid rgba(255,255,255,0.6);
            cursor: pointer;
            position: relative;
        }

        .color-circle.active::after {
            content: "";
            position: absolute;
            inset: 4px;
            border-radius: 50%;
            border: 2px solid #000;
        }

        .color-circle.bg-active::after {
            border-color: #fff;
        }

        .section {
            border-top: 1px solid rgba(255,255,255,0.3);
            padding-top: 8px;
            margin-top: 4px;
        }

        #text-tools,
        #shape-tools {
            display: none;
        }

        #text-tools.visible,
        #shape-tools.visible {
            display: block;
        }

        .font-size-controls {
            display: flex;
            gap: 6px;
            margin-top: 4px;
        }

        .font-btn {
            flex: 1;
            padding: 4px 6px;
            border-radius: 10px;
            background-color: #444;
            border: none;
            cursor: pointer;
            color: #fff;
            font-size: 12px;
            text-align: center;
        }

        .font-btn:hover {
            background-color: #666;
        }

        .font-btn.active {
            background-color: #888;
        }

        .edit-text-btn {
            margin-top: 6px;
            width: 100%;
        }

        .align-controls {
            display: flex;
            gap: 6px;
            margin-top: 6px;
        }

        .align-btn i {
            pointer-events: none;
        }

        .font-size-row,
        .field-name-row {
            margin-top: 6px;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .font-size-row label,
        .field-name-row label {
            font-size: 12px;
            min-width: 70px;
        }

        .font-size-row input,
        .field-name-row input {
            flex: 1;
            border-radius: 6px;
            border: 1px solid #777;
            padding: 3px 6px;
            font-size: 12px;
            color: #000;
        }

        .field-name-row {
            display: none;
        }

        .field-name-row.visible {
            display: flex;
        }

        /* CANVAS */

        .canvas-area {
            flex: 1;
            background-color: #ddd;
            position: relative;
            overflow: auto;
            padding: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        #template-wrapper {
            width: 100%;
            max-width: 1000px;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        #template-canvas {
            position: relative;
            width: 90%;
            max-width: 900px;
            background-color: #fff;
            border: 2px solid #000;
            margin: 0 auto;
            transform-origin: top left;
        }

        /* COMPONENTES */

        .component {
            position: absolute;
            border: 1px solid #000;
            background-color: #fff;
            cursor: move;
            overflow: hidden;
        }

        .component.text-component {
            background-color: transparent;
        }

        .component.shape-component {
            border: none;          /* opcional */
            cursor: move;
            overflow: visible;
        }

        .component.shape-rect {
            border-style: solid;
        }

        .component.shape-circle {
            border-radius: 50%;
            border-style: solid;
            overflow: visible;
        }

        .component.selected {
            outline: 2px dashed #007bff;
        }

        .component .handles {
            position: absolute;
            inset: 0;
            pointer-events: none;
        }

        .resize-handle {
            width: 10px;
            height: 10px;
            background-color: #fff;
            border: 1px solid #007bff;
            position: absolute;
            pointer-events: auto;
        }

        .resize-handle.tl {
            top: -6px;
            left: -6px;
            cursor: nwse-resize;
        }

        .resize-handle.tr {
            top: -6px;
            right: -6px;
            cursor: nesw-resize;
        }

        .resize-handle.bl {
            bottom: -6px;
            left: -6px;
            cursor: nesw-resize;
        }

        .resize-handle.br {
            bottom: -6px;
            right: -6px;
            cursor: nwse-resize;
        }

        .barcode-placeholder {
            width: 100%;
            height: 100%;
            background: repeating-linear-gradient(
                    90deg,
                    #000,
                    #000 3px,
                    #fff 3px,
                    #fff 5px
            );
            display: flex;
            align-items: flex-end;
            justify-content: center;
            font-size: 10px;
            background-color: #fff;
            color: #000;
        }

        .photo-placeholder {
            width: 100%;
            height: 100%;
            background-image: linear-gradient(45deg, #ccc 25%, transparent 25%),
            linear-gradient(-45deg, #ccc 25%, transparent 25%),
            linear-gradient(45deg, transparent 75%, #ccc 75%),
            linear-gradient(-45deg, transparent 75%, #ccc 75%);
            background-size: 20px 20px;
            background-position: 0 0, 0 10px, 10px -10px, -10px 0;
        }

        .logo-placeholder {
            width: 100%;
            height: 100%;
            background-repeat: no-repeat;
            background-position: center center;
            background-size: contain;
        }

        .text-content {
            width: 100%;
            height: 100%;
            padding: 4px;
            overflow: hidden;
            outline: none;
            white-space: pre-wrap;
            background-color: transparent;
            font-family: "DejaVu Sans", Arial, Helvetica, sans-serif;
        }

        .single-line {
            white-space: nowrap;
        }

        .zoom-controls {
            position: absolute;
            right: 10px;
            bottom: 10px;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .zoom-btn {
            width: 32px;
            height: 32px;
            border-radius: 16px;
            border: none;
            background-color: #555;
            color: #fff;
            font-size: 18px;
            cursor: pointer;
        }

        .zoom-btn:hover {
            background-color: #777;
        }

        .zoom-level {
            position: absolute;
            right: 10px;
            bottom: 82px;
            background: rgba(0,0,0,0.6);
            color: #fff;
            padding: 2px 6px;
            border-radius: 4px;
            font-size: 11px;
        }

        .sidebar::-webkit-scrollbar,
        .canvas-area::-webkit-scrollbar {
            width: 6px;
        }

        .sidebar::-webkit-scrollbar-thumb,
        .canvas-area::-webkit-scrollbar-thumb {
            background-color: rgba(0,0,0,0.4);
            border-radius: 3px;
        }
