:root {
    --bg-primary: #f3f4f6;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f9fafb;
    --bg-input: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --accent: #c7d245;
    --accent-dark: #a0ab24;
    --accent-hover: #b5c03e;
    --accent-bg: rgba(199, 210, 69, 0.12);
    --gradient: linear-gradient(20deg, #c7d245 0%, #a0ab24 100%);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--gradient);
    padding: 18px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(160, 171, 36, 0.25);
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,0.25);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #fff;
    font-weight: 700;
    backdrop-filter: blur(4px);
}

/* Search */
.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 180px;
    max-width: 420px;
}

.search-input {
    width: 100%;
    padding: 7px 12px 7px 34px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.search-input:focus {
    border-color: var(--accent-dark);
}

.search-input::placeholder { color: var(--text-muted); }

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
}

.stats-bar {
    display: flex;
    gap: 16px;
    align-items: center;
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    white-space: nowrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-number {
    font-weight: 700;
    color: #ffffff;
}

.sync-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.sync-btn:hover {
    background: rgba(255,255,255,0.3);
}

.sync-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.sync-icon {
    font-size: 14px;
    display: inline-block;
}

.sync-btn.syncing .sync-icon {
    animation: spin 1s linear infinite;
}

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 28px;
}

.login-logo { margin-bottom: 18px; color: var(--text-primary); }
.login-logo .logo-icon { background: var(--gradient); color: #fff; }

.login-card h1 {
    font-size: 22px;
    margin-bottom: 8px;
}

.login-lead {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.45;
    margin-bottom: 18px;
}

.login-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.login-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 15px;
    margin-bottom: 14px;
    background: var(--bg-input);
    color: var(--text-primary);
}

.login-error {
    color: #b91c1c;
    font-size: 13px;
    margin-bottom: 12px;
}

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

.users-modal { max-width: 520px; position: relative; }

.users-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.users-modal .modal-body {
    padding: 8px 24px 24px;
}

.users-modal .login-lead {
    margin-bottom: 16px;
}

.user-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.user-form .login-input,
.user-form .sort-select {
    width: 100%;
    margin: 0;
    padding: 10px 40px 10px 12px;
    font-size: 14px;
}

.user-form .login-input {
    padding-right: 12px;
}

.user-form .finder-btn {
    width: 100%;
    justify-content: center;
    margin-top: 4px;
}

.dropbox-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-primary);
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-list { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

.user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.user-role {
    display: inline-block;
    margin-left: 8px;
    color: var(--text-muted);
    font-size: 12px;
}

.user-delete {
    border: 1px solid var(--border-color);
    background: transparent;
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
    color: #b91c1c;
    flex-shrink: 0;
}

.user-delete:disabled {
    color: var(--text-muted);
    cursor: default;
}

/* Layout */
.main-layout {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    gap: 0;
    min-height: calc(100vh - 73px);
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    height: calc(100vh - 73px);
    position: sticky;
    top: 73px;
}

.sidebar-section {
    margin-bottom: 28px;
}

.sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 0 8px;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-size: 14px;
    color: var(--text-secondary);
}

.filter-item:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.filter-item.pinned {
    font-weight: 650;
    margin-bottom: 6px;
}

.filter-item.active {
    background: var(--accent-bg);
    color: var(--accent-dark);
    font-weight: 600;
}

.filter-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.filter-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

/* Content */
.content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.results-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

.results-count {
    font-size: 14px;
    color: var(--text-secondary);
}

.results-count span {
    font-weight: 700;
    color: var(--text-primary);
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 4px 0 18px;
}

#pagination-bottom {
    margin: 22px 0 8px;
}

.page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

.page-btn.edge {
    padding: 0 14px;
}

.page-btn.active {
    background: var(--gradient);
    border-color: transparent;
    color: #fff;
    font-weight: 700;
}

.page-btn:hover:not(:disabled):not(.active) {
    border-color: var(--accent-dark);
}

.page-btn:disabled {
    color: var(--text-muted);
    cursor: default;
    background: var(--bg-primary);
}

.page-gap {
    color: var(--text-muted);
    padding: 0 2px;
}

.sort-select {
    background-color: var(--bg-secondary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 10px 7px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 40px 8px 16px;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

/* Image Grid */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.image-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    box-shadow: var(--shadow);
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.image-card-thumb {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    display: block;
    background: var(--bg-primary);
}

.image-card-info {
    padding: 12px;
}

.image-card-name {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
}

.image-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
}

.tag-ki {
    background: var(--accent-bg);
    color: var(--accent-dark);
}

.tag-iptc {
    background: rgba(34, 197, 94, 0.1);
    color: #15803d;
}

.tag-manual {
    background: rgba(249, 115, 22, 0.1);
    color: #c2410c;
}

.category-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-primary);
    color: var(--text-secondary);
}

/* Detail Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 90%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px rgba(0,0,0,0.15);
}

.modal-image-banner {
    position: relative;
    width: 100%;
    height: 180px;
    overflow: hidden;
    border-radius: 16px 16px 0 0;
    background: var(--bg-primary);
}

.modal-image-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255,255,255,0.9);
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.modal-close:hover {
    background: #ffffff;
    color: var(--text-primary);
}

.modal-header {
    padding: 16px 24px 0 24px;
    border-bottom: none;
}

.modal-body {
    display: block;
}

.modal-details {
    padding: 12px 24px 24px 24px;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-grid-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.detail-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.detail-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.detail-value {
    font-size: 14px;
    color: var(--text-primary);
    word-break: break-all;
}

.detail-path {
    font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    background: var(--bg-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    word-break: break-all;
    overflow-wrap: anywhere;
}

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    margin-bottom: 8px;
}

.finder-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--gradient);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s, box-shadow 0.15s;
}

.finder-btn:hover {
    opacity: 0.9;
    box-shadow: 0 2px 8px rgba(160, 171, 36, 0.3);
}

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

.project-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.project-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state-text {
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-dark);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .stats-bar { display: none; }
}

@media (max-width: 600px) {
    .image-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
    .results-header { flex-wrap: wrap; }
    .results-tools { flex-basis: 100%; }
    .search-wrapper { max-width: none; }
}
