/* ============================================
 * Google Alerts RSS Aggregator - Styles
 * ============================================ */

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;

    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    --border-radius: 8px;
    --transition: all 0.3s ease;
}

* {
    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(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

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

/* ============================================
 * HEADER
 * ============================================ */

.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 1.5rem 0;
    box-shadow: var(--shadow-md);
}

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

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

/* ============================================
 * BUTTONS
 * ============================================ */

.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

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

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

.btn-warning {
    background-color: #f59e0b;
    color: white;
    border: none;
}

.btn-warning:hover {
    background-color: #d97706;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* ============================================
 * STATS PANEL
 * ============================================ */

.stats-panel {
    padding: 2rem 0;
}

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

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}

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

.stat-card i {
    font-size: 2.5rem;
    color: var(--primary-color);
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ============================================
 * MAIN CONTENT GRID
 * ============================================ */

.main-content {
    padding: 2rem 0 4rem;
}

.content-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
}

/* ============================================
 * SIDEBAR & FILTERS
 * ============================================ */

.sidebar {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    height: fit-content;
    position: sticky;
    top: 1rem;
}

.filter-section {
    margin-bottom: 2rem;
}

.filter-section:last-child {
    margin-bottom: 0;
}

.filter-section h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    transition: var(--transition);
}

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

.filter-group {
    margin-bottom: 1rem;
}

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

.filter-select {
    width: 100%;
    padding: 0.625rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    background-color: white;
    cursor: pointer;
    transition: var(--transition);
}

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

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.15rem 0;
    line-height: 1.2;
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}

.checkbox-label .alert-name {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.checkbox-label .alert-name span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.checkbox-label .alert-counts {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 500;
}

.btn-sort {
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    font-size: 0.85rem;
    flex: 1;
}

.btn-sort:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

/* ============================================
 * ARTICLES SECTION
 * ============================================ */

.articles-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.articles-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
}

.articles-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.sort-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sort-controls label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* ============================================
 * ARTICLE CARDS
 * ============================================ */

.articles-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.article-card {
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    transition: var(--transition);
    background: white;
}

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

.article-card.read {
    opacity: 0.6;
}

.article-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    gap: 1rem;
}

.article-title {
    flex: 1;
}

.article-title h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.article-title h3 a {
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--transition);
}

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

.article-meta {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.article-meta span {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.article-description {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.article-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-alert {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-priority-high {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-priority-normal {
    background-color: #e0e7ff;
    color: #3730a3;
}

.badge-priority-low {
    background-color: #f3f4f6;
    color: #374151;
}

.badge-category {
    background-color: #fef3c7;
    color: #92400e;
}

.article-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
    transition: var(--transition);
    font-size: 1rem;
}

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

.icon-btn.active {
    color: var(--primary-color);
}

/* ============================================
 * LOADING & EMPTY STATES
 * ============================================ */

.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.loading i {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    display: block;
}

/* ============================================
 * MODAL
 * ============================================ */

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

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
}

.modal-close:hover {
    background-color: var(--border-color);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 2px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

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

.form-group:last-child {
    margin-bottom: 0;
}

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

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
}

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

/* ============================================
 * RESPONSIVE DESIGN
 * ============================================ */

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

    .sidebar {
        position: static;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 1.25rem;
    }

    .header-actions {
        width: 100%;
        justify-content: stretch;
    }

    .header-actions .btn {
        flex: 1;
    }

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

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

    .sort-controls {
        width: 100%;
    }

    .sort-controls .filter-select {
        flex: 1;
    }
}

/* Fixed Layout for Independent Scrolling */
html, body { height: 100vh; overflow: hidden; }
body { display: flex; flex-direction: column; }
.header, .stats-panel { flex-shrink: 0; }
.main-content { flex: 1; overflow: hidden; padding: 1rem 0 0 0; min-height: 0; }
.main-content .container { height: 100%; }
.content-grid { height: 100%; padding-bottom: 1rem; }
.sidebar { position: static; height: 100%; overflow-y: auto; }
.articles-section { height: 100%; overflow-y: auto; padding-right: 10px; }

/* Refined Scrolling for Articles */
.articles-section { display: flex; flex-direction: column; overflow: hidden; padding-right: 0; }
#articlesContainer { flex: 1; overflow-y: auto; padding-right: 10px; }

/* Scroll Area Wrapper */
.articles-scroll-area { flex: 1; overflow-y: auto; padding-right: 10px; }
#articlesContainer { flex: none; overflow-y: visible; padding-right: 0; }

/* ============================================
 * COMPACT TABLE VIEW
 * ============================================ */

.articles-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.articles-table thead {
    position: sticky;
    top: 0;
    background: linear-gradient(to bottom, #ffffff, #f8fafc);
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.articles-table th {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 2px solid var(--primary-color);
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.articles-table td {
    padding: 0.5rem 0.5rem;
    vertical-align: middle;
}

/* Row separation with subtle card effect */
.articles-table tbody tr[data-id] {
    border-left: 3px solid transparent;
    transition: var(--transition);
}

.articles-table tbody tr[data-id]:nth-child(4n+1),
.articles-table tbody tr[data-id]:nth-child(4n+2) {
    background-color: #ffffff;
}

.articles-table tbody tr[data-id]:nth-child(4n+3),
.articles-table tbody tr[data-id]:nth-child(4n+4) {
    background-color: #f8fafc;
}

.articles-table tbody tr[data-id]:hover {
    background-color: #eef2ff;
    border-left-color: var(--primary-color);
}

.articles-table tbody tr.read {
    opacity: 0.55;
}

.articles-table tbody tr.read td {
    text-decoration: line-through;
    text-decoration-color: var(--text-muted);
}

.articles-table tbody tr.read .headline-link {
    text-decoration: line-through;
}

.articles-table tbody tr.expanded {
    background-color: #e0e7ff !important;
    border-left-color: var(--primary-color);
}

/* Column widths */
.col-expand { width: 30px; text-align: center; }
.col-status { width: 40px; text-align: center; }
.col-headline { min-width: 300px; }
.col-alert { width: 120px; }
.col-source { width: 120px; }
.col-date { width: 100px; white-space: nowrap; }
.col-actions { width: 120px; text-align: center; }

/* Expand button */
.expand-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0.25rem;
    transition: var(--transition);
}

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

.expand-btn.expanded {
    transform: rotate(90deg);
}

/* Status indicators */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.priority-high { background-color: var(--danger-color); }
.status-dot.priority-normal { background-color: var(--primary-color); }
.status-dot.priority-low { background-color: var(--text-muted); }

/* Headline cell */
.headline-cell {
    max-width: 400px;
}

.headline-link {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.85rem;
}

.headline-link:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* Alert badge in table */
.alert-badge-sm {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background-color: #dbeafe;
    color: #1e40af;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Source cell */
.source-cell {
    color: var(--text-secondary);
    font-size: 0.8rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Domain name styling */
.domain-name {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--primary-color);
    font-weight: 500;
    white-space: nowrap;
}

.domain-badge {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: 'Courier New', monospace;
}

/* Date cell */
.date-cell {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Actions cell */
.table-actions {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
}

.table-actions .icon-btn {
    padding: 0.35rem;
    font-size: 0.85rem;
}

/* Expanded content row */
.expanded-row {
    display: none;
}

.expanded-row.visible {
    display: table-row;
}

.expanded-row td {
    padding: 0.6rem 0.75rem 0.6rem 2.5rem;
    background: linear-gradient(to right, #e0e7ff, #f0f4ff);
    border-left: 3px solid var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.03);
}

/* Compact 3-line expanded content */
.expanded-content-compact {
    font-size: 0.8rem;
    line-height: 1.5;
}

.expanded-line-1 {
    margin-bottom: 0.35rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px dashed var(--border-color);
}

.description-text {
    color: var(--text-primary);
    font-style: italic;
}

.expanded-line-2 {
    margin-bottom: 0.35rem;
}

.meta-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.meta-inline i {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.meta-inline .sep {
    color: var(--border-color);
    margin: 0 0.1rem;
}

.meta-inline .badge {
    padding: 0.15rem 0.5rem;
    font-size: 0.65rem;
    border-radius: 4px;
}

.status-ok {
    color: #059669;
    font-weight: 600;
}

.status-pending {
    color: #d97706;
    font-weight: 600;
}

.status-err {
    color: #dc2626;
    font-weight: 600;
    cursor: help;
}

.expanded-line-3 {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    padding-top: 0.35rem;
}

.expanded-line-3 .sep {
    color: var(--border-color);
    font-size: 0.7rem;
    margin: 0 0.1rem;
}

/* Full content panel (toggled) */
.full-content-panel {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.full-content-text {
    font-size: 0.8rem;
    line-height: 1.5;
    white-space: pre-wrap;
    color: var(--text-primary);
}

.error-content {
    font-size: 0.8rem;
    line-height: 1.5;
    color: #991b1b;
}

.error-content pre {
    margin-top: 10px;
    padding: 10px;
    background: #fee;
    border-radius: 4px;
    white-space: pre-wrap;
    font-size: 12px;
    color: #7f1d1d;
    border-left: 3px solid #dc2626;
}

/* Content status badges */
.content-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
}

.content-badge.scraped {
    background: #d1fae5;
    color: #065f46;
}

.content-badge.error {
    background: #fee2e2;
    color: #991b1b;
}

.content-badge.pending {
    background: #fef3c7;
    color: #92400e;
}

/* Compact buttons for expanded content */
.btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

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

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

.btn-secondary-sm {
    background: #e2e8f0;
    color: var(--text-primary);
}

.btn-secondary-sm:hover {
    background: #cbd5e1;
}

.btn-danger-sm {
    background: #fee2e2;
    color: #991b1b;
}

.btn-danger-sm:hover {
    background: #fecaca;
}

.btn-sm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Compact action links */
.action-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    transition: var(--transition);
}

.action-link:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

.action-link.danger {
    color: #dc2626;
}

.action-link.danger:hover {
    color: #991b1b;
}

.action-link.warning {
    color: #f59e0b;
}

.action-link.warning:hover {
    color: #d97706;
}

.action-link.error {
    color: #f59e0b;
}

.action-link.error:hover {
    color: #d97706;
}

.action-link.disabled {
    color: var(--text-muted);
    pointer-events: none;
    opacity: 0.5;
}

.action-link i {
    font-size: 0.65rem;
}

/* Expanded row action areas */
.scrape-prompt {
    text-align: center;
    padding: 0.5rem;
    background: #f8fafc;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.expanded-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
}

/* Responsive table */
@media (max-width: 768px) {
    .articles-table {
        font-size: 0.8rem;
    }
    
    .col-source, .col-date {
        display: none;
    }
    
    .articles-table th, .articles-table td {
        padding: 0.4rem 0.25rem;
    }
}
