/* ==========================================================================
   app.css — Photo Album stylesheet
   Single comprehensive stylesheet for all pages.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Reset and base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: Verdana, Arial, sans-serif;
    font-size: 13px;
    color: black;
    background-color: #E0E0E0;
}

a {
    color: blue;
    text-decoration: none;
}

a:visited {
    color: purple;
}

a:hover {
    text-decoration: underline;
}

img {
    display: block;
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#app-header {
    background: #6699CC;
    color: white;
    height: 33px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    flex-shrink: 0;
    z-index: 100;
    border-bottom: 1px solid #336699;
}

#site-title {
    color: white;
    font-size: 1.4em;
    font-weight: bold;
}

#site-title:hover {
    text-decoration: underline;
    color: white;
}


#app-main {
    flex: 1;
    overflow: hidden;
}

#app-footer {
    background: #6699CC;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    font-size: 0.72em;
    flex-shrink: 0;
    border-top: 1px solid #336699;
    line-height: 1.2;
    position: relative;
}

#footer-nav {
    position: absolute;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.footer-nav-user {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85em;
}

.footer-nav-link {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.8em;
    padding: 0 4px;
    white-space: nowrap;
}

.footer-nav-link:hover {
    color: white;
    text-decoration: underline;
}

.footer-nav-link:visited {
    color: rgba(255, 255, 255, 0.55);
}

/* --------------------------------------------------------------------------
   Gallery two-pane layout
   -------------------------------------------------------------------------- */
#gallery-layout {
    display: grid;
    grid-template-columns: 325px 1fr;
    height: 100%;
    overflow: hidden;
}

#tree-pane {
    background: #EDF2FC;
    border-right: 1px solid #6699CC;
    overflow-y: auto;
    padding: 4px 0;
}

#content-pane {
    overflow-y: auto;
    padding: 0;
    background: white;
}

#home-pane {
    overflow-y: auto;
    background: #E0E0E0;
}

#home-header {
    background: linear-gradient(180deg, #ffffff 0%, #e8e8e8 100%);
    padding: 12px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

#home-header img {
    display: block;
    max-width: 100%;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.08));
}

#home-content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.home-card {
    background: white;
    border: 1px solid #C8C8C8;
    display: flex;
    gap: 0;
}

.home-card-icon {
    width: 52px;
    flex-shrink: 0;
    background: #6699CC;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 18px;
}

.home-card-icon svg {
    width: 24px;
    height: 24px;
    color: white;
    flex-shrink: 0;
}

.home-card-body {
    padding: 16px 20px;
    flex: 1;
    min-width: 0;
}

.home-card-body h2 {
    font-size: 1.05em;
    font-weight: bold;
    color: #003366;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #E0E0E0;
}

.home-card-body p {
    font-size: 0.95em;
    line-height: 1.7;
    color: #222;
    margin-bottom: 8px;
}

.home-card-body p:last-child {
    margin-bottom: 0;
}

.home-categories {
    margin: 8px 0 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.home-categories > div {
    background: #EDF2FC;
    border-left: 3px solid #6699CC;
    padding: 6px 10px;
}

.home-categories dt {
    font-weight: bold;
    font-size: 0.92em;
    color: #003366;
}

.home-categories dd {
    font-size: 0.92em;
    color: #333;
    line-height: 1.6;
    margin: 2px 0 0;
}

/* --------------------------------------------------------------------------
   Album header — visually distinct panel above thumbnails
   -------------------------------------------------------------------------- */
#album-header {
    background: #E8E8E8;
    border-bottom: 2px solid #E0E0E0;
    padding: 8px 12px;
}

#album-title {
    font-size: 1.4em;
    color: black;
    font-weight: bold;
    display: inline;
}

#album-date {
    color: #555;
    font-size: 0.85em;
    margin-left: 8px;
}

#album-marking,
#album-comment {
    color: black;
    margin-top: 6px;
    line-height: 1.5;
    font-size: 0.9em;
    white-space: pre-line;
}


.admin-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 0.8em;
    padding: 2px 10px;
    border: 1px solid #CCCCCC;
    background: #D8D8D8;
    color: black;
}

.admin-link:hover {
    background: #C6D3EF;
    border-color: #3169C6;
    text-decoration: none;
    color: black;
}

/* --------------------------------------------------------------------------
   Thumbnail grid
   -------------------------------------------------------------------------- */
#thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 240px);
    gap: 10px;
    padding: 12px;
}

.thumb-item,
.album-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    overflow: hidden;
    border: 1px solid white;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.thumb-item:hover,
.album-item:hover {
    border-color: #3169C6;
    background: #C6D3EF;
    text-decoration: none;
}

.thumb-img,
.album-cover {
    width: 240px;
    height: 240px;
    object-fit: contain;
    image-rendering: auto;
    display: block;
    background: white;
}

.album-cover--empty {
    width: 240px;
    height: 240px;
    background: #D8D8D8;
    display: flex;
    align-items: center;
    justify-content: center;
}

.album-cover--empty::after {
    content: '📁';
    font-size: 2em;
}

.thumb-title,
.album-title {
    padding: 4px 4px 2px;
    font-size: 0.9em;
    color: black;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.album-count {
    font-size: 0.75em;
    color: #555;
    padding-bottom: 4px;
}

.album-count::before {
    content: '(';
}

.album-count::after {
    content: ')';
}

#empty-album {
    color: #777;
    text-align: center;
    padding: 40px;
    grid-column: 1 / -1;
}

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
#thumb-pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 16px;
    padding: 12px;
    border-top: 1px solid #E0E0E0;
    flex-wrap: wrap;
}

.page-link {
    padding: 2px 8px;
    border: 1px solid #CCCCCC;
    color: black;
    background: #D8D8D8;
    font-size: 0.85em;
}

.page-link:hover {
    background: #C6D3EF;
    border-color: #3169C6;
    color: black;
    text-decoration: none;
}

.page-link--active {
    background: #3169C6;
    color: white;
    border-color: #3169C6;
    font-weight: bold;
}

.page-link--active:hover {
    color: white;
    background: #3169C6;
}

/* --------------------------------------------------------------------------
   Tree widget
   -------------------------------------------------------------------------- */
#tree-loading {
    padding: 8px 12px;
    color: #777;
    font-size: 0.8em;
}

.tree-list {
    list-style: none;
}

.tree-list--root {
    padding: 0;
}

.tree-node {
    /* container */
}

.tree-row {
    display: flex;
    align-items: center;
    padding: 2px 4px 2px 0;
    cursor: pointer;
}


.tree-node--active > .tree-row .tree-label {
    background: #6699CC;
    color: white;
    border-radius: 2px;
    flex: 0 1 auto;
    padding: 1px 6px;
}

.tree-toggle {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tree-toggle img {
    display: block;
}

.tree-toggle--open {
    transform: none;
}

.tree-toggle--leaf {
    cursor: default;
}

.tree-icon {
    margin-right: 4px;
    flex-shrink: 0;
}

.tree-label {
    display: flex;
    align-items: center;
    flex: 1;
    font-size: 0.9em;
    color: black;
    padding: 1px 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.tree-label:hover {
    text-decoration: underline;
    color: black;
}

.tree-children {
    padding-left: 18px;
}

.tree-children[hidden] {
    display: none;
}

/* --------------------------------------------------------------------------
   Image modal (lightbox)
   -------------------------------------------------------------------------- */
#image-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

#image-modal[aria-hidden="true"] {
    display: none;
}

#modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    cursor: pointer;
}

#modal-dialog {
    position: relative;
    z-index: 1;
    max-width: 90vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#modal-body {
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: calc(92vh - 60px);
}

#modal-img {
    max-width: 90vw;
    max-height: calc(92vh - 60px);
    object-fit: contain;
    display: block;
    border: 12px solid black;
}

#modal-footer {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.65);
    width: 100%;
    justify-content: center;
    color: white;
    font-size: 0.82em;
}

#modal-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#modal-counter {
    color: #ccc;
    flex-shrink: 0;
}

#modal-link {
    color: #C6D3EF;
    font-size: 0.8em;
    flex-shrink: 0;
}

#modal-link:hover {
    color: white;
}

#modal-close,
#modal-prev,
#modal-next {
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

#modal-close:hover,
#modal-prev:hover,
#modal-next:hover {
    background: rgba(0, 0, 0, 0.85);
}

#modal-close {
    top: -16px;
    right: -16px;
}

#modal-prev {
    left: -48px;
    top: 50%;
    transform: translateY(-50%);
}

#modal-next {
    right: -48px;
    top: 50%;
    transform: translateY(-50%);
}

/* --------------------------------------------------------------------------
   Image viewer page — standalone image.php
   -------------------------------------------------------------------------- */
#image-viewer {
    max-width: 1000px;
    margin: 0 auto;
    padding: 16px 20px;
}

#viewer-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #E0E0E0;
}

#viewer-prev,
#viewer-next,
#viewer-index {
    padding: 2px 14px;
    border: 1px solid #CCCCCC;
    color: black;
    font-size: 0.88em;
    background: #D8D8D8;
}

#viewer-prev:hover,
#viewer-next:hover,
#viewer-index:hover {
    background: #C6D3EF;
    border-color: #3169C6;
    text-decoration: none;
    color: black;
}

.disabled {
    color: #aaa;
    pointer-events: none;
    border: 1px solid #E0E0E0;
    padding: 2px 14px;
    font-size: 0.88em;
    background: #E4E4E4;
}

#viewer-index {
    margin: 0 auto;
}

#viewer-body {
    text-align: center;
    margin-bottom: 12px;
}

#viewer-img {
    max-width: 100%;
    max-height: 75vh;
    object-fit: contain;
    display: inline-block;
    border: 12px solid black;
}

#viewer-meta {
    background: #E8E8E8;
    border: 1px solid #E0E0E0;
    padding: 8px 12px;
    display: flex;
    align-items: baseline;
    gap: 16px;
    flex-wrap: wrap;
}

#viewer-title {
    font-size: 1.05em;
    color: black;
    font-weight: bold;
}

#viewer-comment {
    color: black;
    line-height: 1.5;
    font-size: 0.9em;
    white-space: pre-line;
}

#viewer-original {
    font-size: 0.8em;
    color: blue;
}

#viewer-counter {
    margin-left: auto;
    color: #666;
    font-size: 0.82em;
}

.page-image #app-main {
    overflow-y: auto;
    background: #E0E0E0;
}

/* --------------------------------------------------------------------------
   Login page
   -------------------------------------------------------------------------- */
.page-login #app-main {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #E0E0E0;
}

#login-container {
    background: #E8E8E8;
    border: 10px solid #D0D0D0;
    padding: 24px 32px;
    width: 320px;
}

#login-container h1 {
    font-size: 1.1em;
    margin-bottom: 16px;
    color: black;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    margin-bottom: 3px;
    font-size: 0.85em;
    color: black;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #CCCCCC;
    font-size: 0.88em;
    color: black;
    font-family: inherit;
    background: white;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #3169C6;
}

.error {
    background: #fff0f0;
    border: 1px solid #ffaaaa;
    padding: 6px 10px;
    color: red;
    font-size: 0.85em;
    margin-bottom: 12px;
}

.flash {
    padding: 6px 10px;
    margin-bottom: 12px;
    font-size: 0.85em;
    border: 1px solid #E0E0E0;
}

.flash.success {
    background: #f0fff4;
    border-color: #90c0a0;
    color: #276749;
}

.flash.error {
    background: #fff0f0;
    border-color: #ffaaaa;
    color: red;
}

button[type="submit"],
#login-submit {
    width: 100%;
    padding: 7px;
    background: #3169C6;
    color: white;
    border: 1px solid #2050a0;
    font-size: 0.88em;
    cursor: pointer;
    font-family: inherit;
}

button[type="submit"]:hover,
#login-submit:hover {
    background: #2050a0;
}

/* --------------------------------------------------------------------------
   Admin pages
   -------------------------------------------------------------------------- */
.page-admin #app-main {
    overflow-y: auto;
    background: #E0E0E0;
}

#admin-reindex,
#admin-users,
#admin-edit-album {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

#admin-reindex h1,
#admin-users h1,
#admin-edit-album h1 {
    font-size: 1.1em;
    color: black;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #E0E0E0;
}

#users-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background: #E8E8E8;
    border: 1px solid #D0D0D0;
}

#users-table th,
#users-table td {
    padding: 6px 12px;
    text-align: left;
    border-bottom: 1px solid #D0D0D0;
}

#users-table th {
    background: #D8D8D8;
    font-size: 0.85em;
    color: black;
    font-weight: bold;
}

#users-table tbody tr:last-child td {
    border-bottom: none;
}

.inline-form {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.inline-form input[type="password"] {
    padding: 3px 6px;
    width: 140px;
    border: 1px solid #CCCCCC;
    font-size: 0.82em;
    font-family: inherit;
    background: white;
}

.inline-form input[type="password"]:focus {
    outline: none;
    border-color: #3169C6;
}

.inline-form button {
    padding: 3px 10px;
    cursor: pointer;
    border: 1px solid #CCCCCC;
    background: #D8D8D8;
    font-size: 0.8em;
    font-family: inherit;
    color: black;
}

.inline-form button:hover {
    background: #C6D3EF;
    border-color: #3169C6;
}

.btn-danger {
    border-color: #f0a0a0 !important;
    color: #c0392b !important;
}

.btn-danger:hover {
    background: #fff0f0 !important;
    border-color: #e07070 !important;
}

#add-user {
    background: #E8E8E8;
    padding: 16px;
    border: 1px solid #D0D0D0;
    margin-bottom: 16px;
}

#add-user h2 {
    font-size: 0.95em;
    color: black;
    margin-bottom: 12px;
}

#edit-album-form .form-group small {
    display: block;
    color: #777;
    font-size: 0.78em;
    margin-top: 3px;
}

#edit-album-form textarea {
    min-height: 80px;
    resize: vertical;
}

.edit-images-heading {
    font-size: 0.95em;
    color: black;
    margin: 20px 0 10px;
    padding-top: 16px;
    border-top: 1px solid #D0D0D0;
}

#edit-images {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.edit-image-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: #E8E8E8;
    border: 1px solid #D0D0D0;
    padding: 10px;
}

.edit-image-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    flex-shrink: 0;
    display: block;
}

.edit-image-fields {
    flex: 1;
    min-width: 0;
}

.edit-image-fields .form-group {
    margin-bottom: 6px;
}

.edit-image-fields textarea {
    min-height: 0;
    resize: vertical;
}

#reindex-form label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    cursor: pointer;
}

#current-status {
    background: #E8E8E8;
    border: 1px solid #D0D0D0;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 0.88em;
}

/* --------------------------------------------------------------------------
   Hamburger toggle — hidden on desktop, shown on mobile
   -------------------------------------------------------------------------- */
#tree-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: none;
    border: none;
    color: white;
    font-size: 1.3em;
    cursor: pointer;
    padding: 0;
    margin-right: 4px;
}

#tree-toggle:hover {
    background: rgba(0, 0, 0, 0.15);
}

/* --------------------------------------------------------------------------
   Mobile backdrop overlay (for tree drawer)
   -------------------------------------------------------------------------- */
#mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
}

#mobile-backdrop.is-visible {
    display: block;
}

/* --------------------------------------------------------------------------
   Mobile — everything behind this breakpoint is untouched on desktop
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {

    /* Header */
    #app-header {
        height: 44px;
        padding: 0 8px 0 0;
    }

    #tree-toggle {
        display: flex;
    }

    #site-title {
        font-size: 1.1em;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }

    /* Footer nav — hidden on mobile */
    #footer-nav {
        display: none;
    }

    /* Main layout — single column, natural scroll */
    #app-main {
        overflow-y: auto;
    }

    /* Tree becomes a fixed off-canvas drawer */
    #gallery-layout {
        display: block;
        height: auto;
        overflow: visible;
    }

    #tree-pane {
        position: fixed;
        top: 44px;
        left: -325px;
        bottom: 0;
        width: 325px;
        z-index: 200;
        transition: left 0.22s ease;
        overflow-y: auto;
        box-shadow: none;
    }

    #tree-pane.tree-pane--open {
        left: 0;
        box-shadow: 3px 0 12px rgba(0, 0, 0, 0.25);
    }

    /* Content pane fills full width */
    #content-pane {
        overflow-y: visible;
        height: auto;
    }

    #home-pane {
        overflow-y: visible;
        height: auto;
    }

    /* Thumbnail grid — 2 flexible columns */
    #thumb-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 6px;
        padding: 8px;
    }

    .thumb-img,
    .album-cover {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }

    .album-cover--empty {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }

    /* Modal — full screen */
    #modal-dialog {
        max-width: 100vw;
        max-height: 100vh;
        width: 100vw;
        height: 100dvh;
        justify-content: center;
    }

    #modal-body {
        flex: 1;
        max-height: none;
    }

    #modal-img {
        max-width: 100vw;
        max-height: calc(100dvh - 56px);
        border-width: 4px;
    }

    #modal-close {
        top: 8px;
        right: 8px;
    }

    #modal-prev {
        left: 4px;
        top: 50%;
        transform: translateY(-50%);
    }

    #modal-next {
        right: 4px;
        top: 50%;
        transform: translateY(-50%);
    }

    /* Home page cards — stack icon on top */
    .home-card {
        flex-direction: column;
    }

    .home-card-icon {
        width: 100%;
        padding: 12px 0 8px;
        justify-content: center;
        align-items: center;
    }

    #home-content {
        padding: 12px;
    }

    /* Admin / image pages */
    #admin-reindex,
    #admin-users,
    #admin-edit-album {
        padding: 12px;
    }

    .edit-image-row {
        flex-direction: column;
    }

    .edit-image-thumb {
        width: 100%;
        height: 120px;
    }

    #image-viewer {
        padding: 8px 10px;
    }

    #viewer-nav {
        flex-wrap: wrap;
    }
}
