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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --surface-dark: #0d1018;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #e1ebf7;
    --border: #334155;
    --success: #10b981;
    --danger: #ef4444;
    --rating-s: #ffd700;
    --rating-a: #1fe553;
    --rating-b: #cd7f32;
    --status-planned: #3b82f6;
    --status-in-progress: #f59e0b;
    --status-completed: #10b981;
    --status-dropped: #ef4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* Header */
header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.header-left {
    flex: 1;
}

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

.header-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

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

.username-display {
    color: var(--text-secondary);
    font-weight: 500;
}

.logout-btn {
    padding: 0.5rem 1rem;
    background: var(--surface-light);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: var(--danger);
    border-color: var(--danger);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), #ffffff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Search Container */
.search-container {
    position: relative;
    width: 300px;
}

#omdbSearch {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

#omdbSearch:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-results {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 1000;
}

.search-result-item {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

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

.search-result-item:hover {
    background: var(--surface-light);
}

.search-result-poster {
    width: 50px;
    height: 75px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--background);
    flex-shrink: 0;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.search-loading,
.search-error,
.search-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
}

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

.search-cache-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--success);
    color: white;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

/* Local Search and Want to Revisit Row */
.search-filter-row {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.5rem;
    align-items: flex-end;
}

.local-search-group {
    flex: 0 1 600px;
    min-width: 0;
    max-width: 600px;
}

.local-search-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
}

.local-search-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s;
}

.local-search-group input:focus {
    outline: none;
    border-color: var(--primary-hover);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.revisit-filter-group {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    padding-bottom: 0.5rem;
}

/* Add Media Form */
.media-form {
    background: var(--surface);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.media-form h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.poster-preview {
    max-width: 300px;
    width: 100%;
    height: auto;
    border-radius: 8px;
    border: 2px solid var(--border);
    display: block;
    margin-bottom: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

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

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
}

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

.btn-danger {
    background: var(--danger);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-edit {
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.btn-complete {
    background: var(--success);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-complete:hover {
    background: #059669;
}

/* Filters */
.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: flex-end;
    background: var(--surface);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.filter-group {
    flex: 1;
    min-width: 180px;
}

.add-button-group {
    flex: 0 0 auto;
    min-width: auto;
}

.add-button-group .btn {
    white-space: nowrap;
}

.filter-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
}

.filter-group select,
.filter-group input {
    width: 100%;
    padding: 0.5rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* Media Grid */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

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

.media-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.media-poster {
    width: 100%;
    height: 350px;
    object-fit: contain;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.no-poster {
    width: 100%;
    height: 350px;
    background: linear-gradient(135deg, var(--surface-light), var(--surface));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 3rem;
}

.media-content {
    padding: 1rem;
}

.media-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.media-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.media-rating {
    font-size: 1.25rem;
    font-weight: bold;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    background: var(--surface-light);
    flex-shrink: 0;
}

.media-rating.tier-s {
    background: var(--rating-s);
    color: #000;
}

.media-rating.tier-a {
    background: var(--rating-a);
    color: #000;
}

.media-rating.tier-b {
    background: var(--rating-b);
    color: #000;
}

.media-type {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--primary-color);
    color: white;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    margin-right: 0.5rem;
}

.media-release-year {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--surface-dark);
    color: var(--text-tertiary);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    margin-right: 0.5rem;
}

.media-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.media-status.status-planned {
    background: var(--status-planned);
    color: white;
}

.media-status.status-in-progress {
    background: var(--status-in-progress);
    color: white;
}

.media-status.status-completed {
    background: var(--status-completed);
    color: white;
}

.media-status.status-dropped {
    background: var(--status-dropped);
    color: white;
}

.media-status.media-revisit {
    background: #8b5cf6;
    color: white;
}

.media-status.media-completion-date {
    background: var(--success);
    color: white;
}

.media-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.media-review {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    line-height: 1.5;
    font-style: italic;
    border-left: 3px solid var(--primary-color);
    padding-left: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.media-completion-date-text {
    color: var(--success);
    font-size: 0.75rem;
    margin-bottom: 0.75rem;
    margin-left: 0.75rem;
    font-weight: 500;
}

.media-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tag {
    padding: 0.25rem 0.5rem;
    background: var(--surface-light);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.media-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Watch Link Input Groups */
#watchLinksContainer {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.watch-link-input-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.watch-link-input {
    flex: 1;
}

.btn-remove-link {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-remove-link:hover {
    background: #dc2626;
}

/* Watch Links Container */
.watch-links-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Watch Link Badges */
.watch-link {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    color: white;
    text-align: center;
    transition: all 0.2s;
}

.watch-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.watch-link span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.service-netflix {
    background: #e50914;
}

.service-netflix:hover {
    background: #b20710;
}

.service-youtube {
    background: #ff0000;
}

.service-youtube:hover {
    background: #cc0000;
}

.service-disney {
    background: #113ccf;
}

.service-disney:hover {
    background: #0d2e9e;
}

.service-hbo {
    background: #000000;
    border: 1px solid #8b5cf6;
}

.service-hbo:hover {
    background: #1a1a1a;
}

.service-peacock {
    background: #000000;
    border: 1px solid #fed609;
}

.service-peacock:hover {
    background: #1a1a1a;
}

.service-amazon {
    background: #00a8e1;
}

.service-amazon:hover {
    background: #0086b3;
}

.service-sling {
    background: #414141;
}

.service-sling:hover {
    background: #5f5e5e;
}

.service-britbox {
    background: #1d0a19;
    border: 1px solid #00b6e5;
}
.service-britbox:hover {
    background: #2e1b2a;
}

.service-vimeo {
    background: #141a20;
}

.service-vimeo:hover {
    background: #252b32;
}

.service-generic {
    background: var(--primary-color);
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.empty-state p {
    margin: 0;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--surface-light);
    border: none;
    color: var(--text-primary);
    font-size: 2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.modal-close:hover {
    background: var(--danger);
    transform: rotate(90deg);
}

.modal-body {
    display: flex;
    gap: 2rem;
    padding: 2rem;
}

.modal-poster-container {
    flex: 0 0 300px;
}

.modal-poster {
    width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.modal-info {
    flex: 1;
    min-width: 0;
}

.modal-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    line-height: 1.2;
}

.modal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 1rem;
    color: var(--text-secondary);
}

.modal-meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface-light);
    border-radius: 8px;
}

.modal-meta-label {
    font-weight: 600;
    color: var(--primary-color);
}

.modal-actors {
    margin-bottom: 1.5rem;
}

.modal-actors-label {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    display: block;
}

.modal-actors-list {
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-description {
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 2rem;
    font-size: 1rem;
}

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

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        align-items: stretch;
    }

    .search-container {
        width: 100%;
    }

    header h1 {
        font-size: 2rem;
    }

    .search-filter-row {
        flex-direction: column;
        gap: 0.75rem;
        max-width: 100%;
        align-items: stretch;
        justify-content: flex-start;
    }

    .local-search-group {
        flex: none;
        width: 100%;
        max-width: 100%;
        margin-bottom: 0;
    }

    .local-search-group input {
        font-size: 16px;
    }

    .revisit-filter-group {
        flex: none;
        width: 100%;
        padding-bottom: 0;
        margin-top: 0;
        align-items: flex-start;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .filter-group {
        min-width: 100%;
        width: 100%;
        flex: 1 1 100%;
    }

    .add-button-group {
        order: -1;
        width: 100%;
        min-width: 100%;
    }

    .add-button-group .btn {
        width: 100%;
    }

    .filter-group select,
    .filter-group input {
        font-size: 16px;
    }

    .media-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1rem;
    }

    .form-actions {
        flex-direction: column;
    }

    .modal-body {
        flex-direction: column;
        padding: 1.5rem;
    }

    .modal-poster-container {
        flex: 0 0 auto;
    }

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

    .modal-actions {
        flex-direction: column;
    }
}
