:root {
    --bg-dark: #121212;
    --bg-panel: #1e1e1e;
    --bg-hover: #2d2d2d;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --border: #333;
    --accent: #22d3ee;
    --danger: #ef4444;
    --success: #22c55e;
    --font-family: 'Inter', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.top-bar {
    height: 60px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text-main);
}

.logo svg {
    color: var(--primary);
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.btn.primary {
    background-color: var(--primary);
    color: white;
}

.btn.primary:hover {
    background-color: var(--primary-hover);
}

.btn.secondary {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn.secondary:hover {
    background-color: var(--bg-hover);
}

.btn.success {
    background-color: var(--success);
    color: black;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.small {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn.full-width {
    width: 100%;
    justify-content: center;
}

.btn.danger {
    background-color: var(--danger);
    color: white;
}

/* Workspace */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebars */
.sidebar {
    width: 280px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
    gap: 25px;
    flex-shrink: 0;
}

.right-sidebar {
    border-right: none;
    border-left: 1px solid var(--border);
}

.sidebar-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 15px;
}

/* Grid for Filters */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.filter-btn {
    background-color: var(--bg-hover);
    border: 1px solid transparent;
    color: var(--text-main);
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    text-align: center;
    transition: 0.2s;
}

.filter-btn:hover {
    border-color: var(--primary);
}

.filter-btn.active {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Tool Groups (Icons) */
.tool-group {
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.tool-btn {
    width: 45px;
    height: 45px;
    border-radius: 6px;
    background-color: var(--bg-hover);
    border: none;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.tool-btn:hover {
    background-color: var(--primary);
    color: white;
}

/* Inputs & Resize */
.resize-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.input-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.resize-controls input {
    width: 60px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: white;
    padding: 4px 8px;
    font-family: inherit;
}

.resize-controls input:focus {
    outline: none;
    border-color: var(--primary);
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-wrapper label {
    font-size: 0.85rem;
    cursor: pointer;
}

/* Sliders */
.slider-group {
    margin-bottom: 20px;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.slider-header .value {
    color: var(--primary);
    font-feature-settings: "tnum";
}

input[type="range"] {
    width: 100%;
    height: 4px;
    background: var(--bg-hover);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--bg-panel);
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Preview Area */
.preview-area {
    flex: 1;
    background-color: #1a1a1a;
    background-image:
        linear-gradient(45deg, #222 25%, transparent 25%),
        linear-gradient(-45deg, #222 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #222 75%),
        linear-gradient(-45deg, transparent 75%, #222 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
    overflow: hidden;
}

.canvas-container {
    max-width: 100%;
    max-height: 100%;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

canvas {
    display: block;
    max-width: 100%;
    max-height: 80vh;
    /* Keep it within view */
    object-fit: contain;
}

.placeholder-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #555;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.placeholder-text.hidden {
    display: none;
}

/* Crop Overlay */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10;
    cursor: crosshair;
}

.crop-overlay.hidden {
    display: none;
}

.crop-box {
    position: absolute;
    width: 100px;
    height: 100px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid white;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
}

.handle {
    width: 10px;
    height: 10px;
    background: white;
    position: absolute;
    border-radius: 50%;
}

.handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.crop-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.crop-actions.hidden {
    display: none;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .workspace {
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar {
        width: 100%;
        min-height: auto;
        flex-shrink: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .canvas-container {
        margin: 20px 0;
    }

    .preview-area {
        min-height: 400px;
    }
}