:root {
    color-scheme: light;
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-muted: #f1f5f9;
    --surface-soft: #f8fafc;
    --border: #dfe7ef;
    --border-strong: #cbd5e1;
    --text: #102033;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --primary: #0f766e;
    --primary-strong: #115e59;
    --primary-soft: #d9f4ef;
    --blue: #2563eb;
    --blue-soft: #dbeafe;
    --green: #16a34a;
    --green-soft: #dcfce7;
    --amber: #d97706;
    --amber-soft: #fef3c7;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --purple: #7c3aed;
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 6px 20px rgba(15, 23, 42, 0.06);
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-width: 252px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.10), transparent 34rem),
        linear-gradient(135deg, #f8fbfc 0%, var(--bg) 58%, #eef4f8 100%);
    color: var(--text);
    font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: 0;
}

body.app-body {
    display: flex;
}

a {
    color: inherit;
}

.sidebar {
    position: sticky;
    top: 0;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    padding: 22px 18px;
    background: rgba(255, 255, 255, 0.88);
    border-right: 1px solid rgba(203, 213, 225, 0.86);
    backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 6px 18px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #0f766e, #22c55e);
    color: white;
    font-size: 22px;
    font-weight: 800;
    box-shadow: 0 12px 24px rgba(15, 118, 110, 0.24);
}

.brand-title {
    margin: 0;
    font-size: 19px;
    line-height: 1.1;
    font-weight: 800;
}

.brand-subtitle {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
}

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

.user-label {
    margin: 0 0 4px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.user-name {
    color: var(--text);
    font-size: 15px;
    font-weight: 800;
}

.menu-divider {
    height: 1px;
    margin: 8px 0;
    background: var(--border);
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.sidebar a {
    min-height: 42px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 750;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.sidebar a:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.sidebar a.active {
    background: var(--primary-soft);
    color: var(--primary-strong);
}

.nav-icon {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    font-size: 13px;
}

.logout-link {
    margin-top: auto;
    background: var(--red-soft) !important;
    color: #991b1b !important;
}

.content {
    flex: 1;
    min-width: 0;
    padding: 28px;
    overflow-y: auto;
}

.page-shell,
.dashboard-container {
    width: 100%;
    max-width: none;
    margin: 0;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 22px;
}

h1.dashboard-header,
.page-title {
    margin: 0;
    color: var(--text);
    font-size: 32px;
    line-height: 1.15;
    font-weight: 850;
}

.datasource-text,
.page-subtitle {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

.dashboard-top-row {
    display: grid;
    grid-template-columns: minmax(300px, 0.8fr) minmax(360px, 1fr) minmax(440px, 1.35fr);
    gap: 18px;
    align-items: stretch;
}

.panel,
.card,
.chart-container,
.stats-container,
.flow-container-abs,
.login-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(223, 231, 239, 0.95);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.panel {
    padding: 22px;
}

.card {
    width: 100%;
    max-width: none;
    padding: 28px;
}

.panel-title {
    margin: 0 0 16px;
    color: var(--text);
    font-size: 16px;
    line-height: 1.2;
    font-weight: 800;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.panel-header .panel-title {
    margin: 0;
}

.panel-title-icon {
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

.panel-title-icon svg {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.form-field label,
.setting-row label,
.checkbox-row label {
    display: block;
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
}

.form-help {
    display: block;
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
}

.setting-list {
    display: grid;
    gap: 13px;
}

.setting-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 140px;
    align-items: center;
    gap: 14px;
}

.setting-row input {
    margin: 0;
    text-align: right;
}

.checkbox-panel {
    padding: 14px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--blue);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-row input[type="checkbox"] {
    width: 20px;
    min-width: 20px;
    height: 20px;
    min-height: 20px;
    margin: 0;
}

.action-bar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.button-full {
    width: 100%;
}

.button-danger {
    background: var(--red);
}

.button-danger:hover {
    background: #b91c1c;
}

.button-warning {
    background: var(--amber);
}

.button-warning:hover {
    background: #b45309;
}

.button-ghost {
    min-height: 32px;
    padding: 6px 8px;
    background: transparent;
    color: var(--text-muted);
    border-color: transparent;
}

.button-ghost:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.button-ghost.danger {
    color: var(--red);
}

.button-ghost.warning {
    color: var(--amber);
}

.status-message {
    margin-bottom: 18px;
    padding: 13px 14px;
    border: 1px solid rgba(22, 163, 74, 0.22);
    border-left: 4px solid var(--green);
    border-radius: var(--radius);
    background: var(--green-soft);
    color: #166534;
    font-weight: 800;
}

.content-grid-two {
    display: grid;
    grid-template-columns: minmax(280px, 0.75fr) minmax(480px, 1.55fr);
    gap: 18px;
    align-items: start;
}

.price-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 10px;
    max-height: 350px;
    overflow-y: auto;
    padding-right: 4px;
}

.price-card.high-price {
    border-left-color: var(--red);
}

.price-card.high-price .price-value {
    color: var(--red);
}

.price-time {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.35;
}

.price-value {
    color: var(--green);
    font-size: 18px;
    font-weight: 850;
}

.chart-panel {
    margin-top: 18px;
}

.chart-frame {
    height: clamp(380px, 46vh, 620px);
}

.chart-frame canvas {
    width: 100% !important;
    height: 100% !important;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 20px;
    background: rgba(15, 23, 42, 0.46);
    align-items: center;
    justify-content: center;
}

.modal-content {
    position: relative;
    width: min(100%, 440px);
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-content.centered {
    text-align: center;
}

.modal-content h2 {
    margin: 0 0 16px;
    color: var(--text);
    font-size: 22px;
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 14px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
}

.close-btn:hover {
    color: var(--red);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.stats-container {
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.styled-stat-box,
.up-box,
.sell-box,
.price-card {
    min-height: 92px;
    padding: 13px 12px;
    border-radius: var(--radius);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    box-shadow: none;
}

.styled-stat-title,
.section-title {
    margin: 0;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 850;
    letter-spacing: 0;
    text-transform: uppercase;
}

.styled-stat-val,
.up-val,
.sell-val,
.upcoming-price-value {
    color: var(--text);
    font-size: 21px;
    line-height: 1.1;
    font-weight: 850;
}

.box-sol,
.up-box {
    border-left: 4px solid var(--green);
}

.box-forbrug,
.up-box.dyr-strom {
    border-left: 4px solid var(--red);
}

.box-batteri {
    border-left: 4px solid var(--blue);
}

.box-saelger {
    border-left: 4px solid var(--green);
}

.box-koeber,
.sell-box {
    border-left: 4px solid var(--amber);
}

.box-balanceret {
    border-left: 4px solid var(--text-soft);
}

.up-box .up-val,
.box-sol .styled-stat-val,
.box-saelger .styled-stat-val {
    color: var(--green);
}

.up-box.dyr-strom .up-val,
.box-forbrug .styled-stat-val {
    color: var(--red);
}

.sell-val,
.box-koeber .styled-stat-val {
    color: var(--amber);
}

.box-batteri .styled-stat-val {
    color: var(--blue);
}

.new-battery-bg {
    width: 100%;
    height: 6px;
    margin-top: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: #dbe5ee;
}

.new-battery-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), #38bdf8);
}

.price-panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

.prices-stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
}

.upcoming-price-time,
.meta-text {
    color: var(--text-muted);
    font-size: 13px;
}

.flow-container-abs {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: clamp(390px, 34vh, 560px);
    overflow: hidden;
}

.node-abs {
    position: absolute;
    z-index: 10;
    width: 142px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.88);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transform: translate(-50%, -50%);
}

.pos-sol { top: 20%; left: 25%; }
.pos-net { top: 20%; left: 75%; }
.pos-inv { top: 50%; left: 50%; width: auto; background: transparent; border: 0; }
.pos-bat { top: 80%; left: 25%; }
.pos-hus { top: 80%; left: 75%; }

.node-abs .flow-icon,
.node-abs .flow-inverter {
    width: 58px;
    height: 58px;
    margin-bottom: 8px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    display: grid;
    place-items: center;
    color: var(--text);
}

.node-abs .flow-icon svg,
.node-abs .flow-inverter svg {
    width: 27px;
    height: 27px;
    stroke-width: 2.2;
}

.flow-icon-solar {
    color: var(--amber);
    background: var(--amber-soft) !important;
}

.flow-icon-grid {
    color: var(--primary);
    background: var(--primary-soft) !important;
}

.flow-icon-battery {
    color: var(--blue);
    background: var(--blue-soft) !important;
}

.flow-icon-house {
    color: var(--red);
    background: var(--red-soft) !important;
}

.node-abs .flow-inverter {
    border-radius: 14px;
    background: var(--text);
    color: white;
}

.flow-label {
    color: var(--text-muted);
    font-size: 13px;
}

.flow-value {
    color: var(--text);
    font-size: 15px;
    font-weight: 800;
}

.chart-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin: 24px 0 14px;
}

.date-nav {
    min-width: 350px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-soft);
}

.date-nav input {
    margin: 0;
    text-align: center;
}

.button,
button,
.nav-button {
    min-height: 40px;
    width: auto;
    margin: 0;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.button:hover,
button:hover,
.nav-button:hover {
    background: var(--primary-strong);
}

.button-secondary,
.nav-button {
    background: var(--surface-soft);
    color: var(--text);
    border-color: var(--border);
}

.button-secondary:hover,
.nav-button:hover {
    background: var(--surface-muted);
}

input,
select {
    width: 100%;
    min-height: 40px;
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: white;
    color: var(--text);
    font: inherit;
    font-size: 14px;
}

input:focus,
select:focus {
    outline: 3px solid rgba(15, 118, 110, 0.16);
    border-color: var(--primary);
}

.chart-container {
    height: clamp(380px, 42vh, 620px);
    min-height: 380px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.waiting-data {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

.waiting-icon {
    font-size: 34px;
    margin-bottom: 10px;
}

.ai-status {
    min-height: 132px;
    padding: 20px;
    border-left: 4px solid var(--blue);
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.ai-icon {
    min-width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--blue-soft);
    display: grid;
    place-items: center;
    color: #1d4ed8;
    font-size: 25px;
    font-weight: 800;
}

.ai-status h4 {
    margin: 0 0 7px;
    color: var(--text);
    font-size: 17px;
}

.ai-status p {
    margin: 0;
    color: var(--text-muted);
    max-width: none;
    font-size: 14px;
    line-height: 1.65;
    white-space: normal;
    overflow-wrap: anywhere;
}


.login-page {
    min-height: 100vh;
    padding: 32px;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(100%, 390px);
    padding: 34px;
}

.login-card > h1 {
    margin: 0 0 8px;
    font-size: 28px;
}

.chart-toolbar .panel-title {
    margin: 0;
}

.login-card p {
    margin: 0 0 20px;
    color: var(--text-muted);
}

.alert-error {
    margin-bottom: 18px;
    padding: 12px;
    border-radius: var(--radius);
    background: var(--red-soft);
    color: #991b1b;
    font-weight: 700;
}

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

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

th {
    color: var(--text-muted);
    background: var(--surface-soft);
    font-size: 12px;
    font-weight: 850;
    text-transform: uppercase;
}

tr:hover {
    background: rgba(248, 250, 252, 0.8);
}

.badge-admin,
.badge-bruger {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge-admin {
    background: var(--red-soft);
    color: #991b1b;
}

.badge-bruger {
    background: var(--blue-soft);
    color: #1d4ed8;
}

@media (max-width: 1500px) {
    .dashboard-top-row {
        grid-template-columns: minmax(290px, 0.8fr) minmax(340px, 1fr) minmax(380px, 1.2fr);
    }
}

@media (max-width: 1260px) {
    .dashboard-top-row {
        grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.1fr);
    }

    .dashboard-top-row > section:last-child {
        grid-column: 1 / -1;
    }

    .flow-container-abs {
        min-height: 390px;
    }
}

@media (max-width: 1020px) {
    .dashboard-top-row {
        grid-template-columns: 1fr;
    }

    .dashboard-top-row > section:last-child {
        grid-column: auto;
    }

    .content-grid-two {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    body.app-body {
        display: block;
    }

    .sidebar {
        position: relative;
        width: 100%;
        min-width: 0;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .content {
        padding: 20px;
    }

    .page-header,
    .chart-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .date-nav {
        min-width: 0;
        width: 100%;
    }
}

@media (max-width: 620px) {
    .content,
    .login-page {
        padding: 14px;
    }

    h1.dashboard-header,
    .page-title {
        font-size: 26px;
    }

    .stats-container,
    .price-panel-grid,
    .form-grid,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .setting-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .setting-row input {
        text-align: left;
    }

    .panel-header,
    .action-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    .node-abs {
        width: 118px;
        font-size: 12px;
    }

    .flow-container-abs {
        min-height: 360px;
    }
}
