/* The frame's look follows the site palette (set from the template by app.js as CSS variables). */
/* Until it has loaded (and if it can't), neutral stand-ins so the loading page follows the system's light or dark. */
:root { --background: #f3f4f6; --panel: #ffffff; --panelAlt: #f6f7f9; --text: #111827; --muted: #6b7280; --border: #e2e5ea; --accent: #6b7280; --onAccent: #ffffff; --bad: #c62828; --warn: #b26a00; }
@media (prefers-color-scheme: dark) {
  :root { --background: #0f1216; --panel: #171b21; --panelAlt: #1e232b; --text: #e8eaee; --muted: #9aa3ae; --border: #2a3039; --bad: #ef5350; --warn: #f0a63a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Outfit", "Segoe UI", system-ui, sans-serif;
  color: var(--text); background: var(--background);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- sign-in ---------- */
#signin {
  height: 100%; display: grid; place-items: center;
  background: radial-gradient(900px 600px at 10% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%), var(--background);
}
.signin-card {
  width: min(420px, calc(100% - 32px)); padding: 36px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px;
}
.signin-card h1 { margin: 10px 0 0; font-size: 28px; font-weight: 600; }
.signin-card p { margin: 0; }
.signin-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.signin-card input {
  font: inherit; font-size: 15px; color: var(--text); background: var(--panelAlt); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 12px; outline: none;
}
.signin-card input:focus { border-color: var(--accent); }
.signin-card .btn:disabled { opacity: .7; cursor: progress; }
.note { font-size: 12.5px; color: var(--muted); }
.error, .notice { font-size: 13.5px; margin: 0; padding: 10px 12px; border-radius: 9px; line-height: 1.4; }
.error { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.notice { color: var(--text); background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.error[hidden], .notice[hidden] { display: none; }

/* ---------- loading ---------- */
#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--background); z-index: 50; }
.loading-card { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: min(460px, calc(100% - 32px)); text-align: center; color: var(--muted); }
.loading-card p { margin: 0; font-size: 15px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .9s linear infinite; }
.spinner.small { width: 16px; height: 16px; border-width: 2px; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- frame ---------- */
#shell { height: 100%; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 16px; height: 62px; padding: 0 16px; flex: none;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding-right: 16px; border-right: 1px solid var(--border); }
.brand.big { border: 0; padding: 0; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--onAccent); display: grid; place-items: center; font-weight: 700; font-size: 17px; letter-spacing: -1px; }
.brand { flex: none; }
.brand b { display: block; font-size: 16px; font-weight: 600; line-height: 1.1; white-space: nowrap; }
.brand small { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
nav { display: flex; gap: 4px; overflow: hidden; min-width: 0; flex: 0 1 auto; }
/* The menu folds into a button when it doesn't fit beside the rest of the top bar (app.js measures it: .top.folded). */
#menu-toggle { display: none; flex: none; }
.top { position: relative; }
.top.folded #menu-toggle { display: grid; }
.top.folded nav {
  display: none; position: absolute; top: calc(100% + 6px); left: 8px; z-index: 25; flex-direction: column; gap: 2px;
  min-width: 260px; max-width: calc(100vw - 16px); max-height: calc(100vh - 90px); overflow-y: auto; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, .3);
}
.top.folded nav.open { display: flex; }
.top.folded nav a { padding: 11px 12px; }
nav a {
  display: flex; align-items: center; gap: 8px; white-space: nowrap; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; font-size: 15px; text-decoration: none;
}
nav a:hover { color: var(--text); background: var(--panelAlt); }
nav a.active { color: var(--text); background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent); }
nav a.active svg { color: var(--accent); }
.spacer { flex: 1; }
.outdoor { font-size: 14.5px; color: var(--muted); white-space: nowrap; }
.outdoor b { color: var(--text); font-weight: 600; }
.icon-btn { position: relative; width: 36px; height: 36px; border: 0; border-radius: 9px; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; font: inherit; font-size: 16px; }
.icon-btn:hover { color: var(--text); background: var(--panelAlt); }
.icon-btn.small { width: 30px; height: 30px; }
.badge { position: absolute; top: 1px; right: -1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--accent); color: var(--onAccent); font-size: 10.5px; font-weight: 600; display: grid; place-items: center; }
.badge:empty { display: none; }
.user { display: flex; align-items: center; gap: 9px; background: none; border: 0; color: var(--text); font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; padding: 4px 6px; border-radius: 9px; }
.user:hover { background: var(--panelAlt); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--onAccent); display: grid; place-items: center; font-size: 12px; font-weight: 600; }

.subbar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; border-bottom: 1px solid var(--border); flex: none; min-height: 50px; }
.crumbs { display: flex; flex-direction: column; min-width: 0; }
.crumbs span:first-child { font-weight: 600; font-size: 15px; white-space: nowrap; }
.crumbs .muted { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 520px; }
.viewports { display: flex; gap: 6px; flex: 1; overflow-x: auto; justify-content: flex-end; }
.viewports button {
  font: inherit; font-size: 13.5px; color: var(--muted); background: none; border: 1px solid var(--border); border-radius: 99px;
  padding: 5px 12px; cursor: pointer; white-space: nowrap;
}
.viewports button:hover { color: var(--text); }
.viewports button.active { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.zoom { display: flex; gap: 2px; }
.preview-badge { font-size: 12px; color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); border-radius: 99px; padding: 4px 10px; white-space: nowrap; }
.preview-badge.warn { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.preview-badge[hidden] { display: none; }

#stage { flex: 1; position: relative; overflow: hidden; background: var(--background); }
#canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#canvas.panning { cursor: grabbing; }
.act { cursor: pointer; }
.act:hover { filter: brightness(1.12); }
/* A value that isn't there (Bad, no connection, not yet arrived) shows "--", dimmed. */
text.novalue { opacity: .5; }

/* Argus Web's connection: "Connecting …" before the first values, "Connection lost" with the display greyed (old values aren't current). */
#conn-state {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 5; display: flex; align-items: center; gap: 10px;
  max-width: calc(100% - 32px); padding: 9px 16px; border-radius: 99px; font-size: 14px; font-weight: 500;
  background: var(--panel); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
#conn-state.lost { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
#stage.stale #canvas { filter: grayscale(1); opacity: .55; transition: opacity .3s, filter .3s; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(640px, calc(100% - 32px)); z-index: 45;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 18px; font-size: 14.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
/* A write's answer (ADR 0037): accepted in the palette's good colour, refused or failed in its bad colour (and kept longer). */
#toast.good { border-left: 5px solid var(--good); }
#toast.bad { border-left: 5px solid var(--bad); }

/* ---------- underbilder ---------- */
#popup-layer { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 20; }
.popup { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 8px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.popup .close { position: absolute; top: 10px; right: 10px; z-index: 2; }
#popup-canvas { display: block; }

.btn { font: inherit; font-size: 15px; font-weight: 600; border-radius: 9px; padding: 11px 16px; cursor: pointer; border: 1px solid var(--border); background: none; color: var(--text); }
.btn:hover { background: var(--panelAlt); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--onAccent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:focus-visible, .icon-btn:focus-visible, nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- dialogs (write a value, confirm, sites) ---------- */
#dialog-layer { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; z-index: 40; padding: 16px; }
.dialog {
  width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 14px; padding: 22px 24px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}
.dialog h2 { margin: 0; font-size: 19px; font-weight: 600; }
.dialog p { margin: 0; font-size: 14.5px; line-height: 1.45; }
.dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.dialog dt { color: var(--muted); }
.dialog dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.dialog dd.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; font-weight: 400; }
.dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.dialog .field { display: flex; align-items: center; background: var(--panelAlt); border: 1px solid var(--border); border-radius: 9px; }
.dialog .field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.dialog .field.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 18%, transparent); }
.dialog .field input { flex: 1; min-width: 0; font: inherit; font-size: 18px; font-weight: 500; color: var(--text); background: none; border: 0; outline: none; padding: 10px 12px; }
.dialog .field .unit { padding: 0 12px; color: var(--muted); font-size: 15px; }
.dialog .field-error { color: var(--bad); font-size: 13px; margin: -6px 0 0; }
.dialog .buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.dialog .buttons .btn { padding: 9px 18px; font-size: 14.5px; }
.dialog .sites { display: flex; flex-direction: column; gap: 6px; }
.dialog .sites a {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--text); text-decoration: none; font-weight: 500;
}
.dialog .sites a:hover { background: var(--panelAlt); border-color: var(--accent); }
.dialog .sites a.current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.dialog .sites small { color: var(--muted); font-weight: 400; }

/* ---------- alarms (ADR 0038) ---------- */
#bell.alarming { color: var(--bell, var(--alarmCritical)); }
.badge.unacked { background: var(--bell, var(--alarmCritical)); animation: alarm-pulse 1.6s ease-in-out infinite; }
@keyframes alarm-pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .badge.unacked { animation: none; } }
#alarm-layer { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 30; }
.alarm-panel {
  width: min(1200px, calc(100% - 32px)); height: min(760px, calc(100% - 48px)); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); overflow: hidden;
}
.alarm-panel header { display: flex; align-items: center; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.alarm-panel h2 { margin: 0; font-size: 20px; font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tabs button { font: inherit; font-size: 14px; color: var(--muted); background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.tabs button.active { color: var(--text); border-color: var(--border); background: var(--panelAlt); }
.alarm-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.alarm-tools select, .alarm-tools input[type=search], #alarm-comment {
  font: inherit; font-size: 14px; color: var(--text); background: var(--panelAlt); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
.alarm-tools label { font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.alarm-tools .btn { padding: 6px 12px; font-size: 14px; }
.btn.small { padding: 3px 10px; font-size: 12.5px; }
.alarm-table-wrap { flex: 1; overflow: auto; }
.alarm-panel table { width: 100%; border-collapse: collapse; font-size: 14px; }
.alarm-panel th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.alarm-panel th.sortable { cursor: pointer; }
.alarm-panel td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.alarm-panel tr.unacked td:nth-child(4) { font-weight: 600; }
.alarm-panel tr.cleared td { color: var(--muted); }
.alarm-panel .nowrap { white-space: nowrap; }
.alarm-panel footer { padding: 8px 18px; font-size: 13px; border-top: 1px solid var(--border); }
.prio { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  color: var(--prio); background: color-mix(in srgb, var(--prio) 16%, transparent); }

/* ---------- tablets and phones ---------- */
@media (max-width: 1100px) {
  .top { gap: 10px; padding: 0 12px; }
  .brand { padding-right: 10px; }
  .crumbs .muted { max-width: 320px; }
}
@media (max-width: 760px) {
  .top { gap: 4px; padding: 0 8px; height: 56px; }
  .brand { border: 0; padding-right: 2px; }
  .brand-text, #user-name, .outdoor-label { display: none; }
  .user { padding: 4px; }
  .outdoor { font-size: 14px; margin-right: 2px; }
  .subbar { flex-wrap: wrap; gap: 6px 10px; padding: 6px 10px; min-height: 0; }
  .crumbs { flex: 1; }
  .crumbs .muted { display: none; }
  .viewports { order: 3; flex: 1 0 100%; justify-content: flex-start; padding-bottom: 2px; }
  .viewports:empty { display: none; }
  .preview-badge { font-size: 11px; padding: 3px 8px; }
  .signin-card { padding: 26px 22px; }
  .alarm-panel { width: 100%; height: 100%; border-radius: 0; }
  #alarm-layer { place-items: stretch; }
  .alarm-tools #alarm-comment { flex: 1 0 100%; }
}
