/**
 * Sketch Browser - Tree Navigation Styles
 * Matches the site's glassmorphic design language
 */

/* ==========================================================================
   View Container - matches other views (settings, dashboard, search)
   ========================================================================== */

#sketches-view {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    overflow: hidden;
    padding: 40px;
    padding-left: 300px;  /* 260px sidebar + 40px margin */
}

.sketch-browser {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    font-family: var(--ui-font);
    --column-width: 200px;
    --preview-width: 450px;
}

/* ==========================================================================
   Header / Breadcrumb - matches settings-header style
   ========================================================================== */

.sketch-breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 24px;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.breadcrumb-item {
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

/* Page title - large serif font like other view headers */
.breadcrumb-item.breadcrumb-title {
    font-family: CMSerif, 'Times New Roman', serif;
    font-size: 2.5rem;
    color: white;
    font-weight: normal;
    padding-left: 0;
    padding-right: 12px;
}

.breadcrumb-item:hover {
    color: var(--active-color);
    background: rgba(160, 218, 0, 0.1);
}

.breadcrumb-item.active {
    color: var(--active-color);
}

.breadcrumb-separator {
    color: rgba(255, 255, 255, 0.3);
    font-size: 1.2rem;
}

/* ==========================================================================
   Main Layout - Columns + Preview
   ========================================================================== */

.sketch-columns-wrapper {
    display: flex;
    flex: 1;
    gap: 0;
    min-height: 0;
    background: rgba(255, 255, 255, 0.03);
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 0 4px inset rgba(255, 255, 255, 0.05), 0 0 56px inset rgba(100, 100, 100, 0.08);
}

/* ==========================================================================
   Columns Container
   ========================================================================== */

#sketch-columns {
    display: flex;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
}

.sketch-column {
    width: var(--column-width);
    min-width: var(--column-width);
    max-width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    overflow-y: auto;
}

.sketch-column:last-child {
    border-right: none;
}

.sketch-column ul {
    list-style: none;
    margin: 0;
    padding: 12px;
}

.sketch-column li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 2px;
    transition: background 0.2s, color 0.2s;
    color: rgba(255, 255, 255, 0.8);
}

.sketch-column li:hover {
    background: rgba(255, 255, 255, 0.06);
}

.sketch-column li.active {
    background: rgba(160, 218, 0, 0.12);
    color: var(--active-color);
}

.sketch-column li.back-item {
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px 8px 0 0;
    padding-bottom: 12px;
}

.sketch-column li.back-item:hover {
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.04);
}

/* Column slide-in animation */
.sketch-column.column-slide-in {
    animation: columnSlideIn 0.25s ease-out;
}

@keyframes columnSlideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.sketch-column li.folder .item-label {
    font-weight: 500;
}

.item-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.6;
}

.sketch-column li.active .item-icon {
    opacity: 1;
}

.item-icon svg {
    width: 100%;
    height: 100%;
}

.item-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

.sketch-column .empty {
    padding: 24px;
    color: rgba(255, 255, 255, 0.4);
    font-style: italic;
    text-align: center;
}

/* ==========================================================================
   Resizer
   ========================================================================== */

#sketch-resizer {
    width: 6px;
    cursor: col-resize;
    background: rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    transition: background 0.2s;
}

#sketch-resizer:hover,
body.resizing #sketch-resizer {
    background: var(--active-color);
}

body.resizing {
    cursor: col-resize;
    user-select: none;
}

body.resizing * {
    cursor: col-resize !important;
}

/* ==========================================================================
   Preview Panel
   ========================================================================== */

#sketch-preview {
    width: var(--preview-width);
    min-width: 320px;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    gap: 12px;
}

.preview-header h3 {
    margin: 0;
    font-family: var(--ui-font);
    font-size: 1rem;
    font-weight: 500;
    color: white;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-actions {
    display: none;
    gap: 8px;
    flex-shrink: 0;
}

.preview-actions.visible {
    display: flex;
}

.preview-actions button,
.preview-actions a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-family: var(--ui-font);
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
}

.preview-actions button:active,
.preview-actions a:active {
    transform: scale(0.97);
}

.preview-actions .btn-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.preview-actions .btn-icon svg {
    width: 100%;
    height: 100%;
}

/* Theme toggle button - shows sun in dark mode, moon in light mode */
#theme-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    padding: 6px 10px;
}

#theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

#theme-toggle-btn .icon-sun {
    display: block;
}

#theme-toggle-btn .icon-moon {
    display: none;
}

/* When preview is in light mode, show moon icon (button styling stays same) */
#sketch-preview.preview-light #theme-toggle-btn .icon-sun {
    display: none;
}

#sketch-preview.preview-light #theme-toggle-btn .icon-moon {
    display: block;
}

#copy-ref-btn {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
}

#copy-ref-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

#edit-btn {
    background: rgba(160, 218, 0, 0.15);
    color: var(--active-color);
}

#edit-btn:hover {
    background: rgba(160, 218, 0, 0.25);
}

#delete-btn {
    background: rgba(255, 99, 99, 0.15);
    color: #ff6b6b;
}

#delete-btn:hover {
    background: rgba(255, 99, 99, 0.25);
}

/* Preview canvas - contains the sketch, sized by sketch dimensions */
#preview-canvas {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;  /* Transparent in dark mode */
    overflow: hidden;
    position: relative;
    /* Height set by JS based on sketch heightExpr */
}

/* Light mode preview background */
#sketch-preview.preview-light #preview-canvas {
    background: #f5f5f7;
}

#preview-canvas.loading::after {
    content: 'Chargement...';
    color: rgba(255, 255, 255, 0.4);
    font-family: var(--ui-font);
}

#preview-canvas .placeholder {
    color: rgba(255, 255, 255, 0.3);
    font-style: italic;
    font-family: var(--ui-font);
}

#preview-canvas .error {
    color: #ff6b6b;
    padding: 20px;
    text-align: center;
    font-family: var(--ui-font);
}

.preview-params {
    flex: 1;  /* Takes remaining space after sketch */
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    overflow-y: auto;
    min-height: 100px;
}

.preview-params h4 {
    margin: 0 0 10px 0;
    font-family: var(--ui-font);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.5);
}

#params-input {
    width: 100%;
    min-height: 70px;
    padding: 10px 12px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.9);
    resize: vertical;
    transition: border-color 0.2s;
}

#params-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

#params-input:focus {
    outline: none;
    border-color: var(--active-color);
}

/* ==========================================================================
   Mobile Stack (hidden on desktop)
   ========================================================================== */

#sketch-mobile-stack {
    display: none;
}

.sketch-browser.mobile-mode .sketch-columns-wrapper {
    display: none;
}

.sketch-browser.mobile-mode #sketch-mobile-stack {
    display: flex;
    flex: 1;
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.03);
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.mobile-column {
    position: absolute;
    inset: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.mobile-back {
    width: 36px;
    height: 36px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: white;
    transition: background 0.2s;
    flex-shrink: 0;
}

.mobile-back:hover {
    background: rgba(255, 255, 255, 0.15);
}

.mobile-back svg {
    width: 100%;
    height: 100%;
}

.mobile-header h3 {
    margin: 0;
    font-family: var(--ui-font);
    font-size: 1.2rem;
    font-weight: 500;
    color: white;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-column ul {
    list-style: none;
    margin: 0;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}

.mobile-column li {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    cursor: pointer;
    border-radius: 10px;
    margin-bottom: 4px;
    transition: background 0.2s;
    color: rgba(255, 255, 255, 0.9);
}

.mobile-column li:hover,
.mobile-column li:active {
    background: rgba(255, 255, 255, 0.08);
}

.mobile-column .item-icon {
    width: 22px;
    height: 22px;
}

.mobile-column .item-label {
    font-size: 1rem;
}

.mobile-column .item-chevron {
    width: 20px;
    height: 20px;
    opacity: 0.4;
    flex-shrink: 0;
}

.mobile-column .item-chevron svg {
    width: 100%;
    height: 100%;
}

.mobile-column .empty {
    padding: 32px;
    color: rgba(255, 255, 255, 0.4);
    font-style: italic;
    text-align: center;
}

/* Mobile preview content - scrollable container */
.mobile-preview-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

/* Mobile canvas - sized by JS based on sketch dimensions */
.mobile-canvas {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;  /* Transparent in dark mode */
    flex-shrink: 0;
    /* Height set by JS based on sketch heightExpr */
}

.mobile-canvas.preview-light {
    background: #f5f5f7;
}

/* Mobile params section */
.mobile-params {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.mobile-params h4 {
    margin: 0 0 10px 0;
    font-family: var(--ui-font);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.5);
}

#mobile-params-input {
    width: 100%;
    min-height: 70px;
    padding: 10px 12px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.9);
    resize: vertical;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

#mobile-params-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

#mobile-params-input:focus {
    outline: none;
    border-color: var(--active-color);
}

/* Mobile theme toggle button */
.mobile-theme-toggle {
    width: 36px;
    height: 36px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.9);
    transition: background 0.2s;
    flex-shrink: 0;
    margin-left: auto;
}

.mobile-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

.mobile-theme-toggle svg {
    width: 100%;
    height: 100%;
}

/* Mobile slide animations */
.mobile-column.slide-out-left {
    animation: slideOutLeft 0.25s ease forwards;
}

.mobile-column.slide-out-right {
    animation: slideOutRight 0.25s ease forwards;
}

.mobile-column.slide-in-left {
    animation: slideInLeft 0.25s ease forwards;
}

.mobile-column.slide-in-right {
    animation: slideInRight 0.25s ease forwards;
}

@keyframes slideOutLeft {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-30%); opacity: 0; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(30%); opacity: 0; }
}

@keyframes slideInLeft {
    from { transform: translateX(-30%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(30%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 1100px) {
    .sketch-column {
        --column-width: 180px;
        min-width: 180px;
    }
}

@media (max-width: 900px) {
    #sketches-view {
        padding: 40px;
        padding-left: 120px;  /* Collapsed sidebar */
    }

    .sketch-column {
        --column-width: 160px;
        min-width: 160px;
    }
}

@media (max-width: 600px) {
    #sketches-view {
        padding: 20px;
        padding-bottom: 100px;  /* Bottom navbar space */
    }

    .sketch-breadcrumb {
        display: none;
    }

    .sketch-browser {
        --preview-width: 100%;
    }
}

/* ==========================================================================
   Light Theme Overrides
   ========================================================================== */

.theme-light #sketches-view {
    background: linear-gradient(135deg, #f5f5f7 0%, #e8e8ec 50%, #dcdce0 100%);
}

.theme-light .sketch-columns-wrapper,
.theme-light .sketch-browser.mobile-mode #sketch-mobile-stack {
    background: rgba(255, 255, 255, 0.6);
    border-top-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 0 4px inset rgba(0, 0, 0, 0.03), 0 0 56px inset rgba(0, 0, 0, 0.02);
}

.theme-light .breadcrumb-item {
    color: rgba(0, 0, 0, 0.5);
}

.theme-light .breadcrumb-item.breadcrumb-title {
    color: #1a1a2e;
}

.theme-light .breadcrumb-separator {
    color: rgba(0, 0, 0, 0.2);
}

.theme-light .sketch-column {
    border-right-color: rgba(0, 0, 0, 0.08);
}

.theme-light .sketch-column li {
    color: rgba(0, 0, 0, 0.8);
}

.theme-light .sketch-column li:hover {
    background: rgba(0, 0, 0, 0.05);
}

.theme-light .sketch-column li.active {
    background: rgba(100, 160, 0, 0.12);
    color: #4a7c00;
}

.theme-light .sketch-column li.back-item {
    color: rgba(0, 0, 0, 0.5);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.theme-light .sketch-column li.back-item:hover {
    color: rgba(0, 0, 0, 0.75);
    background: rgba(0, 0, 0, 0.04);
}

.theme-light .sketch-column .empty {
    color: rgba(0, 0, 0, 0.4);
}

.theme-light #sketch-resizer {
    background: rgba(0, 0, 0, 0.08);
}

.theme-light #sketch-preview {
    background: rgba(0, 0, 0, 0.03);
}

.theme-light .preview-header {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.theme-light .preview-header h3 {
    color: #1a1a2e;
}

.theme-light #copy-ref-btn {
    background: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.8);
}

.theme-light #copy-ref-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

.theme-light #preview-canvas {
    background: #f0f0f0;
}

.theme-light #preview-canvas .placeholder {
    color: rgba(0, 0, 0, 0.3);
}

.theme-light .preview-params {
    border-top-color: rgba(0, 0, 0, 0.08);
}

.theme-light .preview-params h4 {
    color: rgba(0, 0, 0, 0.5);
}

.theme-light #params-input {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.9);
}

.theme-light #params-input::placeholder {
    color: rgba(0, 0, 0, 0.3);
}

.theme-light .mobile-back {
    background: rgba(0, 0, 0, 0.06);
    color: #1a1a2e;
}

.theme-light .mobile-back:hover {
    background: rgba(0, 0, 0, 0.1);
}

.theme-light .mobile-header h3 {
    color: #1a1a2e;
}

.theme-light .mobile-column li {
    color: rgba(0, 0, 0, 0.85);
}

.theme-light .mobile-column li:hover,
.theme-light .mobile-column li:active {
    background: rgba(0, 0, 0, 0.05);
}

.theme-light .mobile-canvas {
    background: transparent;
}

.theme-light .mobile-canvas.preview-light {
    background: #f5f5f7;
}

.theme-light .mobile-params {
    border-top-color: rgba(0, 0, 0, 0.08);
}

.theme-light .mobile-params h4 {
    color: rgba(0, 0, 0, 0.5);
}

.theme-light #mobile-params-input {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.9);
}

.theme-light #mobile-params-input::placeholder {
    color: rgba(0, 0, 0, 0.3);
}

.theme-light .mobile-theme-toggle {
    background: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.8);
}

.theme-light .mobile-theme-toggle:hover {
    background: rgba(0, 0, 0, 0.1);
}
