:root {
    --bg: #111;
    --surface: #222;
    --surface-hover: #333;
    --text: #eee;
    --text-muted: #aaa;
    --accent: #3498db;
    --danger: #e74c3c;
    --border: #444;
    --fav: #e74c3c;
    --overlay: rgba(0, 0, 0, 0.85);
    --shadow: rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
    --bg: #e2e5e9;
    --surface: #f1f3f6;
    --surface-hover: #e8eaed;
    --text: #2c3e50;
    --text-muted: #6c7a89;
    --border: #d1d5da;
    --overlay: rgba(226, 229, 233, 0.9);
    --shadow: rgba(0, 0, 0, 0.08);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s, color 0.3s;
    overflow-y: scroll;
    scroll-behavior: smooth;
}

.hidden-default { display: none; }
.visible-default { display: block; }
.contents-display { display: contents; }
.m-0 { margin: 0; }
.mb-10 { margin-bottom: 10px; }
.flex-grow-1 { flex-grow: 1; }
.position-relative { position: relative; }
.text-muted { color: var(--text-muted); }
.dir-ltr { direction: ltr; }
.dir-rtl { direction: rtl; }
.ml-5 { margin-left: 5px; }

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 899;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(3px);
}

.mobile-nav-item {
    display: contents; 
}

.stats-text-mobile-only,
.mobile-text-only {
    display: none;
}

.topbar {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface);
    box-shadow: 0 2px 10px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 900;
    gap: 15px;
    overflow: visible;
    view-transition-name: topbar;
}

::view-transition-group(topbar) {
    animation: none;
}

.topbar-right {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
    min-width: max-content;
}

.topbar-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 250px;
}

.topbar-left {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
    min-width: max-content;
}

.hamburger-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
}

.hamburger-btn:hover {
    background: var(--surface-hover);
}

.gallery-title {
    width: 75px;
    margin: -15px 0;
    white-space: nowrap;
    cursor: pointer;
}

.user-area-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-right: 10px;
}

input:focus,
textarea:focus {
    background: var(--bg) !important;
    color: var(--text) !important;
    outline: 1px solid var(--accent);
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--bg) inset !important;
    -webkit-text-fill-color: var(--text) !important;
    transition: background-color 5000s ease-in-out 0s;
}

.input-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.input-wrapper input[type="text"],
.input-wrapper textarea {
    width: 100%;
    padding: 10px 35px 10px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: 0.3s;
    box-sizing: border-box;
    font-family: inherit;
}

.input-wrapper textarea {
    resize: none;
    overflow: hidden;
    min-height: 42px;
}

.clear-btn {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    display: none;
    user-select: none;
    line-height: 1;
    z-index: 2;
    padding: 5px;
    transition: left 0.3s;
}

.clear-btn:hover {
    color: var(--danger);
}

.input-wrapper textarea+.clear-btn {
    top: 10px;
    transform: none;
}

.tags-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    min-height: 42px;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 15px;
    transition: 0.3s;
    cursor: text;
    position: relative;
}

.tags-wrapper:focus-within {
    border-color: var(--accent);
}

.tag-pill {
    background: rgba(52, 152, 219, 0.15);
    border: 1px solid rgba(52, 152, 219, 0.4);
    border-radius: 15px;
    padding: 4px 10px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
}

.tag-pill .remove-tag {
    cursor: pointer;
    color: var(--text-muted);
    font-weight: bold;
    font-size: 16px;
    line-height: 1;
    transition: 0.2s;
}

.tag-pill .remove-tag:hover {
    color: var(--danger);
}

.tag-input-field {
    border: none;
    background: transparent;
    color: var(--text);
    outline: none;
    flex-grow: 1;
    min-width: 80px;
    padding: 4px;
    font-family: inherit;
}

.autocomplete-list {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: calc(100% - 20px);
    max-height: 150px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 15px var(--shadow);
    top: 100%;
    left: 10px;
    display: none;
}

.autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text);
    font-size: 13px;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: var(--surface-hover);
    color: var(--accent);
}

button {
    cursor: pointer;
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 14px;
    transition: 0.2s;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
    flex-shrink: 0;
}

button:hover {
    background: var(--surface-hover);
}

.btn-accent {
    background: var(--accent);
    color: white;
    border: none;
}

.btn-accent:hover {
    background: #2980b9;
}

.btn-accent:disabled {
    background: #555;
    color: #888;
    cursor: not-allowed;
    border: none;
}

.submit-add-btn {
    width: 100%;
    justify-content: center;
}

.submit-add-btn.uploading:disabled {
    color: white !important;
    cursor: wait !important;
}

.custom-dropdown {
    position: relative;
    user-select: none;
}

.custom-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    color: var(--text);
    transition: 0.3s;
    white-space: nowrap;
}

.custom-dropdown-header svg {
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.custom-dropdown.open .custom-dropdown-header svg {
    transform: rotate(180deg);
}

.custom-dropdown-options {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 15px var(--shadow);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform-origin: top;
    overflow: hidden;
    min-width: 100%;
    white-space: nowrap;
}

.custom-dropdown.open .custom-dropdown-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.custom-dropdown-options div {
    padding: 10px 15px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-size: 14px;
}

.custom-dropdown-options div:hover {
    background: var(--surface-hover);
    color: var(--accent);
}

.search-bar-integrated {
    display: flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    height: 42px;
    position: relative;
    width: 100%;
    max-width: 380px;
    transition: 0.3s;
    flex-shrink: 1;
}

.search-bar-integrated:focus-within {
    border-color: var(--accent);
}

.search-bar-integrated .custom-dropdown-header {
    height: 100%;
    padding: 0 10px 0 15px;
    border-left: 1px solid var(--border);
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: max-content;
}

.search-bar-integrated .custom-dropdown-options {
    right: 0;
    min-width: 150px;
}

.search-bar-integrated input[type="text"] {
    border: none;
    background: transparent;
    height: 100%;
    flex-grow: 1;
    color: var(--text);
    outline: none;
    padding: 0 35px 0 10px;
    width: 100%;
    transition: padding 0.3s;
}

.styled-select-header {
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    height: 42px;
    box-sizing: border-box;
    font-size: 14px;
    white-space: nowrap;
}

.size-controls {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    height: 42px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.size-btn {
    background: transparent;
    border: none;
    padding: 5px 10px;
    height: 100%;
    border-radius: 5px;
    color: var(--text-muted);
    transition: 0.2s;
}

.size-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.size-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.size-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.icon-action {
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    transition: 0.3s;
    margin: 0 5px;
    flex-shrink: 0;
}

.icon-action:hover {
    color: var(--accent);
    transform: scale(1.1);
}

.icon-action svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: 0.3s;
}

.fav-filter-icon {
    margin: 0;
}

.fav-filter-icon:hover {
    color: var(--fav);
}

.fav-filter-icon.active {
    color: var(--fav);
}

.fav-filter-icon.active svg {
    fill: currentColor;
}

#backToTop {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--surface);
    color: var(--text);
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
    z-index: 99;
    box-shadow: 0 4px 10px var(--shadow);
    border: 1px solid var(--border);
}

#backToTop.visible {
    opacity: 1;
    pointer-events: auto;
}

#backToTop:hover {
    background: var(--accent);
    color: white;
}

::view-transition-group(*) {
    animation-duration: 0.4s;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

::view-transition-old(lightbox-hero),
::view-transition-new(lightbox-hero) {
    animation-duration: 0.35s;
    animation-timing-function: cubic-bezier(0.25, 1, 0.5, 1);
}

@media (max-width: 1150px) {
    .topbar { padding: 10px 15px; gap: 10px; }
    .topbar-right, .topbar-left { min-width: auto; gap: 8px; }
    .search-bar-integrated { max-width: 320px; }
    button { padding: 8px 12px; font-size: 13px; }
}

@media (max-width: 900px) {
    .topbar { flex-wrap: wrap; }
    .topbar-center { order: 3; flex: 100%; min-width: 100%; margin-top: 5px; }
    .search-bar-integrated { max-width: 100%; }
}

.fav-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: bold;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 10;
    border: 1px solid var(--surface);
}

.fav-filter-icon:hover .fav-badge:not([data-count="0"]),
.fav-badge.show:not([data-count="0"]) {
    opacity: 1;
}

.lb-share-wrapper {
    position: relative;
    display: inline-flex;
}

.lb-share-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 15px var(--shadow);
    display: flex;
    flex-direction: column;
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 1001;
    overflow: hidden;
}

.lb-share-wrapper:hover .lb-share-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lb-share-item {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.lb-share-item svg {
    flex-shrink: 0;
}

.lb-share-item:hover {
    background: var(--surface-hover);
    color: var(--accent);
}