:root {
    color-scheme: light dark;
    --bg: #111827;
    --panel: #1f2937;
    --text: #f9fafb;
    --muted: #9ca3af;
    --accent: #10b981;
    --error-bg: #7f1d1d;
    --error-text: #fee2e2;
    --border: rgba(156, 163, 175, 0.3);
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f3f4f6;
        --panel: #ffffff;
        --text: #111827;
        --muted: #4b5563;
        --accent: #059669;
        --error-bg: #fca5a5;
        --error-text: #7f1d1d;
        --border: rgba(75, 85, 99, 0.3);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.page-header {
    padding: 16px 24px 8px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header h1 {
    margin: 0;
}

.page-header p {
    margin: 6px 0 0;
    color: var(--muted);
}

.header-meta {
    text-align: right;
}

.header-meta p {
    margin: 0 0 6px;
}

.refresh-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.refresh-link:hover {
    text-decoration: underline;
}

.tab-bar {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.tab-button {
    background: transparent;
    color: var(--muted);
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 8px 8px 0 0;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 600;
    min-height: auto;
}

.tab-button.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.tab-panel[hidden] {
    display: none;
}

.growth-section {
    margin-bottom: 20px;
}

.growth-section h2 {
    margin: 0 0 12px;
    font-size: 1.1rem;
}

.growth-section h3 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    color: var(--muted);
}

.growth-empty {
    margin-bottom: 12px;
}

.content {
    padding: 0 16px 20px;
}

.panel {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    padding: 12px;
}

.controls {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

select,
button {
    min-height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    padding: 6px 10px;
}

button {
    background: var(--accent);
    color: #ffffff;
    border: none;
    cursor: pointer;
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

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

.metric-card {
    min-height: 100px;
}

.metric-card h2 {
    font-size: 0.95rem;
    margin: 0 0 8px;
    color: var(--muted);
    font-weight: 600;
}

.metric-card p {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
    gap: 12px;
}

.charts-grid h2 {
    margin: 0 0 10px;
    font-size: 1rem;
}

/* Fixed-height container for chart panels so Chart.js doesn’t keep growing the layout */
.chart-panel {
    display: flex;
    flex-direction: column;
    height: 300px;
}

.chart-container {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
    min-height: 0;
}

/* Fixed height for table widget so it doesn’t keep growing */
.charts-grid > .panel.table-panel {
    display: flex;
    flex-direction: column;
    height: 400px;
}

.charts-grid > .panel.table-panel .table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

th,
td {
    border-bottom: 1px solid var(--border);
    padding: 8px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
}

.muted {
    color: var(--muted);
}

.error-banner {
    margin-bottom: 12px;
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--error-bg);
    color: var(--error-text);
}
