.sidebar {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.tree-project {
    cursor: pointer;
    transition: background-color 0.15s ease;
    user-select: none;
}

.tree-project:hover {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
}

.tree-project.active {
    background-color: var(--bs-primary);
    color: white;
}

.tree-project.active .badge {
    background-color: rgba(255, 255, 255, 0.3) !important;
}

.tree-toggle {
    transition: transform 0.2s ease;
    font-size: 0.75rem;
}

.tree-item.expanded .tree-toggle {
    transform: rotate(90deg);
}

.tree-posts {
    border-left: 2px solid #dee2e6;
    margin-left: 0.5rem;
    padding-left: 0.5rem;
}

.tree-post {
    color: var(--bs-body-color);
    font-size: 0.9rem;
    transition: background-color 0.15s ease;
}

.tree-post:hover {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
    color: var(--bs-body-color);
}

.tree-post.active {
    background-color: rgba(var(--bs-primary-rgb), 0.2);
    color: var(--bs-primary);
    font-weight: 500;
}

.post-content {
    line-height: 1.8;
}

.post-content h2,
.post-content h3,
.post-content h4 {
    margin-top: 2rem;
    margin-bottom: 1rem;
}

.post-content p {
    margin-bottom: 1rem;
}

.post-content img,
.post-content video {
    max-width: 100%;
    height: auto;
    margin: 1.5rem 0;
    border-radius: 0.5rem;
}

.hover-shadow {
    transition: box-shadow 0.2s ease;
}

.hover-shadow:hover {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

@media (max-width: 768px) {
    .sidebar {
        position: relative;
        top: 0;
        max-height: none;
        margin-bottom: 1.5rem;
    }
}

/* ------- New / Edit / authoring UI ------- */

.loft-welcome {
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--hw-radius-lg);
    padding: 2rem;
    box-shadow: var(--hw-shadow-md);
    margin-top: 1rem;
}
.loft-welcome h1 {
    font-family: 'Playfair Display', serif;
    color: var(--hw-forest);
    margin-bottom: 0.5rem;
}
.loft-welcome p {
    color: var(--hw-text-secondary);
    margin-bottom: 1.25rem;
}

.loft-sidebar-new {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--hw-gradient-sage);
    color: #fff;
    text-decoration: none;
    padding: 0.5rem 0.9rem;
    border-radius: var(--hw-radius-md);
    font-weight: 600;
    margin-bottom: 1rem;
    transition: transform var(--hw-transition-fast), box-shadow var(--hw-transition-fast);
}
.loft-sidebar-new:hover {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: var(--hw-shadow-md);
}

.loft-post-toolbar {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.loft-unlisted-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin: 1rem 0;
    padding: 0.85rem 1rem;
    background: var(--hw-bg-cream);
    border: 1px solid var(--hw-gold);
    border-radius: var(--hw-radius-md);
    color: var(--hw-text-secondary);
    box-shadow: var(--hw-shadow-sm);
}

.loft-unlisted-notice i {
    flex: 0 0 auto;
    color: var(--hw-forest);
    font-size: 1.25rem;
    line-height: 1.4;
}

.loft-unlisted-notice strong {
    color: var(--hw-text-primary);
}

.loft-form-card {
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--hw-radius-lg);
    padding: 2rem;
    box-shadow: var(--hw-shadow-md);
    margin-top: 1rem;
}
.loft-form-title {
    font-family: 'Playfair Display', serif;
    color: var(--hw-forest);
    margin: 0;
}
.loft-form-sub {
    color: var(--hw-text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}
.loft-form-note {
    background: rgba(135, 168, 120, 0.12);
    border-left: 3px solid var(--hw-sage);
    color: var(--hw-text-secondary);
    padding: 0.75rem 1rem;
    border-radius: var(--hw-radius-sm);
    margin: 1rem 0 1.5rem;
    font-size: 0.92rem;
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}
.loft-form-note i {
    color: var(--hw-sage-dark);
    margin-top: 0.15rem;
}
.loft-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.loft-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.loft-field-hint {
    color: var(--hw-text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}
.loft-project-or {
    color: var(--hw-text-muted);
    font-size: 0.85rem;
    text-align: center;
    margin: 0.35rem 0;
    font-style: italic;
}
.loft-label {
    font-weight: 600;
    color: var(--hw-text-primary);
}
.loft-input {
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid var(--hw-border);
    border-radius: var(--hw-radius-md);
    padding: 0.6rem 0.85rem;
    font-family: 'Nunito', sans-serif;
    color: var(--hw-text-primary);
    width: 100%;
    transition: border-color var(--hw-transition-fast), box-shadow var(--hw-transition-fast);
}
.loft-input:focus {
    outline: none;
    border-color: var(--hw-sage);
    box-shadow: 0 0 0 4px rgba(135, 168, 120, 0.15);
}
.loft-md-editor {
    font-family: 'SF Mono', ui-monospace, monospace;
    font-size: 0.92rem;
    line-height: 1.5;
    min-height: 320px;
    resize: vertical;
}
.loft-radio-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.loft-radio {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    border: 2px solid var(--hw-border);
    border-radius: var(--hw-radius-md);
    cursor: pointer;
    background: rgba(255, 255, 255, 0.6);
}
.loft-radio:hover {
    border-color: var(--hw-sage-light);
}
.loft-radio input {
    margin-top: 0.25rem;
}
.loft-radio-link {
    margin-left: 0.6rem;
    color: var(--hw-sage-dark);
    font-size: 0.85rem;
    text-decoration: underline;
}
.loft-radio-link:hover {
    color: var(--hw-forest);
}

.loft-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.loft-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--hw-radius-md);
    border: none;
    font-weight: 600;
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    text-decoration: none;
    transition: transform var(--hw-transition-fast), box-shadow var(--hw-transition-fast),
                background var(--hw-transition-fast);
    min-height: 40px;
}
.loft-btn-primary {
    background: var(--hw-gradient-sage);
    color: #fff;
}
.loft-btn-primary:hover {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: var(--hw-shadow-md);
}
.loft-btn-ghost {
    background: rgba(255, 255, 255, 0.7);
    color: var(--hw-text-primary);
    border: 2px solid var(--hw-border);
}
.loft-btn-ghost:hover {
    color: var(--hw-text-primary);
    border-color: var(--hw-sage-light);
    transform: translateY(-2px);
}
.loft-btn-danger {
    background: var(--hw-coral);
    color: #fff;
}
.loft-btn-danger:hover {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: var(--hw-shadow-md);
}
.loft-btn-danger-ghost {
    background: rgba(255, 255, 255, 0.7);
    color: var(--hw-coral);
    border: 2px solid rgba(224, 122, 95, 0.3);
}
.loft-btn-danger-ghost:hover {
    color: var(--hw-coral);
    border-color: var(--hw-coral);
    transform: translateY(-2px);
}
.loft-btn:disabled {
    cursor: wait;
    opacity: 0.7;
    transform: none;
}

.loft-upload-progress {
    margin-top: 1rem;
}
.loft-upload-progress-label {
    color: var(--hw-text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}
.loft-upload-progress-track {
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid var(--hw-border);
    border-radius: var(--hw-radius-full);
    height: 0.85rem;
    overflow: hidden;
}
.loft-upload-progress-bar {
    background: var(--hw-gradient-sage);
    height: 100%;
    transition: width var(--hw-transition-fast);
    width: 0;
}

.loft-divider {
    border: none;
    border-top: 1px solid var(--hw-border);
    margin: 1.5rem 0;
}
.loft-section-title {
    font-family: 'Playfair Display', serif;
    color: var(--hw-forest);
    font-size: 1.4rem;
    margin-bottom: 1rem;
}
.loft-danger-form {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.loft-edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.loft-edit-tile {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: var(--hw-radius-md);
    overflow: hidden;
    background: var(--hw-bg-cream);
    box-shadow: var(--hw-shadow-sm);
    transition: transform var(--hw-transition-fast), box-shadow var(--hw-transition-fast);
}
.loft-edit-tile img,
.loft-edit-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.loft-media-badge {
    position: absolute;
    left: 8px;
    bottom: 8px;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.2rem 0.45rem;
    border-radius: var(--hw-radius-full);
    background: rgba(45, 74, 62, 0.78);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
}
.loft-tile-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 40px;
    height: 40px;
    border-radius: var(--hw-radius-full);
    border: none;
    background: rgba(45, 74, 62, 0.75);
    color: #fff;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.loft-reorder-buttons button,
.loft-video-sound {
    border: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--hw-radius-full);
    background: var(--hw-forest);
    color: var(--hw-bg-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--hw-transition-fast), background var(--hw-transition-fast);
}
.loft-reorder-buttons button:hover,
.loft-video-sound:hover {
    background: var(--hw-sage-dark);
    transform: translateY(-2px);
}
.loft-reorder-buttons button:focus-visible,
.loft-video-sound:focus-visible {
    outline: 3px solid var(--hw-gold);
    outline-offset: 2px;
}
.loft-reorder-buttons {
    position: absolute;
    left: 6px;
    bottom: 6px;
    display: flex;
    gap: 4px;
}
.loft-reorder-buttons button:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}
.loft-edit-tile .loft-media-badge {
    bottom: 52px;
}
.loft-edit-tile .loft-video-sound {
    position: absolute;
    right: 6px;
    bottom: 6px;
}
.loft-tile-delete:hover {
    background: var(--hw-coral);
}
.loft-empty {
    color: var(--hw-text-muted);
    font-style: italic;
    grid-column: 1 / -1;
}

/* Rendered post content (markdown + gallery) */
.loft-post-header h1 {
    font-family: 'Playfair Display', serif;
    color: var(--hw-forest);
    margin-bottom: 0.25rem;
}
.loft-post-meta {
    color: var(--hw-text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.loft-gallery-desc {
    color: var(--hw-text-secondary);
    margin-bottom: 1rem;
}
.loft-gallery .loft-post-header {
    text-align: center;
    margin-bottom: 1.25rem;
}
.loft-gallery-feed {
    display: grid;
    gap: 0.5rem;
    width: min(100%, 680px);
    margin: 0 auto;
}
.loft-gallery-photo {
    position: relative;
    margin: 0;
    overflow: hidden;
}
.loft-gallery-video .loft-video-sound {
    position: absolute;
    right: 0.75rem;
    bottom: 0.75rem;
}
.loft-gallery-photo-btn {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    cursor: zoom-in;
}
.loft-gallery-photo-btn img {
    display: block;
    width: 100%;
    height: auto;
}
.loft-gallery-video video {
    display: block;
    width: 100%;
    height: auto;
    margin: 0;
    background: #000;
    cursor: zoom-in;
}
body.loft-video-expanded {
    overflow: hidden;
}
.loft-gallery-video.is-expanded {
    position: fixed;
    inset: 0;
    z-index: 1000;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1rem, env(safe-area-inset-top))
             max(1rem, env(safe-area-inset-right))
             max(1rem, env(safe-area-inset-bottom))
             max(1rem, env(safe-area-inset-left));
    background: rgba(0, 0, 0, 0.88);
}
.loft-gallery-video.is-expanded video {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    object-fit: contain;
    cursor: zoom-out;
}
.loft-gallery-video.is-expanded .loft-video-sound {
    right: max(1rem, env(safe-area-inset-right));
    bottom: max(1rem, env(safe-area-inset-bottom));
}
.loft-gallery-empty {
    color: var(--hw-text-muted);
    font-style: italic;
    text-align: center;
}

/* Lightbox */
.loft-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.loft-lightbox.open { display: flex; }
.loft-lightbox img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--hw-radius-sm);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    image-orientation: from-image;
}
.loft-lightbox-close {
    position: fixed;
    top: 14px;
    right: 18px;
    color: #fff;
    font-size: 34px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.85;
    user-select: none;
}
.loft-lightbox-close:hover { opacity: 1; }

@media (max-width: 480px) {
    .loft-form-card, .loft-welcome { padding: 1.25rem; }
    .loft-actions { justify-content: stretch; }
    .loft-actions .loft-btn { flex: 1; justify-content: center; }
}
.loft-inline-form {
    display: inline;
}
