/* Novabotics: black / white, high contrast.
   State is never conveyed by color alone: every badge carries a glyph + text,
   and severity is encoded by fill / outline / stripes. The only hue is the
   emergency red, reserved for safety-critical states. */

:root {
  --bg: #000;
  --fg: #fff;
  --muted: #b3b3b3;
  --line: #fff;
  --line-soft: #4d4d4d;
  --emergency: #ff2d2d;
  --font: "Inter", "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --gutter: clamp(16px, 4vw, 48px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
/* `hidden` must win over component display rules (.btn is inline-flex, .vis-tip is grid). */
[hidden] { display: none !important; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--fg); outline-offset: 3px; }

/* --- Header --------------------------------------------------------------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px var(--gutter);
  border-bottom: 2px solid var(--line);
}
.brand {
  font-weight: 800;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  text-decoration: none;
  font-size: 18px;
}
.brand span { font-weight: 300; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border: 2px solid var(--line);
  background: var(--fg);
  color: var(--bg);
  font: 700 13px/1 var(--font);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.btn:hover { background: var(--bg); color: var(--fg); }
.btn.ghost { background: var(--bg); color: var(--fg); }
.btn.ghost:hover { background: var(--fg); color: var(--bg); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.header-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

/* --- Login ---------------------------------------------------------------- */

.login { display: grid; place-items: center; padding: 64px var(--gutter); min-height: calc(100vh - 180px); }
.login-card { width: 100%; max-width: 400px; border: 2px solid var(--line); padding: 32px; display: grid; gap: 18px; }
.login-card h1 { margin: 0; font-size: 32px; font-weight: 900; letter-spacing: -0.02em; text-transform: uppercase; }
.login-sub { margin: -8px 0 4px; color: var(--muted); }
.login-card label {
  display: grid; gap: 8px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase;
}
.login-card input {
  font: 16px/1.2 var(--font); color: var(--fg); background: var(--bg);
  border: 2px solid var(--line-soft); padding: 12px 14px; border-radius: 0;
}
.login-card input:focus { border-color: var(--fg); outline: none; }
.login-card .btn { justify-content: center; padding: 14px 20px; }
.login-error { margin: 0; min-height: 1.3em; font-size: 14px; color: var(--fg); font-weight: 700; }
.login-error:empty { min-height: 0; margin-top: -18px; }

/* --- Home ----------------------------------------------------------------- */

.hero {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 72vh;
  padding: 64px var(--gutter);
}
/* Background film (hero-bg.js). The desktop cut keeps its subjects on the right,
   the shade darkens the left so the white lockup keeps full contrast. */
.hero-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  background: var(--bg);
}
.hero-shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.55) 38%, rgba(0, 0, 0, 0.08) 70%, rgba(0, 0, 0, 0.15) 100%);
  pointer-events: none;
}
.hero .lockup { position: relative; z-index: 2; }
@media (max-aspect-ratio: 4/5) {
  /* Mobile cut: subject in the lower half, lockup on top over a top-down shade. */
  .hero { justify-content: flex-start; padding-top: 10vh; min-height: 78vh; }
  .hero-shade {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.5) 45%, rgba(0, 0, 0, 0.05) 70%, rgba(0, 0, 0, 0.35) 100%);
  }
}
.hero h1 {
  margin: 0;
  font-size: clamp(48px, 11vw, 168px);
  font-weight: 900;
  line-height: 0.88;
  letter-spacing: -0.04em;
  text-transform: uppercase;
}
/* Lockup lines: one word per line, widths equalised by lockup.js. */
.lockup .fit { display: block; width: max-content; white-space: nowrap; }
/* Spacing declared on the scaled spans so it tracks their font-size (em resolves per element). */
.lockup h1 .fit { letter-spacing: -0.04em; }
.lockup h1 .light { font-weight: 300; }  /* NOVA heavy, BOTICS light, like the header brand */
.lockup .tagline .fit { letter-spacing: 0.02em; }
.lockup .tagline strong { font-weight: 800; }
/* Shooting-star underline under "works": a tapered trail that fades in from the
   left and ends in a four-point star; it streaks in once, then the star twinkles. */
.lockup .shooting-star { position: relative; white-space: nowrap; }
.lockup .shooting-star svg {
  position: absolute; left: -5%; bottom: -0.5em; width: 122%; height: auto;
  overflow: visible; pointer-events: none; fill: currentColor;
}
.lockup .shooting-star .trail {
  clip-path: inset(0 100% 0 0);
  animation: star-trail 0.8s cubic-bezier(.5, 0, .2, 1) 0.6s forwards;
}
.lockup .shooting-star .star {
  transform-box: fill-box; transform-origin: center; opacity: 0; transform: scale(0) rotate(-90deg);
  animation: star-pop 0.45s cubic-bezier(.3, 1.6, .5, 1) 1.25s forwards,
             star-twinkle 3.2s ease-in-out 2.2s infinite;
}
.lockup .shooting-star .spark { opacity: 0; animation: star-spark 0.9s ease-out 1.05s forwards; }
.lockup .shooting-star .spark + .spark { animation-delay: 0.9s; }
@keyframes star-trail { to { clip-path: inset(0 0 0 0); } }
@keyframes star-pop { to { opacity: 1; transform: scale(1) rotate(0deg); } }
@keyframes star-twinkle {
  0%, 100% { opacity: 1; transform: scale(1) rotate(0deg); }
  50% { opacity: 0.75; transform: scale(0.82) rotate(45deg); }
}
@keyframes star-spark { 30% { opacity: 0.9; } to { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) {
  .lockup .shooting-star .trail { animation: none; clip-path: none; }
  .lockup .shooting-star .star { animation: none; opacity: 1; transform: none; }
  .lockup .shooting-star .spark { animation: none; opacity: 0.35; }
}
.hero p {
  max-width: 560px;
  margin: 32px 0 0;
  font-size: clamp(17px, 2vw, 21px);
  color: var(--muted);
}
.hero p.tagline {
  max-width: none;
  margin-top: 0.5em;
  color: var(--fg);
  font-size: clamp(20px, 3.2vw, 44px);
  font-weight: 300;
  letter-spacing: 0.24em;
  line-height: 1.2;
}
@media (max-aspect-ratio: 4/5) {
  /* Mobile: compact centred lockup (about 55 % of the former full-width size) so the film carries the hero. */
  .hero .lockup { align-self: center; }
  .hero h1 { font-size: 13.12vw; }
}
.pillars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  border-top: 2px solid var(--line);
}
.pillars div {
  padding: 28px var(--gutter);
  border-right: 1px solid var(--line-soft);
}
.pillars div:last-child { border-right: 0; }
.pillars h2 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.pillars p { margin: 0; color: var(--muted); font-size: 15px; }

.site-footer {
  padding: 16px var(--gutter);
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
}

/* --- Dashboard ------------------------------------------------------------ */

main.dash { flex: 1; padding: 32px var(--gutter) 64px; }

.dash-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}
.dash-head h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 900;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  line-height: 1;
}
.dash-meta { color: var(--muted); font: 13px/1.4 var(--mono); text-align: right; }

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border: 2px solid var(--line);
  margin-bottom: 40px;
}
.summary div { padding: 16px 20px; border-right: 1px solid var(--line-soft); }
.summary div:last-child { border-right: 0; }
.summary .num { display: block; font-size: 40px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.summary .lbl { font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }

.group { margin-bottom: 48px; }
.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--line);
}
.group-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.group-head small { color: var(--muted); font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 20px;
}

.card {
  border: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.card.offline { border-style: dashed; }
.card.emergency { border-color: var(--emergency); box-shadow: 0 0 0 2px var(--emergency); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.card-title { margin: 0; font-size: 20px; font-weight: 800; line-height: 1.15; }
.card-sub {
  margin-top: 4px;
  font: 12px/1.3 var(--mono);
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* Connectivity pill: filled = online, outlined = offline. */
.conn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font: 700 11px/1 var(--font);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border: 2px solid var(--line);
}
.conn.on { background: var(--fg); color: var(--bg); }
.conn.off { background: var(--bg); color: var(--fg); }

/* State band */
.state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  font-weight: 800;
  font-size: 17px;
  border-bottom: 1px solid var(--line-soft);
}
.state .glyph {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  font-size: 15px;
  line-height: 1;
}
.state .txt { min-width: 0; overflow-wrap: anywhere; }
.state.lvl-ok .glyph { background: var(--fg); color: var(--bg); }
.state.lvl-info .glyph { background: var(--bg); color: var(--fg); }
.state.lvl-warning {
  background: repeating-linear-gradient(135deg, #fff 0 6px, #000 6px 12px);
}
.state.lvl-warning .txt,
.state.lvl-warning .glyph { background: var(--bg); color: var(--fg); padding: 2px 8px; }
.state.lvl-warning .glyph { padding: 0; }
.state.lvl-critical { background: var(--fg); color: var(--bg); }
.state.lvl-critical .glyph { border-color: var(--bg); }
.state.lvl-unknown { color: var(--muted); }
.card.emergency .state { background: var(--emergency); color: #fff; }
.card.emergency .state .glyph { border-color: #fff; }

.metrics { margin: 0; padding: 6px 18px 10px; flex: 1; }
.metric {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 16px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}
.metric:last-child { border-bottom: 0; }
.metric dt { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.metric dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric dd .unit { font-weight: 400; color: var(--muted); margin-left: 4px; font-size: 13px; }
.metric .note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); text-align: right; margin-top: -2px; }
.metric.primary dd { font-size: 26px; font-weight: 900; }
.metric.lvl-warning dd::before { content: "▲ "; font-size: 0.6em; vertical-align: middle; }
.metric.lvl-critical dd::before { content: "■ "; font-size: 0.6em; vertical-align: middle; }

/* Percent meter (battery) */
.meter {
  grid-column: 1 / -1;
  height: 10px;
  border: 2px solid var(--line);
  margin-top: 4px;
  position: relative;
}
.meter > i { position: absolute; inset: 0 auto 0 0; background: var(--fg); }
.meter.lvl-warning > i,
.meter.lvl-critical > i { background: repeating-linear-gradient(135deg, #fff 0 3px, #000 3px 6px); }

.card-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-top: 1px solid var(--line-soft);
  font: 12px/1.4 var(--mono);
  color: var(--muted);
}
.card-foot strong { color: var(--fg); font-weight: 700; }
.card-error {
  padding: 8px 18px;
  border-top: 1px dashed var(--line-soft);
  font: 11px/1.4 var(--mono);
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* View toggle (segmented control) */
.toolbar { display: flex; justify-content: flex-end; margin: -16px 0 24px; }
.seg { display: inline-flex; border: 2px solid var(--line); }
.seg button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 0;
  background: var(--bg);
  color: var(--fg);
  font: 700 12px/1 var(--font);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
}
.seg button + button { border-left: 2px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.seg button:not([aria-pressed="true"]):hover { background: #1a1a1a; }

/* List view */
.table-wrap { overflow-x: auto; border: 2px solid var(--line); }
table.fleet { width: 100%; min-width: 760px; border-collapse: collapse; }
.fleet tbody th { min-width: 170px; }
.fleet td:nth-child(5) { min-width: 170px; }
.fleet .cell-sub { overflow-wrap: normal; }
.fleet thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.fleet tbody th, .fleet td {
  text-align: left;
  vertical-align: top;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-weight: 400;
}
.fleet tbody tr:last-child > * { border-bottom: 0; }
.fleet tbody tr:hover > * { background: #111; }
.fleet tr.offline > * { color: var(--muted); }
.fleet tr.offline .cell-main { color: var(--fg); }
.fleet tr.emergency > th { box-shadow: inset 6px 0 0 var(--emergency); }
.cell-main { font-weight: 800; font-size: 16px; }
.cell-sub { margin-top: 4px; font: 12px/1.35 var(--mono); color: var(--muted); overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 2px solid var(--line);
  font-weight: 700;
  font-size: 14px;
}
.badge.lvl-ok { background: var(--fg); color: var(--bg); }
.badge.lvl-warning {
  padding-left: 18px;
  background: repeating-linear-gradient(135deg, #fff 0 3px, #000 3px 6px) left / 9px 100% no-repeat;
}
.badge.lvl-critical { background: var(--fg); color: var(--bg); }
.badge.lvl-unknown { color: var(--muted); border-color: var(--line-soft); }
.badge.emergency { background: var(--emergency); border-color: var(--emergency); color: #fff; }

.kvs { min-width: 200px; }
.kv {
  display: inline-block;
  margin: 0 18px 6px 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kv b {
  display: block;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.kv.lvl-warning::after { content: " ▲"; font-size: 0.7em; }
.kv.lvl-critical::after { content: " ■"; font-size: 0.7em; }

.banner {
  border: 2px dashed var(--line);
  padding: 14px 18px;
  margin-bottom: 24px;
  font-weight: 700;
}

@media (max-width: 520px) {
  .site-header { padding-top: 16px; padding-bottom: 16px; gap: 10px; }
  .brand { letter-spacing: 0.2em; font-size: 15px; }
  .btn { padding: 9px 14px; letter-spacing: 0.12em; }
  .dash-meta { text-align: left; }
  /* Dashboard header: the brand already links home; keep one row with just Log out. */
  .header-actions a.btn[href="/"] { display: none; }
  .header-actions { gap: 8px; flex-wrap: nowrap; }
  .header-actions .btn { padding: 9px 10px; letter-spacing: 0.08em; white-space: nowrap; }
  .site-header:has(.header-actions .btn + .btn) .brand { letter-spacing: 0.12em; }
  .header-actions .btn > [aria-hidden="true"] { display: none; }
}

/* List view, narrow screens: each row becomes a stacked block (device on top,
   short fields in a labelled grid, metrics full width) instead of scrolling. */
@media (max-width: 1000px) {
  table.fleet { min-width: 0; }
  .fleet thead { display: none; }
  .fleet tbody, .fleet tbody tr { display: block; }
  .fleet tbody tr {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px 20px;
    padding: 16px;
    border-bottom: 1px solid var(--line-soft);
  }
  .fleet tbody tr:last-child { border-bottom: 0; }
  .fleet tbody tr > * { display: block; padding: 0; border: 0; min-width: 0 !important; }
  .fleet tbody th { grid-column: 1 / -1; }
  .fleet td.kvs { grid-column: 1 / -1; padding-top: 12px; border-top: 1px solid var(--line-soft); }
  .fleet td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    font-size: 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .fleet td.kvs::before { display: none; }
  .fleet tr.emergency { box-shadow: inset 6px 0 0 var(--emergency); }
  .fleet tr.emergency > th { box-shadow: none; }
}

/* Device web interfaces (Tailscale IP:port), under the device name. */
.dev-links { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; }
.dev-link {
  font-size: 12px;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dev-link:hover, .dev-link:focus-visible { border-bottom-color: var(--fg); }

/* --- Visits (Novabotics only) ---------------------------------------------- */

.vis-block { margin-top: 40px; }
.vis-h {
  margin: 0 0 14px; font-size: 13px; font-weight: 700; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--muted);
}
.vis-chart { position: relative; border: 2px solid var(--line); padding: 16px 16px 8px; }
.vis-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.vis-chart .grid { stroke: var(--line-soft); stroke-width: 1; stroke-dasharray: 2 4; }
.vis-chart .axis { stroke: var(--muted); stroke-width: 1; }
.vis-chart .tick { fill: var(--muted); font: 12px var(--mono); }
.vis-chart .bar { fill: var(--fg); }
.vis-chart .hit { fill: transparent; }
.vis-chart .day.on .hit { fill: rgba(255, 255, 255, 0.06); }
.vis-tip {
  position: absolute; top: 8px; transform: translateX(-50%); pointer-events: none;
  display: grid; gap: 2px; padding: 8px 12px; min-width: 120px;
  background: var(--fg); color: var(--bg); font: 13px/1.35 var(--font);
}
.vis-tip[hidden] { display: none; }
.vis-grid {
  margin-top: 40px; display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.vis-card { border: 2px solid var(--line); padding: 16px 18px; }
.vis-card h3 {
  margin: 0 0 12px; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted);
}
.vis-card ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.vis-card li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 15px; }
.vis-card .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vis-card .v { font-variant-numeric: tabular-nums; font-weight: 700; }
.vis-card .share {
  grid-column: 1 / -1; height: 4px; background: #262626; position: relative;
}
.vis-card .share::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--fg); }
.vis-card .empty, .vis-table .empty { color: var(--muted); }
table.vis-table { width: 100%; min-width: 640px; border-collapse: collapse; }
.vis-table th {
  text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted); border-bottom: 2px solid var(--line); white-space: nowrap;
}
.vis-table td { text-align: left; vertical-align: top; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.vis-table tbody tr:last-child td { border-bottom: 0; }
.vis-table tbody tr:hover td { background: #111; }
.vis-table .mono { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.vis-table .sub { color: var(--muted); font-family: var(--font); }
.vis-table tr.bad td { font-weight: 700; }
