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

:root {
    --primary-color: #d32f2f;
    --secondary-color: #1976d2;
    --background: #f5f5f5;
    --surface: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --border-color: #e0e0e0;
    --success: #4caf50;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.15);
}

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

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

header {
    background: var(--surface);
    border-radius: 8px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.header-image {
    width: 100%;
    height: 100px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-image: url('images/row.avif');
    position: relative;
    display: flex;
    align-items: center;
}

.header-text {
    padding: 20px 30px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    position: relative;
    z-index: 1;
}

h1 {
    color: var(--primary-color);
    font-size: 2.5em;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.subtitle {
    color: black;
    font-size: 1.1em;
    margin: 0;
    text-shadow: 1px 1px 3px rgba(255, 255, 255, 0.8);
}

h2 {
    font-size: 1.5em;
    margin: 0 0 12px 0;
    color: var(--text-primary);
}

section {
    background: var(--surface);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

/* Search Form */
.search-form {
    display: grid;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

label {
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--text-primary);
}

input[type="text"],
input[type="url"],
input[type="datetime-local"],
select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.3s;
}

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

input[type="checkbox"] {
    width: auto;
}

/* Buttons */
.btn {
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

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

.btn-primary:hover {
    background: #b71c1c;
    box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover {
    background: #1565c0;
}

.btn-link {
    background: none;
    border: none;
    color: var(--secondary-color);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9em;
    padding: 0;
    margin-left: 10px;
}

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

.btn-info-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    width: 18px;
    height: 18px;
    background: rgba(255,255,255,0.25);
    border-radius: 50%;
    font-size: 0.75em;
    font-style: normal;
    cursor: pointer;
    transition: background 0.2s;
    vertical-align: middle;
    line-height: 1;
}

.btn-info-inline:hover {
    background: rgba(255,255,255,0.5);
}

#search-btn {
    justify-self: start;
    margin-top: 10px;
}

.btn-searching {
    background: #9e9e9e !important;
    cursor: not-allowed !important;
    opacity: 0.7;
}

.btn-searching:hover {
    background: #9e9e9e !important;
    box-shadow: none !important;
}

/* AI Configuration Section */
.ai-config-section {
    background: #fff9e6;
    border-left: 4px solid var(--secondary-color);
}

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

.provider-badge {
    background: var(--secondary-color);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 500;
}

.ai-features {
    margin: 20px 0;
    padding: 15px;
    background: white;
    border-radius: 4px;
}

.ai-features h3 {
    font-size: 1.1em;
    margin-bottom: 15px;
}

.ai-features label {
    display: block;
    margin-bottom: 10px;
    font-weight: normal;
}

.ai-features input[type="checkbox"] {
    margin-right: 8px;
}

.config-note {
    background: white;
    padding: 15px;
    border-radius: 4px;
    margin: 20px 0;
    border-left: 3px solid var(--secondary-color);
}

.config-note code {
    background: var(--background);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.config-note ul {
    margin: 10px 0 0 20px;
}

/* Sources Section */
.sources-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

.sources-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sources-footer {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    justify-content: flex-end;
}

.source-counter {
    font-size: 0.85em;
    color: var(--text-secondary);
    background: var(--background);
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 500;
}

.sources-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    max-height: 320px;
    overflow-y: auto;
    overflow-x: hidden;
}

.source-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 7px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
    transition: background 0.2s;
}

.source-item:hover {
    background: var(--background);
}

.source-item.disabled {
    opacity: 0.45;
}

.source-checkbox {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.source-name {
    font-weight: 400;
    color: var(--text-primary);
    font-size: 0.82em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.source-type {
    font-size: 0.7em;
    color: var(--text-secondary);
    background: var(--border-color);
    padding: 1px 5px;
    border-radius: 10px;
    white-space: nowrap;
}

.source-delete {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1em;
    padding: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s;
}

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

/* Results Section */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.relevance-info {
    font-size: 0.65em;
    font-weight: 400;
    color: var(--text-secondary);
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 7px;
    vertical-align: middle;
    cursor: default;
    letter-spacing: 0.01em;
}

.article-count {
    font-size: 0.9em;
    color: var(--text-secondary);
    background: var(--background);
    padding: 5px 15px;
    border-radius: 20px;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.article-item {
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--background);
    transition: all 0.3s;
}

.article-item:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary-color);
}

.article-headline {
    font-size: 1.2em;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.article-headline a {
    color: inherit;
    text-decoration: none;
}

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

.article-meta {
    display: flex;
    gap: 20px;
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.score-high {
    color: #4caf50 !important;
    font-weight: 600;
}

.score-medium {
    color: #ff9800 !important;
    font-weight: 600;
}

.score-low {
    color: #f44336 !important;
    font-weight: 600;
}

.matched-terms {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.9em;
}

.match-term {
    background: #e3f2fd;
    color: #1976d2;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 500;
}

.article-summary {
    color: var(--text-secondary);
    line-height: 1.5;
}

.article-entities {
    margin-top: 10px;
    padding: 10px;
    background: #f0f7ff;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.empty-state,
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 1.1em;
}

.searching {
    text-align: center;
    padding: 40px 20px;
}

/* Knight Rider / KITT scanner */
.kitt-scanner {
    position: relative;
    width: 100%;
    height: 52px;
    background: linear-gradient(180deg, #1a0000 0%, #0a0000 50%, #1a0000 100%);
    border-radius: 6px;
    overflow: hidden;
    margin: 0 auto 22px;
    border: 1px solid #2a0000;
    box-shadow: inset 0 2px 12px rgba(0,0,0,0.9), 0 2px 8px rgba(0,0,0,0.4);
}

/* Sweeping glow orb */
.kitt-scanner::before {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 90px;
    height: 36px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center,
        #ff2200 0%,
        #ff4400 25%,
        rgba(255, 60, 0, 0.45) 60%,
        transparent 100%
    );
    box-shadow:
        0 0 18px 6px rgba(255, 30, 0, 0.75),
        0 0 40px 14px rgba(220, 20, 0, 0.35);
    animation: kitt-scan 1.3s ease-in-out infinite alternate;
}

/* Floor shimmer */
.kitt-scanner::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
    pointer-events: none;
}

@keyframes kitt-scan {
    0%   { left: -45px; }
    100% { left: calc(100% - 45px); }
}

.kitt-label {
    font-size: 0.72em;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #cc2200;
    margin-bottom: 14px;
    font-weight: 600;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--surface);
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s;
    display: flex;
    flex-direction: column;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
}

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

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

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-footer .btn {
    white-space: nowrap;
    min-width: 100px;
    font-size: 1em;
    font-weight: 500;
}

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

    .header-image {
        height: 80px;
    }

    .header-text {
        padding: 15px 20px;
        gap: 3px;
    }

    h1 {
        font-size: 1.8em;
    }

    .subtitle {
        font-size: 1em;
    }

    section {
        padding: 20px;
    }

    .sources-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sources-list {
        grid-template-columns: 1fr;
    }

    .article-meta {
        flex-direction: column;
        gap: 5px;
    }
}

/* Search progress indicator */
.search-progress {
    margin: 20px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border-left: 3px solid var(--primary-color);
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    font-size: 0.95em;
}

.progress-icon {
    font-size: 1.2em;
    min-width: 24px;
}

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

.progress-step.active .progress-text {
    color: var(--text-primary);
    font-weight: 500;
}

.progress-step.completed .progress-icon {
    opacity: 0.5;
}

.progress-step.completed .progress-text {
    text-decoration: line-through;
    opacity: 0.6;
}

/* Discovered Sources Modal */
.discovered-sources-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
}

.discovered-source-item {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--background);
    border-radius: 4px;
    transition: background 0.2s;
}

.discovered-source-item:hover {
    background: #e8f5e9;
}

.discovered-source-item:last-child {
    margin-bottom: 0;
}

.discovered-source-item input[type="checkbox"] {
    width: auto;
    margin-top: 2px;
    cursor: pointer;
}

.discovered-source-item label {
    flex: 1;
    line-height: 1.4;
}
