:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242833;
    --bg-hover: #2d3140;
    --text-primary: #e4e6ed;
    --text-secondary: #9ca0ad;
    --text-muted: #6b7084;
    --border: #2d3140;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --danger: #ef4444;
    --success: #22c55e;
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

* { 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;
    overflow-x: hidden;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.header-nav {
    display: flex;
    gap: 4px;
}

.header-nav button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.header-nav button:hover { background: var(--bg-hover); color: var(--text-primary); }
.header-nav button.active { background: var(--accent); color: white; }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.scan-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.scan-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Layout */
.app-layout {
    display: flex;
    height: calc(100vh - 56px);
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    transition: width 0.2s;
}

.sidebar.collapsed { width: 48px; overflow: hidden; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 12px 8px; }

.sidebar-toggle { flex-shrink: 0; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.sidebar-content { padding: 12px; }

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.tag-filter-mode {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}

/* Tags */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: 1.5px solid transparent;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    transition: all 0.15s;
}

.tag-pill:hover { transform: translateY(-1px); }
.tag-pill.selected { border-color: transparent; }

.tag-pill-untagged {
    border: 1.5px dashed var(--text-muted);
    color: var(--text-muted);
}
.tag-pill-untagged.selected {
    background: var(--text-muted);
    color: white;
    border-style: solid;
}

.tag-count {
    font-size: 10px;
    opacity: 0.7;
    background: rgba(255,255,255,0.15);
    padding: 0 5px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.tag-removable {
    cursor: default;
}

.tag-removable button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 16px;
    padding: 0 2px;
    opacity: 0.7;
    line-height: 1;
}

.tag-removable button:hover { opacity: 1; }

.location-pill {
    background: var(--bg-tertiary);
    border-color: var(--text-muted);
}

.mini-tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 10px;
    color: white;
    font-weight: 500;
}

/* Locations sidebar */
.location-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 12px;
}

.location-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-secondary);
    text-align: left;
    width: 100%;
    transition: all 0.15s;
}

.location-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.location-item.selected { background: var(--accent); color: white; }

.location-row {
    display: flex;
    align-items: center;
    gap: 2px;
}

.location-row .location-item { flex: 1; min-width: 0; }

.location-edit-btn {
    opacity: 0;
    transition: opacity 0.15s;
    color: var(--text-muted);
    flex-shrink: 0;
}

.location-row:hover .location-edit-btn { opacity: 1; }
.location-edit-btn:hover { color: var(--text-primary); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.15s;
}

.btn:hover { background: var(--bg-hover); border-color: var(--text-muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 6px; background: none; border: none; }
.btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 12px;
    flex: 1;
    min-width: 200px;
}

.search-box input {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 8px 0;
    font-size: 13px;
    width: 100%;
    outline: none;
}

.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.toolbar-filters {
    display: flex;
    gap: 8px;
    align-items: center;
}

.toolbar-filters input[type="date"],
.toolbar-filters select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 7px 10px;
    border-radius: var(--radius);
    font-size: 12px;
}

.toolbar-info {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* File Grid */
.file-grid-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.file-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}

.file-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.file-thumb {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-duration {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0,0,0,0.75);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.file-info {
    padding: 10px 12px;
}

.file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.file-meta {
    display: flex;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

.file-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

/* Selection */
.file-card-selected {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

.file-checkbox {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
}

.file-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Bulk Action Bar */
.bulk-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--accent);
    color: white;
    font-size: 13px;
    gap: 12px;
    flex-wrap: wrap;
}

.bulk-bar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.bulk-bar-info .btn {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.3);
    color: white;
}

.bulk-bar-info .btn:hover {
    background: rgba(255,255,255,0.3);
}

.bulk-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bulk-select {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 5px 10px;
    border-radius: var(--radius);
    font-size: 12px;
}

.bulk-select option { color: black; }

.bulk-divider {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,0.3);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
    gap: 12px;
}

.empty-state p { font-size: 15px; }
.empty-hint { font-size: 13px !important; }

/* Timeline */
.timeline-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    font-size: 12px;
    color: var(--text-muted);
}

.timeline-toolbar input[type="date"] {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 12px;
}

.timeline-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.timeline-group {
    margin-bottom: 28px;
}

.timeline-month {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--accent);
    display: inline-block;
}

.timeline-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.timeline-item {
    display: flex;
    gap: 10px;
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
}

.timeline-item:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}

.timeline-item img {
    width: 100px;
    height: 56px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.timeline-item-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

/* Map */
.map-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    font-size: 12px;
    color: var(--text-muted);
}

.map-view-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
}

.map-container {
    flex: 1;
    min-height: 500px;
    width: 100%;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 1100px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.modal-header-actions a { text-decoration: none; }

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-body {
    padding: 20px;
}

.modal-lg .modal-body {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
}

/* Player */
.player-container {
    border-radius: var(--radius);
    overflow: hidden;
    background: black;
}

.video-js {
    width: 100%;
    border-radius: var(--radius);
}

/* Detail Panel */
.file-detail-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.detail-section h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}

.detail-row span:first-child { color: var(--text-secondary); flex-shrink: 0; }

.detail-path {
    word-break: break-all;
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
    max-width: 200px;
}

.detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.date-edit {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.date-edit input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 7px 10px;
    border-radius: var(--radius);
    font-size: 12px;
    width: 100%;
}

.date-source {
    font-size: 11px;
    color: var(--text-muted);
}

.tag-add-row {
    display: flex;
    gap: 6px;
}

.tag-add-row select {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 8px;
    border-radius: var(--radius);
    font-size: 12px;
}

/* Form */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
}

.form-group input:focus { border-color: var(--accent); }

.color-picker {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s;
}

.color-swatch.selected { border-color: white; transform: scale(1.15); }

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 200px; }
    .toolbar-filters { display: none; }
    .file-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .modal-lg .modal-body { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .sidebar { position: fixed; left: 0; top: 56px; bottom: 0; z-index: 50; }
    .sidebar.collapsed { width: 0; border: none; }
}
