:root {
    --gap: 5px;
    --radius: 8px;
}

html,
body {
    min-height: 100%;
    background: #ffffff;
    color: #111;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    padding: 0;
    margin: 0;
}

#gallery-content {
    width: 100%;
    max-width: 1750px;
    margin: 0 auto;
    padding: 16px 0;
    box-sizing: border-box;
}

.gallery-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--gap);
    width: 100%;
}

.masonry-column {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.gallery-item {
    display: inline-block;
    width: 100%;
    background: transparent;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    position: relative;
}

.gallery-image > div {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
}

/* Consolidated Delete Icons */
.delete-image-btn,
.modal-comment-card .delete-comment-btn,
.inline-comment .delete-comment-btn {
    position: absolute;
    background: transparent;
    border: none;
    color: red;
    cursor: pointer;
    font-weight: bold;
    z-index: 5;
}

.delete-image-btn {
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    color: #ff3b30;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 1;
    transition:
        opacity 0.22s ease,
        transform 0.22s ease,
        background-color 0.15s ease;
}

.delete-image-btn:hover {
    background: #ff3b30;
    color: #fff;
}

.modal-comment-card .delete-comment-btn,
.inline-comment .delete-comment-btn {
    top: 10px;
    right: 10px;
    font-size: 0.9rem;
}

.gallery-image {
    display: block;
    width: 100%;
    height: auto;
    max-height: 600px;
    object-fit: cover;
    background-color: #666;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin: 0 auto;
}

figcaption {
    padding: 6px 2px;
    text-align: left;
}

/* Consolidated Word Wrapping */
.image-title,
.image-author,
#modal-text-title,
#modal-text-author,
.inline-comment-content,
.modal-comment-card p {
    word-wrap: break-word;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.image-title {
    margin: 0 0 6px 0;
    font-size: 0.95rem;
    line-height: 1.1;
    color: #111;
    text-align: left;
}

.image-author {
    margin: 4px 0 0 0;
    flex: 1;
    display: block;
    font-size: 0.8rem;
    color: #666;
    text-align: left;
}

.hidden {
    display: none !important;
}

/* 12-column helper classes */
.col-1 {
    flex: 0 0 calc(100% * 1 / 12 - (var(--gap) * 11 / 12));
    max-width: calc(100% * 1 / 12 - (var(--gap) * 11 / 12));
}

.col-2 {
    flex: 0 0 calc(100% * 2 / 12 - (var(--gap) * 10 / 12));
    max-width: calc(100% * 2 / 12 - (var(--gap) * 10 / 12));
}

.col-3 {
    flex: 0 0 calc(100% * 3 / 12 - (var(--gap) * 9 / 12));
    max-width: calc(100% * 3 / 12 - (var(--gap) * 9 / 12));
}

.col-4 {
    flex: 0 0 calc(100% * 4 / 12 - (var(--gap) * 8 / 12));
    max-width: calc(100% * 4 / 12 - (var(--gap) * 8 / 12));
}

.col-5 {
    flex: 0 0 calc(100% * 5 / 12 - (var(--gap) * 7 / 12));
    max-width: calc(100% * 5 / 12 - (var(--gap) * 7 / 12));
}

.col-6 {
    flex: 0 0 calc(100% * 6 / 12 - (var(--gap) * 6 / 12));
    max-width: calc(100% * 6 / 12 - (var(--gap) * 6 / 12));
}

.col-7 {
    flex: 0 0 calc(100% * 7 / 12 - (var(--gap) * 5 / 12));
    max-width: calc(100% * 7 / 12 - (var(--gap) * 5 / 12));
}

.col-8 {
    flex: 0 0 calc(100% * 8 / 12 - (var(--gap) * 4 / 12));
    max-width: calc(100% * 8 / 12 - (var(--gap) * 4 / 12));
}

.col-9 {
    flex: 0 0 calc(100% * 9 / 12 - (var(--gap) * 3 / 12));
    max-width: calc(100% * 9 / 12 - (var(--gap) * 3 / 12));
}

.col-10 {
    flex: 0 0 calc(100% * 10 / 12 - (var(--gap) * 2 / 12));
    max-width: calc(100% * 10 / 12 - (var(--gap) * 2 / 12));
}

.col-11 {
    flex: 0 0 calc(100% * 11 / 12 - (var(--gap) * 1 / 12));
    max-width: calc(100% * 11 / 12 - (var(--gap) * 1 / 12));
}

.col-12 {
    flex: 0 0 100%;
    max-width: 100%;
}

/* Header Layout */
header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    max-width: 1750px;
    margin: 0 auto 24px auto;
    padding: 24px 32px 12px 32px;
    border-bottom: 1px solid #e0e0e0;
    box-sizing: border-box;
}

.gallery-header {
    display: flex;
    flex-direction: column;
}

.gallery-main-header {
    margin-bottom: 20px;
}

#current-gallery-title {
    border: none;
    margin-bottom: 0;
}

#back-to-home-btn {
    align-self: flex-start;
}

.app-title {
    font-size: 1.85rem;
    font-weight: 700;
    color: #111;
    margin: 0;
    letter-spacing: -0.5px;
}

.gallery-stats {
    font-size: 0.9rem;
    color: #666;
    margin: 4px 0 0 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

#add-image-btn {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

#add-image-btn:hover {
    background-color: #0056b3;
}

/* Add unified safe-area spacing to the main sections */
#galleries-view,
#gallery-main {
    padding: 0 32px;
    box-sizing: border-box;
    width: 100%;
}

/* Image Form Section */
#image-list {
    width: auto;
    margin: 0 32px 20px 32px;
    /* Added matching 32px margin */
    padding: 16px;
    background-color: #f9f9f9;
    border-radius: var(--radius);
    border: 1px solid #e0e0e0;
    box-sizing: border-box;
}

.form-drawer-container {
    width: 100%;
}

#add-image-form {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    width: 100%;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 200px;
}

.form-group.url-group {
    flex: 2;
}

.form-group label,
#add-comment-form label {
    font-size: 0.9rem;
    color: #333;
    margin-bottom: 4px;
    font-weight: 500;
}

/* Consolidated Inputs */
.form-group input,
#add-comment-form input,
#add-comment-form textarea {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: var(--radius);
    font-size: 0.95rem;
    box-sizing: border-box;
    width: 100%;
    font-family: inherit;
}

.form-group input:focus,
#add-comment-form input:focus,
#add-comment-form textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

#submit-image-btn,
#add-comment-form button[type='submit'] {
    padding: 8px 20px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
    align-self: flex-end;
}

#submit-image-btn:hover {
    background-color: #218838;
}

#add-comment-form button[type='submit'] {
    background-color: #007bff;
}

#add-comment-form button[type='submit']:hover {
    background-color: #0056b3;
}

/* Socket.IO Update Banner */
#update-banner {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #007bff;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-weight: bold;
    transition: all 0.3s ease;
}

/* Comments Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    overflow: hidden;
}

body.modal-open,
html.modal-open {
    overflow: hidden;
}

.modal-content {
    position: relative;
    background-color: #fff;
    border-radius: var(--radius);
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: hidden;
    padding: 24px;
    display: flex;
    gap: 24px;
    flex-direction: row;
}

.close {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 28px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    line-height: 1;
    z-index: 1001;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: #111;
}

#modal-text-title {
    margin: 0;
    font-size: 1.5rem;
    color: #111;
    font-weight: 600;
    line-height: 1.3;
}

#modal-text-author {
    margin: 0;
    font-size: 1rem;
    color: #666;
}

.modal-comments-pane {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    height: auto;
    align-self: center;
    padding-right: 20px;
    box-sizing: border-box;
}

.modal-comments-pane h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #111;
}

#comments-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    max-height: 40vh;
    padding-right: 8px;
}

.comment-item {
    padding: 12px;
    background-color: #f9f9f9;
    border-radius: var(--radius);
    border-left: 3px solid #007bff;
    flex-shrink: 0;
}

.comment-author {
    font-weight: 600;
    color: #111;
    margin-bottom: 4px;
    padding-right: 12px;
}

.comment-text {
    color: #333;
    font-size: 0.95rem;
    padding-right: 12px;
}

#comments-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

#comments-pagination button {
    padding: 6px 12px;
    background-color: #e0e0e0;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

#comments-pagination button:hover {
    background-color: #d0d0d0;
}

#comments-page-info {
    font-size: 0.9rem;
    color: #666;
    min-width: 100px;
    text-align: center;
}

.modal-grid-align {
    align-items: flex-start;
}

#modal-image-display {
    display: flex;
    justify-content: center;
    align-items: center;
    height: auto;
    align-self: center;
}

#modal-image-display img {
    width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--radius);
}

.modal-main-image {
    width: 100%;
    max-height: 600px;
    object-fit: contain;
    border-radius: var(--radius);
    background: #f5f5f5;
}

/* Metadata section for image title, author, date */
#modal-metadata h2 {
    margin: 0;
    font-size: 1.4rem;
    color: #111;
    word-wrap: break-word;
}

.modal-comment-card {
    background: #f9f9f9;
    padding: 10px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    position: relative;
}

.modal-comment-card strong {
    font-size: 0.9rem;
}

.modal-comment-card .comment-date {
    font-size: 0.75rem;
    color: #888;
    margin-left: 10px;
}

.modal-comment-card p {
    margin: 5px 0 0 0;
    font-size: 0.9rem;
}

#modal-metadata p {
    margin: 4px 0 0 0;
    font-size: 0.9rem;
    color: #666;
}

.no-comments-text {
    color: #888;
    font-style: italic;
    padding: 5px 0 !important;
    margin: 0 !important;
}

#comments-modal-title {
    margin: 0 0 12px 0;
    font-size: 1rem;
    color: #111;
}

#add-comment-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#add-comment-form .form-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex: none;
}

#add-comment-form textarea {
    resize: none;
    min-height: 60px;
}

/* Centralized generic styles */
.empty-gallery {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 1rem;
}

.inline-comment {
    font-size: 0.82rem;
    margin-top: 4px;
    text-align: left;
    position: relative;
    padding-right: 52px;
    padding-bottom: 18px;
}

.inline-comment-content {
    color: #444;
    display: block;
}

.inline-comment-date {
    position: absolute;
    bottom: 2px;
    right: 28px;
    font-size: 0.72rem;
    color: #888;
}

.more-comments-btn {
    background: none;
    border: none;
    color: #0066cc;
    padding: 0;
    cursor: pointer;
    font-size: 0.8rem;
    margin-top: 6px;
    display: block;
}

.gallery-figcaption {
    position: relative;
    padding-bottom: 28px;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.inline-comments-wrapper {
    border-top: 1px solid #eee;
    padding-top: 6px;
    margin-top: 6px;
}

.modal-image-wrapper {
    position: relative;
    width: 100%;
    display: block;
}

.image-date {
    font-size: 0.75rem;
    color: #666;
    text-align: right;
    white-space: nowrap;
}

.credits-link {
    position: absolute;
    top: 0;
    right: 0;
    padding: 8px 12px;
    font-size: 0.75rem;
    z-index: 9999;
}

/* --- Header Auth Controls --- */
.auth-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid #007bff;
    color: #007bff;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-btn:hover {
    background: #e6f2ff;
}

.primary-btn {
    background: #007bff !important;
    color: #fff !important;
    border: 1px solid #007bff !important;
}

.primary-btn:hover {
    background: #0056b3 !important;
    border-color: #0056b3 !important;
}

.secondary-btn {
    padding: 8px 16px;
    background: transparent;
    color: #007bff;
    border: 1px solid #007bff;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
}

.secondary-btn:hover {
    background: #e6f2ff;
}

.user-greeting {
    font-size: 0.95rem;
    color: #333;
    font-weight: 500;
}

/* --- Galleries List View --- */
.view-title {
    font-size: 1.5rem;
    color: #111;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #eee;
}

.gallery-card {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius);
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
    flex: 1 1 calc(25% - var(--gap));
    min-width: 200px;
    box-sizing: border-box;
}

.gallery-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
    border-color: #007bff;
}

.gallery-card-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.gallery-card-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: #111;
    margin: 0;
}

/* --- Gallery Pagination Styles --- */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 40px;
    padding: 20px 0;
    width: 100%;
}

.pagination-controls button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        opacity 0.2s ease;
}

.pagination-controls button:hover:not(:disabled) {
    background-color: #0056b3;
}

.pagination-controls button:disabled {
    background-color: #e0e0e0;
    color: #a0a0a0;
    cursor: not-allowed;
}

.pagination-controls span {
    font-family: sans-serif;
    font-size: 1rem;
    color: #444;
    user-select: none;
}

/* --- Auth Modals --- */
.auth-modal-content {
    flex-direction: column;
    width: 90%;
    max-width: 400px;
    height: auto;
    max-height: 90vh;
    padding: 32px;
    gap: 16px;
    align-items: stretch;
}

.auth-title {
    margin: 0 0 10px 0;
    font-size: 1.5rem;
    text-align: center;
    color: #111;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.full-width-btn {
    width: 100%;
    padding: 12px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 10px;
}

.full-width-btn:hover {
    background-color: #0056b3;
}

/* --- Loading Animation --- */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@media (max-width: 900px) {
    #add-image-form {
        flex-direction: column;
        align-items: stretch;
    }

    #submit-image-btn,
    #add-comment-form button[type='submit'] {
        margin-top: 10px;
    }

    .modal-content {
        flex-direction: column;
        height: auto;
        max-height: 92vh;
        overflow-y: auto;
        padding: 16px;
    }

    .modal-content .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    #modal-image-display img {
        max-height: 35vh;
    }

    .modal-comments-pane {
        padding-right: 0;
    }
}
