/* ===== APP TOOL STYLES ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0a0a0f;
    --bg-panel: #0f0f1a;
    --bg-card: rgba(255,255,255,0.04);
    --border: rgba(255,255,255,0.08);
    --text: #e2e8f0;
    --text-muted: #64748b;
    --accent: #7c3aed;
    --accent-2: #06b6d4;
    --gradient: linear-gradient(135deg, #7c3aed, #4f46e5);
    --font: 'Inter', -apple-system, sans-serif;
    --navbar-h: 60px;
}

html, body { height: 100%; overflow: hidden; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}

/* ===== APP NAVBAR ===== */
.app-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-h);
    z-index: 100;
    background: rgba(10,10,15,0.95);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
}

.app-nav-container {
    height: 100%;
    max-width: 100%;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-nav-logo {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.logo-icon {
    font-size: 1.3rem;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.org-chip {
    background: rgba(124,58,237,0.15);
    border: 1px solid rgba(124,58,237,0.3);
    color: #a78bfa;
    padding: 0.25rem 0.75rem;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* ===== LAYOUT ===== */
.app-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: calc(100vh - var(--navbar-h));
    margin-top: var(--navbar-h);
    overflow: hidden;
}

/* ===== LEFT PANEL (FRAMES) ===== */
.panel-frames {
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.frame-count {
    font-size: 0.75rem;
    background: rgba(124,58,237,0.15);
    color: #a78bfa;
    padding: 0.15rem 0.6rem;
    border-radius: 100px;
}

.frames-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
    padding: 0.75rem;
    overflow-y: auto;
    flex: 1;
}

/* Custom scrollbar */
.frames-grid::-webkit-scrollbar { width: 4px; }
.frames-grid::-webkit-scrollbar-track { background: transparent; }
.frames-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
.frames-grid::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.frame-thumb {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid var(--border);
    aspect-ratio: 1;
    background: rgba(255,255,255,0.02);
    transition: all 0.2s;
    outline: none;
}

.frame-thumb:hover { border-color: rgba(124,58,237,0.5); transform: scale(1.03); }
.frame-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124,58,237,0.25); }

.frame-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.frame-thumb-overlay {
    position: absolute;
    inset: 0;
    background: rgba(124,58,237,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
}
.frame-thumb:hover .frame-thumb-overlay { opacity: 1; }

.frame-thumb-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== CENTER PANEL (PREVIEW) ===== */
.panel-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 2rem;
    gap: 1.5rem;
    background: var(--bg);
}

.preview-header {
    text-align: center;
}
.preview-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.3rem;
}
.preview-header p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===== PREVIEW CANVAS ===== */
.preview-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

#preview {
    position: relative;
    width: 380px;
    height: 380px;
    border-radius: 50%;
    overflow: visible;
    background: rgba(255,255,255,0.03);
    box-shadow: 0 0 0 2px var(--border), 0 20px 60px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

#cropArea {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    overflow: hidden;
    z-index: 1;
}

#frameOverlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    border-radius: 50%;
}

.preview-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s;
}
.preview-hint.visible { opacity: 1; }

/* ===== CROPPIE OVERRIDES ===== */
.cr-boundary {
    border-radius: 50% !important;
    overflow: hidden !important;
}
.cr-viewport {
    border: none !important;
    box-shadow: none !important;
}
.cr-slider-wrap { margin: 0 !important; padding: 0 !important; display: none !important; }

/* ===== ACTION BAR ===== */
.action-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    width: 100%;
    max-width: 420px;
}

.upload-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: rgba(255,255,255,0.06);
    border: 1px dashed rgba(255,255,255,0.2);
    border-radius: 12px;
    padding: 0.875rem 1.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    transition: all 0.2s;
    font-family: var(--font);
}
.upload-btn:hover { background: rgba(124,58,237,0.1); border-color: rgba(124,58,237,0.5); }
.upload-btn input[type="file"] { display: none; }
.upload-icon { font-size: 1.1rem; }

.download-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--gradient);
    border: none;
    border-radius: 12px;
    padding: 0.875rem 1.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    transition: all 0.2s;
    font-family: var(--font);
    box-shadow: 0 4px 20px rgba(124,58,237,0.3);
}
.download-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(124,58,237,0.5); }
.download-btn:disabled {
    background: rgba(255,255,255,0.08);
    box-shadow: none;
    cursor: not-allowed;
    color: var(--text-muted);
}
.download-icon { font-size: 1.1rem; }

/* ===== PROGRESS BAR ===== */
.progress-bar-wrap {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: center;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(124,58,237,0.1);
    border-radius: 100px;
    position: relative;
    overflow: hidden;
}

.progress-bar::after {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: var(--progress, 0%);
    background: var(--gradient);
    border-radius: 100px;
    transition: width 0.3s ease;
}

#progressText {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== ZOOM BAR CONTROLS ===== */
.zoom-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 380px;
    margin-top: 0.4rem;
    padding: 0.4rem 0.85rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 100px;
}

.zoom-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.zoom-btn:hover {
    background: rgba(124, 58, 237, 0.3);
    border-color: rgba(124, 58, 237, 0.5);
    transform: scale(1.1);
}

.zoom-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 100px;
    background: rgba(255, 255, 255, 0.12);
    outline: none;
    cursor: pointer;
    transition: background 0.2s;
}

.zoom-slider:hover {
    background: rgba(124, 58, 237, 0.3);
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #a78bfa;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.5);
    transition: transform 0.15s, background 0.15s;
}

.zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.25);
    background: #fff;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    html, body { overflow: auto; }

    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto;
        overflow: visible;
    }

    .panel-frames {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 220px;
    }

    .frames-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }

    .panel-preview {
        overflow-y: visible;
        padding: 1.5rem 1rem;
        min-height: calc(100vh - var(--navbar-h) - 220px);
    }

    #preview {
        width: min(330px, 90vw);
        height: min(330px, 90vw);
    }
}
