:root {
    --bg-color: #121212;
    --panel-bg: #f5f5f7;
    --accent-blue: #0071e3;
    --accent-red: #ff3b30;
    --text-dark: #1d1d1f;
    --input-bg: #e8e8ed;
    --text-secondary: #86868b;
    --font-main: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
    --nav-bg: #1c1c1e;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

#origSize {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
    letter-spacing: 0.3px;
    opacity: 0.8;
    text-align: left;
}

/* Glassmorphism item controls */
.item-ctrl {
    position: absolute;
    top: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.5) !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.25) !important;
    backdrop-filter: blur(10px) saturate(180%);
    -webkit-backdrop-filter: blur(10px) saturate(180%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease;
    z-index: 100;
    padding: 0;
    outline: none;
    color: white;
}

.item-ctrl:hover {
    transform: scale(1.15);
    background: rgba(255, 255, 255, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.7) !important;
}

.btn-del {
    right: -10px !important;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    padding-bottom: 1px;
}

.btn-edit {
    right: 16px !important;
    font-size: 10px;
}

.item-ctrl i {
    pointer-events: none;
}

.sidebar {
    width: 320px;
    background: var(--panel-bg);
    margin: 20px;
    padding: clamp(15px, 3vh, 25px);
    display: flex;
    flex-direction: column;
    border-radius: 35px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    color: var(--text-dark);
    height: calc(100vh - 40px);
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 100;
    overflow-y: auto;
    font-size: clamp(12px, 1.6vh, 14px);
    -webkit-overflow-scrolling: touch;
}

.sidebar h2 {
    font-size: clamp(18px, 2.5vh, 22px);
    font-weight: 700;
    text-align: center;
    margin: 0 0 20px 0;
}

.control-section {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.label-text {
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.file-upload-wrapper {
    position: relative;
    width: 100%;
}

#fileInput {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.file-custom-btn {
    background: var(--input-bg);
    padding: 12px;
    border-radius: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-weight: 500;
    display: block;
    border: 1.5px dashed #ccc;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    height: 100vh;
    box-sizing: border-box;
    overflow: hidden;
    gap: 10px;
}

.img-box {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    background-color: #1a1a1c;
    background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    border-radius: 30px;
    border: 1px solid #333;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.img-box.photos-loaded {
    background-image: conic-gradient(rgb(102, 102, 102) 0 25%, rgb(127, 127, 127) 25% 50%, rgb(102, 102, 102) 50% 75%, rgb(127, 127, 127) 75% 100%);
    background-size: 16px 16px;
}

.img-box.is-loading .cropper-container,
.img-box.is-loading #image {
    display: none !important;
}

.watermark {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.15);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 1px;
    pointer-events: none;
    text-transform: uppercase;
    z-index: 10;
}

.custom-select-wrapper {
    position: relative;
    width: 260px;
    height: 48px;
    background: #1c1c1e;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.dropdown-trigger {
    position: relative;
    padding-left: 12px;
    padding-right: 35px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    height: 48px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    overflow: hidden;
}

.trigger-text {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: left;
    padding-right: 5px;
}

.dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.15);
}

.dropdown-trigger::after {
    content: '';
    position: absolute;
    right: 20px;
    top: 48%;
    width: 7px;
    height: 7px;
    border-right: 2px solid rgba(255, 255, 255, 0.7);
    border-bottom: 2px solid rgba(255, 255, 255, 0.7);
    transform: translateY(-50%) rotate(45deg);
    transition: all 0.3s ease;
    pointer-events: none;
}

.dropdown-trigger.active::after {
    transform: translateY(-20%) rotate(-135deg);
}

.dropdown-menu {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    width: 100%;
    background: rgba(44, 44, 46, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    padding: 6px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
}

.dropdown-item {
    padding: 10px 14px;
    border-radius: 12px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: 0.15s;
}

.dropdown-item:hover {
    background: var(--accent-blue);
}

.dropdown-item.active {
    background: rgba(255, 255, 255, 0.1);
    font-weight: 700;
}

.dropdown-item.is-ready {
    color: #34c759;
    position: relative;
    padding-right: 35px;
}

.dropdown-item.is-ready::after {
    content: '✓';
    position: absolute;
    right: 15px;
    font-weight: bold;
    font-size: 16px;
}

#image {
    max-width: 100%;
    display: block;
}

input[type="text"],
input[type="number"] {
    background: var(--input-bg);
    border: 1.5px solid transparent;
    padding: 10px;
    border-radius: 12px;
    transition: all 0.2s ease-in-out;
    width: 100%;
    box-sizing: border-box;
    font-size: 1em;
    outline: none;
}

input:focus {
    border-color: var(--accent-blue);
    background: #fff;
}

.preset-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.btn-preset {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 8px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

.btn-preset.active {
    background: var(--accent-blue);
    color: white;
}

.btn-main {
    background: var(--accent-blue);
    color: white;
    border: none;
    padding: 16px;
    font-weight: 700;
    border-radius: 16px;
    cursor: pointer;
    width: 100%;
    font-size: 1em;
    margin-top: 10px;
    transition: transform 0.1s ease, background-color 0.2s ease;
}

.btn-main:active {
    transform: scale(0.98);
    background: #005bb5;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: #1c1c1e;
    padding: 25px;
    border-radius: 30px;
    color: white;
    text-align: center;
    width: 300px;
    border: 1px solid #333;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 20px;
}

.modal-btn {
    padding: 12px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    transition: transform 0.1s;
}

.modal-btn.primary {
    background: var(--accent-blue);
    color: white;
}

.modal-btn.secondary {
    background: #2c2c2e;
    color: white;
}

.modal-btn:active {
    transform: scale(0.98);
}

/* Preview Drawer */
.preview-drawer {
    position: relative;
    width: 100%;
    background: rgba(28, 28, 30, 0.95);
    border-radius: 25px;
    border: 1px solid #333;
    display: none;
    flex-direction: column;
    height: 190px;
    flex-shrink: 0;
    overflow: hidden;
}

.drawer-header {
    display: flex;
    align-items: center;
    padding: 0 25px;
    height: 45px;
    color: white;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.preview-list {
    display: flex;
    gap: 15px;
    padding: 15px 25px;
    overflow-x: auto;
    flex-grow: 1;
    align-items: flex-start;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.preview-item {
    flex: 0 0 auto;
    width: 90px;
    position: relative;
    transition: transform 0.2s ease-out, opacity 0.2s ease;
}

.preview-item img {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 18px;
    display: block;
}

.preview-item span {
    font-size: 10px;
    color: #888;
    display: block;
    text-align: center;
    margin-top: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-item[draggable="true"]:hover {
    cursor: grab;
}

body.is-dragging,
body.is-dragging * {
    cursor: grabbing !important;
}

.preview-item.dragging {
    opacity: 0.4;
    transform: scale(1.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.preview-item.drag-over {
    transform: scale(0.95);
    opacity: 0.7;
}

/* Batch Navigation */
.batch-nav {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 15px 0;
}

#batchNav .nav-btn {
    background-color: #2c2c2e !important;
    border: none !important;
    color: white !important;
    font-size: 18px;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    outline: none;
    min-width: 44px;
    min-height: 44px;
}

#batchNav .nav-btn:not(.disabled):not(:disabled):hover {
    background-color: #3a3a3c !important;
}

#batchNav .nav-btn:not(.disabled):not(:disabled):active {
    transform: scale(0.95);
}

#batchNav .nav-btn.disabled,
#batchNav .nav-btn:disabled {
    background-color: rgba(44, 44, 46, 0.3) !important;
    opacity: 0.3 !important;
    cursor: not-allowed !important;
}

.custom-dropdown {
    position: relative;
    width: 280px;
    z-index: 1000;
}

/* Responsive styles */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
        margin: 15px;
        padding: 15px;
    }

    .main-content {
        padding: 15px;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
        height: 100vh !important;
        height: 100dvh !important;
        overflow-y: auto !important;
        overflow-x: hidden;
    }

    .sidebar {
        width: 100%;
        margin: 0;
        border-radius: 0 0 25px 25px;
        height: auto !important;
        padding: 20px;
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
        order: 2;
        overflow-y: visible !important;
        flex-shrink: 0;
    }

    .main-content {
        order: 1;
        padding: 15px;
        padding-top: max(15px, env(safe-area-inset-top));
        height: auto !important;
        min-height: 60vh;
        min-height: 60dvh;
        gap: 8px;
        overflow: visible;
        flex-shrink: 0;
    }

    .img-box {
        min-height: 50vh;
        border-radius: 20px;
    }

    .custom-dropdown {
        width: 200px;
    }

    .dropdown-menu {
        max-height: 60vh;
    }

    .dropdown-item {
        padding: 14px 16px;
        font-size: 15px;
        min-height: 48px;
    }

    .preview-drawer {
        height: 160px;
        border-radius: 20px;
        margin-bottom: 15px;
    }

    .preset-group {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .btn-preset {
        padding: 10px;
        font-size: 14px;
        min-height: 44px;
    }

    input[type="text"],
    input[type="number"] {
        font-size: 16px;
        padding: 12px;
    }

    .btn-main {
        padding: 14px;
        font-size: 16px;
        min-height: 50px;
    }

    .watermark {
        position: fixed;
        bottom: 20px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 15px;
        border-radius: 0 0 20px 20px;
    }

    .main-content {
        padding: 10px;
        min-height: 50vh;
    }

    .img-box {
        min-height: 40vh;
    }

    .custom-dropdown {
        width: 160px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        flex-direction: row;
        height: 100dvh;
        overflow: hidden;
    }

    .sidebar {
        width: 280px;
        height: 100dvh;
        border-radius: 0 25px 25px 0;
        order: 1;
        overflow-y: scroll !important;
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
    }

    .main-content {
        order: 2;
        height: 100dvh;
        overflow-y: auto;
    }

    .img-box {
        min-height: 0;
    }
}