@font-face {
    font-family: 'Berkeley Mono';
    src: url('/static/font/Berkeley Mono.ttf') format('truetype');
}

:root {
    --bg-primary: #0d0e12;
    --bg-secondary: #161820;
    --bg-tertiary: #1e2028;
    --border: #2a2d38;
    --border-hover: #3a3d48;
    --text-primary: #e8e9ed;
    --text-secondary: #8b8d9a;
    --text-muted: #6b6d7e;
    --text-faint: #4a4c58;
    --accent: #9b9db1;
    --accent-hover: #b1b3c4;
    --error: #b07a7a;
    --success: #7a9b8a;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-tertiary: #eaeaec;
    --border: #d8d8dc;
    --border-hover: #c0c0c6;
    --text-primary: #1a1a1c;
    --text-secondary: #5a5a5e;
    --text-muted: #7a7a7e;
    --text-faint: #a0a0a4;
    --accent: #6b6d7e;
    --accent-hover: #4a4c58;
    --error: #c45050;
    --success: #4a8a5a;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Berkeley Mono', monospace;
    font-size: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

code {
    background: var(--bg-tertiary);
    padding: 0.15em 0.35em;
    font-family: inherit;
}

header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

.brand {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.header-actions a {
    color: var(--text-secondary);
}

.header-actions a:hover {
    color: var(--text-primary);
}

.user-info {
    color: var(--text-muted);
}

.header-nav {
    display: flex;
    gap: 0;
    padding: 0 1rem;
}

.header-nav a {
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
}

.header-nav a:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.header-nav a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.theme-switcher {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    background: var(--bg-primary);
}

.theme-switcher button {
    background: none;
    border: none;
    padding: 0.25rem 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.theme-switcher button:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.theme-switcher button.active {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

main {
    display: flex;
    min-height: calc(100vh - 80px);
}

.sidebar {
    width: 200px;
    flex-shrink: 0;
    padding: 1rem;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-section h3 {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.sidebar-search input {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 11px;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-row {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 11px;
    padding: 0.3rem 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

.tag-row:hover {
    background: var(--border);
    border-color: var(--border-hover);
}

.tag-row a {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-row a::before {
    content: "#";
    color: var(--text-muted);
    margin-right: 0.35rem;
}

.tag-row .count {
    color: var(--text-muted);
    font-size: 10px;
    flex-shrink: 0;
}

.sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-links a {
    color: var(--accent);
    font-size: 11px;
}

.content {
    flex: 1;
    padding: 1rem;
    min-width: 0;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.content-header h1 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.content-header .count {
    color: var(--text-muted);
    font-weight: 400;
}

.image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-content: flex-start;
}

.image-thumb {
    display: block;
    width: 150px;
    height: 150px;
    border: 2px solid transparent;
    overflow: hidden;
    background: var(--bg-secondary);
}

.image-thumb:hover {
    border-color: var(--accent);
}

.image-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-thumb.nsfw {
    position: relative;
}

.image-thumb.nsfw img {
    filter: blur(8px);
    image-rendering: pixelated;
    transform: scale(1.1);
    transition: filter 0.2s ease, transform 0.2s ease;
}

.image-thumb.nsfw.revealed img {
    filter: none;
    image-rendering: auto;
    transform: scale(1);
}

.nsfw-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: var(--error);
    padding: 0.25rem 0.5rem;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.image-thumb.nsfw:hover .nsfw-label {
    opacity: 1;
}

.image-thumb.nsfw.revealed .nsfw-label {
    display: none;
}

.image-view {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1rem;
}

.image-container img {
    max-width: 100%;
    max-height: 85vh;
}

.image-info {
    background: var(--bg-secondary);
    padding: 1rem;
    border: 1px solid var(--border);
}

.image-info h3 {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    margin-top: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.image-info h3:first-child {
    margin-top: 0;
}

.info-table {
    width: 100%;
    border: none;
}

.info-table td {
    border: none;
    padding: 0.2rem 0;
    background: transparent;
    font-size: 11px;
    vertical-align: top;
}

.info-table td:first-child {
    color: var(--text-muted);
    width: 45px;
}

.tags-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-chip {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.3rem 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 11px;
}

.tag-chip:hover {
    background: var(--border);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.tag-chip .hash {
    color: var(--text-muted);
}

.tag-chip .count {
    color: var(--text-muted);
    font-size: 10px;
}

.page-form {
    max-width: 500px;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
}

.file-input {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-input input[type="file"] {
    display: none;
}

.file-input-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px dashed var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
}

.file-input-button:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.file-input-name {
    font-size: 11px;
    color: var(--text-muted);
}

.file-input-preview {
    max-width: 300px;
    max-height: 300px;
    border: 1px solid var(--border);
    display: none;
}

.file-input-preview.has-image {
    display: block;
}

.file-input-preview img {
    max-width: 100%;
    max-height: 300px;
    display: block;
}

.hint {
    color: var(--text-muted);
    font-size: 10px;
    margin-top: 0.25rem;
}

input, select {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.checkbox-group label {
    display: inline;
    margin: 0;
    cursor: pointer;
    text-transform: none;
    letter-spacing: normal;
    font-size: 12px;
    color: var(--text-primary);
}

button, .btn {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
}

button:hover, .btn:hover {
    background: var(--border);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-primary);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-danger {
    border-color: var(--error);
    color: var(--error);
}

.btn-danger:hover {
    background: var(--error);
    color: var(--bg-primary);
}

.link-danger {
    color: var(--error);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
}

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

.actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.pagination {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 11px;
}

.pagination a, .pagination span {
    padding: 0.3rem 0.6rem;
}

.pagination span.current {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.pagination span.sep {
    color: var(--text-muted);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

th, td {
    padding: 0.5rem 0.6rem;
    text-align: left;
    border: 1px solid var(--border);
}

th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.05em;
}

td {
    background: var(--bg-primary);
}

.empty {
    color: var(--text-muted);
    font-size: 12px;
}

.error h1 {
    color: var(--error);
}

.content:has(.image-view) {
    padding: 0;
    display: flex;
    flex-direction: column;
}

.image-view {
    display: grid;
    grid-template-columns: 1fr 200px;
    flex: 1;
}

.image-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.image-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-container img {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.image-container img.small-image {
    min-width: 200px;
    min-height: 200px;
    object-fit: contain;
}

.image-container img.tiny-image {
    min-width: 300px;
    min-height: 300px;
    object-fit: contain;
}

.image-sidebar {
    border-left: 1px solid var(--border);
    border-right: none;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 0.2rem 0;
}

.info-row .info-label {
    color: var(--text-muted);
}

.delete-form {
    display: inline-flex;
    align-items: center;
}

.sidebar-links .delete-form {
    line-height: 1.5;
}

button.delete-link {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    min-height: 0;
    color: var(--error);
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    line-height: inherit;
}

button.delete-link:hover {
    background: none;
    color: #d08a8a;
}

.download-options {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.download-options a {
    color: var(--accent);
    font-size: 11px;
}

@media (max-width: 900px) {
    .image-view {
        grid-template-columns: 1fr;
    }
    
    .image-sidebar {
        border-left: none;
        border-top: 1px solid var(--border);
        padding: 1rem;
    }

    .image-container img {
        max-height: 70vh;
    }
}

@media (max-width: 900px) {
    main {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 0.75rem;
    }

    .sidebar-section {
        margin-bottom: 1rem;
    }

    .sidebar-section h3 {
        margin-bottom: 0.4rem;
    }

    .tag-list {
        gap: 0.4rem;
    }

    .sidebar-links {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem 1rem;
    }

    .image-grid {
        gap: 4px;
    }

    .image-thumb {
        width: calc(33.333% - 3px);
        aspect-ratio: 1;
        height: auto;
    }

    .image-view {
        grid-template-columns: 1fr;
    }

    .sort-options,
    .view-options {
        gap: 3px;
    }

    .download-options {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

@media (max-width: 600px) {
    .header-top {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    .header-actions {
        gap: 0.75rem;
        font-size: 11px;
    }

    .header-nav {
        overflow-x: auto;
        padding: 0 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .header-nav::-webkit-scrollbar {
        display: none;
    }

    .header-nav a {
        padding: 0.4rem 0.6rem;
        white-space: nowrap;
    }

    .content {
        padding: 0.75rem;
    }

    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .image-grid {
        gap: 3px;
    }

    .image-thumb {
        width: calc(50% - 2px);
        aspect-ratio: 1;
        height: auto;
    }

    .tags-grid {
        gap: 4px;
    }

    .tag-chip {
        padding: 0.25rem 0.4rem;
        font-size: 10px;
    }

    .page-form {
        max-width: 100%;
    }

    .form-row {
        flex-direction: column;
        align-items: stretch;
    }

    .form-row input,
    .form-row select,
    .form-row button {
        width: 100%;
    }

    .actions {
        flex-wrap: wrap;
    }

    .actions button,
    .actions .btn {
        flex: 1;
        min-width: 0;
        text-align: center;
    }

    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .image-main {
        padding: 0.5rem;
    }

    .image-container img {
        max-height: 60vh;
    }

    .image-sidebar {
        padding: 0.75rem;
    }

    .image-info {
        padding: 0.75rem;
    }

    .stats-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 18px;
    }

    .uploads-chart {
        height: 80px;
        padding-bottom: 30px;
        overflow-x: auto;
        min-width: 100%;
    }

    .chart-bar {
        min-width: 20px;
    }

    .bar-label {
        font-size: 8px;
        bottom: -25px;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .pagination a,
    .pagination span {
        padding: 0.4rem 0.5rem;
    }
}

.autocomplete-wrapper {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-top: none;
    z-index: 1000;
    display: none;
    max-height: 200px;
    overflow-y: auto;
}

.autocomplete-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.5rem;
    cursor: pointer;
    font-size: 11px;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: var(--bg-tertiary);
}

.autocomplete-item .tag-name {
    color: var(--text-primary);
}

.autocomplete-item .tag-count {
    color: var(--text-muted);
    font-size: 10px;
}

.sort-options,
.view-options {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.sort-options a,
.view-options a {
    padding: 0.2rem 0.4rem;
    font-size: 10px;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
}

.sort-options a:hover,
.view-options a:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.sort-options a.active,
.view-options a.active {
    background: var(--bg-tertiary);
    color: var(--accent);
    border-color: var(--accent);
}

code.exclude {
    color: var(--error);
}

.infinite-scroll-sentinel {
    height: 1px;
}

.loading-indicator {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
    font-size: 11px;
}

.stats-page {
    max-width: 900px;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 1rem;
    text-align: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.stats-section {
    margin-bottom: 2rem;
}

.stats-section h2 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.uploads-chart {
    display: flex;
    gap: 4px;
    height: 120px;
    align-items: flex-end;
    padding-bottom: 40px;
    position: relative;
}

.chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    position: relative;
}

.bar-fill {
    width: 100%;
    background: var(--accent);
    position: absolute;
    bottom: 0;
    min-height: 2px;
}

.bar-label {
    position: absolute;
    bottom: -35px;
    font-size: 9px;
    color: var(--text-muted);
    white-space: nowrap;
    transform: rotate(-45deg);
    transform-origin: top left;
}

.bar-value {
    position: absolute;
    top: -18px;
    font-size: 9px;
    color: var(--text-secondary);
}

@media (max-width: 400px) {
    .header-top {
        padding: 0.4rem 0.5rem;
    }

    .brand {
        font-size: 14px;
    }

    .header-actions {
        gap: 0.5rem;
        font-size: 10px;
    }

    .theme-switcher {
        display: none;
    }

    .content {
        padding: 0.5rem;
    }

    .image-thumb {
        width: calc(50% - 1.5px);
    }

    .image-grid {
        gap: 3px;
    }

    .sidebar {
        padding: 0.5rem;
    }

    .tag-row,
    .tag-chip {
        font-size: 10px;
        padding: 0.15rem 0.4rem;
    }

    .stat-card {
        padding: 0.5rem;
    }

    .stat-value {
        font-size: 16px;
    }

    .stat-label {
        font-size: 9px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .header-nav a {
        padding: 0.6rem 0.75rem;
    }

    .tag-row,
    .tag-chip {
        padding: 0.4rem 0.6rem;
    }

    button, .btn {
        padding: 0.5rem 1rem;
        min-height: 44px;
    }

    .pagination a,
    .pagination span {
        padding: 0.5rem 0.75rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .sort-options a,
    .view-options a {
        padding: 0.4rem 0.6rem;
    }

    .autocomplete-item {
        padding: 0.6rem 0.75rem;
    }

    .sidebar-links a {
        padding: 0.3rem 0;
    }

    .image-thumb.nsfw .nsfw-label {
        opacity: 1;
    }
}
