/* BTK Platform dashboard — public status page (Issue #18).
 *
 * Self-contained: dashboard.html blanks the base `stylesheets` block, so this
 * file also owns the shared `.logs-shell` wrapper from base.html.
 * Themed for both colour schemes via prefers-color-scheme. */

:root {
  color-scheme: light dark;

  --ink: #101422;
  --ink-soft: #4d566b;
  --ink-muted: #6b7488;

  --surface: #ffffff;
  --surface-sunken: #f2f4f9;
  --canvas: #f6f7fb;

  --line: #e4e7ef;
  --line-soft: #edeff5;

  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-tint: #eef0fe;

  --live: #067647;
  --live-tint: #e7f6ee;
  --deploying: #1d4ed8;
  --deploying-tint: #e8eefc;
  --degraded: #b54708;
  --degraded-tint: #fdf0e3;
  --offline: #b42318;
  --offline-tint: #fdecea;
  --registered: #5b6478;
  --registered-tint: #eef0f4;

  --shadow-sm: 0 1px 2px rgba(16, 20, 34, 0.05);
  --shadow-md: 0 6px 16px -6px rgba(16, 20, 34, 0.14), 0 2px 5px -2px rgba(16, 20, 34, 0.07);
  --shadow-lg: 0 18px 36px -14px rgba(16, 20, 34, 0.22), 0 4px 10px -4px rgba(16, 20, 34, 0.1);

  --radius: 14px;
  --radius-lg: 20px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* Horizontal breathing room of the shell. Shared so the footer can bleed out
   * to the shell edges with a negative margin and still line its text up. */
  --shell-pad-x: clamp(1rem, 0.4rem + 1.8vw, 2.25rem);

  /* Everything below is sized in rem, so scaling the root scales the whole page
   * with the viewport: fixed at the browser default up to ~1280px, then growing
   * to 1.125x on large displays instead of stranding the layout mid-screen. */
  font-size: clamp(1rem, 0.78rem + 0.28vw, 1.125rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9ecf5;
    --ink-soft: #a8b1c6;
    --ink-muted: #8b94ab;

    --surface: #151a29;
    --surface-sunken: #1b2133;
    --canvas: #0b0e18;

    --line: #262d42;
    --line-soft: #1f2537;

    --accent: #9aa3ff;
    --accent-strong: #b4bbff;
    --accent-tint: #1d2140;

    --live: #4ade80;
    --live-tint: #10281d;
    --deploying: #7cb0ff;
    --deploying-tint: #12203a;
    --degraded: #fbbf24;
    --degraded-tint: #2a2011;
    --offline: #fb8a82;
    --offline-tint: #2d1614;
    --registered: #9aa3b8;
    --registered-tint: #1e2434;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px -8px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 20px 40px -16px rgba(0, 0, 0, 0.8);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body.dashboard-page {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--canvas);
  background-image:
    radial-gradient(58rem 30rem at 12% -12%, color-mix(in srgb, var(--accent) 11%, transparent), transparent 70%),
    radial-gradient(46rem 26rem at 92% -6%, color-mix(in srgb, var(--live) 9%, transparent), transparent 68%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Column layout so the footer can be pushed to the bottom of the viewport even
 * when the registry is short enough to leave the page half empty. */
body.dashboard-page .logs-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 78rem;
  margin: 0 auto;
  padding: clamp(1rem, 0.7rem + 1vw, 1.75rem) var(--shell-pad-x) 0;
}

body.dashboard-page .logs-shell__main {
  flex: 1 0 auto;
  min-width: 0;
}

/* ---------------------------------------------------------------- masthead */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 1.5rem;
}

.masthead__brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius);
}

.masthead__mark {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: var(--shadow-md);
}

@media (prefers-color-scheme: dark) {
  .masthead__mark {
    color: #0b0e18;
  }
}

.masthead__mark svg {
  width: 1.5rem;
  height: 1.5rem;
}

.masthead__wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.masthead__name {
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.masthead__tagline {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.masthead__live {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.masthead__stamp {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.masthead__pulse {
  position: relative;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--live);
  flex-shrink: 0;
}

.masthead__pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 2.4s ease-out infinite;
}

@keyframes pulse {
  0% { opacity: 0.6; transform: scale(1); }
  70% { opacity: 0; transform: scale(2.8); }
  100% { opacity: 0; transform: scale(2.8); }
}

/* -------------------------------------------------------------------- hero */

.hero {
  margin: 0 0 1.75rem;
}

.hero__title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.75rem, 1.2rem + 2.4vw, 2.6rem);
  font-weight: 680;
  letter-spacing: -0.035em;
  line-height: 1.12;
}

.hero__lead {
  margin: 0;
  /* No max-width: the lead is written to sit on one line on desktop.
   * It still wraps naturally once the viewport is too narrow to hold it. */
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink-soft);
  text-wrap: pretty;
}

/* ----------------------------------------------------------------- summary */

.summary {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: grid;
  /* Four across when there is room, two on a phone, one when even that is
   * tight — no breakpoint needed for the step down. */
  grid-template-columns: repeat(auto-fit, minmax(min(9.5rem, 100%), 1fr));
  gap: 0.75rem;
}

.summary__tile {
  --tile-accent: var(--ink-muted);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.summary__tile--live { --tile-accent: var(--live); }
.summary__tile--deploying { --tile-accent: var(--deploying); }
.summary__tile--attention { --tile-accent: var(--degraded); }

.summary__value {
  font-size: 1.6rem;
  font-weight: 660;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--tile-accent);
}

.summary__label {
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
}
/* ------------------------------------------------- master-detail console */

.u-sr-only,
.console__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.console {
  display: grid;
  grid-template-columns: minmax(16rem, 21rem) 1fr;
  align-items: start;
  gap: 1rem;
}

/* ------------------------------------------------------------- left: list */

.console__list {
  display: flex;
  flex-direction: column;
  padding: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.console__item {
  --status-color: var(--registered);
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.6rem 0.65rem;
  font: inherit;
  text-align: left;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}

.console__item--live { --status-color: var(--live); }
.console__item--deploying { --status-color: var(--deploying); }
.console__item--degraded { --status-color: var(--degraded); }
.console__item--offline { --status-color: var(--offline); }

.console__item:hover {
  background: var(--surface-sunken);
}

.console__item[aria-selected="true"] {
  background: var(--accent-tint);
}

/* Accent rail marks the active row without shifting any layout. */
.console__item[aria-selected="true"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55rem;
  bottom: 0.55rem;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.console__item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.console__icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 10px;
  color: var(--accent);
  background: var(--surface-sunken);
  border: 1px solid var(--line-soft);
}

.console__item[aria-selected="true"] .console__icon {
  background: var(--surface);
}

.console__icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

.svc__monogram {
  font-size: 0.85rem;
  font-weight: 660;
  line-height: 1;
}

.console__text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.console__name {
  font-size: 0.925rem;
  font-weight: 610;
  letter-spacing: -0.012em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.console__addr {
  font-family: var(--mono);
  font-size: 0.71rem;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.console__version {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-muted);
  background: var(--surface-sunken);
  border-radius: 6px;
  padding: 0.12rem 0.35rem;
  max-width: 6rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.console__item[aria-selected="true"] .console__version {
  background: var(--surface);
}

.console__dot {
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--status-color);
}

.console__item--deploying .console__dot {
  animation: blink 1.6s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* ----------------------------------------------------------- right: stage */

.console__stage {
  position: sticky;
  top: 1rem;
  display: grid;
  gap: 1rem;
}

.console__panel {
  --status-color: var(--registered);
  --status-tint: var(--registered-tint);
  position: relative;
  padding: 1.4rem 1.5rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.console__panel--live { --status-color: var(--live); --status-tint: var(--live-tint); }
.console__panel--deploying { --status-color: var(--deploying); --status-tint: var(--deploying-tint); }
.console__panel--degraded { --status-color: var(--degraded); --status-tint: var(--degraded-tint); }
.console__panel--offline { --status-color: var(--offline); --status-tint: var(--offline-tint); }

.console__panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--status-color);
}

.console__panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Applied by dashboard.html only when the visitor switches service, so the
 * 30s background refresh never replays the animation under them. */
.console__panel.is-entering {
  animation: panel-in 0.32s var(--ease);
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.detail__head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.detail__icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  border-radius: 14px;
  color: var(--accent);
  background: var(--surface-sunken);
  border: 1px solid var(--line-soft);
}

.detail__icon svg {
  width: 1.6rem;
  height: 1.6rem;
}

.detail__icon .svc__monogram {
  font-size: 1.2rem;
}

.detail__ident {
  flex: 1;
  min-width: 0;
}

.detail__name {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 660;
  letter-spacing: -0.028em;
  line-height: 1.2;
}

.detail__addr {
  margin: 0.1rem 0 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.detail__status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  padding: 0.25rem 0.65rem;
  font-size: 0.7rem;
  font-weight: 620;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--status-color);
  background: var(--status-tint);
  border-radius: 999px;
}

.detail__dot {
  width: 0.44rem;
  height: 0.44rem;
  border-radius: 50%;
  background: currentColor;
}

.console__panel--deploying .detail__dot {
  animation: blink 1.6s ease-in-out infinite;
}

.detail__desc {
  margin: 0 0 1.15rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.detail__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.65rem;
}

.detail__stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 0.85rem;
  background: var(--surface-sunken);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}

.detail__stat-value {
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
}

/* The deployed version is the headline number on this panel. */
.detail__stat--version {
  background: var(--accent-tint);
  border-color: color-mix(in srgb, var(--accent) 20%, transparent);
}

.detail__stat--version .detail__stat-value {
  font-family: var(--mono);
  font-size: 1.15rem;
  color: var(--accent);
}

.detail__stat-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.detail__alert {
  margin: 0.9rem 0 0;
  padding: 0.6rem 0.8rem;
  font-size: 0.82rem;
  color: var(--offline);
  background: var(--offline-tint);
  border-radius: 10px;
}

.detail__links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.detail__visit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  font-size: 0.86rem;
  font-weight: 580;
  text-decoration: none;
  color: #fff;
  background: var(--accent);
  border-radius: 11px;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}

@media (prefers-color-scheme: dark) {
  .detail__visit {
    color: #0b0e18;
  }
}

.detail__visit svg {
  width: 1rem;
  height: 1rem;
}

.detail__visit:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.detail__visit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Secondary to Visit — the repo is a reference, not the thing the page is about. */
.detail__source {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.1rem;
  font-size: 0.86rem;
  font-weight: 580;
  text-decoration: none;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  transition:
    color 0.2s var(--ease),
    border-color 0.2s var(--ease),
    transform 0.2s var(--ease);
}

.detail__source svg {
  width: 1rem;
  height: 1rem;
}

.detail__source:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
  transform: translateY(-1px);
}

.detail__source:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ------------------------------------------------------------- empty state */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  padding: 3.5rem 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
}

.empty__mark {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 0.5rem;
  color: var(--ink-muted);
  background: var(--surface-sunken);
  border-radius: 12px;
}

.empty__mark svg {
  width: 1.5rem;
  height: 1.5rem;
}

.empty__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 620;
}

.empty__lead {
  margin: 0;
  font-size: 0.885rem;
  color: var(--ink-muted);
}

/* ------------------------------------------------------------------ footer */

/* Pinned to the bottom edge of the viewport while the page scrolls, and — via
 * the shell's column layout — resting on the bottom edge when it doesn't. The
 * negative inline margin lets the rule and backdrop bleed to the shell edges. */
.dashboard-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1.5rem;
  margin: 2.5rem calc(-1 * var(--shell-pad-x)) 0;
  padding: 0.85rem var(--shell-pad-x) calc(0.85rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-soft);
  background: var(--canvas);
  background: color-mix(in srgb, var(--canvas) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.dashboard-footer p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.dashboard-footer__note {
  min-width: 0;
  text-wrap: pretty;
}

.dashboard-footer__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1rem;
}

.dashboard-footer__version {
  font-family: var(--mono);
  color: var(--ink-soft);
}

/* -------------------------------------------------------------- responsive */

/* Below this width the split view collapses to a single column: the service
 * list stacks above the detail stage, which stops being sticky. */
@media (max-width: 60rem) {
  .console {
    grid-template-columns: 1fr;
  }

  .console__stage {
    position: static;
  }
}

@media (max-width: 40rem) {
  .masthead {
    padding-bottom: 1.25rem;
  }

  /* Comfortable thumb targets on the list rows. */
  .console__item {
    padding: 0.75rem 0.7rem;
  }

  .console__panel {
    padding: 1.15rem 1.15rem 1.25rem;
  }

  .detail__name {
    font-size: 1.25rem;
  }

  .detail__visit {
    width: 100%;
  }

  /* The footer wraps to three or four lines on a phone — tighten it so the
   * pinned strip keeps taking a small slice of a small viewport. */
  .dashboard-footer {
    gap: 0.15rem 0.75rem;
    padding: 0.6rem var(--shell-pad-x) calc(0.7rem + env(safe-area-inset-bottom, 0px));
  }

  .dashboard-footer p {
    font-size: 0.74rem;
  }
}

@media (max-width: 26rem) {
  /* The version chip is the first thing to go when the row runs out of room —
   * it is repeated prominently in the detail panel anyway. */
  .console__version {
    display: none;
  }

  .detail__stats {
    grid-template-columns: 1fr;
  }
}

/* A pinned footer is worth its space on a normal window; on a short one (phone
 * in landscape, a squat browser window) it just eats the viewport, so let it
 * scroll away and keep only the flex push to the bottom. */
@media (max-height: 34rem) {
  .dashboard-footer {
    position: static;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .detail__visit:hover {
    transform: none;
  }
}
