/* css/style.css */
:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --surface-hover: #2c2c2c;
    --primary-color: #bb86fc;
    --secondary-color: #03dac6;
    --secondary-color-bright: #6ff7e3; /* Twice as bright cyan */
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --error-color: #cf6679;
    --border-radius: 8px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    line-height: 1.6;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

/* Login Screen */
#login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.login-card {
    background: var(--surface-color);
    padding: 40px;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    margin-bottom: var(--spacing-lg);
    font-weight: 300;
    letter-spacing: 1px;
}

input[type="password"] {
    width: 100%;
    padding: 12px;
    margin-bottom: var(--spacing-md);
    background: var(--bg-color);
    border: 1px solid #333;
    border-radius: var(--border-radius);
    color: white;
    font-size: 16px;
    transition: var(--transition);
}

input[type="password"]:focus {
    border-color: var(--primary-color);
    outline: none;
}

button {
    background: var(--primary-color);
    color: #000;
    border: none;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    transition: var(--transition);
    width: 100%;
}

button:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.error-message {
    color: var(--error-color);
    margin-top: var(--spacing-sm);
    min-height: 24px;
    font-size: 14px;
}

/* App Layout */
#app {
    display: none;
    /* Hidden until logged in */
    flex: 1;
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--surface-color);
    display: flex;
    flex-direction: column;
    border-right: 1px solid #333;
    padding: var(--spacing-md);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.folder-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}

.folder-item {
    padding: 10px;
    cursor: pointer;
    border-radius: var(--border-radius);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
    color: var(--text-secondary);
}

.folder-item:hover,
.folder-item.active {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.folder-item.parent-folder {
    color: var(--primary-color);
    font-weight: 500;
}

.folder-item i {
    font-size: 1.1em;
}

/* Create new folder button at bottom */
.create-folder-item {
    margin-top: auto;
    border-top: 1px solid var(--surface-hover);
    padding-top: 12px;
    color: var(--secondary-color);
}

.create-folder-item:hover {
    color: var(--secondary-color-bright);
}

.create-folder-item i {
    color: var(--secondary-color);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-color);
}

.toolbar {
    height: 64px;
    padding: 0 var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(18, 18, 18, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
    gap: var(--spacing-md);
}

.filter-box {
    flex: 1;
    max-width: 300px;
}

.filter-box input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-color);
    border: 2px solid #666;
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.2s ease;
}

.filter-box input::placeholder {
    color: #888;
}

.filter-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(187, 134, 252, 0.3);
}

.toolbar .actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.upload-button-label {
    display: inline-block;
    margin-left: var(--spacing-sm);
}

.upload-button-label button {
    width: auto;
    min-width: 120px;
}

.toolbar .actions button {
    width: auto;
    min-width: 120px;
}

.toolbar-btn {
    background: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--surface-hover);
    padding: 8px 16px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: auto;
}

.toolbar-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
}

.toolbar-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.gallery-grid {
    padding: var(--spacing-lg);
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-md);
    align-content: start;
}

.gallery-item {
    position: relative;
    width: 100%;
    padding-top: 100%; /* Force 1:1 Aspect Ratio */
    height: 0; /* Required for padding hack */
    background: #000;
    /* Dark background for letterboxing */
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid #333;
}

.gallery-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Preserves aspect ratio, fills one dimension */
    transition: transform 0.5s ease;
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.gallery-item:hover img {
    transform: scale(1.05);
}

.gallery-item .overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: var(--transition);
    color: white;
}

.gallery-item .overlay i {
    font-size: 2rem;
    margin-bottom: 8px;
}

.gallery-item .overlay .filename {
    font-size: 0.85rem;
    font-weight: 500;
    max-width: 90%;
    text-align: center;
    word-break: break-word;
    color: var(--text-primary);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.gallery-item:hover .overlay {
    opacity: 1;
}

/* Hidden Utilities */
.hidden {
    display: none !important;
}

/* File input hidden but still functional for programmatic clicks */
input[type="file"].visually-hidden {
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    overflow: hidden !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
}


/* Upload Overlay */
.upload-zone {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.upload-zone.active {
    opacity: 1;
    pointer-events: all;
}

.upload-zone.highlight {
    background: rgba(187, 134, 252, 0.2);
    border: 4px dashed var(--primary-color);
}

.gallery-loading {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 60px;
}

.gallery-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #444;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Editor Modal - Simple and Clean */
.editor-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 400;
    display: flex;
    flex-direction: column;
}

.editor-toolbar {
    height: 60px;
    background: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.editor-controls {
    display: flex;
    gap: 10px;
}

.editor-controls button {
    padding: 8px 16px;
    background: #555;
    color: white;
    border: none;
    cursor: pointer;
    min-width: 80px;
}

.editor-controls button:hover {
    background: #666;
}

#editor-close-btn {
    background: #777;
}

.editor-canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    border: 1px solid #444;
}

/* Lightbox */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 300;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.lightbox.active {
    opacity: 1;
    pointer-events: all;
}

.lightbox-container {
    display: flex;
    width: 90%;
    height: 85%;
    gap: 30px;
}

.lightbox-sidebar {
    width: 300px;
    background: rgba(30, 30, 30, 0.6);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #e0e0e0;
}

.lightbox-sidebar h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    word-break: break-all;
}

.lbs-meta {
    margin-bottom: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.url-copy-box {
    display: flex;
    gap: 5px;
    margin-top: 10px;
}

.url-copy-box input {
    background: #111;
    border: 1px solid #333;
    color: #bbb;
    padding: 8px;
    border-radius: 4px;
    width: 100%;
    font-size: 0.8rem;
}

.url-copy-box button {
    width: 40px;
    flex-shrink: 0;
    padding: 0;
    cursor: pointer;
    background: #333;
    border: none;
    color: #fff;
    border-radius: 4px;
}

.lightbox-actions {
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lightbox-btn {
    background: var(--surface-hover);
    border: 1px solid #444;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    padding: 12px;
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.lightbox-btn:hover {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
}

.lightbox-btn.delete-btn:hover {
    background: #ff4444;
    color: white;
    border-color: #ff4444;
}

.lightbox-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    max-width: calc(100% - 330px);
    /* Subtract sidebar width + gap */
}

.lightbox-content img {
    max-width: 100%;
    max-height: 100%;
    display: block;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    border-radius: 4px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 2rem; /* Reduced from 2.5rem */
    color: #ffffff;
    opacity: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    background: none;
    border: none;
    z-index: 310; /* Only slightly higher than lightbox (300) */
    pointer-events: none; /* Inherit from lightbox when hidden */
    transition: transform 0.2s, color 0.2s;
}

/* Only enable pointer-events when lightbox is active */
.lightbox.active .lightbox-close {
    pointer-events: auto;
}

.lightbox-close:hover {
    transform: scale(1.2);
    color: var(--primary-color);
}

@media (max-width: 768px) {
    .lightbox-container {
        flex-direction: column-reverse;
        /* Info below image */
        padding: 20px;
    }

    .lightbox-sidebar {
        width: 100%;
        max-height: 40%;
        overflow-y: auto;
    }

    .lightbox-content {
        max-width: 100%;
        flex: 1;
        margin-bottom: 20px;
    }

    .lightbox-content img {
        max-height: 50vh;
        /* Ensure space for sidebar */
    }
}

/* Help Modal Styles */
.help-modal-content {
    max-width: 900px;
    width: 90%;
    max-height: 85vh;
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    cursor: grab;
    user-select: none;
    background: var(--surface-color);
    border: 1px solid var(--surface-hover);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

.help-modal-content.dragging {
    cursor: grabbing;
    transition: none;
}

.help-modal-content .modal-header {
    cursor: grab;
    user-select: none;
    background: var(--surface-hover);
    border-bottom: 1px solid var(--surface-hover);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.help-modal-content .modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text-primary);
}

.help-modal-content .close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.help-modal-content .close-btn:hover {
    color: var(--text-primary);
    background: var(--surface-color);
}

.help-modal-content.dragging .modal-header {
    cursor: grabbing;
}

.help-content {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(85vh - 80px);
    line-height: 1.8;
    color: var(--text-primary);
    cursor: default;
    user-select: text;
    background: var(--surface-color);
}

.help-content h1 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--secondary-color);
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 10px;
}

.help-content h2 {
    font-size: 1.5rem;
    margin-top: 30px;
    margin-bottom: 15px;
    color: var(--primary-color);
}

.help-content h3 {
    font-size: 1.2rem;
    margin-top: 25px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.help-content p {
    margin-bottom: 15px;
}

.help-content ul,
.help-content ol {
    margin-left: 20px;
    margin-bottom: 15px;
}

.help-content li {
    margin-bottom: 8px;
}

.help-content code {
    background: var(--surface-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.help-content pre {
    background: var(--surface-hover);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 15px;
}

.help-content blockquote {
    border-left: 4px solid var(--secondary-color);
    padding-left: 15px;
    margin: 15px 0;
    color: var(--text-secondary);
    font-style: italic;
}

.help-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.help-content th,
.help-content td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--surface-hover);
}

.help-content th {
    background: var(--surface-hover);
    font-weight: 600;
    color: var(--secondary-color);
}

.help-content tr:hover {
    background: var(--surface-hover);
}

.help-content hr {
    border: none;
    border-top: 1px solid var(--surface-hover);
    margin: 30px 0;
}

.help-content a {
    color: var(--secondary-color);
    text-decoration: none;
}

.help-content a:hover {
    text-decoration: underline;
}

.help-loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 1.2rem;
}

.help-loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--surface-hover);
    border-top-color: var(--secondary-color);
    border-radius: 50%;
    margin-left: 10px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Help button in toolbar */
#help-btn {
    color: var(--secondary-color);
}

#help-btn:hover {
    color: var(--secondary-color-bright);
}