/* ============================================================
   Databend Studio — Photoshop-Style Dark UI
   ============================================================ */

/* --- Reset & Base ------------------------------------------ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Adobe Dark Grey Theme Palette */
    --bg-canvas:      #1a1a1a; /* Background of canvas viewport */
    --bg-workspace:   #232323; /* Intermediate background */
    --bg-panel:       #2b2b2b; /* Standard panel background */
    --bg-panel-header:#323232; /* Top bar / header of cards */
    --bg-input:       #181818; /* Input/track background */
    --bg-button:      #3c3c3c; /* Flat buttons */
    --bg-button-hover:#474747;
    
    --border-dark:    #1c1c1c; /* Shadow border */
    --border-light:   #434343; /* UI element outline border */
    
    --adobe-blue:     #1473e6; /* Active selection / highlights */
    --adobe-blue-hover:#2680eb;
    
    --text-primary:   #d5d5d5;
    --text-secondary: #adadad;
    --text-muted:     #8e8e8e;
    
    --font-ui:   "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Arial", sans-serif;
    --font-mono: "Consolas", "Courier New", monospace;
    
    --radius-sm: 2px;
    --radius-md: 4px;
    
    --transition: background-color 0.15s ease, border-color 0.15s ease;
}

html {
    font-size: 13px; /* Compact Photoshop layout */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-ui);
    color: var(--text-primary);
    background: var(--bg-workspace);
    overflow: hidden;
    min-height: 100vh;
    user-select: none;
}

/* --- App Shell --------------------------------------------- */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background: var(--bg-workspace);
}

/* --- Photoshop Menu Bar ------------------------------------ */
.header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    height: 36px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-dark);
    padding: 0 12px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 6px;
}

.logo-icon {
    flex-shrink: 0;
}

.logo h1 {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
}

.logo h1 .accent {
    color: var(--adobe-blue);
}

.menu-bar {
    display: flex;
    gap: 16px;
}

.menu-item {
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
}

.menu-item:hover {
    color: #fff;
    background: var(--bg-button);
}

.subtitle {
    font-size: 10px;
    color: var(--text-muted);
}

/* --- Photoshop File Welcome / Upload Zone ------------------ */
.upload-zone {
    max-width: 460px;
    width: calc(100% - 40px);
    margin: auto;
    padding: 40px 30px;
    border: 1px dashed var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-panel);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.upload-zone:hover {
    border-color: var(--adobe-blue);
    background: rgba(255, 255, 255, 0.01);
}

.upload-zone.drag-over {
    border-color: var(--adobe-blue);
    background: rgba(20, 115, 230, 0.05);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.upload-icon {
    color: var(--text-muted);
}

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

.upload-link {
    color: var(--adobe-blue);
    font-weight: 600;
}

.upload-link:hover {
    text-decoration: underline;
}

.upload-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* --- Main Workspace (Photoshop Panels Grid) ---------------- */
.workspace {
    display: grid;
    grid-template-rows: auto auto 1fr;
    grid-template-columns: 240px 1fr 280px; /* left sidebar, main canvas, right sidebar */
    grid-template-areas: 
        "toolbar canvas effects"
        "preset canvas effects"
        "layers canvas effects";
    flex: 1;
    overflow: hidden;
    background: var(--bg-workspace);
    animation: none;
}

/* --- Top Options / Left Tools Panel ------------------------ */
.toolbar {
    grid-area: toolbar;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    height: auto;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-dark);
    padding: 12px;
    gap: 16px;
    z-index: 10;
}

.toolbar-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
}

.toolbar-right {
    margin-left: 0;
    gap: 12px;
}

.toolbar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-input);
    padding: 2px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    width: 100%;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 6px 10px;
    font-size: 11px;
    font-family: var(--font-ui);
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 1px;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.tool-btn:hover {
    color: #fff;
    background: var(--bg-button);
}

.tool-btn.active {
    color: #fff;
    background: var(--adobe-blue);
    box-shadow: none;
}

/* Preset Bar */
.preset-bar {
    grid-area: preset;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    background: var(--bg-workspace);
    border-bottom: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-dark);
    align-items: stretch;
}

.preset-btn {
    padding: 6px 10px;
    font-size: 11px;
    font-family: var(--font-ui);
    color: var(--text-secondary);
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    width: 100%;
}

.preset-btn:hover {
    color: #fff;
    background: var(--bg-button-hover);
}

.preset-btn.active {
    color: #fff;
    background: var(--adobe-blue);
    border-color: var(--adobe-blue);
}

/* Layers Bar */
.layers-bar {
    grid-area: layers;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    background: var(--bg-workspace);
    border-right: 1px solid var(--border-dark);
    align-items: stretch;
    height: 100%;
}

.layers-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: stretch;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}

.layer-tab {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 6px 10px;
    font-size: 11px;
    font-family: var(--font-ui);
    color: var(--text-secondary);
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.layer-tab:hover {
    color: #fff;
    background: var(--bg-button-hover);
}

.layer-tab.active {
    color: #fff;
    background: var(--adobe-blue);
    border-color: var(--adobe-blue);
    font-weight: 600;
}

.layer-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

/* Channel Switch */
.channel-switch {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
}

.switch-group {
    display: flex;
    width: 100%;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.mode-btn {
    flex: 1;
    padding: 6px 8px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    background: var(--bg-panel);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.mode-btn:hover {
    color: #fff;
    background: var(--bg-button);
}

.mode-btn.active {
    color: #fff;
    background: var(--adobe-blue);
}

.mode-btn:not(:last-child) {
    border-right: 1px solid var(--border-light);
}

/* Toolbar Actions */
.toolbar-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 6px 10px;
    font-size: 11px;
    font-family: var(--font-ui);
    color: var(--text-primary);
    background: var(--bg-button);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.action-btn:hover {
    color: #fff;
    background: var(--bg-button-hover);
}

.export-btn {
    color: #fff !important;
    background: var(--adobe-blue) !important;
    border-color: var(--adobe-blue) !important;
    font-weight: 600;
    box-shadow: none !important;
    transform: none !important;
}

.export-btn:hover {
    background: var(--adobe-blue-hover) !important;
    box-shadow: none !important;
    transform: none !important;
}

/* --- Canvas Area (Viewport Panel) -------------------------- */
.canvas-area {
    width: 95%;
    grid-area: canvas;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    background: var(--bg-canvas);
    border-right: 1px solid var(--border-dark);
}

.canvas-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-dark);
    margin: 8px;
}

.panel-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-panel-header);
    border-bottom: 1px solid var(--border-dark);
    padding: 6px 10px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
    border-radius: 0;
    transform: none;
}

.canvas-wrapper {
    position: relative;
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-canvas);
    padding: 30px 10px 10px 10px; /* Space for the panel-label */
}

.canvas-container-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-dark);
    
    /* Classic checkerboard pattern for alpha transparency behind the image */
    background-image: 
        linear-gradient(45deg, #1f1f1f 25%, transparent 25%), 
        linear-gradient(-45deg, #1f1f1f 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #1f1f1f 75%), 
        linear-gradient(-45deg, transparent 75%, #1f1f1f 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.canvas-container-inner canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    cursor: default;
}

.selection-overlay.active {
    pointer-events: auto;
    cursor: crosshair;
}

/* Canvas Divider */
.canvas-divider {
    width: 8px;
    background: var(--bg-canvas);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.divider-line {
    width: 1px;
    height: 100%;
    background: var(--border-dark);
    box-shadow: none;
}

/* --- Processing Badge -------------------------------------- */
.processing-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 6px;
    font-size: 9px;
    font-weight: 600;
    color: var(--adobe-blue);
    background: rgba(20, 115, 230, 0.1);
    border: 1px solid rgba(20, 115, 230, 0.2);
    border-radius: var(--radius-sm);
    animation: none;
}

.spinner {
    width: 10px;
    height: 10px;
    border: 1.5px solid rgba(20, 115, 230, 0.2);
    border-top-color: var(--adobe-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Effects Panel (Right Sidebar Dock) -------------------- */
.effects-panel {
    grid-area: effects;
    display: flex;
    flex-direction: column-reverse;
    gap: 1px; /* Divider lines between docked panels */
    background: var(--border-dark);
    border-left: 1px solid var(--border-dark);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-button) transparent;
}

/* --- Effect Panel Card (Docked Panel) ---------------------- */
.effect-card {
    min-width: unset;
    flex-shrink: 0;
    background: var(--bg-panel);
    border: none;
    border-bottom: 1px solid var(--border-dark);
    border-radius: 0;
    padding: 10px 12px;
    transition: none;
}

.effect-card:hover {
    background: var(--bg-panel);
}

.effect-card[data-active] {
    box-shadow: none;
    border-bottom: 1px solid var(--border-dark);
}

/* --- Effect Header ----------------------------------------- */
.effect-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    height: 20px;
}

.effect-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}

.effect-icon {
    margin-left: auto;
    font-size: 12px;
    line-height: 1;
    filter: grayscale(1);
    opacity: 0.5;
}

.effect-card.active .effect-icon {
    filter: grayscale(0);
    opacity: 1;
}

/* --- Photoshop Checkbox Style Toggle ----------------------- */
.toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: relative;
    width: 14px;
    height: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    transition: var(--transition);
    flex-shrink: 0;
}

.toggle-thumb {
    display: none; /* We will show a checkmark instead */
}

/* Checked state checkbox */
.toggle input:checked + .toggle-track {
    background: var(--adobe-blue);
    border-color: var(--adobe-blue);
}

.toggle input:checked + .toggle-track::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 7px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* --- Effect Controls --------------------------------------- */
.effect-controls {
    margin-top: 8px;
    border-left: 1px solid var(--border-light);
    padding-left: 10px;
    display: none; /* Collapse when disabled like Photoshop Adjustments */
}

.effect-card.active .effect-controls {
    display: block;
}

/* --- Slider Group ------------------------------------------ */
.slider-group {
    margin-top: 6px;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.slider-header label {
    font-size: 10px;
    color: var(--text-secondary);
}

.slider-val {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-primary) !important; /* Uniform text color */
}

/* --- Adobe Sliders (Flat, with Vertical Notch Handle) ------ */
.styled-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 3px;
    background: var(--bg-input);
    border-radius: 0;
    outline: none;
    cursor: pointer;
}

/* Webkit Track */
.styled-slider::-webkit-slider-runnable-track {
    height: 3px;
    background: var(--bg-input);
}

/* Webkit Thumb - Photoshop vertical notch thumb */
.styled-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 6px;
    height: 12px;
    background: #adadad;
    border: 1px solid var(--border-dark);
    margin-top: -4px;
    border-radius: 0;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.styled-slider::-webkit-slider-thumb:hover {
    background: #fff;
    transform: none;
    box-shadow: none;
}

/* Firefox Track */
.styled-slider::-moz-range-track {
    height: 3px;
    background: var(--bg-input);
    border: none;
}

/* Firefox Thumb */
.styled-slider::-moz-range-thumb {
    width: 6px;
    height: 12px;
    background: #adadad;
    border: 1px solid var(--border-dark);
    border-radius: 0;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.styled-slider::-moz-range-thumb:hover {
    background: #fff;
    transform: none;
    box-shadow: none;
}

/* Firefox Progress (none in Photoshop, just clean track) */
.styled-slider::-moz-range-progress {
    background: var(--bg-input);
}

/* --- Scrollbar Styling ------------------------------------- */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-workspace);
    border-left: 1px solid var(--border-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-button);
    border: 2px solid var(--bg-workspace);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-button-hover);
}

/* Firefox scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-button) var(--bg-workspace);
}

/* --- Responsive Adjustments -------------------------------- */
@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto 1fr 200px;
        grid-template-areas: 
            "toolbar"
            "preset"
            "layers"
            "canvas"
            "effects";
    }
    
    .effects-panel {
        flex-direction: row;
        border-left: none;
        border-top: 1px solid var(--border-dark);
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    .effect-card {
        min-width: 200px;
        border-bottom: none;
        border-right: 1px solid var(--border-dark);
    }
    
    .effect-controls {
        display: block !important; /* Always show in compact horizontal view */
    }
}
