* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'Devant';
    src: url('Devant-Medium.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.app-container {
    max-width: 100%;
    margin: 0 auto;
}

header {
    background: #333;
    color: white;
    padding: 1.2rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

.main-content {
    display: flex;
    min-height: calc(100vh - 100px);
}

/* Control Panel */
.control-panel {
    width: 320px;
    background: white;
    padding: 1.5rem;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
    overflow-y: auto;
    max-height: calc(100vh - 100px);
}

.control-panel h2 {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
    color: #667eea;
}

.control-panel h3 {
    font-size: 1rem;
    margin-bottom: 0.8rem;
    color: #555;
}

.control-group {
    margin-bottom: 1.5rem;
}

.control-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #555;
}

.form-control {
    width: 100%;
    padding: 0.6rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: #667eea;
}

.size-inputs {
    display: flex;
    gap: 0.5rem;
    flex-direction: column;
}

.size-inputs input {
    flex: 1;
    padding: 0.5rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Sticker Zone Controls */
.sticker-zone-control {
    background: #f9f9f9;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #e0e0e0;
}

.sticker-zone-control h4 {
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
    color: #667eea;
    font-weight: 600;
}

.dropzone {
    border: 2px dashed #ccc;
    border-radius: 6px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: white;
    margin-bottom: 0.8rem;
}

.dropzone:hover, .dropzone.dragover {
    border-color: #667eea;
    background: #f0f4ff;
}

.dropzone.has-image {
    border-style: solid;
    border-color: #4caf50;
    padding: 0.5rem;
}

.dropzone img {
    max-width: 100%;
    max-height: 120px;
    object-fit: contain;
    border-radius: 4px;
}

.dropzone p {
    color: #888;
    font-size: 0.85rem;
}

.label-input {
    width: 100%;
    padding: 0.6rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
}

.font-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.8rem;
}

.font-controls label {
    margin: 0;
    flex-shrink: 0;
}

.font-controls button {
    padding: 0.4rem 0.8rem;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.font-controls button:hover {
    background: #f0f0f0;
}

.font-controls span {
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

.image-controls {
    display: flex;
    gap: 0.5rem;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-crop {
    background: #ff9800;
    color: white;
}

.btn-crop:hover {
    background: #f57c00;
}

/* Dimensions Display */
.dimensions-display {
    background: #f9f9f9;
    padding: 0.8rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.dimension-item {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px solid #e0e0e0;
}

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

.dimension-label {
    font-weight: 500;
    color: #555;
}

.dimension-value {
    color: #4481c5;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.btn-primary {
    background: #4481c5;
    color: white;
    font-weight: bold;
}

.btn-primary:hover {
    background: #294e77;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-success {
    background: #4caf50;
    color: white;
}

.btn-success:hover {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.btn-info {
    background: #2196F3;
    color: white;
}

.btn-info:hover {
    background: #0b7dda;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

.btn-secondary {
    background: #757575;
    color: white;
}

.btn-secondary:hover {
    background: #616161;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}

/* Preview Area */
.preview-area {
    flex: 1;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
}

.page-container {
    position: relative;
    background: white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    margin: 2rem;
}

.a4-page {
    background: white;
    position: relative;
    /* A4 size: 21cm × 29.7cm at 28.346px/cm (72 DPI) */
    width: 595.28px; /* 21cm */
    height: 841.89px; /* 29.7cm */
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    position: relative;
}

.a4-page.landscape {
    width: 841.89px; /* 29.7cm */
    height: 595.28px; /* 21cm */
}

/* Rulers */
.rulers {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1000;
}

.ruler {
    background: #f0f0f0;
    position: absolute;
    display: flex;
}

.ruler-horizontal {
    top: -30px;
    left: 0;
    height: 30px;
    width: 100%;
    flex-direction: row;
}

.ruler-vertical {
    left: -30px;
    top: 0;
    width: 30px;
    height: 100%;
    flex-direction: column;
}

.ruler-mark {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ruler-horizontal .ruler-mark {
    border-left: 1px solid #999;
    height: 100%;
}

.ruler-vertical .ruler-mark {
    border-top: 1px solid #999;
    width: 100%;
}

.ruler-label {
    font-size: 9px;
    color: #666;
    position: absolute;
}

.ruler-horizontal .ruler-label {
    top: 2px;
    left: 2px;
}

.ruler-vertical .ruler-label {
    left: 2px;
    top: 2px;
    writing-mode: vertical-lr;
    transform: rotate(180deg);
}

/* Sticker Styles */
.sticker-container {
    position: absolute;
    border: 1px solid #edebeb;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 10px;
    overflow: visible;
}

.sticker-dropzone {
    border: 2px dashed #ccc;
    border-radius: 6px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: transparent;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.sticker-dropzone:hover, .sticker-dropzone.dragover {
    border-color: #667eea;
    background: #f0f4ff;
}

.sticker-dropzone p {
    color: #888;
    font-size: 0.75rem;
    margin: 0;
}

.sticker-image-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    z-index: 5;
}

.sticker-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
}

.image-controls-overlay {
    position: absolute;
    left: -200px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    flex-direction: column;
    gap: 5px;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1100;
}

.image-controls-row {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.image-controls-overlay button {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.image-controls-overlay button.btn-crop {
    background: #ff9800;
}

.image-controls-overlay button.btn-crop:hover {
    background: #f57c00;
}

.image-controls-overlay button.btn-rotate {
    background: #2196F3;
}

.image-controls-overlay button.btn-rotate:hover {
    background: #0b7dda;
}

.image-controls-overlay button.btn-delete {
    background: #dc3545;
}

.image-controls-overlay button.btn-delete:hover {
    background: #c82333;
}

.image-controls-overlay button.btn-resize-plus,
.image-controls-overlay button.btn-resize-minus {
    background: #4CAF50;
}

.image-controls-overlay button.btn-resize-plus:hover,
.image-controls-overlay button.btn-resize-minus:hover {
    background: #45a049;
}

.image-controls-overlay button.btn-move {
    background: #9C27B0;
}

.image-controls-overlay button.btn-move:hover {
    background: #7B1FA2;
}

.sticker-container:has(.sticker-image-container.selected) .image-controls-overlay {
    display: flex;
}

.sticker-image-container.selected .image-controls-overlay {
    display: flex;
}

.sticker-label-wrapper {
    position: absolute;
    width: 100%;
    bottom: 0;
    left: 0;
    z-index: 20;
}

/*
.sticker-label-wrapper.no-image {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    bottom: auto;
}
*/

.sticker-label-input {
    text-align: center;
    word-wrap: break-word;
    width: 100%;
    font-family: 'Devant', 'Segoe UI', sans-serif;
    /* font-weight: 100; */
    color: #294e77;
    line-height: 1.0;
    border: 2px solid transparent;
    background: transparent;
    outline: none;
    cursor: text;
    resize: none;
    overflow: hidden;
    position: relative;
    z-index: 20;
}

.sticker-label-input:focus {
    border-color: #667eea;
    background: #f0f4ff;
}

.font-controls-overlay {
    position: absolute;
    top: -35px;
    right: 0;
    display: none;
    gap: 5px;
    background: rgba(255, 255, 255, 0.95);
    padding: 5px;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    align-items: center;
    z-index: 1100;
}

.sticker-label-wrapper.focused .font-controls-overlay {
    display: flex;
}

.font-controls-overlay button {
    width: 28px;
    height: 28px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.font-controls-overlay button:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.sticker-side {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 5px;
    position: absolute;
    overflow: visible;
}

.sticker-side.rotated {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sticker-side.rotated .sticker-label-wrapper {
    transform: rotate(-90deg);
    transform-origin: center center;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(-90deg);
}

.sticker-side.rotated .sticker-label-input {
    white-space: nowrap;
    width: auto;
    text-overflow: ellipsis;
    overflow: hidden;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.5rem;
    color: #667eea;
}

.close-modal {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #999;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
}

.close-modal:hover {
    color: #333;
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow: auto;
}

#cropContainer {
    max-width: 100%;
    max-height: 500px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#cropContainer img {
    max-width: 100%;
    max-height: 500px;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Print Styles */
@media print {
    body * {
        visibility: hidden;
    }

    .a4-page, .a4-page * {
        visibility: visible;
    }

    .a4-page {
        position: absolute;
        left: 0;
        top: 0;
        width: 21cm;
        height: 29.7cm;
        box-shadow: none;
        margin: 0;
        padding: 0;
    }

    .a4-page.landscape {
        width: 29.7cm;
        height: 21cm;
    }

    .rulers {
        display: none !important;
    }

    .resize-handle {
        display: none !important;
    }
}

/* Responsive */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .control-panel {
        width: 100%;
        max-height: none;
    }

    .preview-area {
        padding: 0rem;
    }

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