:root {
    --stats-bg: #0b0d12;
    --stats-surface: #13161d;
    --stats-surface-elevated: #1a1f2a;
    --stats-border: #252b36;
    --stats-border-subtle: #1e2430;
    --stats-text: #e8eaef;
    --stats-text-muted: #9aa3b2;
    --stats-accent: #818cf8;
    --stats-accent-strong: #6366f1;
    --stats-accent-soft: rgba(99, 102, 241, 0.12);
    --stats-success: #34d399;
    --stats-warning: #fbbf24;
    --stats-danger: #f87171;
    --stats-radius: 12px;
    --stats-radius-lg: 16px;
    --stats-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, 0.18), transparent 55%),
                radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.08), transparent 50%),
                var(--stats-bg);
    color: var(--stats-text);
    min-height: 100vh;
    padding: 24px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

body.embedded-mode {
    padding: 0;
    overflow: auto;
    background: var(--stats-surface);
    min-height: 0;
}

html.embedded-html {
    background: var(--stats-surface);
}

.container {
    max-width: 1440px;
    margin: 0 auto;
    background: var(--stats-surface);
    border: 1px solid var(--stats-border);
    border-radius: var(--stats-radius-lg);
    box-shadow: var(--stats-shadow);
    overflow: visible;
}

body.embedded-mode .container {
    max-width: none;
    min-height: 0 !important;
    height: auto !important;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

body.embedded-mode .header,
body.embedded-mode .nav-tabs {
    display: none !important;
}

.header {
    padding: 28px 32px 24px;
    border-bottom: 1px solid var(--stats-border);
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.08) 0%, transparent 100%);
}

.header-inner {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--stats-accent-soft);
    color: var(--stats-accent);
    font-size: 1.25rem;
    border: 1px solid rgba(129, 140, 248, 0.25);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.header p {
    font-size: 0.875rem;
    color: var(--stats-text-muted);
}

.embedded-project-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--stats-surface-elevated);
    border: 1px solid var(--stats-border);
    font-size: 0.8125rem;
    font-weight: 600;
}

.embedded-project-badge span {
    color: var(--stats-accent);
}

body:not(.embedded-mode) .embedded-only { display: none !important; }
body.embedded-mode .standalone-only { display: none !important; }

.nav-tabs {
    display: flex;
    gap: 4px;
    padding: 0 24px;
    background: var(--stats-surface);
    border-bottom: 1px solid var(--stats-border);
}

.nav-tab {
    padding: 14px 18px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--stats-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    text-decoration: none;
    display: inline-block;
}

.nav-tab:hover {
    color: var(--stats-text);
}

.nav-tab.active {
    color: var(--stats-accent);
    border-bottom-color: var(--stats-accent);
}

.controls {
    padding: 20px 24px;
    background: var(--stats-surface-elevated);
    border-bottom: 1px solid var(--stats-border);
}

.control-group {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-item > label {
    font-weight: 600;
    color: var(--stats-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.control-item select,
.control-item input[type="text"],
.control-item input[type="date"] {
    padding: 10px 14px;
    border: 1px solid var(--stats-border);
    border-radius: 10px;
    font-size: 0.875rem;
    background: var(--stats-surface);
    color: var(--stats-text);
    min-width: 180px;
}

.control-item select:focus,
.control-item input:focus {
    outline: none;
    border-color: var(--stats-accent);
    box-shadow: 0 0 0 3px var(--stats-accent-soft);
}

.btn {
    padding: 10px 18px;
    background: linear-gradient(135deg, var(--stats-accent-strong) 0%, #4f46e5 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    min-width: 110px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35);
}

.refresh-btn {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
}

.stats-summary {
    padding: 20px 24px;
    background: var(--stats-surface);
    border-bottom: 1px solid var(--stats-border);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.stat-card {
    background: var(--stats-surface-elevated);
    padding: 16px 18px;
    border-radius: var(--stats-radius);
    border: 1px solid var(--stats-border-subtle);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    color: var(--stats-text-muted);
    font-size: 0.75rem;
}

.table-container,
.chart-section {
    padding: 20px 24px 28px;
}

.chart-section {
    padding-top: 0;
    padding-bottom: 8px;
    background: var(--stats-surface);
    border-bottom: 1px solid var(--stats-border);
}

.chart-card {
    background: var(--stats-surface-elevated);
    border: 1px solid var(--stats-border);
    border-radius: var(--stats-radius-lg);
    padding: 18px 20px 12px;
}

.chart-card__title {
    font-size: 0.9375rem;
    font-weight: 650;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-wrap {
    width: 100%;
    height: 360px;
}

.loading, .empty-state, .error {
    text-align: center;
    padding: 40px 20px;
    color: var(--stats-text-muted);
}

.error {
    color: var(--stats-danger);
}

@media (max-width: 768px) {
    body { padding: 12px; }
    .control-item select, .control-item input { min-width: auto; width: 100%; }
    .chart-wrap { height: 280px; }
}
