/* Basic styles for Birdhole Simplified */

body {
    font-family: sans-serif;
    margin: 0;
    background-color: #282c34;
    color: #abb2bf;
}

header {
    background-color: #21252b;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #181a1f;
}

header h1 {
    margin: 0;
    font-size: 1.5em;
    color: #61afef;
}

nav {
    padding: 10px 20px;
    background-color: #2c313a;
    border-bottom: 1px solid #181a1f;
}

nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

nav a, nav select, nav button {
    display: inline-block;
    padding: 5px 10px;
    background-color: #3e4451;
    color: #abb2bf;
    text-decoration: none;
    border-radius: 4px;
    border: 1px solid #181a1f;
    font-size: 0.9em;
    cursor: pointer;
}

nav a:hover, nav select:hover, nav button:hover {
    background-color: #4b5263;
}

nav .active {
    background-color: #61afef;
    color: #282c34;
}

/* Style for the filter controls container */
.filter-controls {
    display: flex;
    /* Mobile First: Stack vertically by default */
    flex-direction: column;
    padding: 10px 20px;
    background-color: #2c313a;
    border-bottom: 1px solid #181a1f;
    gap: 15px; /* Gap between stacked panels */
}

/* New panels for layout */
.filter-panel-left,
.filter-panel-right {
    width: 100%; /* Take full width when stacked */
    display: flex;
    flex-direction: column; /* Stack controls within left panel */
    gap: 15px;
}

.filter-panel-right {
    /* Adjustments for tag panel if needed */
}

/* Individual filter groups - Adjustments */
.tag-filters,
.select-filters,
.search-filter,
.checkbox-filters { /* Add new checkbox group */
    display: flex;
    flex-direction: column; /* Stack label and controls */
    align-items: flex-start; /* Align left */
    gap: 8px; /* Gap between label and controls */
    width: 100%; /* Make groups take full width */
    box-sizing: border-box;
}

.tag-filters > span, /* Tag label */
.checkbox-filters > div > span { /* Show/Hide labels */
    font-weight: bold;
    margin-bottom: 5px; /* Space below label */
    color: #abb2bf; /* Match other labels */
    font-size: 0.9em; /* Match other labels */
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px; /* Gap between checkboxes */
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9em;
    background-color: #3e4451;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #181a1f;
    cursor: pointer;
    color: #abb2bf;
}

.checkbox-group label:hover {
    background-color: #4b5263;
}

.checkbox-group input[type="checkbox"] {
    cursor: pointer;
}

/* Adjust tag list container */
#tag-link-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px; /* Keep tag gap small */
}

/* Tag styling (mostly unchanged, ensure wrapping works) */
.tag-filters a,
.tag-filters span {
    display: inline-block;
    padding: 5px 10px;
    background-color: #3e4451;
    color: #abb2bf;
    text-decoration: none;
    border-radius: 4px;
    border: 1px solid #181a1f;
    font-size: 0.9em;
    cursor: pointer;
    /* margin-bottom: 5px; Removed, rely on gap */
    /* margin-right: 5px; Removed, rely on gap */
}

/* Add specific active style for tag links */
.tag-filters a.active {
    background-color: #61afef; /* Same as nav .active */
    color: #282c34; /* Same as nav .active */
    border-color: #61afef; /* Optional: highlight border too */
}

/* Style selects and labels */
.select-filters label {
    margin-right: 3px; /* REDUCED */
    font-size: 0.9em;
}

.select-filters select {
    padding: 5px 8px;
    background-color: #3e4451;
    color: #abb2bf;
    border: 1px solid #181a1f;
    border-radius: 4px;
    font-size: 0.9em;
    cursor: pointer;
}

/* Style search input */
.search-filter input[type="search"] {
    padding: 6px 10px;
    background-color: #3e4451;
    color: #abb2bf;
    border: 1px solid #181a1f;
    border-radius: 4px;
    font-size: 0.9em;
    min-width: 150px; /* REDUCED search input min-width */
}

/* Reset hidden input display */
.filter-controls input[type="hidden"] {
    display: none;
}

/* Remove padding from main container if it's only for gallery */
main {
    padding: 0; 
}

/* Base gallery grid layout (Mobile First - 1 column) */
#gallery-items,
.gallery-grid {
    display: grid;
    grid-template-columns: 1fr; 
    gap: 0; 
    padding: 0; 
}

.gallery-item {
    background-color: #2c313a; /* Fallback bg */
    overflow: hidden;
    position: relative; /* Needed for absolute positioning of details */
    display: flex; /* Keep flex */
    align-items: stretch; /* MODIFIED: Stretch items vertically */
    justify-content: center; /* Keep horizontal centering */
    text-align: center;
    min-width: 150px; 
    min-height: 150px; 
    box-sizing: border-box; 
}

.gallery-item a {
    display: block;
    width: 100%;
    height: 100%; /* ADDED: Make link fill parent */
    color: inherit;
    text-decoration: none;
    position: relative; /* Ensure link covers item for hover */
    /* ADDED: Make the link a flex container if needed for snippet alignment */
    display: flex; 
    align-items: center; /* Center content like icon/text within link */
    justify-content: center;
}

/* Details overlay - initially hidden, covers full item */
.gallery-item-details {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0; /* Or height: 100% */
    background-color: rgba(0, 0, 0, 0.7); /* Darker overlay */
    color: #e0e0e0; /* Lighter text for contrast */
    padding: 10px;
    font-size: 0.85em;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
    pointer-events: none; /* Don't interfere with link clicks */
    display: flex; /* Use flexbox */
    flex-direction: column; /* Stack content vertically */
    justify-content: flex-end; /* Push content to bottom */
    text-align: left;
}

/* Show details on hover */
.gallery-item:hover .gallery-item-details {
    opacity: 1;
    visibility: visible;
}

.gallery-item-details p {
    margin: 1px 0; /* Tighter spacing */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gallery-item-details p strong {
    color: #bdbdbd; /* Slightly dimmer strong */
    margin-right: 4px;
    display: inline-block;
    min-width: 35px; /* Smaller min-width */
}

.gallery-item img, .gallery-item video {
    /* Ensure images/videos don't override link height */
    max-height: 100%; /* ADDED */
    object-fit: cover; 
    display: block; 
    width: 100%;
    height: auto; /* Allow natural height */
    /* Ensure image/video doesn't shrink in flex container */
    flex-shrink: 0;
    min-height: 0; /* Fix potential flexbox overflow issue */
}

.gallery-item-text-snippet {
    font-size: 0.8em;
    padding: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    /* display: -webkit-box; */ /* REMOVED: Not reliable with flex */
    /* -webkit-line-clamp: 5; */ /* REMOVED */
    /* -webkit-box-orient: vertical; */ /* REMOVED */
    width: 100%; 
    height: 100%; 
    box-sizing: border-box; 
    color: #abb2bf; 
    background-color: #21252b; 
    /* ADDED: Ensure text aligns okay within flex parent */
    text-align: left;
    align-self: stretch; /* Allow snippet to take full height within link */
}

.gallery-item-icon {
    font-size: 3em; /* Style for icons (e.g., audio) */
    color: #61afef;
    /* Ensure icon doesn't shrink */
    flex-shrink: 0; 
}

/* NEW rule for the delete button specifically on gallery items */
.gallery-item-delete-button {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: rgba(224, 82, 82, 0.8);
    color: white;
    border: none;
    border-radius: 3px;
    padding: 3px 6px;
    font-size: 0.8em;
    line-height: 1; /* Ensure X fits */
    cursor: pointer;
    z-index: 10; /* Ensure it's above the overlay */
}

.gallery-item-delete-button:hover {
    background-color: rgb(194, 59, 59);
}

/* Detail View */
.detail-container {
    padding: 20px;
    max-width: 900px;
    margin: 20px auto;
    background-color: #2c313a;
    border: 1px solid #181a1f;
    border-radius: 5px;
    box-sizing: border-box; /* Ensure padding doesn't increase width */
}

.detail-preview img,
.detail-preview video,
.detail-preview audio {
    max-width: 100%;
    display: block;
    margin: 15px auto;
}

.detail-content {
    margin-top: 20px;
    padding: 15px;
    background-color: #21252b;
    border-radius: 4px;
    border: 1px solid #181a1f;
}

/* Basic styles for rendered markdown */
.detail-content h1, .detail-content h2, .detail-content h3 {
    color: #61afef;
    margin-top: 1em;
    margin-bottom: 0.5em;
    border-bottom: 1px solid #3e4451;
    padding-bottom: 0.3em;
}

.detail-content p {
    line-height: 1.6;
}

.detail-content code {
    background-color: #3e4451;
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
}

.detail-content pre {
    background-color: #21252b;
    border: 1px solid #181a1f;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
}

.detail-content pre code {
    background-color: transparent;
    padding: 0;
}

.detail-content blockquote {
    border-left: 4px solid #5c6370;
    padding-left: 10px;
    margin-left: 0;
    color: #98c379;
}

.detail-content ul, .detail-content ol {
    padding-left: 20px;
}

.detail-content table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
}

.detail-content th, .detail-content td {
    border: 1px solid #3e4451;
    padding: 8px;
}

.detail-content th {
    background-color: #2c313a;
}

/* HTMX indicator */
.htmx-indicator{
    opacity:0;
    transition: opacity 200ms ease-in;
}
.htmx-request .htmx-indicator{
    opacity:1
}
.htmx-request.htmx-indicator{
    opacity:1
}

/* Style for the added loading indicator */
.loading-indicator {
    padding: 10px;
    text-align: center;
    color: #61afef;
}

/* Load more trigger - now invisible for infinite scroll */
#load-more-trigger {
    visibility: hidden;
    height: 1px;
    margin: 0;
    padding: 0;
}

/* === Detail Page Enhancements === */

.detail-header {
    background-color: #21252b;
    padding: 15px 25px;
    border-bottom: 1px solid #181a1f;
}

.back-link {
    color: #61afef;
    text-decoration: none;
    display: block;
    margin-bottom: 10px;
    font-size: 0.9em;
}

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

.detail-header h2 {
    margin: 0 0 5px 0;
    font-size: 1.8em;
    color: #e5c07b;
}

.detail-description {
    margin: 0;
    color: #98c379;
    font-size: 1em;
}

/* Container for the main content below the header */
.detail-container {
    padding: 20px;
}

/* Grid layout for info blocks */
.detail-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); /* Adjust minmax as needed */
    gap: 20px;
    margin-bottom: 20px; /* Space before metadata/content */
}

/* Common styling for info blocks */
.info-block {
    background-color: #2c313a;
    border: 1px solid #181a1f;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px; /* Add margin for blocks outside the grid too */
}

.info-block h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #61afef;
    font-size: 1.1em;
    border-bottom: 1px solid #3e4451;
    padding-bottom: 8px;
}

.info-block p {
    margin: 8px 0;
    font-size: 0.95em;
}

.info-block p strong {
    color: #98c379;
    margin-right: 5px;
    display: inline-block;
    min-width: 90px; /* Align labels somewhat */
}

/* Tags Block Specifics */
.detail-tags {
    /* This block might span full width if not in grid, handled by placement */
    /* margin-bottom: 20px; */ /* Use common info-block margin */
}

.tag-badge {
    display: inline-block;
    background-color: #3e4451;
    color: #abb2bf;
    padding: 4px 8px;
    border-radius: 4px;
    margin-right: 5px;
    margin-bottom: 5px; /* Allow wrapping */
    font-size: 0.85em;
}

/* Action Buttons */
.action-button {
    display: block; /* Stack buttons */
    width: 100%;
    padding: 10px 15px;
    margin-bottom: 10px;
    border: none;
    border-radius: 4px;
    font-size: 1em;
    text-align: center;
    cursor: pointer;
    text-decoration: none; /* For link styled as button */
    box-sizing: border-box; /* Ensure padding doesn't increase width */
}

.action-button:last-child {
    margin-bottom: 0;
    background-color: #529bcf;
}

.download-button {
    background-color: #61afef;
    color: #282c34;
}

.download-button:hover {
    background-color: #529bcf;
}

/* NEW styles for the View button */
.view-button {
    background-color: #56b6c2; /* Teal/Cyan color */
    color: #282c34;
}

.view-button:hover {
    background-color: #46a1ab;
}

.edit-button {
    background-color: #c678dd; /* Purple color */
    color: #282c34;
}

.edit-button:hover {
    background-color: #b565cc;
}

/* Custom Metadata Table */
.metadata-block table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.metadata-block th,
.metadata-block td {
    border: 1px solid #3e4451;
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
    word-break: break-all; /* Prevent long values overflowing */
}

.metadata-block th {
    background-color: #21252b;
    color: #98c379;
    width: 30%; /* Adjust width as needed */
}

/* Rendered Content Preview */
.detail-content {
    /* Use common info-block styling */
}

.detail-preview img,
.detail-preview video,
.detail-preview audio {
    max-width: 100%;
    display: block;
    margin: 0 auto 20px auto; /* Center preview, add bottom margin */
    border-radius: 4px;
}

.detail-preview #panorama-viewer { /* For panorama */
    width: 100%;
    height: 500px;
    margin-bottom: 20px; /* Add bottom margin */
}

/* Ensure detail page delete button gets red background */
.action-button.delete-button {
    background-color: #e06c75;
    color: #282c34;
}

.delete-button:hover {
    background-color: #be5046;
}

/* Filter controls layout */
.filter-controls {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    align-items: center; /* Align items vertically */
    gap: 20px; /* Space between filter groups */
    padding: 10px 0; /* Add some vertical padding */
}

.tag-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px; /* Space between tags */
    align-items: center;
}

.tag-filters span {
    margin-right: 5px; /* Space after "Tags:" label */
    font-weight: bold;
}

.select-filters, .search-filter {
    display: flex;
    gap: 8px; /* Space between label and select/input */
    align-items: center;
}

.search-filter input[type="search"] {
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid #181a1f;
    background-color: #3e4451;
    color: #abb2bf;
    min-width: 200px; /* Give search some base width */
}

/* Stack gallery filters */
.filter-controls {
    flex-direction: column;
    align-items: flex-start; /* Align items to start when stacked */
}
/* Add some space between stacked filter groups */
.filter-controls > div { /* Target direct div children */
    margin-bottom: 10px;
    box-sizing: border-box; /* Include padding in width calculation */
}
.filter-controls > div:last-child {
    margin-bottom: 0;
}
/* Make selects/search fill width */
.select-filters select,
.search-filter input {
    width: 100%;
    box-sizing: border-box; /* Include padding/border in width */
}

/* === Mobile Responsiveness === */

/* Apply 2 columns for screens wider than 480px */
@media (min-width: 481px) {
    #gallery-items,
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Apply auto-fill columns for screens wider than 768px */
@media (min-width: 769px) {
    #gallery-items,
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }

    /* Desktop Layout for Filters */
    .filter-controls {
        flex-direction: row; /* Side-by-side */
        align-items: flex-start; /* Align panels to top */
        gap: 25px; /* Gap between left and right panels */
    }

    .filter-panel-left {
        flex: 2; /* Give filter panel more space */
        /* width: auto; Let flex handle width */
        gap: 15px; /* Keep gap between filter sections */
    }

    .filter-panel-right {
        flex: 3; /* Give tags panel more space */
        /* width: auto; Let flex handle width */
    }

     /* Adjust filter groups for horizontal layout on desktop */
    .checkbox-filters {
        flex-direction: column; /* Keep show/hide stacked */
        align-items: flex-start;
        width: 100%; /* Take full width within left panel */
    }
    .show-types { /* Renamed from .show-types, .hide-types */
        width: 100%;
        /* Removed bottom margin as there's only one group now */
    }
    .checkbox-group {
        /* Allow checkboxes to wrap within their container */
         gap: 8px; /* Adjust gap */
    }
    .checkbox-group label {
         /* Adjust padding/size if needed */
    }

    .select-filters,
    .search-filter {
        flex-direction: row; /* Label and input side-by-side */
        align-items: center;
        width: auto; /* Don't force full width */
    }

    .select-filters label {
        margin-right: 5px; /* Space after label */
        margin-bottom: 0; /* Remove bottom margin */
        width: auto;
    }

    .select-filters select,
    .search-filter input[type="search"] {
        width: auto; /* Allow natural width */
        min-width: 150px; /* Restore min-width */
    }

    .tag-filters {
        flex-direction: row; /* Label and tags side-by-side */
        align-items: center;
        width: 100%; /* Take full width within right panel */
    }
    .tag-filters > span { /* Tag label */
        margin-bottom: 0; /* Remove bottom margin */
        margin-right: 8px; /* Space after label */
    }
    #tag-link-list {
         /* Ensure tag links wrap correctly */
         gap: 8px;
    }

    /* Desktop Layout Specifics for Sort/Search */
    .sort-search-container {
        flex-direction: row; /* Side-by-side on desktop */
        align-items: center; /* Vertically align items */
        gap: 20px; /* Adjust gap between search and sort */
        width: 100%; /* Container takes full width of left panel */
        padding: 10px 0; /* Add vertical padding */
    }
    .search-filter { order: 1; flex-grow: 1; flex-basis: 0; } /* Search first & grow */
    .select-filters { order: 2; flex-grow: 1; flex-basis: 0; } /* Sort second & grow */

    .search-filter,
    .select-filters {
        align-items: center;
    }
    
    /* Make input/select fill their containers */
    .search-filter input[type="search"],
    .select-filters select {
        width: 100%; /* Fill the flex item */
        box-sizing: border-box; /* Include padding/border */
        min-width: auto; /* Override previous min-width */
    }

    .select-filters label,
    .search-filter label { /* Ensure labels don't prevent shrinking */
        margin-right: 5px; /* Space after label */
        margin-bottom: 0; /* Remove bottom margin */
        width: auto;
    }

}

/* Keep other mobile styles below, remove old gallery-items rules from max-width queries */
@media (max-width: 768px) {
    /* Detail: Stack info grid */
    .detail-info-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    /* Reduce padding slightly */
    .detail-container {
        padding: 15px;
    }
    .detail-header {
        padding: 10px 15px;
    }
    /* Adjust panorama height to viewport */
    .detail-preview #panorama-viewer {
        height: 60vh; /* Use viewport height */
    }
    /* Slightly smaller fonts */
    body {
        font-size: 0.95em;
    }
    header h1 {
        font-size: 1.3em;
    }
    .detail-header h2 {
        font-size: 1.5em;
    }
    /* Smaller action buttons */
    .action-button {
        padding: 8px 12px;
        font-size: 0.9em;
    }
}

/* === Welcome Page Styles === */

.welcome-container {
    max-width: 500px;
    margin: 50px auto; /* Add top margin */
    padding: 30px;
    background-color: #2c313a;
    border: 1px solid #181a1f;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.welcome-container h1 {
    color: #61afef;
    margin-bottom: 20px;
}

.welcome-container p {
    color: #abb2bf;
    margin-bottom: 25px;
    font-size: 1.1em;
}

.welcome-form label {
    display: block;
    margin-bottom: 8px;
    color: #98c379;
    font-weight: bold;
    font-size: 0.95em;
}

.welcome-form input[type="password"] {
    width: calc(100% - 22px); /* Adjust width for padding/border */
    padding: 10px;
    margin-bottom: 20px;
    background-color: #3e4451;
    color: #abb2bf;
    border: 1px solid #181a1f;
    border-radius: 4px;
    font-size: 1em;
}

.welcome-form button {
    padding: 12px 25px;
    background-color: #61afef;
    color: #282c34;
    border: none;
    border-radius: 4px;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.welcome-form button:hover {
    background-color: #529bcf;
}

/* Removed duplicate .gallery-grid definition - now unified above */

/* Detail View Styles */
.detail-view {
    /* ... existing code ... */
}

/* Derived files section styling - Full width */
.derived-content-section {
    background-color: #2c313a;
    border: 1px solid #181a1f;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    width: 100%;
    box-sizing: border-box;
}

.derived-content-section h3 {
    color: #61afef;
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.derived-files-description {
    font-size: 0.9em;
    color: #898989;
    margin-bottom: 20px;
    font-style: italic;
    line-height: 1.4;
}

.derived-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #3e4451;
    border: 1px solid #181a1f;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 12px;
}

.derived-file-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.derived-file-icon {
    font-size: 1.2em;
}

.derived-file-label {
    font-weight: 600;
    color: #abb2bf;
    font-size: 1em;
}

.derived-file-details {
    font-size: 0.85em;
    color: #898989;
    margin-left: 8px;
}

.derived-file-actions {
    display: flex;
    gap: 10px;
}

.derived-file-actions .action-button {
    min-width: 100px;
    width: 100px;
    height: 40px;
    padding: 0;
    font-size: 0.9em;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .derived-file-item {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .derived-file-info {
        justify-content: center;
    }
    
    .derived-file-actions {
        justify-content: center;
    }
    
    .derived-file-actions .action-button {
        flex: 1;
        max-width: 120px;
    }
}
