/* Prevent zoom on mobile when focusing inputs */
input,
textarea,
select {
    font-size: 16px !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Prevent zoom on iOS Safari */
@supports (-webkit-touch-callout: none) {

    input,
    textarea,
    select {
        font-size: 16px !important;
        transform: scale(1);
        -webkit-transform: scale(1);
    }
}

/* Main styles for the image editor */
body {
    background-color: #dddddd;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.editor-container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.canvas-container {
    position: relative;
    display: inline-block;
    overflow: hidden;
    background: #ffffff;
}

#mainCanvas {
    display: block;
    cursor: move;
    max-width: 100%;
    height: auto;
    border: solid 1px #747474;
}

.image-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.resize-handle {
    position: absolute;
    pointer-events: all;
    background: #007bff;
    border: 2px solid white;
    border-radius: 50%;
    width: 10px;
    height: 10px;
    cursor: pointer;
    display: none;
    z-index: 10;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Corner handles */
.corner-tl {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.corner-tr {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.corner-bl {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.corner-br {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

/* Rotation handle */
.rotation-handle {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #28a745;
    border: 2px solid white;
    border-radius: 50%;
    cursor: grab;
    display: none;
    z-index: 1001;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: all;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.rotation-handle:hover {
    transform: translateX(-50%) scale(1.1);
    background: #218838;
}

.rotation-handle:active {
    cursor: grabbing;
    transform: translateX(-50%) scale(0.95);
}

.rotation-handle::before {
    content: '↻';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
    pointer-events: none;
}

/* Edge handles */
.edge-t {
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    cursor: n-resize;
}

.edge-r {
    top: 50%;
    right: -5px;
    transform: translateY(-50%);
    cursor: e-resize;
}

.edge-b {
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    cursor: s-resize;
}

.edge-l {
    top: 50%;
    left: -5px;
    transform: translateY(-50%);
    cursor: w-resize;
}

.control-panel {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
}

.position-controls {
    text-align: center;
}

.position-controls .btn-group {
    margin: 2px 0;
}

.position-controls .btn {
    width: 35px;
    height: 35px;
    padding: 0;
    margin: 1px;
}

.sticker-selection,
.text-tools {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    height: fit-content;
}

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding: 15px 0;
}

.sticker-item {
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 5px;
    cursor: pointer;
    transition: all 0.2s;
    background: #f8f9fa;
    text-align: center;
}

.sticker-item:hover {
    border-color: #007bff;
    transform: translateY(-2px);
}

.sticker-item.selected {
    border-color: #28a745;
    background: #e8f5e8;
}

.sticker-item img {
    width: 100%;
    height: 50px;
    object-fit: contain;
    border-radius: 4px;
}

.sticker-item .sticker-name {
    font-size: 10px;
    text-align: center;
    margin-top: 5px;
    color: #666;
}

.selected-element {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    cursor: pointer;
    display: none;
}

.selected-element .delete-btn {
    display: block;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Responsive design */
@media (max-width: 768px) {
    .canvas-container {
        max-width: 100%;
    }

    #mainCanvas {
        max-width: 100%;
        height: auto;
    }

    .position-controls .btn {
        width: 30px;
        height: 30px;
    }

    /* Ensure inputs don't zoom on mobile */
    input,
    textarea,
    select {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100%;
        -webkit-appearance: none;
        appearance: none;
    }
}

/* Tab content styling */
.tab-content {
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 0.375rem 0.375rem;
}

.tab-pane {
    padding: 0;
}

/* Button standardization */
.btn-sm {
    height: 32px !important;
    line-height: 1.2 !important;
    font-size: 13px !important;
    padding: 4px 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s;
}

.btn:hover {
    transform: translateY(-1px);
}

/* Vignette controls styling */
#vignetteColor,
#vignetteOpacity {
    height: 32px !important;
}

/* Row alignment fix */
.row.g-1,
.row.g-2 {
    align-items: center;
}

.row .col-1,
.row .col-2,
.row .col-3,
.row .col-4,
.row .col-5,
.row .col-6 {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Form controls standardization */
.form-control-sm:not(textarea),
.form-select-sm,
.form-range-sm {
    height: 28px !important;
}

.form-control-color {
    height: 32px !important;
    width: 100% !important;
    padding: 2px !important;
}

/* Range slider styling */
.form-range {
    height: 28px !important;
    background: transparent !important;
}

.form-range::-webkit-slider-thumb {
    height: 20px !important;
    width: 20px !important;
}

/* Blue slider styling - only thumbs are blue, tracks remain gray */
.slider-blue {
    background: transparent !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    height: 6px !important;
    outline: none !important;
}

.slider-blue::-webkit-slider-track {
    background: #dee2e6 !important;
    border-radius: 3px !important;
    height: 6px !important;
    border: none !important;
}

.slider-blue::-webkit-slider-thumb {
    appearance: none !important;
    -webkit-appearance: none !important;
    height: 20px !important;
    width: 20px !important;
    border-radius: 50% !important;
    background: #007bff !important;
    border: 2px solid #ffffff !important;
    cursor: pointer !important;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3) !important;
    transition: all 0.2s ease !important;
}

.slider-blue::-webkit-slider-thumb:hover {
    background: #0056b3 !important;
    box-shadow: 0 3px 6px rgba(0, 123, 255, 0.5) !important;
    transform: scale(1.1) !important;
}

.slider-blue::-moz-range-track {
    background: #dee2e6 !important;
    border-radius: 3px !important;
    height: 6px !important;
    border: none !important;
}

.slider-blue::-moz-range-thumb {
    height: 16px !important;
    width: 16px !important;
    border-radius: 50% !important;
    background: #007bff !important;
    border: 2px solid #ffffff !important;
    cursor: pointer !important;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3) !important;
    transition: all 0.2s ease !important;
}

.slider-blue::-moz-range-thumb:hover {
    background: #0056b3 !important;
    box-shadow: 0 3px 6px rgba(0, 123, 255, 0.5) !important;
    transform: scale(1.1) !important;
}

/* Modal styling */
.modal-body {
    background: #f8f9fa;
}

#resultImage {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Success message styling */
.success-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #28a745;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 9999;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Mobile optimized position grid */
.position-3x3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    width: 90px;
    margin: 0 auto;
}

.position-3x3 button {
    width: 28px;
    height: 22px !important;
    padding: 0;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Button active state */
.btn-outline-secondary.active {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    color: white !important;
}

/* Desktop responsive adjustments */
@media (min-width: 769px) {
    .canvas-container {
        max-width: 100%;
        display: flex;
        justify-content: center;
    }

    #mainCanvas {
        max-width: 100%;
        height: auto;

    }
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .canvas-container {
        max-width: 100%;
        margin: 0 auto;
    }

    #mainCanvas {
        max-width: 100%;
        height: auto;
    }

    .controls-panel {
        margin-top: 20px;
    }

    .sticker-grid {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        gap: 10px;
        max-width: 100%;
    }

    .form-control-sm {
        font-size: 12px;
    }

    .btn-sm {
        font-size: 12px;
        padding: 0.25rem 0.5rem;
    }

    .container-fluid {
        padding: 0.5rem;
    }

    .editor-container {
        padding: 10px;
        margin-bottom: 10px;
    }

    /* Larger resize handles for mobile touch */
    .resize-handle {
        width: 20px;
        height: 20px;
        border-width: 3px;
    }
}

/* Mobile-fixed sticker scroll */


.sticker-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.sticker-tabs::-webkit-scrollbar {
    display: none;
}

.sticker-tab {
    flex-shrink: 0;
    padding: 4px 8px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: capitalize;
}

.sticker-tab.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.sticker-tab:hover {
    background: #e9ecef;
}

.sticker-tab.active:hover {
    background: #0056b3;
}

.sticker-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
    scrollbar-width: thin;
}

.sticker-scroll::-webkit-scrollbar {
    height: 6px;
}

.sticker-scroll::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.sticker-scroll::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.sticker-item {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 4px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.sticker-item:hover {
    border-color: #007bff;
    transform: scale(1.1);
}

/* Compact text tools */
.text-tools-compact {
    background: white;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.form-label-sm {
    font-size: 10px;
    margin-bottom: 2px;
    font-weight: 600;
}

.form-range-sm {
    height: 1rem;
}

/* Mobile position grid adjustments */
.position-3x3 {
    width: 90px;
    gap: 1px;
}

.position-3x3 button {
    width: 28px;
    height: 28px;
    font-size: 11px;
}

/* Album Layout Styles */
.album-layout {
    position: relative;
    width: 100%;
    height: 100%;
    display: none;
}

.album-layout.active {
    display: block;
}

.album-zone {
    position: absolute;
    outline: 2px dashed #007bff;
    outline-offset: -2px;
    background: rgba(0, 123, 255, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
}

.album-zone:hover {
    background: rgba(0, 123, 255, 0.2);
    border-color: #0056b3;
}

.album-zone.has-image {
    outline: 2px solid #28a745;
    outline-offset: -2px;
    background: transparent;
}

.album-image {
    position: absolute;
    top: 0;
    left: 0;
    cursor: grab;
    transition: none;
    transform-origin: top left;
    user-select: none;
    pointer-events: auto;
}

.album-image:active {
    cursor: grabbing;
}

.album-image.zooming {
    transition: none;
}

.album-image.selected {
    border: 3px solid #ffc107;
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.5);
}

/* Album Resizers */
.album-resizer {
    position: absolute;
    background-color: transparent;
    z-index: 100;
    transition: background-color 0.2s;
}

.album-resizer:hover,
.album-resizer.active {
    background-color: rgba(0, 123, 255, 0.5);
}

.album-resizer-v {
    width: 10px;
    height: 100%;
    cursor: col-resize;
    transform: translateX(-50%);
}

.album-resizer-h {
    height: 10px;
    width: 100%;
    cursor: row-resize;
    transform: translateY(-50%);
}

/* Layout specific styles - will be updated dynamically by JavaScript */
/* Gap between zones controlled by --gap-size CSS variable */

.layout-vertical .album-zone:first-child {
    left: 0;
    top: 0;
    width: calc(50% - var(--gap-size, 0px));
    height: 100%;
}

.layout-vertical .album-zone:last-child {
    left: calc(50% + var(--gap-size, 0px));
    top: 0;
    width: calc(50% - var(--gap-size, 0px));
    height: 100%;
}

.layout-horizontal .album-zone:first-child {
    left: 0;
    top: 0;
    width: 100%;
    height: calc(50% - var(--gap-size, 0px));
}

.layout-horizontal .album-zone:last-child {
    left: 0;
    top: calc(50% + var(--gap-size, 0px));
    width: 100%;
    height: calc(50% - var(--gap-size, 0px));
}

.layout-three-top .album-zone:nth-child(1) {
    left: 0;
    top: 0;
    width: calc(50% - var(--gap-size, 0px));
    height: calc(50% - var(--gap-size, 0px));
}

.layout-three-top .album-zone:nth-child(2) {
    left: calc(50% + var(--gap-size, 0px));
    top: 0;
    width: calc(50% - var(--gap-size, 0px));
    height: calc(50% - var(--gap-size, 0px));
}

.layout-three-top .album-zone:nth-child(3) {
    left: 0;
    top: calc(50% + var(--gap-size, 0px));
    width: 100%;
    height: calc(50% - var(--gap-size, 0px));
}

.layout-three-bottom .album-zone:nth-child(1) {
    left: 0;
    top: 0;
    width: 100%;
    height: calc(50% - var(--gap-size, 0px));
}

.layout-three-bottom .album-zone:nth-child(2) {
    left: 0;
    top: calc(50% + var(--gap-size, 0px));
    width: calc(50% - var(--gap-size, 0px));
    height: calc(50% - var(--gap-size, 0px));
}

.layout-three-bottom .album-zone:nth-child(3) {
    left: calc(50% + var(--gap-size, 0px));
    top: calc(50% + var(--gap-size, 0px));
    width: calc(50% - var(--gap-size, 0px));
    height: calc(50% - var(--gap-size, 0px));
}

/* Three Left Layout - 1 large left, 2 small right */
.layout-three-left .album-zone:nth-child(1) {
    left: 0;
    top: 0;
    width: calc(50% - var(--gap-size, 0px)/2);
    height: 100%;
}

.layout-three-left .album-zone:nth-child(2) {
    left: calc(50% + var(--gap-size, 0px)/2);
    top: 0;
    width: calc(50% - var(--gap-size, 0px)/2);
    height: calc(50% - var(--gap-size, 0px)/2);
}

.layout-three-left .album-zone:nth-child(3) {
    left: calc(50% + var(--gap-size, 0px)/2);
    top: calc(50% + var(--gap-size, 0px)/2);
    width: calc(50% - var(--gap-size, 0px)/2);
    height: calc(50% - var(--gap-size, 0px)/2);
}

/* Three Right Layout - 2 small left, 1 large right */
.layout-three-right .album-zone:nth-child(1) {
    left: 0;
    top: 0;
    width: calc(50% - var(--gap-size, 0px)/2);
    height: calc(50% - var(--gap-size, 0px)/2);
}

.layout-three-right .album-zone:nth-child(2) {
    left: 0;
    top: calc(50% + var(--gap-size, 0px)/2);
    width: calc(50% - var(--gap-size, 0px)/2);
    height: calc(50% - var(--gap-size, 0px)/2);
}

.layout-three-right .album-zone:nth-child(3) {
    left: calc(50% + var(--gap-size, 0px)/2);
    top: 0;
    width: calc(50% - var(--gap-size, 0px)/2);
    height: 100%;
}

/* Album finished state */
.album-layout.finished {
    pointer-events: none;
    z-index: 0;
}

.album-layout.finished .album-zone {
    border: none;
    background: transparent;
}

.album-layout.finished .album-zone:hover {
    background: transparent;
    border: none;
}

/* Padding styles for album zones */
.album-zone.with-padding {
    box-sizing: border-box;
}

/* Compact album layout buttons */
.album-controls .btn-sm {
    font-size: 0.7rem;
    padding: 0.25rem 0.2rem;
    line-height: 1.2;
}

.album-controls small {
    font-size: 0.65rem;
    margin-top: 2px;
}

/* Mobile optimizations for album */
@media (max-width: 768px) {
    .album-controls .btn-sm {
        font-size: 0.65rem;
        padding: 0.2rem 0.15rem;
    }

    .album-controls small {
        font-size: 0.6rem;
    }
}

/* New Layout Styles */
.tools-panel {
    background: #f8f9fa;
    padding: 15px;
    height: fit-content;
}

.control-section {
    background: white;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 2px solid #e9ecef;
}

/* Responsive adjustments for new layout */
@media (max-width: 992px) {
    .tools-panel {
        margin-top: 20px;
        max-height: none;
    }

    .container-fluid {
        max-width: 100% !important;
    }
}

@media (max-width: 768px) {
    .tools-panel {
        padding: 10px;
    }

    .control-section {
        padding: 10px;
        margin-bottom: 10px;
    }

    .section-title {
        font-size: 12px;
        margin-bottom: 8px;
    }

    /* Mobile: Move stickers above canvas */
    .row {
        display: flex;
        flex-wrap: wrap;
    }

    /* Column 3 (Tools) - Order 1 (First) */
    #col-right {
        order: 1;
        margin-bottom: 15px;
    }

    /* Column 2 (Canvas) - Order 2 (Second) */
    #col-center {
        order: 2;
        margin-bottom: 15px;
    }

    /* Column 1 (Vietbai) - Order 3 (Last) */
    #col-left {
        order: 3;
    }



    /* Make sticker section more compact on mobile */
    .sticker-container {
        max-height: 200px;
        overflow-y: auto;
    }

    .sticker-scroll {
        max-height: 150px;
        overflow-y: auto;
    }
}

/* Font Size Input Group */
#fontSizeInput {
    border-left: none;
    border-right: none;
    font-weight: bold;
    color: #333;
    width: 73px !important;
    flex: 0 0 auto;
}

#decreaseFontSize,
#increaseFontSize {
    border-color: #ced4da;
    color: #555;
    font-weight: bold;
    width: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#decreaseFontSize:hover,
#increaseFontSize:hover {
    background-color: #e9ecef;
    color: #000;
}

#decreaseFontSize {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

#increaseFontSize {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Text Input Textarea */
#textInput {
    resize: vertical !important;
    overflow: auto;
}