/* ═══════════════════════════════════════════════════════════
   Topic Speed Monitor — App CSS
   Modernes Dashboard-Design, Dark/Light Mode
   ═══════════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties ─────────────────────────────── */
:root {
    /* Dark Theme (Default) */
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-tertiary: #1a1a1a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --rpm-color: #ef4444;
    --rpm-bg: rgba(239, 68, 68, 0.1);
    --rpm-border: rgba(239, 68, 68, 0.3);
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.4);
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-width: 240px;
    --header-height: 56px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --font-mono: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, monospace;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-card: rgba(0, 0, 0, 0.02);
    --bg-card-hover: rgba(0, 0, 0, 0.04);
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.15);
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── Header ────────────────────────────────────────────── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-icon { font-size: 20px; }

.header-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.last-update {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 8px;
}

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    font-size: 13px;
    font-family: var(--font);
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 16px;
}

.btn-sm { padding: 4px 8px; font-size: 12px; }

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

.btn-danger {
    color: var(--error);
    border-color: var(--error);
}
.btn-danger:hover {
    background: var(--error);
    color: #fff;
}

/* ─── Notification ──────────────────────────────────────── */
.notification {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
}

.notification-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
}
.notification-close:hover { opacity: 1; }

/* ─── Layout ────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: calc(100vh - var(--header-height));
}

/* ─── Sidebar ───────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 20px 16px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-range {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.filter-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.filter-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 4px;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 24px;
    transition: 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: 0.2s;
}
.toggle input:checked + .toggle-slider {
    background: var(--rpm-color);
}
.toggle input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
}
.stat-label { color: var(--text-muted); }
.stat-value { color: var(--text-secondary); font-weight: 500; }

/* ─── Main Content ──────────────────────────────────────── */
.main {
    flex: 1;
    padding: 20px;
    min-width: 0;
    overflow-x: hidden;
}

/* ─── KPI Cards ─────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.kpi-card {
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(8px);
    transition: border-color 0.15s;
}
.kpi-card:hover {
    border-color: var(--border-hover);
}

.kpi-rpm {
    border-color: var(--rpm-border);
    background: var(--rpm-bg);
}
.kpi-rpm .kpi-value { color: var(--rpm-color); }

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.kpi-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

.kpi-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Tabs ──────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 2px;
    padding: 3px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 16px;
    width: fit-content;
}

.tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font);
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.tab-content { margin-bottom: 24px; }

/* ─── Charts ────────────────────────────────────────────── */
.chart-container {
    width: 100%;
    min-height: 600px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px;
    margin-bottom: 16px;
}

/* ─── Topics List ───────────────────────────────────────── */
.topics-list, .ranking-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.topic-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.15s;
}
.topic-card:hover { border-color: var(--border-hover); }

.topic-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
}
.topic-header:hover { background: var(--bg-card-hover); }

.topic-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.topic-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.topic-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.topic-body {
    display: none;
    padding: 0 16px 16px;
}
.topic-card.open .topic-body { display: block; }
.topic-card.open .topic-chevron { transform: rotate(180deg); }

.topic-chevron {
    font-size: 12px;
    transition: transform 0.2s;
    color: var(--text-muted);
}

/* Topic Timeline (mini) */
.topic-timeline {
    position: relative;
    height: 32px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    margin: 12px 0;
    overflow: hidden;
}

.topic-timeline-dot {
    position: absolute;
    width: 20px;
    height: 20px;
    top: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    transition: transform 0.15s;
}
.topic-timeline-dot:hover { transform: scale(1.3); z-index: 10; }
.topic-timeline-dot img {
    width: 16px;
    height: 16px;
    border-radius: 50%;
}

/* ─── Ranking Cards ─────────────────────────────────────── */
.ranking-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.ranking-card-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}
.ranking-item:last-child { border-bottom: none; }

.ranking-rank {
    font-size: 18px;
    width: 28px;
    text-align: center;
}

.ranking-domain {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    font-size: 13px;
    font-weight: 500;
}

.ranking-domain img {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.rpm-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    background: var(--rpm-bg);
    color: var(--rpm-color);
    border: 1px solid var(--rpm-border);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ranking-time {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.ranking-diff {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    min-width: 60px;
    text-align: right;
}

/* ─── Data Table ────────────────────────────────────────── */
.table-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

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

.table-title {
    font-size: 14px;
    font-weight: 600;
}

.table-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-search {
    padding: 6px 12px;
    font-size: 13px;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    width: 200px;
    transition: border-color 0.15s;
}

.table-search:focus { border-color: var(--accent); }
.table-search::placeholder { color: var(--text-muted); }

.table-wrapper { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}
.data-table th.sortable:hover { color: var(--text-primary); }
.data-table th.sort-asc::after { content: ' ↑'; }
.data-table th.sort-desc::after { content: ' ↓'; }

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tr:hover td { background: var(--bg-card-hover); }

.data-table .col-domain {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.data-table .col-domain img {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.data-table .col-title {
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table .col-title a {
    color: var(--text-secondary);
}
.data-table .col-title a:hover { color: var(--accent); }

.data-table .col-time {
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: 12px;
}

.data-table .col-topic {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-muted);
}

/* ─── Table Footer ──────────────────────────────────────── */
.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.pagination {
    display: flex;
    gap: 4px;
}

.pagination button {
    padding: 4px 10px;
    font-size: 12px;
    font-family: var(--font);
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.pagination button:hover { background: var(--bg-card-hover); }
.pagination button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 1024px) {
    .sidebar { display: none; }
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .header-title { font-size: 14px; }
    .main { padding: 12px; }
}

/* ─── Verpasste Topics Alert ────────────────────────────── */
.missed-topics-alert {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid var(--rpm-border);
    border-left: 4px solid var(--rpm-color);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease-out;
}

.missed-topics-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.missed-topics-icon {
    font-size: 20px;
    animation: pulse 2s ease-in-out infinite;
}

.missed-topics-title {
    flex: 1;
    font-size: 14px;
    font-weight: 700;
    color: var(--rpm-color);
    letter-spacing: -0.01em;
}

.missed-topics-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.missed-topics-close:hover { color: var(--text-primary); }

.missed-topics-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.missed-topic-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.05);
    border-radius: var(--radius);
    font-size: 13px;
}

.missed-topic-name {
    flex: 1;
    font-weight: 600;
    color: var(--text-primary);
}

.missed-topic-count {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--rpm-bg);
    color: var(--rpm-color);
    font-weight: 600;
}

.missed-topic-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ─── KPI Reaction Card ─────────────────────────────────── */
.kpi-reaction {
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.06);
}
.kpi-reaction .kpi-value { color: #f59e0b; }

/* ─── Breaking Indicator ────────────────────────────────── */
.breaking-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.breaking-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    animation: breakingPulse 1s ease-in-out infinite;
}

@keyframes breakingPulse {
    0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    50% { opacity: 0.8; transform: scale(1.4); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.topic-card.is-breaking {
    border-color: var(--rpm-border);
    background: rgba(239, 68, 68, 0.03);
}

/* ─── Sparkline ─────────────────────────────────────────── */
.sparkline-container {
    margin: 10px 0 4px;
    padding: 6px 0;
}

.sparkline-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.sparkline-svg {
    display: block;
    width: 100%;
    height: 32px;
}

/* ─── Global Leaderboard ────────────────────────────────── */
.global-leaderboard {
    margin-bottom: 24px;
}

.leaderboard-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.leaderboard-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-row:hover { background: var(--bg-card-hover); }

.leaderboard-rank {
    font-size: 22px;
    width: 36px;
    text-align: center;
    flex-shrink: 0;
}

.leaderboard-domain {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.leaderboard-domain img {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.leaderboard-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

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

.leaderboard-stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.leaderboard-stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.leaderboard-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
    width: 120px;
}

.leaderboard-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}

.ranking-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ─── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Loading / Empty States ────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-text { font-size: 14px; }

/* ─── Animations ────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.2s ease-out; }

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

.loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
