:root {
    --bg-dark: #0d1117;
    --bg-card: #161b22;
    --bg-hover: #21262d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --danger: #f85149;
    --radius: 8px;
    --font: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
}

.hidden { display: none !important; }

.screen {
    min-height: 100vh;
}

/* login */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0d1117 0%, #1a1f2e 50%, #0d1117 100%);
}

.login-box {
    background: var(--bg-card);
    padding: 3rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 360px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

.login-box h1 {
    text-align: center;
    margin-bottom: 2rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.login-box input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s;
}

.login-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.login-box button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover {
    background: var(--accent-hover);
}

.error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 1rem;
    text-align: center;
}

/* gallery header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: color 0.2s;
}

.btn-text:hover {
    color: var(--text-primary);
}

/* main layout */
.main-content {
    display: flex;
    height: calc(100vh - 57px);
}

/* folders panel */
#folders-panel {
    width: 260px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    overflow-y: auto;
    flex-shrink: 0;
}

#folders-panel h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

#folder-tree {
    margin-bottom: 1.5rem;
}

.folder-item {
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 2px;
    transition: background 0.15s;
}

.folder-item:hover {
    background: var(--bg-hover);
}

.folder-item.active {
    background: var(--accent);
    color: #fff;
}

.folder-item.nested {
    padding-left: 24px;
}

.folder-item.nested-2 {
    padding-left: 36px;
}

.new-folder {
    display: flex;
    gap: 8px;
}

.new-folder input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
}

.new-folder button {
    padding: 8px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
}

/* main area */
main {
    flex: 1;
    padding: 1.5rem 2rem;
    overflow-y: auto;
}

/* breadcrumbs */
#breadcrumbs {
    display: flex;
    gap: 8px;
    margin-bottom: 1.5rem;
    font-size: 14px;
    color: var(--text-secondary);
}

#breadcrumbs span {
    cursor: pointer;
    transition: color 0.2s;
}

#breadcrumbs span:hover {
    color: var(--text-primary);
}

#breadcrumbs span:last-child {
    color: var(--text-primary);
    cursor: default;
}

#breadcrumbs span::after {
    content: '/';
    margin-left: 8px;
    color: var(--border);
}

#breadcrumbs span:last-child::after {
    content: '';
}

/* upload zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    margin-bottom: 1.5rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(88, 166, 255, 0.05);
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* images grid */
.images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.image-card {
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-card .name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.lightbox img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius);
}

.lightbox-btn {
    position: fixed;
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    font-size: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.lightbox-btn:hover {
    background: rgba(255,255,255,0.2);
}

.lightbox-btn.close {
    top: 20px;
    right: 20px;
}

.lightbox-btn.prev {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-btn.next {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

#lightbox-caption {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    color: var(--text-secondary);
}

/* responsive - tablet */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    #folders-panel {
        width: 100%;
        height: auto;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 1rem;
    }

    #folders-panel.collapsed {
        max-height: 0;
        padding: 0 1rem;
        overflow: hidden;
    }

    #folders-panel.collapsed #folder-tree,
    #folders-panel.collapsed .new-folder,
    #folders-panel.collapsed h2 {
        display: none;
    }

    main {
        padding: 1rem;
    }

    .images-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }
}

/* responsive - mobile (iPhone 12 mini = 375px) */
@media (max-width: 480px) {
    /* header */
    header {
        padding: 0.75rem 1rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    /* login */
    .login-box {
        margin: 1rem;
        padding: 2rem 1.5rem;
        max-width: none;
    }

    .login-box h1 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .login-box input,
    .login-box button {
        padding: 14px 16px;
        font-size: 16px; /* prevents iOS zoom on focus */
    }

    /* folders panel - collapsible on mobile */
    #folders-panel {
        padding: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease, padding 0.3s ease;
    }

    #folders-panel.expanded {
        max-height: 50vh;
        padding: 1rem;
        overflow-y: auto;
    }

    .folder-toggle {
        display: flex !important;
    }

    /* main content */
    main {
        padding: 0.75rem;
        height: calc(100vh - 100px);
    }

    /* breadcrumbs */
    #breadcrumbs {
        font-size: 13px;
        margin-bottom: 1rem;
        flex-wrap: wrap;
        gap: 4px;
    }

    #breadcrumbs span::after {
        margin-left: 4px;
    }

    /* upload zone */
    .upload-zone {
        padding: 1.25rem;
        margin-bottom: 1rem;
    }

    .upload-zone p {
        font-size: 13px;
    }

    /* images grid - 2 columns on small screens */
    .images-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .image-card {
        border-radius: 6px;
    }

    .image-card .name {
        font-size: 11px;
        padding: 6px;
    }

    /* new folder input */
    .new-folder input {
        font-size: 16px;
        padding: 10px 12px;
    }

    .new-folder button {
        padding: 10px 16px;
        min-width: 44px;
        min-height: 44px;
    }

    /* lightbox mobile */
    .lightbox img {
        max-width: 100vw;
        max-height: 80vh;
        border-radius: 0;
    }

    .lightbox-btn {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    .lightbox-btn.close {
        top: 10px;
        right: 10px;
    }

    .lightbox-btn.prev {
        left: 10px;
        bottom: 50%;
        top: auto;
        transform: translateY(50%);
    }

    .lightbox-btn.next {
        right: 10px;
        bottom: 50%;
        top: auto;
        transform: translateY(50%);
    }

    #lightbox-caption {
        bottom: 10px;
        font-size: 13px;
        max-width: 80%;
        text-align: center;
    }
}

/* folder toggle button - hidden by default, shown on mobile */
.folder-toggle {
    display: none;
    width: 100%;
    padding: 12px 1rem;
    background: var(--bg-card);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    justify-content: space-between;
    align-items: center;
}

.folder-toggle:active {
    background: var(--bg-hover);
}

.folder-toggle .arrow {
    transition: transform 0.3s;
}

.folder-toggle.open .arrow {
    transform: rotate(180deg);
}

/* touch-friendly improvements */
@media (pointer: coarse) {
    .folder-item {
        padding: 12px;
        min-height: 44px;
    }

    .btn-text {
        padding: 8px 12px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}
