:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
}

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

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.nav {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.nav a {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    transition: color 0.2s;
}

.nav a:hover {
    color: var(--primary-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

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

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

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

/* Cards */
.card {
    background: var(--surface);
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Grid */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

.grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1024px) {
    .grid-cols-4 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {

    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 480px) {

    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
}

/* Collection Card */
.collection-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.collection-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.collection-name {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.collection-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

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

/* Gallery */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.media-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: pointer;
    background: var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.media-item.selected {
    box-shadow: 0 0 0 3px var(--primary-color);
}

.media-checkbox {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s;
}

.media-item:hover .media-checkbox,
.media-item.selected .media-checkbox {
    opacity: 1;
}

.media-checkbox input[type="checkbox"] {
    width: 1.5rem;
    height: 1.5rem;
    cursor: pointer;
    accent-color: var(--primary-color);
    border-radius: 0.25rem;
}

.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.media-item:hover img {
    transform: scale(1.05);
}

.media-item.selected img {
    opacity: 0.8;
}

.selection-overlay {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.media-type-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.75rem;
    border-radius: 0.25rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 0.5rem;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

/* Form */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-family: inherit;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Utilities */
.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.hidden {
    display: none;
}

/* Drag & Drop Upload */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 0.5rem;
    padding: 1rem 2rem;
    text-align: center;
    background: var(--surface);
    transition: all 0.2s;
    cursor: pointer;
    margin-bottom: 2rem;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.upload-zone-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.upload-icon {
    font-size: 1.5rem;
}

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

/* Progress Bar */
.upload-progress {
    margin-top: 1rem;
}

.progress-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s;
}

.progress-status {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.progress-status.success {
    color: var(--success-color);
}

.progress-status.error {
    color: var(--danger-color);
}

/* Detail Modal */
.detail-modal .modal-content {
    max-width: 1200px;
    width: 95%;
}

.detail-container {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 2rem;
    position: relative;
}

@media (max-width: 1024px) {
    .detail-container {
        grid-template-columns: 1fr;
    }
}

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

.detail-image {
    width: 100%;
    border-radius: 0.5rem;
    max-height: 70vh;
    object-fit: contain;
}

.nav-button {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.nav-button:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: translateY(-50%) scale(1.1);
}

.nav-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-button.prev {
    left: -60px;
}

.nav-button.next {
    right: -60px;
}

@media (max-width: 1024px) {
    .nav-button.prev {
        left: 10px;
    }

    .nav-button.next {
        right: 10px;
    }
}

.detail-sidebar {
    overflow-y: auto;
    max-height: 70vh;
}

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

.metadata-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.metadata-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.metadata-label {
    color: var(--text-secondary);
}

.metadata-value {
    font-weight: 500;
    text-align: right;
}

/* Persons Gallery */
.persons-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.persons-container h2 {
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.persons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

.person-card {
    background: var(--surface);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
    display: flex;
    flex-direction: column;
}

.person-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.face-image {
    width: 100%;
    aspect-ratio: 1;
    background: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.face-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.face-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-secondary);
    background: linear-gradient(135deg, #e0e7ff, #f0f4ff);
}

.person-info {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
}

.person-name-input {
    font-size: 1rem;
    font-weight: 600;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color 0.2s;
}

.person-name-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.detection-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.btn-view-detections,
.btn-delete-person,
.btn-view-media,
.btn-back {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-view-detections {
    background: var(--primary-color);
    color: white;
}

.btn-view-detections:hover {
    background: var(--primary-hover);
}

.btn-delete-person {
    background: var(--danger-color);
    color: white;
}

.btn-delete-person:hover {
    background: #dc2626;
}

.btn-view-media {
    background: var(--primary-color);
    color: white;
}

.btn-view-media:hover {
    background: var(--primary-hover);
}

.btn-back {
    background: var(--secondary-color);
    color: white;
    margin-bottom: 1rem;
}

.btn-back:hover {
    background: #475569;
}

/* Detections View */
.detections-view {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.detections-view h2 {
    margin: 1rem 0 2rem;
    color: var(--text-primary);
}

.detections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.detection-card {
    background: var(--surface);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
}

.detection-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.detection-image {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--background);
    overflow: hidden;
}

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

.detection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.detection-box {
    position: absolute;
    border: 2px solid #10b981;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5);
}

.detection-info {
    padding: 1rem;
}

.detection-info p {
    margin: 0.25rem 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.detection-info small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.no-data {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    font-style: italic;
}