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

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
    --chart-blue: #3b82f6;
    --chart-green: #10b981;
    --button-bg: #334155;
    --button-hover: #475569;
    --button-active: #3b82f6;
    --chart-error-bg: rgba(239, 68, 68, 0.1);
    --chart-error-stroke: rgba(239, 68, 68, 0.4);
}

body.light-theme {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.08);
    --chart-blue: #2563eb;
    --chart-green: #10b981;
    --button-bg: #f7fafc;
    --button-hover: #edf2f7;
    --button-active: #2563eb;
    --chart-error-bg: rgba(239, 68, 68, 0.08);
    --chart-error-stroke: rgba(239, 68, 68, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    padding: 15px;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-y: auto;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    height: calc(100vh - 30px);
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 12px 20px;
    background: var(--bg-card);
    border-radius: 12px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border-color);
    position: relative;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

h1 {
    font-size: 1.5em;
    margin-bottom: 3px;
    color: var(--text-primary);
    font-weight: 700;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.85em;
    font-weight: 500;
}

.last-updated {
    margin-top: 4px;
    font-size: 0.75em;
    color: var(--text-muted);
}

.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 0.9em;
    font-weight: 500;
}

.theme-toggle:hover {
    background: var(--button-hover);
    transform: translateY(-2px);
}

.theme-icon {
    font-size: 1.2em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.stat-card {
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.stat-label {
    font-size: 0.7em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0;
    font-weight: 600;
    white-space: nowrap;
}

.stat-value {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--chart-blue);
}

.chart-container {
    background: var(--bg-card);
    padding: 20px 20px 15px 20px;
    border-radius: 12px;
    margin-bottom: 0;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.chart-title-section {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.chart-title {
    font-size: 1.4em;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.chart-toggle {
    display: flex;
    background: var(--button-bg);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}

.toggle-btn {
    padding: 6px 14px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85em;
    font-weight: 500;
}

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

.toggle-btn.active {
    background: var(--button-active);
    color: #ffffff;
    font-weight: 600;
}

.time-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.time-btn {
    padding: 8px 16px;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
    font-weight: 500;
}

.time-btn:hover {
    background: var(--button-hover);
    border-color: var(--border-color);
}

.time-btn.active {
    background: var(--button-active);
    border-color: var(--button-active);
    color: #ffffff;
    font-weight: 600;
}

#mainChart {
    flex: 1;
    min-height: 0;
    position: relative;
}

.chart-svg {
    width: 100%;
    overflow: visible;
}

.line {
    fill: none;
    stroke-width: 3;
    transition: stroke-width 0.3s ease;
}

.line:hover {
    stroke-width: 4;
}

.line-total {
    stroke: var(--chart-blue);
}

.line-unique {
    stroke: var(--chart-green);
}

.grid line {
    stroke: var(--border-color);
    stroke-opacity: 0.5;
    stroke-dasharray: 2,2;
}

.grid path {
    stroke-width: 0;
}

.axis text {
    fill: var(--text-muted);
    font-size: 12px;
}

.axis path,
.axis line {
    stroke: var(--border-color);
}

.tooltip {
    position: absolute;
    padding: 12px 16px;
    background: #1a202c;
    border: 1px solid #2d3748;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-size: 0.9em;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    color: #ffffff;
}

.tooltip.visible {
    opacity: 1;
}

.tooltip-date {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--chart-blue);
}

.tooltip-line {
    margin: 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 8px;
    margin-bottom: 0;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 5px;
    transition: background 0.3s ease, opacity 0.3s ease;
    font-size: 0.9em;
}

.legend-item:hover {
    background: var(--button-bg);
}

.legend-item.disabled {
    opacity: 0.3;
    text-decoration: line-through;
}

.legend-item.disabled:hover {
    opacity: 0.5;
}

.legend-color {
    width: 16px;
    height: 3px;
    border-radius: 2px;
}

.loading {
    text-align: center;
    padding: 60px;
    font-size: 1.2em;
    color: #718096;
}

.loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

.error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    color: #dc2626;
}

.dot {
    fill: white;
    stroke-width: 2;
    opacity: 0;
    pointer-events: none;
}

.dot.visible {
    opacity: 1;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        height: calc(100vh - 20px);
    }

    h1 {
        font-size: 1.5em;
    }

    .subtitle {
        font-size: 0.85em;
    }

    .theme-toggle {
        position: static;
        margin: 15px auto 0;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .chart-title-section {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .chart-title {
        font-size: 1.2em;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-label {
        font-size: 0.7em;
    }

    .stat-value {
        font-size: 1.5em;
    }

    .time-selector {
        width: 100%;
    }

    .time-btn {
        flex: 1;
        min-width: 60px;
        padding: 6px 10px;
        font-size: 0.8em;
    }
}

