:root {
  --bg: #16181d;
  --panel: #1f232b;
  --panel-border: #2c313b;
  --text: #e6e8eb;
  --text-dim: #9aa1ab;
  --accent: #4f8cff;
  --danger: #e5484d;
  --offline: #3a2a2a;
  --offline-text: #e5a3a3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
}

header h1 {
  font-size: 16px;
  margin: 0 16px 0 0;
  white-space: nowrap;
}

select, button, input[type="text"] {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

button {
  cursor: pointer;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--panel-border);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

#customer-select-bar {
  /* Always shown today: there is no real login system yet (see dashboard.js's
     comment), so every request runs as a platform admin, which always requires an
     explicit customer selection. This becomes conditional once real auth exists. */
  display: flex;
  gap: 8px;
  align-items: center;
}

main {
  padding: 16px;
}

#empty-state {
  color: var(--text-dim);
  padding: 40px;
  text-align: center;
}

.grid-stack {
  background: transparent;
}

.grid-stack-item-content {
  background: #000;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: var(--panel);
  font-size: 12px;
  color: var(--text-dim);
}

.tile-header button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}

.tile-body {
  flex: 1;
  position: relative;
  min-height: 0;
  cursor: pointer;
}

.tile-body img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.tile-offline {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--offline);
  color: var(--offline-text);
  font-size: 13px;
  text-align: center;
  padding: 8px;
}

/* --- modal --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* An author display:flex rule otherwise beats the browser's default [hidden]
   behavior at equal specificity (author stylesheets always win over the UA
   stylesheet) — without this, toggling .hidden via the DOM attribute would do
   nothing and every modal would render open at load. */
.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 20px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 80vh;
  overflow: auto;
}

.modal h2 {
  margin-top: 0;
  font-size: 15px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.camera-picker-list {
  list-style: none;
  margin: 0;
  padding: 0;

  /* Taller than the 300px it was, because rows now carry a thumbnail and three visible rows is not
     a picker. Still bounded: the dialog has to fit a laptop screen with the header and buttons. */
  max-height: 60vh;
  overflow: auto;
}

.camera-picker-list li {
  padding: 8px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

/* Big enough to recognise a doorway or a car park, small enough that fifty of them scroll.
   `object-fit: cover` because Blue Iris cameras are not all the same aspect ratio and a row of
   letterboxed thumbnails of different shapes is harder to scan than a row of uniform ones. */
.camera-picker-thumb {
  flex: 0 0 auto;
  width: 96px;
  height: 54px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
}

/* What replaces the image when the snapshot does not arrive — an offline site, a blocked
   credential, a camera Blue Iris no longer reports. Same footprint, so the list does not reflow as
   images resolve one by one while you scroll. */
.camera-picker-thumb-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-dim);
}

/* Takes the slack, so the Add button stays hard right however long the camera and site names are. */
.camera-picker-name {
  flex: 1 1 auto;
  min-width: 0;
}

.camera-picker-list li button {
  flex: 0 0 auto;
  padding: 4px 10px;
  font-size: 12px;
}

.hint {
  color: var(--text-dim);
  font-size: 11px;
}

/* --- top bar: customer scope and account (work order 06) ------------------- */

/* A customer user's scope is not selectable, so it is rendered as text rather than a
   disabled dropdown — a disabled control invites people to try to enable it. */
.scope-label {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  color: var(--text);
  white-space: nowrap;
}

/* Pushes the account block to the far right of the header, away from the controls. */
#account-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

#account-email {
  white-space: nowrap;
}

/* --- the shared shell nav (work order 08) --- */

#shell-nav {
  display: flex;
  gap: 4px;
  align-items: center;
}

#shell-nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

#shell-nav a:hover {
  color: var(--text);
  background: var(--bg);
}

/* The page you are on. Marked rather than removed — a nav that hides where you are makes it
   harder to tell one screen from another, not easier. */
#shell-nav a.current {
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--panel-border);
}

/* The filter row — scope selectors and per-screen filters, on their own line **below** the
   navigation rather than wedged between the page title and the nav links.

   Sitting in the header, a scope selector read as part of the page's identity: "Sites [Thermal Club]"
   looked like a title rather than a control somebody had set, and on a narrow window it wrapped into
   the nav. On its own row it reads as what it is — the thing currently narrowing what is below it.

   Quieter than the header on purpose: the page background rather than the panel, so the two rows
   separate without a second heavy band. */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--panel-border);
}

/* A screen whose only control is one a customer user cannot change would otherwise leave an empty
   band under the nav. `hidden` is what the scripts toggle, so the row keys on the same thing. */
.toolbar:not(:has(> :not([hidden]))) {
  display: none;
}
