:root {
    --primary-color: #fe2c55;
    /* TikTok Red */
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #333333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    color: #000;
    margin-bottom: 30px;
}

.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
}

input[type="text"] {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid #ddd;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

input[type="text"]:focus {
    border-color: var(--primary-color);
}

button {
    padding: 12px 30px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.3s;
}

button:hover {
    opacity: 0.9;
}

.hidden {
    display: none;
}

#loading {
    text-align: center;
    color: #666;
    margin: 20px 0;
}

.answer-box {
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
    border-left: 5px solid var(--primary-color);
}

.answer-box h3 {
    margin-top: 0;
    color: var(--primary-color);
}

.matches-list h3 {
    margin-bottom: 15px;
}

.match-card {
    background-color: var(--card-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 0.9em;
}

.score {
    background-color: #eee;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
}

.video-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: bold;
}

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

/* Source citations */
.source-number {
    background-color: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.9em;
    margin-right: 5px;
}

.source-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.source-link:hover {
    text-decoration: underline;
    opacity: 0.8;
}

/* Highlight animation for scrolled-to source */
.match-card.highlight {
    animation: highlightPulse 2s ease-out;
}

@keyframes highlightPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(254, 44, 85, 0.7);
        transform: scale(1.01);
    }
    50% {
        box-shadow: 0 0 20px 5px rgba(254, 44, 85, 0.3);
    }
    100% {
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
        transform: scale(1);
    }
}

.match-summary {
    margin: 0;
    color: #555;
}

/* Tabs */
.tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    background-color: transparent;
    color: #666;
    border: 2px solid transparent;
    border-radius: 20px;
    padding: 8px 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.tab-btn.active {
    background-color: #fff;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.tab-content.hidden {
    display: none;
}

/* Ingestion Form */
.ingest-box {
    background-color: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.ingest-box h3 {
    margin-top: 0;
    margin-bottom: 20px;
}

.ingest-box input {
    width: 80%;
    padding: 12px 20px;
    border: 2px solid #ddd;
    border-radius: 25px;
    font-size: 16px;
    margin-bottom: 20px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.status-msg {
    margin-top: 15px;
    font-weight: bold;
}

.status-msg.processing {
    color: #666;
}

.status-msg.success {
    color: green;
}

.status-msg.error {
    color: red;
}

/* Filters */
.filters {
    margin-bottom: 20px;
}

.filters details {
    background-color: var(--card-bg);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.filters summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--primary-color);
    user-select: none;
}

.filters summary:hover {
    opacity: 0.8;
}

.filter-controls {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.filter-controls label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 14px;
}

.filter-controls input[type="range"] {
    width: 100%;
}

.filter-controls input[type="text"] {
    width: 100%;
}

/* Video metadata */
.video-title {
    margin: 10px 0 5px 0;
    color: var(--text-color);
    font-size: 1.1em;
}

.video-author {
    margin: 0 0 10px 0;
    color: #666;
    font-size: 0.9em;
    font-style: italic;
}

/* Topic badge */
.topic-badge {
    background-color: var(--primary-color);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
}

/* Bulk Upload */
.help-text {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 15px;
}

textarea {
    width: 100%;
    min-height: 150px;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 12px;
    font-size: 14px;
    font-family: monospace;
    resize: vertical;
    margin-bottom: 15px;
    box-sizing: border-box;
}

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

.bulk-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

#urlCount {
    font-size: 0.9em;
    color: #666;
    font-weight: 600;
}

#urlCount.error {
    color: #d32f2f;
}

/* Library Tab */
.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.library-header h3 {
    margin: 0;
}

.library-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.library-filters select {
    padding: 8px 15px;
    border: 2px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    background-color: white;
    cursor: pointer;
}

.library-filters select:focus {
    border-color: var(--primary-color);
    outline: none;
}

.library-filters button {
    padding: 8px 15px;
    font-size: 14px;
}

.library-stats {
    margin-bottom: 15px;
    color: #666;
}

.library-stats p {
    margin: 0;
}

.empty-state {
    text-align: center;
    color: #666;
    padding: 40px 20px;
    background-color: var(--card-bg);
    border-radius: 12px;
}

/* Library Sections */
.library-section {
    margin-bottom: 30px;
}

.topic-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-color);
}

.topic-name {
    font-size: 1.2em;
    color: var(--text-color);
}

.topic-count {
    color: #666;
    font-weight: normal;
    font-size: 0.9em;
}

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

.library-card {
    background-color: var(--card-bg);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
}

.library-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.library-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.library-title {
    margin: 0;
    font-size: 1em;
    color: var(--text-color);
    line-height: 1.3;
}

.library-author {
    margin: 5px 0 8px 0;
    color: var(--primary-color);
    font-size: 0.9em;
    font-weight: 600;
}

.library-meta {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    font-size: 0.8em;
    color: #888;
}

.library-summary {
    margin: 0;
    font-size: 0.85em;
    color: #555;
    line-height: 1.4;
}

/* Key Takeaway Styles */
.key-takeaway {
    background: linear-gradient(135deg, #fff5f7 0%, #ffe8ec 100%);
    border-left: 4px solid var(--primary-color);
    padding: 12px 15px;
    margin: 10px 0;
    border-radius: 0 8px 8px 0;
    font-size: 0.95em;
}

.takeaway-label {
    color: var(--primary-color);
    font-weight: 700;
}

.key-takeaway-small {
    background: #fff5f7;
    padding: 8px 12px;
    margin: 8px 0;
    border-radius: 6px;
    font-size: 0.85em;
    color: #444;
}

.key-takeaway-small strong {
    color: var(--primary-color);
}

/* Content Details (expandable) */
.content-details {
    margin-top: 10px;
    border: 1px solid #eee;
    border-radius: 6px;
    overflow: hidden;
}

.content-details summary {
    padding: 8px 12px;
    background: #f9f9f9;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85em;
    color: #666;
    user-select: none;
}

.content-details summary:hover {
    background: #f0f0f0;
}

.content-details[open] summary {
    border-bottom: 1px solid #eee;
}

.content-details p {
    padding: 12px;
    margin: 0;
    font-size: 0.9em;
    color: #555;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
}

.transcript-text {
    white-space: pre-wrap;
    font-family: inherit;
}

/* Category Navigation */
.category-nav {
    background: var(--card-bg);
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.nav-label {
    font-weight: 600;
    color: #666;
    font-size: 0.9em;
}

.category-nav-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.85em;
    padding: 4px 10px;
    background: #fff5f7;
    border-radius: 12px;
    transition: all 0.2s;
}

.category-nav-link:hover {
    background: var(--primary-color);
    color: white;
}

/* Card Actions */
.card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.edit-categories-btn {
    padding: 4px 10px;
    font-size: 0.75em;
    background: #f0f0f0;
    color: #666;
    border-radius: 4px;
}

.edit-categories-btn:hover {
    background: #e0e0e0;
}

/* Multi-category badges */
.multi-category-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin: 8px 0;
}

.small-badge {
    background: #f0f0f0;
    color: #666;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75em;
}

/* Secondary Button */
.secondary-btn {
    background: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.secondary-btn:hover {
    background: #fff5f7;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.modal.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Native dialog element styles */
.native-dialog {
    border: none;
    border-radius: 12px;
    padding: 0;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: visible;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.native-dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.native-dialog .dialog-content {
    display: flex;
    flex-direction: column;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: visible;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0 5px;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* Add Category Form */
.add-category-form {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.add-category-form input {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 20px;
}

.add-category-form button {
    padding: 10px 20px;
}

/* Category List */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #f9f9f9;
    border-radius: 8px;
}

.delete-category-btn {
    background: none;
    border: none;
    color: #999;
    font-size: 18px;
    cursor: pointer;
    padding: 0 5px;
}

.delete-category-btn:hover {
    color: var(--primary-color);
}

/* Video Category Edit */
.edit-video-title {
    font-weight: 600;
    margin-bottom: 15px;
    color: #333;
}

.category-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.category-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: #f9f9f9;
    border-radius: 8px;
    cursor: pointer;
}

.category-checkbox:hover {
    background: #f0f0f0;
}

.category-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
}

.save-btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
}

/* Larger modal for edit form */
.modal-large {
    max-width: 600px;
}

/* Edit form styles */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.edit-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.edit-label {
    font-weight: 600;
    color: #333;
    font-size: 0.9em;
    display: block;
}

.edit-input {
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s;
    width: 100%;
    box-sizing: border-box;
    user-select: text;
    -webkit-user-select: text;
    overflow-x: auto;
    text-overflow: ellipsis;
}

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

.edit-textarea {
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 120px;
    transition: border-color 0.2s;
    width: 100%;
    box-sizing: border-box;
    user-select: text;
    -webkit-user-select: text;
}

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

/* Icon buttons for card actions */
.edit-details-btn,
.edit-categories-btn {
    padding: 4px 8px;
    font-size: 14px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.edit-details-btn:hover,
.edit-categories-btn:hover {
    background: #e8e8e8;
    border-color: #ccc;
}

/* Responsive */
@media (max-width: 600px) {
    .tabs {
        flex-wrap: wrap;
    }

    .tab-btn {
        flex: 1 1 45%;
        text-align: center;
    }

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

    .library-filters {
        flex-direction: column;
    }

    .video-grid {
        grid-template-columns: 1fr;
    }

    .bulk-actions {
        flex-direction: column;
        gap: 10px;
    }

    .category-nav {
        flex-direction: column;
        align-items: flex-start;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
}