/* ========== Catppuccin Mocha Palette ========== */
:root {
    /* Catppuccin Mocha Base */
    --ctp-mocha-rosewater: #dc8a78;
    --ctp-mocha-flamingo: #dd7878;
    --ctp-mocha-pink: #ea76cb;
    --ctp-mocha-mauve: #8839ef;
    --ctp-mocha-red: #d20f39;
    --ctp-mocha-maroon: #e64553;
    --ctp-mocha-peach: #fe640b;
    --ctp-mocha-yellow: #df8e1d;
    --ctp-mocha-green: #40a02b;
    --ctp-mocha-teal: #179299;
    --ctp-mocha-sky: #04a5e5;
    --ctp-mocha-sapphire: #209fb5;
    --ctp-mocha-blue: #1e66f5;
    --ctp-mocha-lavender: #7287fd;
    --ctp-mocha-text: #cdd6f4;
    --ctp-mocha-subtext1: #bac2de;
    --ctp-mocha-subtext0: #a6adc8;
    --ctp-mocha-overlay2: #9399b2;
    --ctp-mocha-overlay1: #7f849c;
    --ctp-mocha-overlay0: #6c7086;
    --ctp-mocha-surface2: #585b70;
    --ctp-mocha-surface1: #45475a;
    --ctp-mocha-surface0: #313244;
    --ctp-mocha-base: #1e1e2e;
    --ctp-mocha-mantle: #181825;
    --ctp-mocha-crust: #11111b;

    /* Semantic Mappings (Material‑like to Catppuccin) */
    --md-sys-color-background: var(--ctp-mocha-crust);
    --md-sys-color-surface: var(--ctp-mocha-base);
    --md-sys-color-primary: var(--ctp-mocha-mauve);
    --md-sys-color-on-primary: var(--ctp-mocha-crust);
    --md-sys-color-secondary: var(--ctp-mocha-teal);
    --md-sys-color-on-secondary: var(--ctp-mocha-crust);
    --md-sys-color-error: var(--ctp-mocha-red);
    --md-sys-color-on-error: var(--ctp-mocha-crust);
    --md-sys-color-surface-variant: var(--ctp-mocha-surface1);
    --md-sys-color-on-surface: var(--ctp-mocha-text);
    --md-sys-color-on-surface-variant: var(--ctp-mocha-subtext0);
    --md-sys-color-outline: var(--ctp-mocha-overlay0);

    /* Accent Colors (preserved for status/rating differentiation) */
    --color-safe: #40a02b;
    --color-questionable: #fe640b;
    --color-explicit: #d20f39;
    --color-custom: #8839ef;
    --color-deleted: #dd7878;
    --color-unknown: #45475a;
    --color-auto: #1e66f5;
    --color-exists: #fe640b;
    --color-not-found: #ea76cb;
}

/* ========== Base (used globally) ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-surface);
    font-family: 'Roboto', sans-serif;
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

/* ========== App Bar (base.html) ========== */
.app-bar {
    background-color: var(--md-sys-color-surface);
    padding: 6px 24px 2px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}
.app-bar-title {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--md-sys-color-primary);
}
.app-bar-title img {
    height: 4rem;
    width: auto;
}
.app-bar-nav a {
    color: var(--md-sys-color-on-surface);
    text-decoration: none;
    margin-left: 24px;
    display: inline-flex;
    align-items: center;
}
.app-bar-nav a i {
    margin-right: 6px;
}
.app-bar-nav a:hover {
    color: var(--md-sys-color-primary);
}
.version-badge {
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    padding: 4px 8px;
    border-radius: 16px;
    white-space: nowrap;
}
.version-badge i {
    font-size: 0.7rem;
}
.separator {
    opacity: 0.6;
    margin: 0 2px;
}
.desktop-version { display: inline-flex; }
.mobile-version { display: none; }

@media (max-width: 700px) {
    .app-bar-nav .nav-text { display: none; }
    .desktop-version { display: none; }
    .mobile-version { display: inline-flex; }
}

/* ========== Main Container ========== */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    flex: 1;
    padding: 24px;
}
.main-content {
    width: 100%;
    flex: 1;
    padding: 24px;
}
.centered-wrapper {
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    width: 25%;
}
.centered-wrapper.register { width: 45%; }
.centered-wrapper.duplicates { width: 40%; }

/* ========== Gallery Grid ========== */
.gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* default: 2 columns */
    gap: 16px;
    width: 100%;
}
/* Increase columns as screen widens */
@media (min-width: 500px) {
    .gallery { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
    .gallery { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 960px) {
    .gallery { grid-template-columns: repeat(5, 1fr); }
}
@media (min-width: 1200px) {
    .gallery { grid-template-columns: repeat(6, 1fr); }
}

.gallery-tiny{
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* default: 2 columns */
    gap: 16px;
    width: 100%;
}
.gallery-item {
    background-color: var(--md-sys-color-surface);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
}
.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}
/* Status & Rating borders */
.gallery-item.status-matched.rating-s,
.gallery-item.rating-s {
    border: 4px solid var(--color-safe);
}
.gallery-item.status-matched.rating-q,
.gallery-item.rating-q {
    border: 4px solid var(--color-questionable);
}
.gallery-item.status-matched.rating-e,
.gallery-item.rating-e {
    border: 4px solid var(--color-explicit);
}
.gallery-item.status-custom.rating-custom-s {
    border: 4px solid var(--color-safe);
    background-color: var(--color-custom);
}
.gallery-item.status-custom.rating-custom-q {
    border: 4px solid var(--color-questionable);
    background-color: var(--color-custom);
}
.gallery-item.status-custom.rating-custom-e {
    border: 4px solid var(--color-explicit);
    background-color: var(--color-custom);
}
.gallery-item.status-unknown {
    border: 4px solid var(--color-unknown);
}
.gallery-item.status-not_found {
    border: 4px solid var(--color-not-found);
}
.gallery-item.status-deleted {
    border: 4px solid var(--color-deleted);
}

.thumbnail {
    aspect-ratio: 1 / 1;
    background-color: var(--md-sys-color-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.thumbnail img,
.thumbnail video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.filename {
    padding: 8px;
    font-size: 0.875rem;
    text-align: center;
    word-break: break-word;
}
.filesize {
    padding: 0 8px 8px 8px;
    font-size: 0.75rem;
    text-align: center;
    color: var(--ctp-mocha-text);
}
.thumbnail .library-exists,
.thumbnail .library-missing {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    pointer-events: none;
    font-size: 1.5em;
    text-shadow: 0 0 8px var(--ctp-mocha-text);
}
.thumbnail .library-exists {
    color: var(--ctp-mocha-green);
}
.thumbnail .library-missing {
    color: var(--ctp-mocha-red);
}

/* ========== Pagination ========== */
.pagination {
    margin-top: 24px;
    text-align: center;
}
.pagination a,
.pagination span {
    display: inline-block;
    padding: 8px 12px;
    margin: 0 4px;
    background-color: var(--md-sys-color-surface);
    border-radius: 20px;
    text-decoration: none;
    color: inherit;
}
.pagination a:hover {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.current-page {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

/* ========== Gallery Controls ========== */
.gallery-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.sort-selector,
.per-page-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}
.sort-selector select,
.per-page-selector select {
    padding: 6px 10px;
    border-radius: 20px;
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    border: 1px solid var(--md-sys-color-outline);
}
.pagination-info {
    font-size: 0.9rem;
}

/* ========== Detail View ========== */
.detail-container {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}
.media {
    flex: 2;
    min-width: 300px;
}
.media img,
.media video {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 12px;
}
.info {
    flex: 1;
    min-width: 250px;
    background-color: var(--md-sys-color-surface);
    padding: 16px;
    border-radius: 12px;
    align-self: flex-start;
}
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--md-sys-color-on-primary);
}
.badge-safe { background-color: var(--color-safe); }
.badge-questionable { background-color: var(--color-questionable); }
.badge-explicit { background-color: var(--color-explicit); }
.badge-matched { background-color: var(--color-safe); }
.badge-not-found { background-color: var(--color-explicit); }
.badge-deleted { background-color: var(--color-explicit); }
.badge-unknown { background-color: var(--color-unknown); }
.badge-custom { background-color: var(--color-custom); }
.badge-custom-safe {
    background: linear-gradient(90deg, var(--color-custom) 0%, var(--color-safe) 100%);
}
.badge-custom-questionable {
    background: linear-gradient(90deg, var(--color-custom) 0%, var(--color-questionable) 100%);
}
.badge-custom-explicit {
    background: linear-gradient(90deg, var(--color-custom) 0%, var(--color-explicit) 100%);
}
.badge-optimized {
    background-color: var(--ctp-mocha-green);
}
.badge-processing {
    background-color: var(--ctp-mocha-mauve);
}
.badge-not-optimized{
    background-color: var(--ctp-mocha-lavender);
}
#past-opt-badge-container {
    display: inline-block;
}
.rating {
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: bold;
}
.rating-s { background-color: var(--color-safe); color: var(--md-sys-color-on-primary); }
.rating-q { background-color: var(--color-questionable); color: var(--md-sys-color-on-primary); }
.rating-e { background-color: var(--color-explicit); color: var(--md-sys-color-on-primary); }
.download-btn,
.fuzzysearch-btn {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 24px;
    font-weight: 500;
    margin-top: 0.2rem;
    margin-bottom: 0.2rem;
    display: inline-block;
}
.download-btn:hover,
.fuzzysearch-btn:hover {
    background: var(--ctp-mocha-pink); /* lighter hover */
}
.download-btn.disabled {
    background-color: var(--md-sys-color-outline);
}
.download-btn-success,
#favorite-btn.btn-success {
background-color: var(--color-safe);
color: var(--md-sys-color-on-primary);
cursor: default;
}
.match-e621-section {
    margin-top: 16px;
}

/* Optimize Modal */
.optimize-modal-content {
    max-width: 900px;
    width: 90%;
}
.optimize-preview-container {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    align-items: flex-start;
}
.preview-original,
.preview-processed {
    flex: 1;
    text-align: center;
    min-width: 0;
}
.preview-original video,
.preview-original img,
.preview-processed video,
.preview-processed img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    background: var(--md-sys-color-surface-variant);
    object-fit: contain;
}
#original-preview-container,
#processed-preview-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
}
.options-panel { margin-top: 15px; }
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}
.modal-close-x {
    color: var(--md-sys-color-on-surface-variant);
    transition: color 0.2s;
}
.modal-close-x:hover {
    color: var(--md-sys-color-error);
}
.status-message {
    margin-top: 10px;
    font-style: italic;
}
.file-size {
    margin-top: 5px;
    font-size: 0.8rem;
    color: var(--md-sys-color-on-surface-variant);
}
.metadata-info {
    margin-top: 5px;
    font-size: 0.8rem;
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}
.metadata-item { display: inline-block; }
.metadata-separator {
    color: var(--md-sys-color-outline);
    user-select: none;
}
#optimize-status {
    margin: 10px 0;
    padding: 8px;
    border-radius: 4px;
    background-color: var(--md-sys-color-surface-variant);
}

/* ========== Tag Cloud & Clickable Tags ========== */
.tag-cloud {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 8px;
}
.tag-cloud .tag,
.tag.clickable {
    display: inline-block;
    background: var(--md-sys-color-surface-variant);
    padding: 4px 8px;
    border-radius: 16px;
    font-size: 0.8rem;
    margin: 2px;
    text-decoration: none;
    color: var(--md-sys-color-on-surface);
}
.tag-cloud .tag:hover,
.tag.clickable:hover {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    cursor: pointer;
}
.tag-item { cursor: pointer; }

/* ========== Sidebar ========== */
.sidebar-toggle {
    position: fixed;
    top: 70px;
    left: 16px;
    z-index: 100;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-primary);
    border: none;
    font-size: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.sidebar-toggle:hover {
    background: var(--md-sys-color-surface-variant);
}
.sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 300px;
    height: 100%;
    background: var(--md-sys-color-surface);
    border-right: 1px solid var(--md-sys-color-outline);
    transition: left 0.3s ease;
    z-index: 200;
    padding: 20px;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0,0,0,0.3);
}
.sidebar-open .sidebar { left: 0; }
.sidebar-open .main-content { margin-left: 320px; }
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--md-sys-color-outline);
}
.sidebar-header h3 {
    margin: 0;
    font-weight: 500;
}
.close-sidebar {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
}
.close-sidebar:hover {
    color: var(--md-sys-color-primary);
}
.filter-section {
    margin-bottom: 24px;
}
.filter-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}
.filter-section input[type="text"],
.filter-section select {
    width: 100%;
    padding: 8px;
    margin-bottom: 8px;
    background: var(--md-sys-color-surface-variant);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    color: var(--md-sys-color-on-surface);
}
.filter-section button { margin-top: 8px; }

.sidebar-pool-item,
.sidebar-tag-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--md-sys-color-outline);
}
.sidebar-pool-item a,
.sidebar-tag-item a {
    flex: 1;
    margin-right: 8px;
    color: var(--md-sys-color-on-surface);
    text-decoration: none;
    word-break: break-word;
}
.sidebar-pool-item a:hover,
.sidebar-tag-item a:hover {
    color: var(--md-sys-color-primary);
}
.follow-tag-icon,
.follow-pool-icon {
    flex-shrink: 0;
    margin-left: auto;
    cursor: pointer;
    transition: color 0.2s;
}
.follow-tag-icon:hover,
.follow-pool-icon:hover {
    opacity: 0.8;
}

/* ========== Suggestions Dropdown ========== */
.suggestions-dropdown,
.tag-suggestions-dropdown {
    position: absolute;
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    width: 100%;
    margin-top: 4px;
}
.suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface);
    transition: background 0.2s;
}
.suggestion-item:hover {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.tag-input-wrapper {
    position: relative;
    width: 100%;
}
.tag-search-input {
    width: 100%;
    padding: 8px;
    background: var(--md-sys-color-surface-variant);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    color: var(--md-sys-color-on-surface);
}

/* ========== Selected Tags ========== */
.selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.selected-tag {
    display: inline-flex;
    background: var(--md-sys-color-surface-variant);
    padding: 4px 8px;
    border-radius: 16px;
    font-size: 0.8rem;
    color: var(--md-sys-color-on-surface);
    gap: 4px;
    align-items: center;
}
.selected-tag .remove {
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--md-sys-color-error);
}

/* ========== Forms & Buttons ========== */
button,
.btn {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    padding: 8px 16px;
    border-radius: 24px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}
button:hover,
.btn:hover {
    background-color: var(--ctp-mocha-pink);
}
.btn-secondary {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
}
.btn-secondary:hover {
    background-color: var(--md-sys-color-outline);
}
input,
select,
textarea {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    border: 1px solid var(--md-sys-color-outline);
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 8px;
}
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 4px;
    color: var(--md-sys-color-on-surface-variant);
}

.token-hint {
    font-size: 0.85rem;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 16px;
}
.token-hint code {
    background: var(--md-sys-color-surface-variant);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--md-sys-color-on-surface);
}

/* ========== User Bar & Auth Bar ========== */
.user-bar {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 1000;
}
.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
}
.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.default-avatar {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.user-menu {
    position: absolute;
    bottom: 60px;
    right: 0;
    background: var(--md-sys-color-surface);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    width: 200px;
    display: none;
    padding-bottom: 0.2rem;
    z-index: 1001;
}
.user-menu a,
.user-info {
    display: block;
    padding: 10px 16px;
    text-decoration: none;
    color: var(--md-sys-color-on-surface);
}
.user-menu a.user-edit {
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
}
.user-menu a:hover {
    background: var(--md-sys-color-surface-variant);
}
.user-info {
    border-bottom: 1px solid var(--md-sys-color-outline);
    padding: 0;
}
.logout-button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font: inherit;
    width: 100%;
    text-align: left;
}
.logout-button:hover {
    color: var(--md-sys-color-primary);
}
.auth-bar {
    position: fixed;
    bottom: 16px;
    right: 16px;
    background: var(--md-sys-color-surface);
    padding: 8px 12px;
    border-radius: 24px;
    font-size: 0.9rem;
}
.auth-bar a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
}
.auth-bar a:hover {
    text-decoration: underline;
}

/* ========== Upload Page ========== */
.dropzone {
    border: 2px dashed var(--md-sys-color-outline);
    border-radius: 12px;
    padding: 48px;
    text-align: center;
    cursor: pointer;
    background: var(--md-sys-color-surface);
}
.dropzone.dragover {
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-surface-variant);
}
.file-list {
    margin-top: 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}
.file-item {
    background: var(--md-sys-color-surface);
    border-radius: 8px;
    overflow: hidden;
}
.file-item .thumbnail {
    aspect-ratio: 1;
    background: var(--md-sys-color-surface-variant);
}
.file-item .meta-btn {
    width: 100%;
    padding: 8px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    cursor: pointer;
}
.file-item .meta-btn.completed {
    background: var(--color-safe);
    color: var(--md-sys-color-on-primary);
    cursor: default;
}
.file-item .meta-btn.auto-completed {
    background: var(--color-auto);
    color: var(--md-sys-color-on-primary);
    cursor: default;
}
.file-item .meta-btn.already-exists {
    background: var(--color-exists);
    color: var(--md-sys-color-on-primary);
    cursor: default;
}
.section {
    border-top: 1px solid var(--md-sys-color-outline);
    padding-top: 1rem;
}
.section h3 {
    margin-bottom: 12px;
    font-size: 1rem;
    font-weight: 500;
}

.upload-columns {
    display: flex;
    gap: 16px;
    width: 100%;
    margin-top: 1.5rem;
}
.upload-column {
    flex: 1;
    min-width: 0;
    width: 33.33%;
}
.upload-column .upload-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

/* Batch progress */
.batch-progress {
    margin: 12px 0;
    padding: 12px 16px;
    background: var(--md-sys-color-surface);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}
.batch-progress .batch-bar {
    flex: 1;
}

/* Upload progress bar */
.upload-progress {
    padding: 8px;
}
.progress-track {
    width: 100%;
    height: 6px;
    background: var(--md-sys-color-surface-variant);
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: var(--md-sys-color-primary);
    transition: width 0.3s ease;
    width: 0%;
    border-radius: 3px;
}

/* Visual match purple button */
.file-item .meta-btn.visual-match {
    background: var(--color-custom);
    color: var(--md-sys-color-on-primary);
}

/* Visual match info in modal */
.visual-match-info {
    background: var(--md-sys-color-surface-variant);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    border-left: 4px solid var(--color-custom);
}
.visual-match-info .match-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.visual-match-info .match-thumb {
    width: 64px;
    height: 64px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}
.visual-match-info .match-details {
    font-size: 0.85rem;
}
.visual-match-info .match-details strong {
    color: var(--color-custom);
}
.visual-match-info .similarity-badge {
    display: inline-block;
    background: var(--color-custom);
    color: var(--md-sys-color-on-primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}
.visual-match-group {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--md-sys-color-outline);
}
.visual-match-group .group-label {
    font-size: 0.8rem;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 6px;
}
.visual-match-group .group-members {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.visual-match-group .group-member {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}
.visual-match-group .group-member:hover {
    border-color: var(--md-sys-color-primary);
}
.visual-match-group .group-member img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* iqdb results modal */
.iqdb-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}
.iqdb-match-card {
    display: flex;
    flex-direction: column;
    background: var(--md-sys-color-surface-variant);
    border-radius: 8px;
    overflow: hidden;
}
.iqdb-match-card .gallery-item {
    border-radius: 0;
}
.iqdb-match-card .iqdb-download-btn {
    width: 100%;
    padding: 6px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.iqdb-match-card .iqdb-download-btn:hover {
    background: var(--ctp-mocha-pink);
}
.iqdb-match-card .iqdb-download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.iqdb-match-card .iqdb-download-btn.downloaded {
    background: var(--color-safe);
    cursor: default;
}

/* Mobile: stack columns, 2-grid per container */
@media (max-width: 700px) {
    .upload-columns {
        flex-direction: column;
        gap: 0;
    }
    .upload-column {
        width: 100%;
    }
    .upload-column .upload-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .iqdb-results {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* ========== Modal ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.modal-content {
    background: var(--md-sys-color-surface);
    padding: 24px;
    border-radius: 12px;
    width: 500px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}
.close {
    float: right;
    font-size: 24px;
    cursor: pointer;
}
.tab-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.tab-btn {
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
}
.tab-btn.active {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}
.modal-preview {
    text-align: center;
    margin-bottom: 16px;
}
.modal-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    object-fit: contain;
    background: var(--md-sys-color-surface-variant);
}

/* ========== Delete Page ========== */
.delete-container {
    max-width: 800px;
    margin: 0 auto;
}
.delete-container textarea {
    width: 100%;
    min-height: 120px;
    font-family: monospace;
}

.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin: 16px 0;
}
.folder-card {
    background: var(--md-sys-color-surface-variant);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.folder-card .folder-icon {
    font-size: 24px;
    color: var(--ctp-mocha-text);
    margin-bottom: 4px;
}
.folder-card .folder-name {
    font-weight: 600;
    font-size: 14px;
}
.folder-card .folder-count {
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
}
.folder-card .folder-size {
    font-size: 13px;
    margin-bottom: 8px;
}
.folder-card .btn-clear {
    background: var(--ctp-mocha-red);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 14px;
    font-size: 12px;
    cursor: pointer;
}
.folder-card .btn-clear:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.library-info {
    background: var(--md-sys-color-surface);
    border-radius: 10px;
    padding: 12px 16px;
    margin-top: 12px;
    font-size: 13px;
    line-height: 1.6;
}

/* ========== Duplicates Page ========== */
.duplicate-set {
    background: var(--md-sys-color-surface);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}
.duplicate-files {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 12px;
}
.duplicate-file-item {
    width: 150px;
    position: relative;
}
.duplicate-file-item .delete-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    z-index: 1;
}
.visual-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}
.similarity-badge {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.7rem;
    margin-top: 4px;
    text-align: center;
}
.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.close-group-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--md-sys-color-error);
}
.threshold-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 1em 0;
}
#similarity-threshold {
width: 200px;
}
.delete-btn {
    background: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    padding: 6px 10px;
}

/* ========== Statistics Page ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}
.card {
    background: var(--md-sys-color-surface);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.log-card {
    grid-column: 1 / -1;
}
.log-container {
    background: var(--ctp-mocha-crust);
    color: var(--ctp-mocha-text);
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    padding: 12px;
    border-radius: 8px;
    height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}
.log-container pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th,
td {
    text-align: left;
    padding: 4px 0;
    border-bottom: 1px solid var(--md-sys-color-outline);
}
.error {
    color: var(--md-sys-color-error);
}
.badge.badge-stats{
    color: var(--ctp-mocha-text);
    background-color: var(--ctp-mocha-mauve);
}

/* ========== Avatar Picker ========== */
.avatar-option {
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
}
.avatar-option.selected {
    border: 3px solid var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px rgba(var(--ctp-mocha-mauve), 0.3);
}

/* ========== Pool Cards ========== */
.pool-card {
    cursor: pointer;
}
.pool-thumbnail .loading-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--md-sys-color-surface-variant);
}
.no-preview {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
}
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--md-sys-color-on-surface-variant);
}

/* ========== Admin Overrides ========== */
body.django-admin {
    background: var(--md-sys-color-background);
    color: var(--md-sys-color-on-surface);
}
#header {
background: var(--md-sys-color-surface);
border-bottom: 1px solid var(--md-sys-color-outline);
padding: 16px 24px;
display: flex;
justify-content: space-between;
align-items: center;
}
#branding h1 a {
color: var(--md-sys-color-primary);
text-decoration: none;
font-size: 1.5rem;
font-weight: 500;
}
#user-tools {
font-size: 0.875rem;
display: flex;
gap: 12px;
align-items: center;
}
#user-tools a,
#user-tools button {
background: none;
border: none;
color: var(--md-sys-color-primary);
cursor: pointer;
font: inherit;
padding: 0;
}
#user-tools a:hover,
#user-tools button:hover {
text-decoration: underline;
}
div.breadcrumbs {
    background: var(--md-sys-color-surface-variant);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.875rem;
    margin: 16px 24px;
}
div.breadcrumbs a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
}
.module {
    background: var(--md-sys-color-surface);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 24px;
}
.module h2,
.module caption {
    background: var(--md-sys-color-surface-variant);
    padding: 12px 16px;
    font-weight: 500;
}
.module table {
    width: 100%;
    border-collapse: collapse;
}
.module th,
.module td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--md-sys-color-outline);
}
.module th {
    text-align: left;
    font-weight: 500;
    background: var(--md-sys-color-surface-variant);
}
.module tr:hover {
    background: var(--md-sys-color-surface-variant);
}
.button,
input[type="submit"],
.submit-row input {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
}
.button:hover,
input[type="submit"]:hover,
.submit-row input:hover {
    background: var(--ctp-mocha-pink);
}
a.addlink,
a.changelink,
a.deletelink {
    color: var(--md-sys-color-primary);
    text-decoration: none;
}
.errornote {
    background: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 16px;
}
.login #container {
    align-items: center;
    justify-content: center;
}
.login #content {
    max-width: 400px;
    margin: 40px auto;
    background: var(--md-sys-color-surface);
    padding: 24px;
    border-radius: 28px;
}
.login .form-row {
    margin-bottom: 16px;
}
.login label {
    display: block;
    margin-bottom: 4px;
}
.login input[type="text"],
.login input[type="password"] {
    width: 100%;
    padding: 8px;
    background: var(--md-sys-color-surface-variant);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    color: var(--md-sys-color-on-surface);
}

/* ========== Blacklisted follows ========== */
.gallery-item.blacklisted .thumbnail img,
.gallery-item.blacklisted .thumbnail video,
.gallery-item.blacklisted .thumbnail .no-preview { display: none; }
.gallery-item.blacklisted .thumbnail {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--md-sys-color-surface-variant);
}
.blacklisted-overlay {
    color: var(--ctp-mocha-red);
    font-weight: 700;
    font-size: 13px;
    text-align: center;
    padding: 8px;
}

/* ========== HTMX ========== */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: block; }
.htmx-request.htmx-indicator { display: block; }

/* ========== Home Page ========== */
.home-hero {
    background: var(--md-sys-color-surface);
    border-radius: 16px;
    padding: 48px 32px;
    text-align: center;
    margin-bottom: 24px;
    border: 1px solid var(--md-sys-color-outline);
}
.home-hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--md-sys-color-primary);
    margin-bottom: 12px;
}
.home-hero p {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 1.1rem;
    max-width: 640px;
    margin: 0 auto 8px auto;
}
.home-hero .home-hero-sub {
    font-size: 0.95rem;
    max-width: 560px;
}
.home-hero-actions {
    margin-top: 24px;
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}
.btn-primary {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 24px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-primary:hover {
    background: var(--ctp-mocha-pink);
}
.btn-secondary {
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 24px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-secondary:hover {
    background: var(--md-sys-color-outline);
}

.home-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--md-sys-color-surface);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--md-sys-color-outline);
}
.stat-card i {
    font-size: 1.5rem;
    color: var(--md-sys-color-primary);
}
.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
}
.stat-label {
    font-size: 0.8rem;
    color: var(--md-sys-color-on-surface-variant);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.home-section {
    margin-bottom: 32px;
}
.home-section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 16px;
}
.home-section-header h2 {
    font-size: 1.3rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}
.home-section-link {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.pack-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}
.pack-card {
    background: var(--md-sys-color-surface);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--md-sys-color-outline);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}
.pack-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}
.pack-card-thumb {
    aspect-ratio: 16 / 9;
    background: var(--md-sys-color-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.pack-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.pack-card-body {
    padding: 12px 16px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}
.pack-card-body h3 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}
.pack-card-author {
    font-size: 0.8rem;
    color: var(--md-sys-color-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.pack-card-desc {
    font-size: 0.85rem;
    color: var(--md-sys-color-on-surface-variant);
    flex: 1;
}
.pack-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--md-sys-color-on-surface-variant);
}
.pack-card-version,
.pack-card-downloads {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.how-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.how-card {
    background: var(--md-sys-color-surface);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--md-sys-color-outline);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.how-card i {
    font-size: 1.5rem;
    color: var(--md-sys-color-primary);
}
.how-card h3 {
    font-size: 1rem;
    font-weight: 500;
}
.how-card p {
    font-size: 0.85rem;
    color: var(--md-sys-color-on-surface-variant);
    line-height: 1.5;
}

.home-gate-note {
    background: var(--md-sys-color-surface-variant);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--md-sys-color-on-surface-variant);
}
.home-gate-note i {
    color: var(--md-sys-color-primary);
    font-size: 1.2rem;
}
.home-gate-note code {
    background: var(--md-sys-color-surface);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--md-sys-color-on-surface);
}
