:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --dark-bg: #0f172a;
    --darker-bg: #1e293b;
    --card-bg: #1e293b;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
}

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

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

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 40px;
    padding: 30px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.header-content h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.header-content .subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

.header-status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.kpi-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kpi-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.kpi-value {
    font-size: 1.7rem;
    font-weight: 700;
    color: #8fb7ff;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.status-indicator.healthy {
    background: rgba(16, 185, 129, 0.3);
    color: var(--success-color);
}

.pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: currentColor;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.last-updated {
    font-size: 0.85rem;
    opacity: 0.8;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.card-large {
    grid-column: span 2;
}

.card-full {
    grid-column: 1 / -1;
}

@media (max-width: 1200px) {
    .card-large {
        grid-column: span 1;
    }
}

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

.card-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--warning-color);
    color: white;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-badge.posted {
    background: var(--success-color);
}

.status-badge.pending {
    background: var(--warning-color);
}

.status-badge.failed {
    background: var(--danger-color);
}

/* Today Section */
.today-content {
    margin-bottom: 20px;
}

.today-info h3 {
    font-size: 1.4rem;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.script-preview {
    background: var(--darker-bg);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 15px;
    max-height: 200px;
    overflow-y: auto;
}

.today-meta {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-item strong {
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* Progress Bars */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--darker-bg);
    border-radius: 4px;
    overflow: hidden;
    margin: 10px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-bar.large {
    height: 12px;
}

/* API Items */
.api-item {
    margin-bottom: 25px;
}

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

.api-item h4 {
    font-size: 0.95rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.api-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

.status-light {
    font-size: 1rem;
    display: inline-block;
}

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

.status-light.warning {
    color: var(--warning-color);
}

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

/* Statistics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.stat-box {
    background: var(--darker-bg);
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Queue Stats */
.queue-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.queue-item,
.cache-item {
    background: var(--darker-bg);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.queue-item h4,
.cache-item h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.queue-value,
.cache-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Cache Stats */
.cache-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-secondary {
    background: var(--darker-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    width: 100%;
    margin-top: 15px;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}

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

/* Trending Topics */
.trending-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.trending-item {
    background: var(--darker-bg);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.trending-item .topic-name {
    font-weight: 500;
    color: var(--text-primary);
}

.trending-item .topic-stats {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    gap: 15px;
}

.history-header {
    gap: 12px;
}

.history-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.history-controls select {
    background: var(--darker-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 10px;
}

.history-layout {
    display: grid;
    grid-template-columns: 2.2fr 1fr;
    gap: 18px;
}

.history-table-wrap {
    overflow: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

.history-table th,
.history-table td {
    border-bottom: 1px solid var(--border-color);
    padding: 10px;
    text-align: left;
    font-size: 0.9rem;
}

.history-table th {
    color: var(--text-muted);
    font-weight: 600;
}

.history-table tbody tr {
    cursor: pointer;
}

.history-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.08);
}

.table-status {
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.75rem;
}

.table-status.posted {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.table-status.pending {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}

.table-status.failed {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

.history-pagination {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.post-detail {
    border: 1px solid var(--border-color);
    background: var(--darker-bg);
    border-radius: 10px;
    padding: 14px;
    max-height: 560px;
    overflow: auto;
}

.post-detail h3 {
    margin-bottom: 10px;
    color: #a8c3ff;
}

.post-detail h4 {
    margin-top: 14px;
    margin-bottom: 8px;
}

.detail-script {
    white-space: pre-wrap;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    line-height: 1.5;
}

.recommend-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.recommend-box {
    border: 1px solid var(--border-color);
    background: var(--darker-bg);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.recommend-label {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.recommend-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #9db8ff;
}

.recommend-sub {
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.recommend-list-wrap h4 {
    margin: 8px 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.recommend-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.recommend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-color);
    background: rgba(99, 102, 241, 0.07);
    border-radius: 8px;
    padding: 8px 10px;
}

.recommend-rank {
    font-weight: 700;
    color: #93c5fd;
    min-width: 26px;
}

.recommend-topic-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.recommend-topic {
    font-size: 0.92rem;
    color: var(--text-primary);
}

.recommend-topic-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.youtube-wall {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.youtube-item {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    background: var(--darker-bg);
}

.youtube-frame-wrap {
    width: 100%;
    aspect-ratio: 9 / 16;
    background: #020617;
    position: relative;
    overflow: hidden;
}

.youtube-frame-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* YouTube channel stats banner */
.yt-channel-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    padding: 16px 20px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(255,0,51,0.15), rgba(0,0,0,0.2));
    border: 1px solid rgba(255,51,51,0.3);
    margin-bottom: 16px;
}

.yt-channel-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.yt-channel-title {
    font-size: 1rem;
    font-weight: 700;
    color: #f5f5f5;
    margin: 0;
}

.yt-channel-sub {
    font-size: 0.82rem;
    color: #aaa;
    margin: 0;
}

.yt-channel-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.yt-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.yt-stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #f5f5f5;
}

.yt-stat-label {
    font-size: 0.75rem;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.yt-analytics-note {
    font-size: 0.82rem;
    color: #888;
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    background: rgba(0,0,0,0.2);
    margin-bottom: 14px;
}

.yt-analytics-note a {
    color: #60a5fa;
    text-decoration: none;
}

.youtube-meta {
    padding: 10px;
}

.youtube-meta p {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.youtube-stats {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.youtube-meta a {
    color: #93c5fd;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
}

.wall-cta-row {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.wall-cta-link[aria-disabled="true"] {
    opacity: 0.5;
    pointer-events: none;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
}

/* Chart Container */
#engagementChart {
    max-height: 400px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 40px 20px;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    margin-top: 60px;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--darker-bg);
    color: var(--text-primary);
    padding: 16px 24px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    max-width: 400px;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 20px;
    }

    .header-content h1 {
        font-size: 1.8rem;
    }

    .header-status {
        width: 100%;
        align-items: flex-start;
    }

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

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

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

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

    .history-layout {
        grid-template-columns: 1fr;
    }

    .history-table {
        min-width: 680px;
    }

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

    .youtube-wall {
        grid-template-columns: 1fr;
    }

    .wall-cta-row {
        justify-content: stretch;
    }

    .wall-cta-link {
        width: 100%;
        text-align: center;
    }

    .today-meta {
        flex-direction: column;
        gap: 10px;
    }
}

/* Loading animation */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.shimmer {
    background: linear-gradient(
        90deg,
        var(--darker-bg) 25%,
        var(--border-color) 50%,
        var(--darker-bg) 75%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}
