@font-face {
    font-family: "DSEG7";
    src: url("../fonts/DSEG7Classic-BoldItalic.woff2") format("woff2");
    font-weight: 700;
    font-style: italic;
    font-display: swap;
}

:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --warn: #b45309;
    --alarm: #b91c1c;
    --alarm-bg: #fee2e2;
    --off: #4b5563;
    --off-bg: #e5e7eb;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117;
        --surface: #161b22;
        --ink: #e6edf3;
        --muted: #8b949e;
        --border: #30363d;
        --accent: #58a6ff;
        --ok: #56d364;
        --ok-bg: #0f2d1a;
        --warn: #e3b341;
        --alarm: #ff7b72;
        --alarm-bg: #3a1618;
        --off: #9da7b3;
        --off-bg: #21262d;
        --shadow: none;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }

/* ---------- application shell: fixed top header + left navigation ---------- */
:root { --header-h: 3.5rem; --side-w: 250px; }
html { scroll-padding-top: calc(var(--header-h) + .75rem); } /* anchors (#history) must not hide under the fixed header */
[hidden] { display: none !important; }

body:has(> .app-header) {
    display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr);
    min-height: 100vh; padding-top: var(--header-h);
}

.app-header {
    position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); z-index: 40;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.hdr-left, .hdr-right { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; color: var(--ink); line-height: 1.15; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; flex: none; width: 2.2rem; height: 2.2rem; padding: 0;
    background: transparent; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }

.hdr-status {
    display: inline-flex; align-items: center; gap: .55rem; padding: .3rem .8rem; border-radius: 999px; white-space: nowrap;
    background: var(--bg); border: 1px solid var(--border); color: var(--ink); font-size: .85rem; font-weight: 600;
}
.hdr-status:hover { text-decoration: none; border-color: var(--muted); }
.hdr-dot { width: .6rem; height: .6rem; border-radius: 50%; background: #9ca3af; flex: none; }
.hdr-status.ok .hdr-dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
.hdr-status.warn .hdr-dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .25); }
.hdr-status.alarm { background: var(--alarm-bg); border-color: var(--alarm); color: var(--alarm); }
.hdr-status.alarm .hdr-dot { background: var(--alarm); box-shadow: 0 0 0 3px rgba(185, 28, 28, .25); }
.hdr-faults { padding-left: .55rem; border-left: 1px solid currentColor; }
.hdr-clock { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.usermenu { position: relative; }
.hdr-user {
    display: flex; align-items: center; gap: .55rem; padding: .25rem .4rem .25rem .25rem; border: 0; border-radius: 10px;
    background: transparent; color: var(--ink); font: inherit; cursor: pointer;
}
.hdr-user:hover, .hdr-user[aria-expanded="true"] { background: var(--bg); }
.hdr-user .chev { color: var(--muted); }
.user-pop {
    position: absolute; right: 0; top: calc(100% + .45rem); min-width: 220px; padding: .4rem; z-index: 50;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(16, 24, 40, .2);
}
.pop-head { padding: .5rem .7rem .6rem; margin-bottom: .3rem; border-bottom: 1px solid var(--border); }
.pop-head strong, .pop-head small { display: block; line-height: 1.3; }
.user-pop form { margin: 0; }
.pop-link {
    display: flex; align-items: center; gap: .65rem; width: 100%; padding: .5rem .7rem; border: 0; border-radius: 8px;
    background: transparent; color: var(--ink); font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.pop-link:hover { background: var(--bg); text-decoration: none; }
.pop-link.danger:hover { color: var(--alarm); }

.sidebar {
    position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto;
    background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem;
}
.side-nav { display: flex; flex-direction: column; gap: .2rem; }
.side-section { margin: 1rem .75rem .3rem; font-size: .72rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.side-link {
    display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem; border-radius: 9px;
    color: var(--muted); font-weight: 600;
}
.side-link svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.side-link:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.side-link.active { background: #111827; color: #c6f04a; }
@media (prefers-color-scheme: dark) { .side-link.active { background: #21262d; } }
.nav-backdrop { display: none; }

/* ---------- layout ---------- */
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
.page-narrow { max-width: 720px; }
.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: .4rem; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.title-row h1 { margin-bottom: 0; }

.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .7rem; }

/* ---------- buttons / pills ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-sm { padding: .3rem .7rem; font-size: .87rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-warn { background: #f59e0b; border-color: #f59e0b; color: #1f1300; }
.btn-danger { background: transparent; color: var(--alarm); border-color: var(--alarm); }
.btn-danger:hover { background: var(--alarm-bg); border-color: var(--alarm); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pill { display: inline-block; padding: .15rem .65rem; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.pill-lg { font-size: .9rem; padding: .3rem .9rem; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-off { background: var(--off-bg); color: var(--off); }
.pill-alarm { background: var(--alarm-bg); color: var(--alarm); }

.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: #9ca3af; margin-right: .35rem; }
.dot-on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }

/* ---------- flash ---------- */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-weight: 500; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-err { background: var(--alarm-bg); color: var(--alarm); }

/* ---------- dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1.1rem; box-shadow: var(--shadow); }
.tile-label { display: block; color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile strong { font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.tile strong small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.tile-alarm { border-color: var(--alarm); }
.tile-alarm strong { color: var(--alarm); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.meter-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .8rem; }
.card-head h2 a { color: var(--ink); }
.card-head p { margin: 0; font-size: .87rem; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .8rem; font-size: .87rem; }
.device-link:hover { text-decoration: none; }
.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- detail ---------- */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; margin-bottom: 1rem; }
.device-wrap .device { font-size: 17px; margin: 0 auto 1rem; }
.hint { color: var(--muted); font-size: .84rem; margin: .3rem 0 1rem; }
.device-wrap .hint { text-align: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.fault-form { display: flex; gap: .6rem; }
.fault-form select { flex: 1; }
.danger-zone { border-color: color-mix(in srgb, var(--alarm) 40%, var(--border)); }

.seg-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-tabs button { border: 0; background: transparent; color: var(--muted); padding: .3rem .8rem; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.seg-tabs button.active { background: var(--accent); color: #fff; }
.activity-tabs { margin: 1.25rem 0 .9rem; }
#chart { width: 100%; height: 240px; display: block; }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: flex; gap: .75rem; padding: .45rem 0; border-top: 1px solid var(--border); font-size: .9rem; }
.events li:first-child { border-top: 0; }
.events time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev-level { font-size: .72rem; font-weight: 800; letter-spacing: .05em; padding: .05rem .4rem; border-radius: 4px; align-self: center; background: var(--off-bg); color: var(--off); }
.ev-alarm .ev-level { background: var(--alarm-bg); color: var(--alarm); }
.ev-warning .ev-level { background: #fef3c7; color: var(--warn); }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: .4rem .6rem; border-bottom: 1px solid var(--border); }
.table td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }

/* ---------- forms ---------- */
.form fieldset { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 1rem 1.1rem .4rem; margin: 0 0 1rem; }
.form legend { font-weight: 700; padding: 0 .4rem; }
.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; font-size: .9rem; }
input[type=text], input[type=number], input[type=password], input[type=datetime-local], select {
    width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--ink); font: inherit;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.err { color: var(--alarm); font-size: .85rem; margin: .25rem 0 0; }
.form-actions { display: flex; gap: .75rem; }

/* =====================================================================
   Device replica: AMICI Smart AS-MUL-PRO WiFi multi-function protector.
   Everything is sized in em so `font-size` on .device scales the whole unit.
   ===================================================================== */
.device { font-size: 14px; width: 24em; max-width: 100%; margin: 0 auto; color: #2b2f36; }
.dev-rail {
    display: flex; justify-content: space-between; padding: .55em 1.9em .3em;
    background: linear-gradient(#f7f7f5, #ececE8); border: 1px solid #d5d5d0; border-bottom: 0;
    border-radius: .5em .5em 0 0;
}
.dev-rail-bottom { border-bottom: 1px solid #d5d5d0; border-top: 0; border-radius: 0 0 .5em .5em; padding: .3em 1.9em .55em; }
.screw {
    width: 1.35em; height: 1.35em; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #d4d4d4, #6b6f76 70%);
    box-shadow: inset 0 0 0 .2em #a8abb0;
}
.dev-face {
    background: linear-gradient(#f4f4f1, #e9e9e5); border: 1px solid #cfcfca; margin: 0 -.35em;
    padding: .6em 1em .7em; border-radius: .5em; box-shadow: 0 .3em .8em rgba(0, 0, 0, .18);
}
.dev-title { text-align: center; font-size: .78em; font-weight: 800; letter-spacing: .02em; color: #555; margin-bottom: .55em; text-shadow: 0 1px 0 #fff; }

.dev-mid { display: grid; grid-template-columns: 1.6em 1fr 4.4em; gap: .5em; align-items: center; }
.dev-tags { display: flex; flex-direction: column; gap: .5em; }
.dev-tags span {
    writing-mode: vertical-rl; transform: rotate(180deg); font-size: .62em; font-weight: 800; color: #d8d8d8;
    background: #3a3d42; border-radius: .4em; padding: .55em .25em; text-align: center; letter-spacing: .05em;
}

.lcd {
    background: #04060a; border-radius: .35em; padding: .55em .8em .45em;
    box-shadow: 0 0 0 .32em #e4f0f5, 0 0 .9em .4em rgba(190, 230, 255, .55), inset 0 0 .6em rgba(0, 0, 0, .9);
    margin: .4em .3em;
}
.lcd-row { display: flex; justify-content: space-between; align-items: baseline; gap: .5em; min-height: 2.1em; }
.lcd-row-end { justify-content: flex-end; }
.seg { display: inline-flex; align-items: baseline; gap: .25em; white-space: nowrap; }
.seg b { font: 700 italic 1.75em/1.1 "DSEG7", "Consolas", monospace; letter-spacing: .02em; }
.seg i { font: 700 normal 1.05em/1 system-ui, sans-serif; opacity: .9; }
.seg-v { color: #c6f04a; }
.seg-ma { color: #e6f6ff; }
.seg-a { color: #ff3e3e; }
.seg-kw { color: #3a9dff; }
.seg-kw b { font-size: 2.1em; }
.relay-icon { color: #ff5a78; align-self: center; margin-right: 1.2em; }
.relay-open { display: none; }
.lcd-open .relay-closed { display: none; }
.lcd-open .relay-open { display: inline; }
.lcd-open .seg-a b, .lcd-open .seg-kw b, .lcd-open .seg-ma b { opacity: .55; }
.device.stale .lcd .seg b { opacity: .4; }

.leds { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5em; font-size: .62em; font-weight: 800; color: #555; }
.leds li { display: flex; align-items: center; gap: .55em; }
.led { width: 1.3em; height: 1.3em; border-radius: 50%; background: #56606b; box-shadow: inset 0 .1em .2em rgba(0, 0, 0, .5); flex: none; }
.led.on { background: #38e06a; box-shadow: 0 0 .5em .15em rgba(56, 224, 106, .75); }
.led-red.on { background: #ff4a4a; box-shadow: 0 0 .5em .15em rgba(255, 74, 74, .8); }

.dev-buttons { display: flex; justify-content: space-between; margin: .8em .2em .5em; }
.dev-buttons form { margin: 0; }
.dbtn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
    width: 3.5em; height: 3.5em; border-radius: 50%; border: .12em solid #7b7f86; color: #333;
    background: radial-gradient(circle at 35% 30%, #ffffff, #dcdcd8); font: 800 .8em system-ui, sans-serif;
    box-shadow: 0 .12em .25em rgba(0, 0, 0, .3); cursor: pointer; padding: 0; text-decoration: none;
}
a.dbtn:hover, button.dbtn:hover { filter: brightness(.95); text-decoration: none; }
.dbtn:active { transform: translateY(1px); box-shadow: 0 0 .1em rgba(0, 0, 0, .4); }
.dbtn-stack small { font-size: .7em; margin-bottom: .1em; }
.dev-buttons-static .dbtn { cursor: inherit; box-shadow: 0 .1em .2em rgba(0, 0, 0, .25); }

.dev-brand { display: flex; align-items: center; gap: .9em; font-size: .68em; font-weight: 800; color: #666; }
.dev-brand .logo { color: #2a4ea3; font-style: italic; font-size: 1.15em; }
.dev-brand .logo b { color: #d02c2c; }
.dev-brand .model { margin-left: .3em; }
.dev-brand .rating { font-size: .85em; }
.dev-brand .ce { margin-left: auto; font-size: 1.2em; }

/* ---------- small (dashboard cards) ---------- */
.meter-card .device { font-size: 13.5px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .row2 { grid-template-columns: 1fr; }
    .cards { grid-template-columns: 1fr; }
    .device-wrap .device { font-size: 14px; }
    .events li { flex-wrap: wrap; gap: .3rem .6rem; }
}

/* ---------- user avatar ---------- */
.avatar {
    width: 2rem; height: 2rem; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
    background: #111827; color: #c6f04a; font-weight: 800; font-size: .9rem;
}
.who { display: flex; flex-direction: column; line-height: 1.15; font-weight: 600; font-size: .88rem; text-align: left; }
.who small { color: var(--muted); font-weight: 500; font-size: .74rem; }

/* ---------- users ---------- */
.right { text-align: right; }
.table-scroll { overflow-x: auto; }
form.inline { display: inline; margin: 0; }
.role { display: inline-block; padding: .1rem .55rem; border-radius: 6px; font-size: .78rem; font-weight: 700; background: var(--off-bg); color: var(--off); }
.role-admin { background: #ede9fe; color: #6d28d9; }
.role-operator { background: #dbeafe; color: #1d4ed8; }
@media (prefers-color-scheme: dark) {
    .role-admin { background: #2b1d4f; color: #c4b5fd; }
    .role-operator { background: #16294a; color: #93c5fd; }
}
.badge-you { font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 .3rem; margin-left: .3rem; }
.kv dd.normal { font-weight: 400; }
.check { display: flex !important; align-items: center; gap: .5rem; font-weight: 500 !important; cursor: pointer; margin-top: .4rem; }
.check input { width: auto; }
.btn-block { width: 100%; padding: .65rem 1rem; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    padding: 1.5rem 1.6rem 1.7rem; box-shadow: 0 10px 30px rgba(16, 24, 40, .12);
}
.login-lcd {
    display: flex; justify-content: space-between; align-items: baseline; gap: .5rem;
    background: #04060a; border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1.3rem;
    box-shadow: 0 0 0 4px #e4f0f5, 0 0 16px 4px rgba(190, 230, 255, .35), inset 0 0 10px #000;
    font: 700 italic 1.25rem/1.2 "DSEG7", monospace;
}
@media (prefers-color-scheme: dark) { .login-lcd { box-shadow: 0 0 0 4px #3a4650, 0 0 16px 4px rgba(120, 180, 255, .18), inset 0 0 10px #000; } }
.login-lcd small { font: 700 .7rem system-ui, sans-serif; margin-left: .2rem; }
.c-v { color: #c6f04a; } .c-a { color: #ff3e3e; } .c-kw { color: #3a9dff; }
.login-brand { display: flex; align-items: center; gap: .65rem; }
.login-brand h1 { margin: 0; font-size: 1.35rem; }
.login-sub { margin: .35rem 0 1.1rem; }
.login-card .form fieldset { border: 0; padding: 0; }
.login-foot { text-align: center; font-size: .85rem; margin-top: 1rem; }

/* ---------- home ---------- */
.hero { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.hero h1 { margin-bottom: .1rem; }
.hero p { margin: 0; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.attn { list-style: none; margin: 0; padding: 0; }
.attn li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.attn li:first-child { border-top: 0; }
.shortcuts { display: grid; gap: .6rem; }
.shortcut { display: flex; flex-direction: column; gap: .1rem; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); }
.shortcut:hover { text-decoration: none; border-color: var(--accent); background: var(--bg); }

/* ---------- left panel hidden (desktop) ---------- */
@media (min-width: 861px) {
    html.nav-hidden body:has(> .app-header) { grid-template-columns: minmax(0, 1fr); }
    html.nav-hidden .sidebar { display: none; }
}

/* ---------- small screens: the panel becomes a slide-in drawer under the header ---------- */
@media (max-width: 1000px) { .hdr-clock { display: none; } }
@media (max-width: 860px) {
    body:has(> .app-header) { display: block; }
    .sidebar {
        position: fixed; top: var(--header-h); left: 0; bottom: 0; width: min(280px, 84vw); height: auto; z-index: 35;
        transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility .2s;
        box-shadow: 0 0 30px rgba(0, 0, 0, .25);
    }
    .sidebar.open { transform: none; visibility: visible; }
    .nav-backdrop.show { display: block; position: fixed; top: var(--header-h); left: 0; right: 0; bottom: 0; z-index: 34; background: rgba(0, 0, 0, .35); }
    .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) { .hdr-user .who { display: none; } }
@media (max-width: 560px) {
    .app-header { padding: 0 .6rem; gap: .5rem; }
    .hdr-left, .hdr-right { gap: .5rem; }
    .brand-text, .hdr-word { display: none; }
    .hdr-status { padding: .3rem .6rem; }
}

/* ---------- roles: feature chips and the check-box list ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; max-width: 34rem; }
.chip { font-size: .74rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--ink); white-space: nowrap; }
.chip-none { color: var(--muted); font-weight: 500; font-style: italic; }
.perm-fieldset { padding-bottom: .5rem; }
.perm {
    display: flex; align-items: flex-start; gap: .75rem; padding: .6rem .5rem; margin: 0 -.5rem; border-radius: 10px; cursor: pointer;
}
.perm:hover { background: var(--bg); }
.perm input[type=checkbox] { width: 1.15rem; height: 1.15rem; margin-top: .2rem; flex: none; accent-color: var(--accent); }
.perm span { display: flex; flex-direction: column; gap: .05rem; }
.perm small { line-height: 1.35; }
.perm-note { color: var(--warn); font-weight: 600; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }

/* ---------- activity report + the "are you still working?" popup ---------- */
.filters { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters label { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
.filters select { min-width: 12rem; }
.text-alarm { color: var(--alarm); font-weight: 700; }

#activity-root { display: contents; } /* the wrapper is not a cell of the page grid (else it pushes the sidebar aside) */
.activity-dialog {
    border: 0; border-radius: 16px; padding: 1.7rem 1.8rem 1.4rem; width: min(92vw, 420px); text-align: center;
    background: var(--surface); color: var(--ink); box-shadow: 0 24px 70px rgba(0, 0, 0, .4);
}
.activity-dialog::backdrop { background: rgba(10, 15, 25, .6); backdrop-filter: blur(2px); }
.activity-dialog h2 { font-size: 1.25rem; margin: 0 0 .35rem; }
.activity-dialog p { margin: 0 0 .9rem; color: var(--muted); }
.act-icon { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto .9rem; background: #111827; color: #c6f04a; }
.activity-dialog.inactive .act-icon { background: var(--alarm-bg); color: var(--alarm); }
.act-timer { margin: 0 0 1.1rem; }
.act-timer small { color: var(--muted); }
.act-bar { height: 7px; border-radius: 99px; background: var(--border); overflow: hidden; margin-bottom: .45rem; }
.act-bar span { display: block; height: 100%; width: 100%; background: #22c55e; transition: width 1s linear, background .3s; }
.act-bar span.low { background: var(--alarm); }
.act-foot { display: block; margin-top: .9rem; }

.mystatus-body { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.mystatus-state { flex: none; }

/* ---------- mandatory power-on reason + confirmation popup ---------- */
.reason-modal {
    border: 0; border-radius: 16px; padding: 1.6rem 1.7rem 1.4rem; width: min(92vw, 440px);
    background: var(--surface); color: var(--ink); box-shadow: 0 24px 70px rgba(0, 0, 0, .4);
}
.reason-modal::backdrop { background: rgba(10, 15, 25, .6); backdrop-filter: blur(2px); }
.reason-modal h2 { font-size: 1.2rem; margin: 0 0 .35rem; }
.reason-form textarea {
    width: 100%; resize: vertical; min-height: 4.5rem; font: inherit; padding: .6rem .7rem; margin-top: .3rem;
    border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--ink); box-sizing: border-box;
}
.reason-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.reason-form .form-actions { margin-top: 1rem; }
@media (max-width: 480px) {
    .reason-modal { padding: 1.3rem 1.2rem 1.1rem; }
    .reason-form .form-actions { flex-direction: column-reverse; }
    .reason-form .form-actions .btn { width: 100%; }
}

/* ---------- dashboard: grid / list layout ---------- */
.view-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: 0 0 .8rem; }
.view-title { font-size: 1.05rem; }
.view-toggle button { display: inline-flex; align-items: center; gap: .4rem; }
.view-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* scoped to .dashboard-view (the Dashboard page only) so the Meter List page's list is not affected by
   whichever Grid/List choice was last remembered - it always shows its own list, unconditionally. */
html.view-list .dashboard-view .meter-cards { display: none; }
html:not(.view-list) .dashboard-view .meter-list { display: none; }
.meter-list { margin-bottom: 1.25rem; }
.meter-list .panel { padding: .3rem .8rem; margin-bottom: 0; }
.meter-table th, .meter-table td { padding-left: .5rem; padding-right: .5rem; }
.meter-table td { vertical-align: middle; padding-top: .6rem; padding-bottom: .6rem; }
.meter-table th.num { white-space: nowrap; }
.meter-table .name { min-width: 11.5rem; }
.meter-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.meter-table .strong { font-weight: 700; }
.meter-table .name a { font-weight: 700; color: var(--ink); }
.meter-table .conn { white-space: nowrap; }
.meter-row.row-fault { background: color-mix(in srgb, var(--alarm) 8%, transparent); box-shadow: inset 3px 0 0 var(--alarm); }

/* ---------- Meter List: "Schedule" column + inline editor row ---------- */
.schedule-toggle-btn { display: block; margin-top: .3rem; }
.schedule-edit-row td { padding: 0; }
.schedule-edit-panel {
    padding: 1rem 1.1rem; background: var(--bg); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.schedule-edit-panel .control-toggle-row.compact { padding: .6rem .85rem; margin-bottom: .75rem; }
.schedule-edit-panel .mode-tabs { max-width: 26rem; }
.schedule-edit-panel .schedule-days-fields, .schedule-edit-panel .schedule-interval-fields { margin-top: .9rem; }
.schedule-edit-panel .form-actions { margin-top: .9rem; }

/* ---------- roles: "Manage activity check popup" interval slider ---------- */
.interval-box {
    margin: .1rem 0 .7rem 2rem; padding: .85rem 1rem .8rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
}
.interval-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .1rem; }
.interval-head label { margin: 0; }
.interval-out { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.interval-slider { width: 100%; margin: .8rem 0 .15rem; height: 1.6rem; accent-color: var(--accent); cursor: pointer; }
.interval-scale { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-bottom: .6rem; }
.interval-picks { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.pick {
    padding: .2rem .65rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--ink);
    font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.pick:hover { border-color: var(--accent); }
.pick.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (max-width: 560px) { .interval-box { margin-left: 0; } }

/* ---------- add meter: "Device load" two-handle range slider ---------- */
.range-box { padding: .85rem 1rem .8rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.range-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .1rem; }
.range-head label { margin: 0; font-weight: 700; }
.range-out { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.range-box .hint { margin: .2rem 0 .9rem; }
.range-slider-wrap { position: relative; height: 2.1rem; }
.range-track-bg {
    position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
    height: .3rem; border-radius: 99px; background: var(--border);
}
.range-fill {
    position: absolute; top: 50%; transform: translateY(-50%);
    height: .3rem; border-radius: 99px; background: var(--accent);
}
.range-input {
    position: absolute; left: 0; top: 0; width: 100%; height: 2.1rem; margin: 0;
    -webkit-appearance: none; appearance: none; background: transparent; pointer-events: none;
}
.range-input:focus-visible { outline: none; }
.range-input::-webkit-slider-runnable-track { -webkit-appearance: none; background: transparent; height: 2.1rem; }
.range-input::-webkit-slider-thumb {
    -webkit-appearance: none; pointer-events: auto; width: 1.3rem; height: 1.3rem; margin-top: .4rem;
    border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); cursor: pointer;
}
.range-input:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.range-input::-moz-range-track { background: transparent; height: 2.1rem; border: 0; }
.range-input::-moz-range-thumb {
    pointer-events: auto; width: 1.3rem; height: 1.3rem; border-radius: 50%;
    background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); cursor: pointer;
}
.range-input:focus-visible::-moz-range-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.range-scale { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: .3rem; }

/* the box dims and its handles stop responding while "Device load monitoring" is Inactive (JS sets .is-disabled) */
.range-box.is-disabled { opacity: .55; }
.range-box.is-disabled .range-input { pointer-events: none; }
#device-load-req-star, #schedule-days-req-star { color: var(--alarm); }

/* ---------- add meter: "Scheduled relay off" day picker (Mon..Sun toggle chips) ---------- */
.day-picker { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.day-chip { position: relative; display: inline-flex; }
.day-chip input {
    position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer;
}
.day-chip label {
    display: inline-flex; align-items: center; justify-content: center; width: 3rem; height: 2.2rem;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
    font-size: .78rem; font-weight: 700; color: var(--muted); cursor: pointer; transition: background-color .15s, border-color .15s, color .15s;
}
.day-chip input:checked ~ label { background: var(--accent); border-color: var(--accent); color: #fff; }
.day-chip input:focus-visible ~ label { outline: 2px solid var(--accent); outline-offset: 2px; }
.range-box.is-disabled .day-chip input { pointer-events: none; }

/* ---------- add meter: "Scheduled relay off" mode switch (By days & time / By recurring interval) ---------- */
.mode-tabs { display: flex; gap: .5rem; margin: 0 0 1rem; }
.mode-tab { position: relative; flex: 1; }
.mode-tab input {
    position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer;
}
.mode-tab label {
    display: block; text-align: center; padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); font-size: .85rem; font-weight: 700; color: var(--muted); cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}
.mode-tab input:checked ~ label { background: var(--accent); border-color: var(--accent); color: #fff; }
.mode-tab input:focus-visible ~ label { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- add meter: "Every N [unit]" / "Off for N [unit]" number + dropdown pairs ---------- */
.unit-pair { display: grid; grid-template-columns: 1fr 1.3fr; gap: .5rem; }

/* ---------- add meter: "Device load monitoring" active/inactive toggle, top of the Control section ---------- */
.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.control-toggle-row {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 1.25rem;
    padding: .85rem 1rem; margin-bottom: 1.1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
}
.control-toggle-row .hint { margin: .25rem 0 0; }
.control-toggle-state {
    display: inline-block; margin-left: .5rem; padding: .05rem .5rem; border-radius: 999px;
    font-size: .74rem; font-weight: 700; letter-spacing: .02em; background: var(--off-bg); color: var(--off);
}
.control-toggle-state.is-active { background: var(--ok-bg); color: var(--ok); }

.switch { position: relative; display: inline-flex; align-items: center; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
    display: inline-block; width: 3rem; height: 1.7rem; border-radius: 999px; background: var(--off-bg);
    border: 1px solid var(--border); transition: background-color .15s, border-color .15s; flex: none;
}
.switch-thumb {
    display: block; width: 1.25rem; height: 1.25rem; margin: .2rem; border-radius: 50%; background: var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .35); transition: transform .15s;
}
/* ~ (general sibling), not + : th:field on a checkbox makes Thymeleaf inject a hidden "_name" marker input
   right after the checkbox, so .switch-track is no longer its literal next sibling. */
.switch input:checked ~ .switch-track { background: var(--ok); border-color: var(--ok); }
.switch input:checked ~ .switch-track .switch-thumb { transform: translateX(1.3rem); }
.switch input:focus-visible ~ .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 560px) { .control-toggle-row { flex-direction: column; align-items: stretch; } }

.tile-note { display: block; margin-top: .15rem; font-size: .78rem; font-weight: 600; color: var(--muted); }
.tile-note.warn { color: var(--warn); }
