/* DUI Varme – stylesheet. Ingen eksterne afhængigheder (CSP: self). */

:root {
    --bg: #f6f2ec;
    --surface: #ffffff;
    --surface-2: #fbf8f3;
    --border: #e7dfd3;
    --text: #2b2620;
    --muted: #786e61;
    --accent: #c25f1d;
    --accent-dark: #a34c12;
    --accent-soft: #fbe9da;
    --ok: #2c7a4b;
    --ok-soft: #e2f1e7;
    --bad: #ad362d;
    --bad-soft: #fae5e2;
    --view: #5b6470;
    --view-soft: #eaeef2;
    --warn: #8a6d1d;
    --warn-soft: #f7efd8;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(43, 38, 32, .05), 0 10px 28px -16px rgba(43, 38, 32, .28);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17130f;
        --surface: #221c16;
        --surface-2: #2a231c;
        --border: #3a3128;
        --text: #f3ece3;
        --muted: #b3a696;
        --accent: #e07c38;
        --accent-dark: #f0924f;
        --accent-soft: #3a2417;
        --ok: #6fd39a;
        --ok-soft: #1c3326;
        --bad: #f08a80;
        --bad-soft: #3a201d;
        --view: #a4b0bd;
        --view-soft: #263039;
        --warn: #e4c56f;
        --warn-soft: #332c17;
        --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 12px 30px -18px rgba(0, 0, 0, .7);
    }
}

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

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1 0 auto;
    width: 100%;
}

a {
    color: var(--accent-dark);
}

h1, h2, h3 {
    line-height: 1.2;
    margin: 0 0 .4rem;
    font-weight: 650;
    letter-spacing: -.01em;
}

h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

p { margin: .25rem 0 .75rem; }

code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: .86em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .1rem .35rem;
}

.small { font-size: .85rem; }
.muted { color: var(--muted); }
.text-bad { color: var(--bad); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--accent);
    color: #fff;
    padding: .6rem 1rem;
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 100;
}
.skip-link:focus { left: 0; }

/* ---------------------------------------------------------------- topbar */

.topbar {
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(10px);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: .65rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 1.05rem;
}

.brand-mark-lg {
    width: 3rem;
    height: 3rem;
    font-size: 1.6rem;
    border-radius: 14px;
    margin-bottom: .5rem;
}

.main-nav {
    display: flex;
    gap: .25rem;
    margin-left: .5rem;
}

.main-nav a {
    text-decoration: none;
    color: var(--muted);
    padding: .45rem .7rem;
    border-radius: 999px;
    font-weight: 550;
    font-size: .95rem;
}

.main-nav a:hover,
.main-nav a:focus-visible {
    color: var(--text);
    background: var(--surface-2);
}

.userbox {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.user-name { font-weight: 600; }
.user-link { font-size: .88rem; color: var(--muted); }
.user-link:hover { color: var(--text); }

.inline-form { display: inline; margin: 0; }

/* --------------------------------------------------------------- banners */

.demo-banner {
    max-width: 1200px;
    margin: .9rem auto 0;
    padding: .6rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--warn-soft);
    color: var(--warn);
    border: 1px dashed color-mix(in srgb, var(--warn) 45%, transparent);
    font-size: .92rem;
    display: flex;
    gap: .5rem;
    align-items: baseline;
}

.flash {
    max-width: 1200px;
    margin: .9rem auto 0;
    padding: .7rem 1rem;
    border-radius: var(--radius-sm);
    font-size: .95rem;
    border: 1px solid var(--border);
    background: var(--surface);
}

.flash-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }
.flash-fejl { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: var(--bad); }
.flash-info { background: var(--view-soft); border-color: var(--border); color: var(--text); }

/* ----------------------------------------------------------------- pages */

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.page-head h1 { margin-bottom: .15rem; }
.page-head .muted { margin: 0; }

.page-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.15rem 1.25rem;
    margin-bottom: 1.1rem;
}

.panel > h2 { margin-bottom: .6rem; }

.empty-state {
    padding: 2rem;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

/* ------------------------------------------------------------- assoc tabs */

.assoc-tabs {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.assoc-tab {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .45rem .9rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    text-decoration: none;
    font-weight: 550;
    font-size: .95rem;
}

.assoc-tab:hover { color: var(--text); }

.assoc-tab.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.assoc-dot {
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
    background: var(--dot, var(--accent));
    display: inline-block;
    flex: none;
}

.assoc-single {
    font-weight: 600;
    margin-bottom: .8rem;
}

/* ------------------------------------------------------------ room cards */

.room-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 1rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.room-card {
    padding: 1rem 1.1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: .7rem;
    transition: opacity .15s ease, transform .15s ease;
}

.room-card.is-busy { opacity: .6; pointer-events: none; }

.room-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .5rem;
}

.room-head h2 { margin: 0; font-size: 1.08rem; }
.room-floor { margin: 0; font-size: .83rem; }

.temps {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem;
    align-items: stretch;
}

.temp {
    border-radius: var(--radius-sm);
    padding: .55rem .7rem;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .15rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.temp-current .temp-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; }
.temp-unit { font-size: .95rem; color: var(--muted); }
.temp-label {
    flex-basis: 100%;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}

.temp-target {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
    background: var(--accent-soft);
}

.target-wrap { text-align: center; }
.target-wrap .temp-value { display: block; font-size: 1.35rem; font-weight: 700; color: var(--accent-dark); }

.btn-round {
    width: 2.1rem;
    height: 2.1rem;
    flex: none;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
    background: var(--surface);
    color: var(--accent-dark);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
}

.btn-round:hover:not(:disabled) { background: var(--accent); color: #fff; }
.btn-round:disabled { opacity: .4; cursor: not-allowed; }

.room-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    flex-wrap: wrap;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    font-size: .9rem;
    user-select: none;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.switch-track {
    width: 2.6rem;
    height: 1.5rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--muted) 35%, var(--surface));
    position: relative;
    transition: background .15s ease;
    flex: none;
}

.switch-knob {
    position: absolute;
    top: .18rem;
    left: .18rem;
    width: 1.14rem;
    height: 1.14rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
    transition: transform .15s ease;
}

.switch input:checked + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track .switch-knob { transform: translateX(1.1rem); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .5; }

.switch-text { color: var(--muted); }
.switch-text [data-field="switch-text"] { color: var(--text); font-weight: 600; }

.modes { display: flex; gap: .3rem; flex-wrap: wrap; }

.pill {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .18rem .6rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    border: 1px solid transparent;
    background: var(--view-soft);
    color: var(--view);
    white-space: nowrap;
}

.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-view { background: var(--view-soft); color: var(--view); }
.pill-super { background: var(--accent-soft); color: var(--accent-dark); }

.mode {
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-family: inherit;
}

.mode.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.mode:disabled { opacity: .5; cursor: not-allowed; }

.room-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    flex-wrap: wrap;
    margin-top: auto;
}

.room-status:empty { display: none; }

.room-error {
    margin: 0;
    font-size: .82rem;
    color: var(--bad);
    background: var(--bad-soft);
    border-radius: var(--radius-sm);
    padding: .4rem .6rem;
}

.no-device {
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: .8rem;
    background: var(--surface-2);
}

.no-device p { margin: 0 0 .25rem; }

/* -------------------------------------------------------------- activity */

.activity-list,
.simple-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .45rem;
}

.activity-list li {
    display: flex;
    gap: .6rem;
    align-items: baseline;
    flex-wrap: wrap;
    font-size: .9rem;
    padding-bottom: .4rem;
    border-bottom: 1px solid var(--border);
}

.activity-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.activity-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .82rem; min-width: 8.5rem; }
.activity-who { font-weight: 600; }
.activity-what { color: var(--muted); }

.simple-list li { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

.checklist { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .45rem; }
.checklist li::marker { color: var(--accent); font-weight: 700; }

/* --------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1rem;
    border-radius: 999px;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: .93rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 80%, #000); }

.btn-small { padding: .32rem .7rem; font-size: .84rem; }
.btn-block { width: 100%; }

/* ----------------------------------------------------------------- forms */

.form { display: flex; flex-direction: column; gap: .8rem; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: .8rem;
    align-items: end;
}

.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--muted); }

.field input,
.field select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .5rem .65rem;
    width: 100%;
}

.field input:focus,
.field select:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.checkbox-field {
    flex-direction: row;
    align-items: center;
    gap: .5rem;
    padding-bottom: .4rem;
}

.checkbox-field input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: .4rem;
    margin-bottom: .8rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .45rem .6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-size: .9rem;
}

.checkbox-item input { accent-color: var(--accent); width: 1rem; height: 1rem; }

.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ----------------------------------------------------------------- tables */

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: .55rem .6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table th {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tr.row-bad { background: var(--bad-soft); }

/* ------------------------------------------------------------ admin views */

.admin-nav {
    display: flex;
    gap: .3rem;
    flex-wrap: wrap;
    margin-bottom: 1.1rem;
    padding: .3rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    width: fit-content;
    max-width: 100%;
}

.admin-nav-link {
    padding: .4rem .85rem;
    border-radius: 999px;
    text-decoration: none;
    color: var(--muted);
    font-size: .9rem;
    font-weight: 550;
    white-space: nowrap;
}

.admin-nav-link:hover { color: var(--text); background: var(--surface-2); }
.admin-nav-link.is-active { background: var(--accent); color: #fff; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: .8rem;
    margin-bottom: 1.1rem;
}

.stat {
    padding: .8rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.stat-number { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-warn .stat-number { color: var(--warn); }

.admin-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 0;
}

.admin-columns > .panel { min-width: 0; }
.admin-columns > .panel:first-child { margin-right: .55rem; }
.admin-columns > .panel:last-child { margin-left: .55rem; }

@media (max-width: 760px) {
    .admin-columns > .panel:first-child,
    .admin-columns > .panel:last-child { margin-left: 0; margin-right: 0; }
}

.kv {
    display: grid;
    grid-template-columns: minmax(8rem, auto) 1fr;
    gap: .3rem .8rem;
    margin: .6rem 0 0;
    font-size: .9rem;
}

.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.user-list { display: flex; flex-direction: column; gap: .8rem; }

.user-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .9rem 1rem;
    background: var(--surface-2);
}

.user-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .8rem;
    flex-wrap: wrap;
}

.user-card-head h3 { margin: 0; }
.user-badges { display: flex; gap: .3rem; flex-wrap: wrap; }

.membership-list { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0; }
.membership-chip { margin: 0; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .2rem .3rem .2rem .7rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: .84rem;
}

.chip-remove {
    border: 0;
    background: transparent;
    color: var(--bad);
    font-size: 1rem;
    line-height: 1;
    padding: .1rem .35rem;
    border-radius: 50%;
    cursor: pointer;
}

.chip-remove:hover { background: var(--bad-soft); }

.row-actions summary {
    cursor: pointer;
    font-size: .87rem;
    font-weight: 600;
    color: var(--accent-dark);
    margin-top: .4rem;
}

.row-action-grid {
    display: flex;
    flex-direction: column;
    gap: .8rem;
    margin-top: .7rem;
    padding-top: .7rem;
    border-top: 1px solid var(--border);
}

.action-buttons { display: flex; gap: .4rem; flex-wrap: wrap; }
.action-buttons form { margin: 0; }

.assoc-list { display: flex; flex-direction: column; gap: .8rem; }

.assoc-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .9rem 1rem;
    background: var(--surface-2);
}

.assoc-card header {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    justify-content: space-between;
    margin-bottom: .7rem;
    flex-wrap: wrap;
}

.assoc-card h3 { margin: 0; display: inline-flex; align-items: center; gap: .45rem; }

.notice {
    border-radius: var(--radius-sm);
    padding: .8rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    background: var(--surface);
}

.notice-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.notice-bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }

.code-block {
    overflow-x: auto;
    max-height: 22rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .8rem;
    font-size: .8rem;
    line-height: 1.45;
}

.danger-zone { border-color: color-mix(in srgb, var(--bad) 30%, var(--border)); }

/* ----------------------------------------------------------------- login */

.auth-wrap {
    min-height: 78vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: var(--shadow);
    padding: 2rem;
}

.auth-brand { text-align: center; margin-bottom: 1.4rem; }
.auth-brand h1 { margin: 0 0 .3rem; }
.auth-help { margin-top: 1.2rem; font-size: .88rem; text-align: center; }

/* ---------------------------------------------------------------- footer */

.site-footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .82rem;
    padding: 1rem 1.25rem;
    display: flex;
    gap: .8rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* --------------------------------------------------------------- toast */

.toast-stack {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: .45rem;
    max-width: min(360px, calc(100vw - 2rem));
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: .7rem .9rem;
    font-size: .9rem;
    animation: toast-in .18s ease;
}

.toast-fejl { border-left-color: var(--bad); }
.toast-ok { border-left-color: var(--ok); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 620px) {
    .topbar-inner { flex-wrap: wrap; }
    .userbox { margin-left: 0; justify-content: flex-start; }
    .temps { grid-template-columns: 1fr; }
    .activity-time { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
