/* Elforbrug – lyst tema, mobil først. */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e3e6eb;
    --text: #17202c;
    --muted: #5b6573;
    --primary: #1f5fbf;
    --primary-hover: #194f9f;
    --accent: #f2a900;
    --error: #b42318;
    --error-bg: #fdecea;
    --info-bg: #e8f0fb;
    --ok: #1a7f37;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --nav-h: 64px;
    --tap: 48px;
    --chart-bar: #1f5fbf;
    --chart-weekend: #7fa7e3;
    --chart-ly: #111111;
    --chart-temp: #d9480f;
    --chart-note: #7c3aed;
    --delta-down: #1a7f37;
    --delta-up: #b54708;
    /* Kategoriske seriefarver (perioder, ugedage). */
    --series-0: #1f5fbf;
    --series-1: #e08a00;
    --series-2: #2a9d8f;
    --series-3: #c2410c;
    --series-4: #7c3aed;
    --series-5: #db2777;
    --series-6: #64748b;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 var(--font);
    font-variant-numeric: tabular-nums;
}

a { color: var(--primary); }
code { font-size: .9em; background: #eef0f3; padding: .1em .35em; border-radius: 4px; }
h1, h2, h3 { line-height: 1.25; }

.main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

.page-title { font-size: 1.5rem; margin: 4px 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.text-error { color: var(--error); }

/* --- Kort ---------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
.card-title { font-size: 1.05rem; margin: 0 0 12px; }

.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 16px; margin: 0 0 12px; }
.kv dd { text-align: right; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* --- Beskeder ------------------------------------------------------------ */

.flash { border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; }
.flash-error { background: var(--error-bg); color: var(--error); }
.flash-info { background: var(--info-bg); color: var(--primary-hover); }

/* --- Formularer ---------------------------------------------------------- */

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
.field input {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 12px;
    font: inherit;
    font-size: 16px; /* undgår zoom på iOS */
    color: var(--text);
    background: var(--surface);
    border: 1px solid #c9ced6;
    border-radius: 8px;
}
.field input:focus { outline: 3px solid rgba(31, 95, 191, .25); border-color: var(--primary); }

.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); margin-bottom: 12px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: var(--tap);
    padding: 0 20px;
    font: inherit; font-weight: 600;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
}
.btn { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 8px; font: inherit; color: var(--muted); cursor: pointer; min-height: var(--tap); }
.btn-link:hover { color: var(--text); }

/* --- Login --------------------------------------------------------------- */

.is-guest .main { padding-bottom: 24px; }
.login { max-width: 400px; margin: 8vh auto 0; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 20px; }
.login-brand svg { width: 36px; height: 36px; fill: var(--accent); }
.login-brand h1 { margin: 0; font-size: 1.75rem; }
.login-card { padding: 20px; }

/* --- Nøgletal ------------------------------------------------------------ */

.data-status { color: var(--muted); font-size: .875rem; margin: -8px 0 16px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-grid .card { margin-bottom: 0; }
.stat-grid + .small { margin: 8px 0 0; }
.card-grid { display: grid; gap: 0 16px; margin-top: 16px; }

.stat { display: block; color: inherit; text-decoration: none; }
a.stat:hover { border-color: #c9d6ea; }
.stat-label { color: var(--muted); font-size: .875rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin: 4px 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.stat-empty { font-size: 1rem; font-weight: 600; color: var(--muted); }
.stat-sub { color: var(--muted); font-size: .875rem; }

.delta { font-size: .9rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eef0f3; }
.delta-down { color: var(--delta-down); background: #e7f5ec; }
.delta-up { color: var(--delta-up); background: #fdf0e3; }

.method { margin-top: 8px; font-size: .875rem; color: var(--muted); }
.method summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.method p { margin: 4px 0 0; }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

/* --- Grafer -------------------------------------------------------------- */

.chart { width: 100%; }
.chart-small { height: 220px; }
.chart-main { height: 340px; }
.chart-card { padding: 12px 8px 8px; }
.chart-card .hint { margin: 4px 8px 0; }
.is-loading .chart-main { opacity: .5; transition: opacity .15s; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 4px 8px 0; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.sw-bar { background: var(--chart-bar); }
.sw-weekend { background: var(--chart-weekend); }
.sw-partial { background: var(--chart-bar); opacity: .4; }
.sw-estimated { background: repeating-linear-gradient(-45deg, var(--chart-bar) 0 3px, #a9c1e8 3px 5px); }

.chart-tooltip { font: 14px/1.4 var(--font) !important; }
.tt-title { color: var(--muted); }
.tt-value { font-weight: 700; font-size: 1rem; }
.tt-note { color: var(--delta-up); }
.tt-hint { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.tt-ly { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
.tt-down { color: var(--delta-down); }
.tt-up { color: var(--delta-up); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--chart-ly); margin-right: 6px; vertical-align: 0; }

/* --- Drill-down -------------------------------------------------------- */

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: .9rem; margin-bottom: 4px; }
.crumbs a { padding: 6px 2px; text-decoration: none; }
.crumbs .sep { color: var(--muted); }
.crumbs [aria-current] { color: var(--muted); }

.period-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.period-head .page-title { margin: 0; text-align: center; flex: 1; font-size: 1.3rem; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--tap); height: var(--tap); flex: none;
    border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
    font-size: 1.6rem; line-height: 1; color: var(--primary); text-decoration: none;
    user-select: none;
}
.icon-btn:hover { background: var(--info-bg); }
.icon-btn[aria-disabled="true"] { color: #c3c8d0; pointer-events: none; }

.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-row > div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.stat-row strong { display: block; font-size: 1.05rem; }

/* --- Sammenligning ------------------------------------------------------- */

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.tab {
    display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px;
    border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); text-decoration: none; font-size: .9rem; white-space: nowrap;
}
.tab.is-active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.controls .full { flex-basis: 100%; margin: 0; }
.field-inline { margin: 0; flex: 1 1 140px; }
.field-inline > span { font-size: .8rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.field select {
    width: 100%; min-height: var(--tap); padding: 8px 10px; font: inherit; font-size: 16px;
    color: var(--text); background: var(--surface); border: 1px solid #c9ced6; border-radius: 8px;
}
.stepper { display: flex; align-items: flex-end; gap: 8px; flex: 2 1 260px; }
.stepper .field-inline { flex: 1; }

.toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.toggle button { border: 0; background: var(--surface); padding: 6px 12px; font: inherit; font-size: .85rem; color: var(--muted); cursor: pointer; min-height: 36px; }
.toggle button.is-active { background: var(--info-bg); color: var(--primary); font-weight: 600; }

.table-card { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.table .num { text-align: right; white-space: nowrap; }
.table .sw { margin-right: 6px; vertical-align: -1px; }
.table-sortable th button {
    background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: inherit; white-space: nowrap;
}
.table-sortable th[aria-sort="ascending"] button::after { content: " ▲"; font-size: .7em; }
.table-sortable th[aria-sort="descending"] button::after { content: " ▼"; font-size: .7em; }
.sw-series-0 { background: var(--series-0); }
.sw-series-1 { background: var(--series-1); }
.sw-series-2 { background: var(--series-2); }
.sw-series-3 { background: var(--series-3); }

.quick-links { margin: 0 0 12px; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--primary); }
.btn-secondary:hover { background: var(--info-bg); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .875rem; }

/* --- Grafdetaljer: temperatur, noter, advarsler ------------------------------ */

.chart-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin: 4px 8px 0; }
.chart-foot .legend { margin: 0; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); min-height: 36px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--chart-temp); }
.ln { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; }
.ln-temp { border-color: var(--chart-temp); }
.sw-alert { background: transparent; border: 2px solid var(--error); }
.sw-note { background: var(--chart-note); opacity: .35; }
.tt-temp { color: var(--chart-temp); }
.tt-alert { color: var(--error); font-weight: 600; }
.tt-notetag { color: var(--chart-note); }

.period-notes { list-style: none; margin: 8px 8px 0; padding: 0; font-size: .9rem; }
.period-notes li { padding: 6px 0; border-top: 1px solid var(--border); }
.tag { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 4px; margin-right: 6px; vertical-align: 1px; }
.tag-note { background: #f1eafe; color: var(--chart-note); }
.tag-alert { background: var(--error-bg); color: var(--error); }

.alert-card { border-color: #f4c7c3; }
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.alert-list li:first-child { border-top: 0; }
.alert-list a { color: var(--error); font-weight: 600; text-decoration: none; }
.alert-actions { display: flex; gap: 4px; }

/* --- Noter -------------------------------------------------------------- */

.form-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field input[type="date"], .field input[type="month"] { min-width: 0; -webkit-appearance: none; appearance: none; }
.field textarea {
    width: 100%; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text);
    background: var(--surface); border: 1px solid #c9ced6; border-radius: 8px; resize: vertical;
}
.form-actions { display: flex; gap: 8px; }
.note-list { list-style: none; padding: 0; margin: 0; }
.note-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.note-period { color: var(--muted); font-size: .85rem; }
.note-actions { display: flex; align-items: center; gap: 4px; }
.note-body { margin: 8px 0 0; color: var(--muted); }
.btn-danger { color: var(--error); }

/* --- Analyse ---------------------------------------------------------- */

.tabs-5 { grid-template-columns: repeat(3, 1fr); }
.chart-calendar { height: 860px; }
.chart-heatmap { height: 520px; }
.card-grid-tight { margin-top: 0; }

/* --- Navigation: bundmenu på mobil ------------------------------------- */

.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 16px;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand svg { width: 24px; height: 24px; fill: var(--accent); }
.logout { margin-left: auto; }

.nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: flex;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.nav-item {
    flex: 1;
    min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: .75rem;
}
.nav-item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.is-active { color: var(--primary); font-weight: 600; }

/* --- Desktop: menu i topbjælken ---------------------------------------- */

@media (min-width: 800px) {
    .main { padding: 24px; }
    .card-grid { grid-template-columns: 1fr 1fr; }
    .stat-row { grid-template-columns: repeat(4, 1fr); }
    .tabs { display: flex; }
    .chart-calendar { height: 280px; }
    .tab { flex: none; }
    .chart-main { height: 440px; }
    .chart-small { height: 260px; }
    .nav {
        position: static;
        height: auto; padding: 0;
        background: none; border: 0;
        gap: 4px;
    }
    .nav-item { flex: none; flex-direction: row; gap: 8px; padding: 8px 12px; border-radius: 8px; font-size: .95rem; }
    .nav-item svg { width: 20px; height: 20px; }
    .nav-item:hover { background: var(--bg); color: var(--text); }
    .nav-item.is-active { background: var(--info-bg); }
}
