/*
 * cloud/console/console.css — the camera console's look. CLOUD-CONSOLE-SPEC.md
 * section D's own "Look" bullet: reuse the NVR box's own colour tokens and
 * type (copied from agent/ui/system.html's <style> block below, as custom
 * properties) so the console looks like the NVR box's own pages, in light AND dark
 * (system.html itself is dark-only; this page adds the light half those
 * tokens never needed on the box).
 *
 * Phone first: a 16px side gutter, tap targets at least 44px, no sideways
 * scroll at 360px wide, readable at arm's length on a ladder.
 *
 * No inline style anywhere (strict CSP, section E) -- this file is the only
 * place any of it lives.
 */

:root {
  --bg: #f5f6f8;
  --fg: #14161a;
  --dim: #5f6368;
  --good: #1e7d43;
  --warn: #8a6d1d;
  --bad: #b3261e;
  --panel: #ffffff;
  --border: #d6d9de;
  --accent: #2f5fce;
  --accent-fg: #ffffff;
  --chip-good-bg: #e3f5e9;
  --chip-warn-bg: #fbf3d9;
  --chip-bad-bg: #fbe4e4;
  --input-bg: #ffffff;
  --error-bg: #fbe4e4;
  --error-fg: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* The box's own tokens, verbatim from agent/ui/system.html. */
    --bg: #14161a;
    --fg: #e8eaed;
    --dim: #9aa0a6;
    --good: #7ddc9a;
    --warn: #f1e3a0;
    --bad: #ffb4b4;
    --panel: #1b1d22;
    --border: #2c2f36;
    --accent: #4c8bf5;
    --accent-fg: #ffffff;
    --chip-good-bg: #1b2a1f;
    --chip-warn-bg: #2c2a1d;
    --chip-bad-bg: #3a1d1d;
    --input-bg: #14161a;
    --error-bg: #3a1d1d;
    --error-fg: #ffb4b4;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  padding: 16px;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, sans-serif;
  max-width: 720px;
  margin: 0 auto;
}

h1 { margin: 0 0 16px; font-size: 20px; }
h2 { margin: 24px 0 8px; font-size: 16px; }
h3 {
  margin: 20px 0 6px; font-size: 12px; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.5px;
}
h4 { margin: 12px 0 4px; font-size: 14px; font-weight: 600; }
/* Customer and site names are typed by people: a long unbroken one wraps. */
h2, h3, h4, #installerName, #inviteTitle { overflow-wrap: anywhere; }

section { margin-bottom: 24px; }

label {
  display: block; margin: 10px 0 4px; font-size: 13px; color: var(--dim);
}

/* Every field is 16px, wherever it is (the Add NVR form, the customers and sites forms,
   the people form, the login, the cards): a phone zooms into any field smaller than
   that when it takes focus, and the page does not come back by itself. */
input[type="text"], input[type="password"], select {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  font: inherit;
  font-size: 16px;
  color: var(--fg);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

input[readonly] { background: var(--bg); }
#inviteLinkInput { overflow-wrap: anywhere; }

button {
  display: inline-block;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 18px;
  margin-top: 10px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-fg);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }

.hint { margin: 2px 0 0; font-size: 12px; color: var(--dim); }

.error, #loginError, #fleetError, #acceptError,
#claimStatus, #addOrgStatus, #addSiteStatus, #addGroupStatus, #siteGroupStatus, #inviteStatus {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.error, #loginError, #fleetError, #acceptError {
  background: var(--error-bg);
  color: var(--error-fg);
}
#claimStatus, #addOrgStatus, #addSiteStatus, #addGroupStatus, #siteGroupStatus, #inviteStatus {
  background: var(--panel);
  border: 1px solid var(--border);
}
/* The login form's one-time note after a session ended (console.mjs
   SESSION_NOTE): a plain line above the form, read at body size. */
#loginNote { margin: 8px 0 12px; font-size: 14px; color: var(--fg); }
/* Customer and site names are typed by people and can be long and unbroken. */
#claimStatus, #claimWarning { overflow-wrap: anywhere; }

/* ---- "Add an NVR": the + New site / + New customer boxes. They open under
   the site picker, set off by a rule on the left so it is plain they belong
   to the choice just made. The same-name warning is the one thing on this
   panel that asks for a decision, so it is tinted like the "Late" chip. ---- */

#claimNewBox, #claimNewOrgBox, #claimSiteBox, #claimTimeZoneBox {
  margin-top: 6px;
  padding: 0 0 4px 12px;
  border-left: 3px solid var(--border);
}
#claimWarning {
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--warn);
  background: var(--chip-warn-bg);
}
#claimWarning p { margin: 0 0 2px; }
#claimWarning button { margin-top: 8px; margin-right: 8px; }
#claimChangeNameBtn {
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}

/* ---- "Waiting for the NVR..." then "Online", under the claim line. The same
   chip colours as the NVR list's status words. ---- */

#claimArrival { margin: 10px 0 0; font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
.arrival { padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border); }
.arrival.good { color: var(--good); background: var(--chip-good-bg); }
.arrival.warn { color: var(--warn); background: var(--chip-warn-bg); }
.arrival.dim { color: var(--dim); background: var(--bg); }
.arrival.bad { color: var(--bad); background: var(--chip-bad-bg); }

[hidden] { display: none !important; }

#mainHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
#installerName { font-weight: 600; font-size: 16px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.device {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 8px 0;
}
.device { min-width: 0; }
.device > div { margin: 4px 0; overflow-wrap: anywhere; }
.device-id { font-weight: 600; }
/* On a phone the id and the status word share a line when they fit and the
   status drops under the id when they do not: never a sideways scroll. The
   last-seen line and the rest stack under them at body size. */
.device > .device-id { display: inline-block; max-width: 100%; margin: 4px 8px 4px 0; }
.device > .status { vertical-align: middle; }
/* A named NVR: the name is the title and the id sits small and grey beneath it (WARNINGS-SPEC.md 4.9, 6.3). */
.device > .device-name { font-weight: 600; font-size: 16px; }
.device > .device-id.named { font-weight: 400; font-size: 12px; color: var(--dim); }
/* The name box and its Save button on an NVR's card (console.mjs buildNameEdit). 16px controls so a phone does not zoom on
   focus, and every target at least 44px, like the time zone picker. */
.device > .name-edit { margin: 8px 0; }
.name-edit label { display: block; margin-top: 6px; }
.name-edit input[type="text"] { display: block; min-height: 44px; margin: 6px 0; font-size: 16px; max-width: 100%; }
.name-edit button { min-height: 44px; min-width: 44px; }
.name-edit .error, .name-edit .hint { margin-top: 8px; }

.status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
}
.status.good { color: var(--good); background: var(--chip-good-bg); }
.status.warn { color: var(--warn); background: var(--chip-warn-bg); }
.status.bad { color: var(--bad); background: var(--chip-bad-bg); }
.status.dim { color: var(--dim); background: var(--bg); border: 1px solid var(--border); }

.device select { margin-top: 6px; }

/* The time zone picker on an NVR's card (console.mjs buildZoneFix), shown only to an
   installer for an NVR on a site that said it has no usable time zone. Set off by a
   rule on the left like the Add NVR boxes. The controls are 16px so a phone does not
   zoom into them on focus, and every target is at least 44px. */
.device > .zone-fix { padding: 0 0 4px 12px; border-left: 3px solid var(--border); }
.zone-fix label { margin-top: 6px; }
.zone-fix select, .zone-fix input[type="text"] { min-height: 44px; margin-top: 6px; font-size: 16px; }
.zone-fix button { min-height: 44px; min-width: 44px; }
.zone-fix .error { margin-top: 8px; }

/* What the NVR itself reported about its setup (the card's own words, drawn from
   the fleet row's setup problem): the same red as the "Offline" chip. */
.setup-problem {
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 600;
  color: var(--bad);
  background: var(--chip-bad-bg);
}

/* ---- The Health panel (healthView.mjs; console.mjs renderHealth draws these classes, all with textContent). The count and the
   "nothing wrong found" block sit at body size; each NVR that needs a look is a card like "Your NVRs", edged in the colour of its
   badge (never colour alone: the badge carries the words). Long names wrap. ---- */

#healthError {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  background: var(--error-bg);
  color: var(--error-fg);
}
#healthList { overflow-wrap: anywhere; }
#healthList > .hint { margin: 8px 0; font-size: 14px; }
.health-count { margin: 4px 0 8px; font-weight: 700; font-size: 14px; }
.health-block { margin: 6px 0; font-size: 14px; }
.health-block.clear { color: var(--good); font-weight: 600; }
.health-block.warn { color: var(--warn); font-weight: 600; }
.health-block.note { color: var(--dim); font-size: 13px; }

/* A customer or a location heading with its worst badge beside it; the badge drops under the name when they do not fit. */
.health-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.health-head > h3, .health-head > h4 { margin: 12px 0 4px; min-width: 0; }

.health-nvr {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 8px 0;
  min-width: 0;
}
.health-nvr.bad { border-left-color: var(--bad); }
.health-nvr.warn { border-left-color: var(--warn); }
.health-nvr.dim { border-left-color: var(--dim); }
.health-nvr > div { margin: 4px 0; }
.health-nvr-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.health-nvr-title { font-weight: 600; }
.health-line.bad { color: var(--bad); font-weight: 600; }
.health-line.warn { color: var(--warn); font-weight: 600; }
.health-line.dim { color: var(--dim); }
.health-group { margin-top: 10px; padding: 0 0 2px 12px; border-left: 3px solid var(--border); }
.health-group > div { margin: 3px 0; }
.health-group-head { font-weight: 700; font-size: 13px; }
.health-group-head.bad, .health-item.bad { color: var(--bad); }
.health-group-head.warn, .health-item.warn { color: var(--warn); }
.health-group-head.dim, .health-item.dim { color: var(--dim); }
.health-note { font-size: 12px; color: var(--dim); padding-left: 12px; }
/* The buttons on a line or an item ("Known, leave it", "Removed on purpose", "Put it back"): thumb-sized, wrapping, with a refusal beside them. */
.health-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.health-actions button { min-height: 44px; min-width: 44px; }
.health-actions .error { flex: 1 1 100%; margin: 0; }
.health-notice { margin: 6px 0; font-size: 14px; font-weight: 600; color: var(--warn); }

/* A Health badge beside the status word on a card: a small gap, not two chips touching. */
.status + .status { margin-left: 6px; }

/* ---- "Write to a customer" (healthEmail.mjs; console.mjs renderList draws these classes, all with textContent). The tick rows are
   labels around a checkbox so the whole row is the tap target, at least 44px. The message box is a plain editable field (16px like
   every field, so a phone does not zoom into it) that keeps its line breaks. ---- */

#listError, #listStatus {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}
#listError { background: var(--error-bg); color: var(--error-fg); }
#listStatus { background: var(--panel); border: 1px solid var(--border); }
#listChooser { overflow-wrap: anywhere; }
.list-loc { margin: 10px 0; padding: 0 0 2px 0; }
.list-nvrs { margin: 2px 0 0 14px; padding: 0 0 2px 12px; border-left: 3px solid var(--border); }
.list-nvr { margin: 6px 0; }
.list-nvr > .hint { margin: 0 0 2px 34px; }
.list-nvr > .pick.known { margin-left: 34px; min-height: 44px; font-size: 13px; }
label.pick {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; margin: 0;
  font-size: 14px; color: var(--fg);
}
label.pick.loc { font-weight: 600; }
.list-nvr-name { font-weight: 600; overflow-wrap: anywhere; }
input[type="checkbox"] {
  flex: 0 0 auto;
  width: 24px; min-width: 24px; height: 24px; margin: 0;
  font-size: 16px;
  accent-color: var(--accent);
}
textarea {
  display: block;
  width: 100%;
  min-height: 320px;
  padding: 8px 10px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  color: var(--fg);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
  white-space: pre-wrap;
}
.list-warning {
  margin: 8px 0; padding: 8px 12px; border-radius: 6px;
  font-size: 13px; color: var(--warn); background: var(--chip-warn-bg);
  overflow-wrap: anywhere;
}
#listNewer {
  margin: 8px 0; padding: 8px 12px; border-radius: 6px;
  color: var(--warn); background: var(--chip-warn-bg);
}
#listNewerText { margin: 0; font-size: 14px; font-weight: 600; }
.list-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.list-actions button, a.list-mail { min-height: 44px; min-width: 44px; }
#listCopyBodyBtn { margin-top: 10px; }
a.list-mail {
  display: inline-flex; align-items: center;
  margin-top: 10px; padding: 8px 18px;
  font-weight: 600; text-decoration: none;
  color: var(--fg); border: 1px solid var(--border); border-radius: 6px;
}
#listCopySubjectBtn, #listPrintBtn, #listRebuildBtn {
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}

/* ---- Print / PDF (WARNINGS-SPEC.md 6.8). Print rules apply ONLY while console.mjs has put the print class on the body; without it
   Ctrl+P prints what it always did and nothing of a list, so a later print never shows the last customer's text. The print-only
   element is empty at every other time and never shown on screen. The named page keeps the margin off the browser's own header and
   footer in browsers that honour it; the help text beside the button covers the rest. ---- */

#printArea { display: none; }
@page printlist { margin: 0; }
@media print {
  body.printing-list { margin: 0; padding: 0; max-width: none; background: #ffffff; color: #000000; }
  body.printing-list > :not(#printArea) { display: none !important; }
  body.printing-list #printArea {
    display: block;
    page: printlist;
    padding: 2cm;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 12pt/1.45 system-ui, sans-serif;
    color: #000000;
    background: #ffffff;
  }
}

/* ---- The invite screen (CLOUD-INVITES-SPEC.md section F3). One line for
   "<role> · <place>", one for "Set up by <installer>": the page joins them
   with a line break that only this rule makes visible. ---- */

#inviteInfo { white-space: pre-line; color: var(--dim); margin: 0 0 8px; }

/* ---- "No NVRs yet": the one line under "Your NVRs" when the list is empty.
   It is the only thing in that area, so it is read at body size, not as a
   12px footnote. ---- */

#fleetList > .hint { margin: 8px 0; font-size: 14px; }

/* ---- Regions sit under the customer and site forms in one panel. ---- */

.panel h3 { margin-top: 18px; }
.panel form + form { margin-top: 14px; }

/* ---- The People panel (people.mjs draws these classes). ---- */

.person, .invite-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 8px 0;
}
.person > div, .invite-row > div { margin: 4px 0; overflow-wrap: anywhere; }
.person-login, .invite-login, .person-name, .invite-name { font-weight: 600; }
/* A person with a name: the name is the heading and the email sits under it, quieter. */
.person-name + .person-login, .invite-name + .invite-login { font-weight: 400; font-size: 13px; color: var(--dim); margin-top: 0; }
.person-you { font-weight: 400; color: var(--dim); }
.person-detail, .invite-detail, .invite-expiry { font-size: 13px; color: var(--dim); }
.person-removed .person-name, .person-removed .person-login, .person-removed .person-detail { opacity: 0.7; }
.invite-expired .invite-name, .invite-expired .invite-login, .invite-expired .invite-detail { opacity: 0.7; }
.invite-expired .invite-expiry { color: var(--bad); }

/* Row buttons are secondary: a list of six solid blue "Remove access"
   buttons would read as six things to press. */
.person button, .invite-row button {
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}

/* ---- The recorder sign-in screen (NVR-CLOUD-PASS-SPEC.md section 4). One
   question, who it is for, and a big Sign in with the two ways out under it.
   The place and the person's name are typed by people: a long unbroken one
   wraps. ---- */

#signinPlace { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
#signinPlace, #signinWho, #signinStatus { overflow-wrap: anywhere; }
#signinWho { margin: 0 0 12px; font-size: 14px; }
#signinStatus {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--border);
}
#signinStatus.error { background: var(--error-bg); color: var(--error-fg); border-color: transparent; }
#signinSection button { display: block; width: 100%; }
#signinCancelBtn, #signinSwitchBtn {
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}

#inviteLinkBox {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* ---- The office (staff) page (staff.html; view.mjs's renderStaff* draw these
   classes). A line is "label: value"; a blank is drawn dim and in words, so it is
   never mistaken for a reading. How long ago footage was last saved is the one signal
   drawn larger -- the box's "recording" flag is a small line under it. The only
   coloured thing on a box is the reachability chip (the .status classes above):
   nothing here is ever a green tick. ---- */

.kv { margin: 4px 0; overflow-wrap: anywhere; }
.kv-label { color: var(--dim); }
.not-reported .kv-value { color: var(--dim); font-style: italic; }
.sealed-age { font-size: 15px; font-weight: 700; }
.sealed-age .kv-label { font-weight: 400; }
.staff-panel { margin: 12px 0; }
.staff-panel h3 { margin-top: 4px; }
.staff-panel > p { margin: 6px 0; overflow-wrap: anywhere; }
.staff-camera { background: var(--bg); }
.staff-row > .hint { margin: 2px 0 6px; }

/* A box id on a list card opens that box: a button that reads as a link. */
button.device-open {
  min-height: 44px;
  margin-top: 0;
  padding: 4px 0;
  color: var(--fg);
  background: transparent;
  text-align: left;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

/* The filter controls and the status buttons. */
#filterForm select, #filterForm input[type="text"] { margin-bottom: 4px; }
#filterForm button, #refreshBtn { margin-right: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chips button {
  margin-top: 0;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}

/* ---- Show recovery key (DRIVE-ENCRYPTION-SPEC.md 9.6). The row sits on the
   installer's NVR card; the key itself is shown in a dialog that console.mjs
   appends to the page body, because the 60 s poll rebuilds the cards and would
   wipe a key mid-read. Phone first: the panel is as wide as the screen allows,
   the key wraps anywhere, and every button keeps the 44px tap target. ---- */

.recovery-key-row > button {
  margin: 6px 0 0 10px;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}
.recovery-key-row .error { margin: 6px 0 0; }

.key-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.55);
}
.key-panel {
  width: 100%;
  max-width: 560px;
  min-width: 0;
  margin: 24px 0;
  padding: 14px 16px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.key-panel h2 { margin: 0 0 6px; }
.key-item {
  margin: 12px 0;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.key-heading { font-weight: 600; overflow-wrap: anywhere; }
.key-meta { font-size: 13px; color: var(--dim); overflow-wrap: anywhere; }
.key-retired {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--warn);
  background: var(--chip-warn-bg);
  overflow-wrap: anywhere;
}
.key-value {
  display: block;
  margin-top: 8px;
  padding: 10px 12px;
  font: 16px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.5px;
  word-break: break-all;
  user-select: all;
  color: var(--fg);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.key-note { margin: 8px 0 0; font-size: 12px; color: var(--dim); overflow-wrap: anywhere; }
.key-panel button {
  margin-right: 8px;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}
.chips button[aria-pressed="true"] {
  color: var(--accent-fg);
  background: var(--accent);
  border-color: var(--accent);
}
#fleetSummary { margin: 8px 0 2px; font-weight: 600; }
#fleetNote > div, #boxNote { margin: 2px 0; font-size: 12px; color: var(--dim); }
#boxError { margin-top: 10px; }
#staffWho { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
#backBtn, #refreshBtn, #boxRefreshBtn, #moreBtn {
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}
.key-panel .key-hide {
  color: var(--accent-fg);
  background: var(--accent);
  border: 0;
}
