:root {
    /* Dark theme (default) */
    --bg-base: #121212;
    --bg-surface: #1e1e1e;
    --bg-surface-elevated: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --border-color: #333333;
    
    --accent-primary: #3b82f6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}

[data-theme='light'] {
    --bg-base: #f3f4f6;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f9fafb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

#app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, border-color 0.3s;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.sidebar-nav {
    padding: 1rem 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sidebar-nav h3 {
    padding: 0 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.sidebar-nav li:hover, .sidebar-nav li.active {
    color: var(--text-primary);
    background-color: var(--bg-surface-elevated);
}

.sidebar-nav li.active {
    border-left: 3px solid var(--accent-primary);
    padding-left: calc(1.5rem - 3px);
}

.spacer {
    flex: 1;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Topbar */
.topbar {
    height: 64px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    transition: background-color 0.3s, border-color 0.3s;
}

.topbar select {
    background-color: var(--bg-surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    outline: none;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.time-ranges {
    display: flex;
    background-color: var(--bg-surface-elevated);
    border-radius: 0.25rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.time-ranges button {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.time-ranges button:hover {
    color: var(--text-primary);
}

.time-ranges button.active {
    background-color: var(--accent-primary);
    color: white;
}

#pause-toggle {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 0.25rem;
    cursor: pointer;
}

/* Dashboard Grid */
.dashboard-grid {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

/* Stat Cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.stat-title {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 600;
}

.stat-trend {
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

.trend-up { color: var(--accent-success); }
.trend-down { color: var(--accent-danger); }

/* Charts */
.chart-row {
    display: flex;
    gap: 1.5rem;
}

.chart-card {
    flex: 1;
    min-width: 0;
}

.chart-card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.flex-2 { flex: 2; }
.flex-1 { flex: 1; }

.uplot-chart {
    width: 100%;
    height: 300px;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    position: sticky;
    top: 0;
    background-color: var(--bg-surface);
}

/* Unique Visitors */
.unique-visitors {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: calc(100% - 2rem);
}

.uv-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent-primary);
}

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

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--bg-surface);
    padding: 2rem;
    border-radius: 0.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    text-align: center;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.25rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-base);
    color: var(--text-primary);
}

button[type="submit"] {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

button[type="submit"]:hover {
    background-color: #2563eb;
}

.error-msg {
    color: var(--accent-danger);
    font-size: 0.875rem;
    text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .sidebar-header {
        border-bottom: none;
        border-right: 1px solid var(--border-color);
    }
    .sidebar-nav {
        flex-direction: row;
        align-items: center;
    }
    .chart-row {
        flex-direction: column;
    }
}
