:root {
    --bg: #0f172a;
    --bg-2: #111c33;
    --card: #1e293b;
    --card-2: #243349;
    --border: #2c3a52;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --on: #fbbf24;
    --ok: #22c55e;
    --err: #ef4444;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(15, 23, 42, .85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}
.topbar__inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: .75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }
.topbar__right { display: flex; align-items: center; gap: .75rem; }
.user { color: var(--muted); font-size: .9rem; }
.conn { color: var(--muted); font-size: 1.1rem; line-height: 1; }
.conn.is-ok { color: var(--ok); }
.conn.is-err { color: var(--err); }

/* ---------- Buttons / inputs ---------- */
.btn {
    background: var(--card-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .5rem .8rem;
    font-size: .9rem;
    cursor: pointer;
}
.btn:hover { background: #2c3e58; }
.btn--ghost { background: transparent; }
.input {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .55rem .8rem;
    font-size: .95rem;
    min-width: 0;
}
.input:focus { outline: none; border-color: var(--accent); }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.dash__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.dash__head h1 { font-size: 1.4rem; margin: 0; }
.dash__tools { display: flex; gap: .5rem; flex: 1; max-width: 480px; }
.dash__tools .input { flex: 1; }

/* Flytende toast – tas ut av flyten så kortene ikke flytter seg */
.status {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    z-index: 60;
    max-width: 90vw;
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .6rem 1rem;
    color: var(--text);
    box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
}

/* ---------- Grid of entities ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: .8rem;
}
.loading { color: var(--muted); padding: 2rem 0; }

.domain { grid-column: 1 / -1; margin: 1rem 0 .25rem; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .55rem;
    min-height: 64px;
    justify-content: space-between;
    transition: border-color .2s, background .2s;
}
.card.is-on { border-color: var(--on); background: linear-gradient(180deg, var(--card-2), var(--card)); }

/* Vertikal kontrollkort-layout: navn i full bredde øverst, state + bryter under */
.card__head { display: flex; align-items: flex-start; gap: .55rem; }
.card__icon { font-size: 1.4rem; line-height: 1.2; flex: none; }

/* Lyspære som lyser i sin egen farge når på (currentColor settes inline) */
.bulb { display: inline-flex; line-height: 1; transition: color .2s, filter .2s; }
.bulb svg { width: 1.4rem; height: 1.4rem; display: block; }
.bulb.is-lit { filter: drop-shadow(0 0 6px currentColor); }
.card__name { font-weight: 600; flex: 1; min-width: 0; line-height: 1.25; overflow-wrap: anywhere; }
.card__foot { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; row-gap: .4rem; }
.card__control { display: flex; align-items: center; gap: .5rem; flex: none; }
.colorpick {
    width: 30px; height: 30px; padding: 0; flex: none; cursor: pointer;
    border: 1px solid var(--border); border-radius: 8px; background: none;
}
.colorpick::-webkit-color-swatch-wrapper { padding: 3px; }
.colorpick::-webkit-color-swatch { border: none; border-radius: 6px; }
.colorpick::-moz-color-swatch { border: none; border-radius: 6px; }
.card__body { flex: 1; min-width: 0; }
.card__state { color: var(--muted); font-size: .85rem; }
.card.is-on .card__state { color: var(--on); }
.card__admin { display: flex; gap: .1rem; flex: none; }
.hidebtn, .editbtn {
    background: transparent; border: none; color: var(--muted); cursor: pointer;
    font-size: .92rem; line-height: 1; padding: .1rem .2rem; flex: none; opacity: .55;
}
.hidebtn:hover, .editbtn:hover { opacity: 1; }
.rename-input { flex: 1; min-width: 0; font-weight: 600; }

/* ---------- Toggle switch ---------- */
.toggle { position: relative; width: 46px; height: 28px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track {
    position: absolute; inset: 0;
    background: #475569; border-radius: 999px; transition: background .2s;
}
.toggle .thumb {
    position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%;
    background: #fff; transition: transform .2s;
}
.toggle input:checked + .track { background: var(--on); }
.toggle input:checked + .track .thumb { transform: translateX(18px); }
.toggle input:disabled + .track { opacity: .5; }

/* Lysdimmer (slider på dimbare lys) */
.dimrow { display: flex; align-items: center; gap: .6rem; }
.dimmer { flex: 1; min-width: 0; accent-color: var(--on); cursor: pointer; height: 1.5rem; }
.dimval { color: var(--muted); font-size: .8rem; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Media player ---------- */
.card--media .media__info { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mediabtns { display: flex; gap: .5rem; justify-content: center; }
.mediabtn {
    background: var(--card-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 10px; font-size: 1.15rem; line-height: 1; width: 46px; height: 40px; cursor: pointer;
}
.mediabtn:hover { background: #2c3e58; }
.media__volicon { font-size: .9rem; flex: none; }

/* ---------- Auth ---------- */
body.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(1200px 600px at 50% -10%, #16233f, var(--bg));
    padding: 1rem;
}
.auth__card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
}
.auth__brand { font-size: 1.8rem; margin: 0; text-align: center; }
.auth__sub { color: var(--muted); text-align: center; margin: .25rem 0 1.5rem; }
.auth__card form { display: flex; flex-direction: column; gap: .85rem; }
.auth__card input[type=text],
.auth__card input[type=email],
.auth__card input[type=password] {
    background: var(--bg-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .7rem .85rem;
    font-size: 1rem;
    width: 100%;
}
.auth__card input:focus { outline: none; border-color: var(--accent); }
.auth__card button[type=submit] {
    background: var(--accent);
    color: #06283a;
    border: none;
    border-radius: 10px;
    padding: .75rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: .25rem;
}
.auth__card label { font-size: .9rem; color: var(--muted); }
.auth__card .form-check,
.auth__card .checkbox { display: flex; align-items: center; gap: .5rem; color: var(--muted); }

.alert { border-radius: 10px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .9rem; }
.alert--error { background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .4); color: #fecaca; }
.alert--info { background: rgba(56, 189, 248, .12); border: 1px solid rgba(56, 189, 248, .4); color: #bae6fd; }

/* ---------- Navigasjon ---------- */
.brand { color: var(--text); text-decoration: none; }
.nav { border-top: 1px solid var(--border); }
.nav__inner {
    max-width: 1100px; margin: 0 auto; padding: .4rem 1rem;
    display: flex; gap: .35rem; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.nav__link {
    color: var(--muted); padding: .45rem .75rem; border-radius: 9px;
    white-space: nowrap; font-size: .92rem;
}
.nav__link:hover { background: var(--card); color: var(--text); }
.nav__link.is-active { background: var(--card-2); color: var(--text); }

.hint { color: var(--muted); font-size: .9rem; margin: .1rem 0 1rem; }
.muted { color: var(--muted); font-size: .85rem; }

/* ---------- Oversikt: redigerbare kort ---------- */
.card--edit { flex-direction: column; align-items: stretch; gap: .6rem; }
.card__top { display: flex; align-items: center; gap: .7rem; }
.card__id {
    color: var(--muted); font-size: .76rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card__edit { display: flex; gap: .5rem; }
.input--sm { padding: .4rem .5rem; font-size: .85rem; }
.card__edit .js-label { flex: 1; min-width: 0; }
.card__edit .js-room { flex: none; width: 42%; }
.star {
    background: transparent; border: none; color: #475569;
    font-size: 1.4rem; line-height: 1; cursor: pointer; padding: .1rem .3rem; flex: none;
}
.star.is-on { color: var(--on); }

/* ---------- Profil ---------- */
.profile { max-width: 560px; }
.panel {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; margin-top: 1rem;
}
.profile__meta { display: flex; gap: 2rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.form { display: flex; flex-direction: column; gap: .85rem; max-width: 360px; }
.form label { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; color: var(--muted); }
.form input {
    background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
    border-radius: 10px; padding: .6rem .75rem; font-size: 1rem;
}
.form input:focus { outline: none; border-color: var(--accent); }
.btn--primary { background: var(--accent); color: #06283a; border: none; font-weight: 700; }

.card__id .warn { color: var(--on); }

/* ---------- Rom-admin ---------- */
.panel h2 { margin-top: 0; font-size: 1.1rem; }
.rooms-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.room-row { display: flex; align-items: center; gap: .5rem; }
.drag-handle {
    cursor: grab; touch-action: none; user-select: none; flex: none;
    color: var(--muted); font-size: 1.3rem; line-height: 1; padding: 0 .15rem;
}
.drag-handle:active { cursor: grabbing; }
.room-row.dragging { opacity: .6; background: var(--card-2); border-radius: 8px; }
.room-row .js-icon { width: 58px; flex: none; text-align: center; }
.room-row .js-label { flex: 1; min-width: 0; }
.room-row__count { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.newroom { display: flex; gap: .5rem; align-items: center; }
.newroom #newicon { width: 64px; flex: none; text-align: center; }
.newroom #newlabel { flex: 1; min-width: 0; }
.btn--danger { background: transparent; border: 1px solid var(--border); }
.btn--danger:hover { background: rgba(239, 68, 68, .15); border-color: var(--err); }
.room-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.room-row__main .input { width: 100%; }
.room-row__slug { color: var(--muted); font-size: .72rem; }
.iconbar { display: flex; flex-wrap: wrap; gap: .3rem; margin: -.25rem 0 .75rem; }
.iconchip {
    background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px;
    font-size: 1.15rem; line-height: 1; padding: .25rem .4rem; cursor: pointer;
}
.iconchip:hover { border-color: var(--accent); }
.domain--hidden { color: var(--muted); margin-top: 1.5rem; }

.areas-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: .5rem; margin-top: .75rem;
}
.area-row {
    display: flex; align-items: center; gap: .5rem;
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: 10px; padding: .4rem .6rem;
}
.area-row.is-linked { border-color: var(--accent); }
.area-row__name {
    flex: 1; min-width: 0; font-size: .9rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.area-row .js-room { flex: none; width: 46%; }

/* ---------- Brukeradmin ---------- */
.chk { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.chk input { accent-color: var(--accent); }
.newuser { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.newuser .input { flex: 1; min-width: 150px; }
.users-list { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.user-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem; display: flex; flex-direction: column; gap: .6rem;
}
.user-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.user-row .input { flex: 1; min-width: 160px; }
.user-rooms { display: flex; flex-wrap: wrap; gap: .45rem 1rem; align-items: center; font-size: .9rem; }
.user-rooms__label { color: var(--muted); }
.user-actions { display: flex; gap: .5rem; align-items: center; }
.user-tag { color: var(--accent); font-size: .78rem; border: 1px solid var(--border); border-radius: 6px; padding: .1rem .45rem; }

/* ---------- Termostat ---------- */
.thermo { display: flex; align-items: center; gap: .4rem; flex: none; }
.thermo__btn {
    width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--card-2); color: var(--text); font-size: 1.35rem; line-height: 1; cursor: pointer;
}
.thermo__btn:hover { background: #2c3e58; }
.thermo__val { min-width: 48px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.thermo.is-pending { opacity: .55; }
.card--thermo.is-on { border-color: var(--on); }

/* ---------- Oversikt: handlingsknapper + skjulte ---------- */
.card__actions { display: flex; flex-direction: column; gap: .2rem; flex: none; }
.eye {
    background: transparent; border: none; font-size: 1.1rem; line-height: 1;
    cursor: pointer; padding: .1rem .25rem; opacity: .85;
}
.eye:hover { opacity: 1; }
.card.is-hidden { opacity: .5; }
.card.is-hidden .card__name { text-decoration: line-through; }

/* Tydelige kurerings-knapper i Oversikt */
.ovbtns { display: flex; gap: .4rem; flex-wrap: wrap; }
.ovbtn {
    flex: 1 1 auto; min-width: 92px; background: var(--bg-2); border: 1px solid var(--border); color: var(--muted);
    border-radius: 9px; padding: .45rem .3rem; font-size: .82rem; cursor: pointer; white-space: nowrap;
}
.ovbtn:hover { color: var(--text); }
.ovbtn.is-on { background: var(--card-2); border-color: var(--accent); color: var(--text); }
.ovbtn.js-fav.is-on { border-color: var(--on); color: var(--on); }

@media (max-width: 520px) {
    .dash__tools { max-width: none; width: 100%; flex-wrap: wrap; }
}
