/**
 * lucidimage.dev - Styles
 * Copyright (c) 2024. All rights reserved.
 */

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

body {
    font-family: 'Google Sans', system-ui, sans-serif;
    overflow: hidden;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow selection in input fields */
input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Disable image dragging */
img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

/* Disable printing (basic) */
@media print {
    body {
        display: none !important;
    }
}

/* Tool Buttons - Figma/Adobe style */
.tool-btn {
    padding: 6px;
    border-radius: 4px;
    color: #6b6b6b;
    transition: all 0.15s ease;
    background: transparent;
    border: none;
    cursor: pointer;
}

.tool-btn:hover {
    background: #ebebeb;
    color: #1e1e1e;
}

.tool-btn.active {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.tool-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Preset Buttons */
.preset-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    color: #0f172a;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.preset-btn:hover {
    background: linear-gradient(145deg, #ffffff, #f1f5f9);
    border-color: #3b82f6;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.15), 0 2px 6px rgba(0, 0, 0, 0.04);
    transform: translateY(-2px);
}

.preset-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

/* Hover states for preset buttons - icons turn blue with glow */
.preset-btn:hover .preset-icon {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.preset-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

/* Keyboard shortcuts */
.kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 9px;
    font-family: 'Inter', monospace;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    margin-right: 4px;
    color: #475569;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Canvas Container */
#canvas-container {
    position: relative;
    transform-origin: center center;
    transition: transform 0.1s ease-out;
}

#appCanvas {
    display: block;
    background: #ffffff;
}

/* Selection Overlay */
#selection-overlay {
    position: absolute;
    border: 2px solid #3b82f6;
    background: linear-gradient(145deg, rgba(59, 130, 246, 0.08), rgba(37, 99, 235, 0.12));
    pointer-events: none;
    display: none;
    box-sizing: border-box;
    border-radius: 6px;
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.3), 0 4px 12px rgba(37, 99, 235, 0.15);
}

.selection-handles .handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: linear-gradient(145deg, #ffffff, #f1f5f9);
    border: 2px solid #3b82f6;
    border-radius: 3px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.selection-handles .handle.nw { top: -5px; left: -5px; cursor: nwse-resize; }
.selection-handles .handle.ne { top: -5px; right: -5px; cursor: nesw-resize; }
.selection-handles .handle.sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.selection-handles .handle.se { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* Checkerboard background for transparency */
.checkerboard-bg {
    background-image:
        linear-gradient(45deg, #d1d5db 25%, transparent 25%),
        linear-gradient(-45deg, #d1d5db 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d1d5db 75%),
        linear-gradient(-45deg, transparent 75%, #d1d5db 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

/* Cursor styles */
.cursor-select { cursor: crosshair; }
.cursor-pan { cursor: grab; }
.cursor-panning { cursor: grabbing; }
.cursor-move { cursor: move; }

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* History item */
.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #64748b;
    border: 1px solid transparent;
}

.history-item:hover {
    background: linear-gradient(145deg, #f8fafc, #f1f5f9);
    color: #334155;
    border-color: #e2e8f0;
}

.history-item.active {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    border-color: transparent;
}

/* Processing overlay animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* Drag and drop overlay */
.drop-zone-active::after {
    content: 'Drop image here';
    position: absolute;
    inset: 0;
    background: rgba(37, 99, 235, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: white;
    border: 3px dashed #60a5fa;
    border-radius: 12px;
    z-index: 1000;
}

/* Toast notifications */
.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    border: 1px solid rgba(226, 232, 240, 0.8);
    padding: 14px 18px;
    border-radius: 14px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(24px) scale(0.95);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
}

.toast.show {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.toast-icon {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    background: linear-gradient(145deg, #ecfdf5, #d1fae5);
    color: #059669;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

.toast.error .toast-icon {
    background: linear-gradient(145deg, #fef2f2, #fee2e2);
    color: #dc2626;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

.toast.info .toast-icon {
    background: linear-gradient(145deg, #eff6ff, #dbeafe);
    color: #2563eb;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.toast-message {
    font-size: 14px;
    color: #09090b;
    font-weight: 500;
}

/* Focus styles */
input:focus, button:focus {
    outline: none;
}

input:focus-visible, button:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Disable text selection on canvas area */
#viewport {
    user-select: none;
    -webkit-user-select: none;
}

/* API Key Button States */
#api-key-btn.has-key {
    background: #e6f9ed;
    color: #14ae5c;
}

#api-key-btn.no-key {
    background: #feefec;
    color: #f24822;
}

#api-key-btn:hover {
    background: #ebebeb;
}

/* Checkbox styling */
input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #2563eb;
}

/* Modal animation */
#api-key-modal > div {
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Create size buttons - Figma style */
.create-size-btn {
    background: #f5f5f5;
    border-color: #e0e0e0;
    color: #6b6b6b;
}

.create-size-btn:hover {
    background: #ebebeb;
    border-color: #c4c4c4;
    color: #1e1e1e;
}

.create-size-btn.active {
    background: #e6f4ff;
    border-color: #0d99ff;
    color: #0d99ff;
}

/* Compact Pill Buttons for One-Click Tools */
.preset-pill {
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 4px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    color: #6b6b6b;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.preset-pill:hover {
    background: #ebebeb;
    border-color: #c4c4c4;
    color: #1e1e1e;
}

.preset-pill:active {
    background: #e0e0e0;
}

/* Free preset indicator - subtle green tint */
.preset-pill[data-free="true"] {
    background: linear-gradient(145deg, #f0fdf4, #ecfdf5);
    border-color: #bbf7d0;
    color: #166534;
}

.preset-pill[data-free="true"]:hover {
    background: linear-gradient(145deg, #dcfce7, #d1fae5);
    border-color: #86efac;
}

/* Primary Action Buttons - matches active history item */
.btn-primary {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    border: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary:hover {
    background: linear-gradient(145deg, #2563eb, #1d4ed8);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

/* Spinner animation */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.animate-spin {
    animation: spin 0.8s linear infinite;
}

/* Export dropdown menu */
#export-menu {
    animation: dropdownSlide 0.15s ease-out;
}

@keyframes dropdownSlide {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Mobile toggle buttons */
.mobile-toggle {
    display: none;
    padding: 8px;
    background: transparent;
    border: none;
    color: #6b6b6b;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.mobile-toggle:hover {
    background: #ebebeb;
    color: #1e1e1e;
}

.mobile-toggle.active {
    background: #e6f4ff;
    color: #0d99ff;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sidebar-overlay.show {
    opacity: 1;
}

/* Mobile breakpoint */
@media (max-width: 768px) {
    /* Show mobile toggles */
    .mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    /* Header adjustments */
    header {
        padding: 8px 10px !important;
        gap: 6px !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    header > div {
        flex-shrink: 0;
    }

    header h1,
    header span.font-semibold {
        font-size: 13px !important;
    }

    /* Hide zoom controls on mobile */
    #zoom-controls {
        display: none !important;
    }

    /* Hide dividers on mobile */
    header .w-px {
        display: none !important;
    }

    /* Hide Import text button on mobile - move to sidebar */
    header button[onclick*="file-upload"] {
        display: none !important;
    }

    /* Compact API key button */
    #api-key-btn {
        padding: 6px !important;
    }

    #api-key-btn span {
        display: none !important;
    }

    /* Compact export button */
    #export-btn {
        padding: 6px 10px !important;
    }

    #export-btn svg {
        display: none !important;
    }

    /* Compact help button */
    #help-btn {
        padding: 6px !important;
    }

    /* Sidebars - hidden by default, slide in when active */
    aside {
        position: fixed !important;
        top: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        max-width: 85vw;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    /* Left sidebar */
    aside:first-of-type {
        left: 0;
        width: 260px !important;
    }

    aside:first-of-type.open {
        transform: translateX(0);
    }

    /* Right sidebar */
    aside:last-of-type {
        right: 0;
        left: auto;
        transform: translateX(100%);
        width: 220px !important;
    }

    aside:last-of-type.open {
        transform: translateX(0);
    }

    /* Show overlay when sidebar is open */
    .sidebar-overlay.show {
        display: block;
    }

    /* Main canvas area - full width */
    main#viewport {
        width: 100% !important;
    }

    /* Prompt bar - full width on mobile */
    #prompt-bar {
        left: 12px !important;
        right: 12px !important;
        transform: none !important;
        bottom: 12px !important;
    }

    #prompt-bar > div {
        width: 100% !important;
    }

    #prompt-bar input {
        min-width: 0 !important;
    }

    /* Select all button */
    #select-all-btn {
        left: 12px !important;
        right: 12px !important;
        transform: none !important;
        width: auto !important;
        justify-content: center;
    }

    /* Empty state - smaller on mobile */
    #empty-state > div {
        width: calc(100% - 24px) !important;
        max-width: 320px;
        margin: 0 12px;
    }

    /* Processing overlay pill */
    #processing-overlay > div {
        margin: 0 16px;
        max-width: calc(100% - 32px);
    }

    /* Modals - full width on mobile */
    #api-key-modal > div,
    #help-modal > div,
    #exit-warning-modal > div {
        max-width: calc(100% - 24px) !important;
        margin: 12px !important;
    }

    /* Toast positioning */
    #toast-container {
        left: 12px !important;
        right: 12px !important;
        transform: none !important;
    }

    .toast {
        width: 100%;
    }

    /* Zoom controls - hide text, show icons only */
    #zoom-level {
        min-width: auto !important;
        padding: 4px 8px !important;
    }

    /* Tool buttons in header - compact */
    .tool-btn {
        padding: 6px !important;
    }

    /* Preset pills - allow wrapping */
    .preset-pill {
        font-size: 10px;
        padding: 4px 8px;
    }

    /* Scrollable sidebar content */
    aside > div {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 480px) {
    header h1 {
        font-size: 12px !important;
    }

    /* Hide some header elements on very small screens */
    #api-key-btn span {
        display: none;
    }

    #export-btn span {
        display: none;
    }

    #export-btn svg:last-child {
        display: none;
    }

    /* Prompt bar even more compact */
    #prompt-bar > div {
        padding: 8px !important;
        gap: 8px !important;
    }

    #prompt-bar input {
        padding: 10px 12px !important;
        font-size: 14px !important;
    }

    #prompt-bar button {
        padding: 10px !important;
    }

    /* Hide prompt hints on small screens */
    #prompt-bar > div + div {
        display: none !important;
    }
}
