:root {
    --bg: #0b1220;
    --card: #111a2e;
    --muted: #8ea0c6;
    --text: #eaf0ff;
    --line: #1e2a47;
    --good: #2ecc71;
    --warn: #f1c40f;
    --bad: #e74c3c;
    --accent: #6aa7ff;
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
    z-index: 1;
}

/* Animated Background Layer */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background:
        radial-gradient(circle at 15% 50%, rgba(106, 167, 255, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(46, 204, 113, 0.10), transparent 30%),
        radial-gradient(circle at 50% 80%, rgba(241, 196, 15, 0.08), transparent 40%);
    filter: blur(40px);
    animation: floatBg 15s ease-in-out infinite alternate;
    background-size: 150% 150%;
}

@keyframes floatBg {
    0% {
        background-position: 0% 0%;
        transform: scale(1);
    }

    100% {
        background-position: 100% 50%;
        transform: scale(1.1);
    }
}

/* Card Entry Animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px
}

.top {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 2px 18px;
    border-bottom: 1px solid var(--line);
}

h1 {
    margin: 0;
    font-size: 20px;
    letter-spacing: .3px
}

.sub {
    color: var(--muted);
    font-size: 13px
}

.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.card {
    background: linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(255, 255, 255, .02));
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .25);
    animation: fadeInUp 0.6s ease-out forwards;
    opacity: 0;
    /* Fallback controlled by animation */
}

/* Stagger animation slightly */
.card:nth-child(1) {
    animation-delay: 0.1s;
}

.card:nth-child(2) {
    animation-delay: 0.15s;
}

.card:nth-child(3) {
    animation-delay: 0.2s;
}

.card:nth-child(4) {
    animation-delay: 0.25s;
}

.card:nth-child(5) {
    animation-delay: 0.3s;
}

.card:nth-child(6) {
    animation-delay: 0.35s;
}

.card:nth-child(7) {
    animation-delay: 0.4s;
}

.card:nth-child(8) {
    animation-delay: 0.45s;
}

.card:nth-child(9) {
    animation-delay: 0.5s;
}

/* Wide card */
.card:nth-child(10) {
    animation-delay: 0.55s;
}

.card:nth-child(11) {
    animation-delay: 0.6s;
}

.kpi {
    grid-column: span 3;
}

.kpi .label {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px
}

.kpi .value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1
}

.kpi .unit {
    font-size: 12px;
    color: var(--muted);
    margin-left: 6px;
    font-weight: 600
}

.kpi .meta {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px
}

.wide {
    grid-column: span 12;
}

.half {
    grid-column: span 6;
}

canvas {
    width: 100% !important;
    height: 360px !important;
}

.pill {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .10);
    color: var(--muted);
    font-size: 12px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block
}

.err {
    background: rgba(231, 76, 60, .12);
    border: 1px solid rgba(231, 76, 60, .35);
    color: #ffd7d3;
    padding: 12px 14px;
    border-radius: 12px;
    margin-top: 14px;
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
}

@media (max-width: 1000px) {
    .kpi {
        grid-column: span 6;
    }

    .half {
        grid-column: span 12;
    }

    canvas {
        height: 320px !important;
    }
}

@media (max-width: 520px) {
    .kpi {
        grid-column: span 12;
    }
}

/* History & Utilities */
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.title-bold {
    font-weight: 700;
}

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

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.control-input {
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

.btn-primary:hover {
    opacity: 0.9;
}

.chart-container-history {
    height: 400px;
    position: relative;
    width: 100%;
}

.hidden {
    display: none !important;
}

.kpi-row {
    margin-top: 20px;
}

/* Progress Bars */
.progress-track {
    background: rgba(255, 255, 255, 0.1);
    height: 8px;
    border-radius: 4px;
    width: 100%;
    margin-top: 12px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 1s ease-out;
    border-radius: 4px;
}

.fill-autarky {
    background: var(--good);
}

.fill-self {
    background: var(--warn);
}