/**
 * Viewer chrome — ink on paper, with a single blue accent.
 *
 * These same styles are bundled into the Lovelace card, so the tokens are
 * declared here rather than inherited: in a Home Assistant dashboard there is
 * no page stylesheet behind this one, and the card still has to come out
 * looking like itself.
 */
:root {
  --panel: rgba(242, 244, 240, 0.86);
  --panel-line: rgba(16, 23, 21, 0.16);
  --text: #101715;
  --muted: #626b67;
  --accent: #1f55ff;
  --accent-ink: #ffffff;

  /* Everything a host page needs to re-skin the viewer without forking this
     file. A second stylesheet loaded after this one redefines these and the
     whole panel follows; the blueprint tags below stay out of it on purpose,
     because that mode is a drawing with its own fixed palette. */
  --surface: #e9ebe7;
  --hover: rgba(16, 23, 21, .06);
  --gate: #111816;
  --gate-text: #9ba39f;
  --gate-line: rgba(255, 255, 255, .2);
  --label-bg: rgba(16, 23, 21, .72);
  --label-line: rgba(255, 255, 255, .18);
  --scrim: rgba(233, 235, 231, .62);
  --shadow: rgba(16, 23, 21, .10);

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  font: 14px/1.45 "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#scene, #labels {
  position: fixed;
  inset: 0;
}
#labels { pointer-events: none; overflow: hidden; }
canvas { display: block; }

/* ---------- loading ---------- */
#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--gate);
  z-index: 40;
  transition: opacity .5s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
#loading p {
  color: var(--gate-text); margin: 0; letter-spacing: .09em; font-size: 10px; text-transform: uppercase;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.spinner {
  width: 34px; height: 34px;
  border: 1px solid var(--gate-line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1.1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- panel ---------- */
#panel {
  position: fixed;
  top: 14px; left: 14px;
  width: 264px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  padding: 15px 16px 12px;
  border-radius: 0;
  /* The rule along the top edge is a background layer rather than a
     pseudo-element because the panel scrolls: an absolutely positioned strip
     would scroll away with the content, whereas a background stays pinned to
     the element's own box. */
  background:
    linear-gradient(var(--text), var(--text)) top center / 100% 1px no-repeat,
    var(--panel);
  border: 1px solid var(--panel-line);
  border-top: 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 18px 40px var(--shadow);
  z-index: 20;
  transition: transform .28s cubic-bezier(.3,.8,.4,1), opacity .2s;
}
#panel.hidden { transform: translateX(-115%); opacity: 0; }
#panel::-webkit-scrollbar { width: 6px; }
#panel::-webkit-scrollbar-thumb { background: var(--panel-line); border-radius: 3px; }

#panel header {
  margin-bottom: 16px; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 10px;
  border-radius: 8px; margin-left: -6px; margin-right: -6px;
  padding: 6px; transition: background .15s ease;
}
#panel header:hover { background: var(--hover); }
#panel header:focus-visible { outline: 2px solid var(--accent, #f0b429); outline-offset: 2px; }
#panel header > div, #panel header h1, #panel header p { flex: 1 1 auto; }
#panel-chevron {
  flex: none; width: 9px; height: 9px; margin-left: auto; margin-right: 2px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  opacity: .55; transform: rotate(45deg); transition: transform .18s ease;
}
/* Collapsed: everything but the title bar folds away. */
#panel.collapsed { padding-bottom: 6px; }
#panel.collapsed #panel-body { display: none; }
#panel.collapsed header { margin-bottom: 0; }
#panel.collapsed #panel-chevron { transform: rotate(-135deg); }
@media (prefers-reduced-motion: reduce) {
  #panel header, #panel-chevron { transition: none; }
}
#panel h1 { font-size: 20px; margin: 0; letter-spacing: -.035em; font-weight: 500; }
#panel header p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }

#panel section { margin-bottom: 16px; }
#panel h2 {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 600;
  display: flex; justify-content: space-between; align-items: baseline;
}
#panel h2 small, #panel h2 span { font-size: 10px; letter-spacing: .04em; text-transform: none; opacity: .8; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.segmented button {
  appearance: none;
  border: 1px solid var(--panel-line);
  background: transparent;
  color: var(--text);
  padding: 9px 6px;
  border-radius: 0;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease;
}
.segmented button:hover { background: var(--hover); border-color: var(--text); }
.segmented button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.check {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; cursor: pointer; font-size: 13px; color: var(--text);
  transition: color .2s ease;
}
/* `display: flex` above outranks the UA sheet's `[hidden] { display: none }`,
   so a toggle hidden from script would otherwise stay on screen. */
.check[hidden] { display: none; }
.check:hover { color: var(--accent); }
.check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

input[type=range] {
  width: 100%; accent-color: var(--accent);
  background: transparent; cursor: pointer;
}

.rooms { display: flex; flex-wrap: wrap; gap: 5px; }
.rooms button {
  appearance: none;
  border: 1px solid var(--panel-line);
  background: transparent;
  color: var(--text);
  border-radius: 0;
  padding: 5px 11px;
  font: inherit; font-size: 11.5px;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}
.rooms button:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

#panel footer { border-top: 1px solid var(--panel-line); padding-top: 9px; color: var(--muted); font-size: 11px; }

#panel-toggle {
  position: fixed; top: 14px; left: 14px;
  width: 38px; height: 38px;
  border-radius: 0;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 15px; cursor: pointer;
  z-index: 21;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, background .16s ease;
}
#panel-toggle:hover { background: var(--hover); }
#panel.hidden ~ #panel-toggle { opacity: 1; pointer-events: auto; }

/* ---------- room labels ---------- */
.room-label {
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-shadow: 0 1px 6px rgba(0,0,0,.85);
  padding: 3px 9px;
  border-radius: 0;
  background: var(--label-bg);
  border: 1px solid var(--label-line);
  white-space: nowrap;
  pointer-events: none;
}
.room-label em { display: block; font-style: normal; font-weight: 400; opacity: .7; font-size: 10px; letter-spacing: .02em; }

/* ---------- walk mode ---------- */
#crosshair {
  position: fixed; left: 50%; top: 50%;
  width: 6px; height: 6px; margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: rgba(255,255,255,.75);
  box-shadow: 0 0 0 1px rgba(0,0,0,.45);
  pointer-events: none;
}
#walk-hint {
  position: fixed; left: 50%; bottom: 22px;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 0;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px);
  color: var(--text); font-size: 12px;
  pointer-events: none; white-space: nowrap;
}
kbd {
  display: inline-block;
  padding: 1px 6px; margin: 0 1px;
  border-radius: 0;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  color: var(--accent);
  font: inherit;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

#lock-prompt {
  position: fixed; inset: 0;
  display: grid; place-content: center;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  z-index: 15;
  cursor: pointer;
  text-align: center;
}
#lock-prompt[hidden] { display: none; }
#lock-prompt div { display: grid; gap: 6px; }
#lock-prompt strong { font-size: 22px; font-weight: 500; letter-spacing: -.03em; }
#lock-prompt span { color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  #panel { width: calc(100vw - 28px); max-height: 46vh; }
  #walk-hint { font-size: 10.5px; white-space: normal; max-width: 90vw; text-align: center; }
}

/* ---------------------------------------------- blueprint dimension annotation */
.dim-tag {
  font: 600 10px/1.25 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  color: #ffdf9e; white-space: nowrap; pointer-events: none;
  text-shadow: 0 0 4px rgba(6,32,54,.95), 0 0 2px rgba(6,32,54,.95);
  letter-spacing: .02em;
}
.dim-tag.name {
  color: #eaf4ff; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  background: rgba(8,38,62,.82); border: 1px solid rgba(244,185,66,.5);
  border-radius: 3px; padding: 2px 6px;
}
/* A room switched on in the blueprint set. The tags out in the scene stay
   amber-on-navy, which is the drawing's own palette; this chip lives in the
   paper panel and follows that instead. */
#rooms button.picked {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent) 52%, transparent); color: var(--accent);
}

/* North tag on the plan compass: a bare letter, not a room chip. */
.room-label.compass-n {
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .06em;
  color: #2c3242;
  /* Navy on grass is barely legible; the halo carries it over any ground. */
  text-shadow: 0 0 3px rgba(255, 255, 255, .95), 0 0 7px rgba(255, 255, 255, .8);
}

/* ------------------------------------------------------------------ devices */
.pill {
  float: right; font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 999px;
}
.pill.live    { background: rgba(64, 200, 120, .18); color: #2e9c5e; }
.pill.offline { background: rgba(180, 180, 190, .18); color: #8a8a96; }

.devices { display: flex; flex-direction: column; gap: 3px; }

.dev-group {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 10px 0 2px; font-size: 11px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; opacity: .55;
}
.dev-group em { font-style: normal; font-weight: 600; opacity: .8; }

button.dev {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px; border-radius: 0; cursor: pointer;
  border: 1px solid var(--panel-line); background: transparent;
  font: inherit; font-size: 12px; text-align: left; color: var(--text);
  transition: background .16s ease, border-color .16s ease;
}
button.dev:hover { background: var(--hover); border-color: var(--text); }
button.dev.on {
  background: color-mix(in srgb, var(--accent) 11%, transparent);
  border-color: color-mix(in srgb, var(--accent) 46%, transparent);
}
.dev-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-s { flex: none; font-variant-numeric: tabular-nums; opacity: .6; font-size: 11px; }

.device-label {
  padding: 3px 8px; border-radius: 7px; font-size: 11px; font-weight: 600;
  color: #fff; background: rgba(20, 24, 34, .8); white-space: nowrap;
  pointer-events: none; transform: translateY(-4px);
}
.device-label.on { background: color-mix(in srgb, var(--accent) 88%, black); }

#edit-tools { margin: 6px 0 10px; }
#edit-tools .hint {
  margin: 6px 0; font-size: 11px; line-height: 1.45; opacity: .62;
}
#edit-tools .segmented { margin-top: 6px; }
#edit-note:empty { display: none; }
#edit-note { color: var(--accent, #c8892a); opacity: .95; }
