@import url("/static/fonts/fonts.css");

/* ==========================================================================
   Meshtastic Observatory — listening post
   Night slate plus dial amber. The mono face carries every number, and the
   stretched Archivo carries the station identity like an engraved plate.
   ========================================================================== */

:root {
  --bg:            #0b131d;
  --bg-plate:      #0e1825;
  --surface:       #131f2d;
  --surface-hi:    #182636;
  --edge:          rgba(255, 255, 255, 0.07);
  --edge-strong:   rgba(255, 255, 255, 0.15);
  --text:          #e6edf5;
  --text-dim:      #8ca0b6;
  --text-faint:    #5c7188;
  --signal:        #ff9e3d;
  --signal-soft:   rgba(255, 158, 61, 0.13);
  --live:          #45d9c4;
  --live-soft:     rgba(69, 217, 196, 0.13);
  --down:          #f4666f;
  --down-soft:     rgba(244, 102, 111, 0.13);
  --grid:          rgba(140, 160, 182, 0.16);

  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Archivo", ui-sans-serif, system-ui, "Segoe UI", Helvetica, Arial, sans-serif;

  --radius: 3px;
  --page: 1180px;
  --step: 0.9rem;

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:          #efece4;
    --bg-plate:    #e7e3d9;
    --surface:     #faf8f4;
    --surface-hi:  #f3f0e9;
    --edge:        rgba(16, 30, 46, 0.11);
    --edge-strong: rgba(16, 30, 46, 0.22);
    --text:        #15202c;
    --text-dim:    #566575;
    --text-faint:  #7f8c9b;
    --signal:      #b8540b;
    --signal-soft: rgba(184, 84, 11, 0.11);
    --live:        #0d7d6c;
    --live-soft:   rgba(13, 125, 108, 0.11);
    --down:        #b32f3a;
    --down-soft:   rgba(179, 47, 58, 0.1);
    --grid:        rgba(86, 101, 117, 0.2);
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg:          #efece4;
  --bg-plate:    #e7e3d9;
  --surface:     #faf8f4;
  --surface-hi:  #f3f0e9;
  --edge:        rgba(16, 30, 46, 0.11);
  --edge-strong: rgba(16, 30, 46, 0.22);
  --text:        #15202c;
  --text-dim:    #566575;
  --text-faint:  #7f8c9b;
  --signal:      #b8540b;
  --signal-soft: rgba(184, 84, 11, 0.11);
  --live:        #0d7d6c;
  --live-soft:   rgba(13, 125, 108, 0.11);
  --down:        #b32f3a;
  --down-soft:   rgba(179, 47, 58, 0.1);
  --grid:        rgba(86, 101, 117, 0.2);
  color-scheme: light;
}

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

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--signal); }

:where(a, button, [tabindex]):focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: 2px;
}

.shell {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 clamp(0.9rem, 3vw, 2rem) 4rem;
}

/* -- Station plate -------------------------------------------------------- */

.plate {
  background: var(--bg-plate);
  border-bottom: 1px solid var(--edge);
  padding-top: clamp(1.6rem, 4vw, 2.8rem);
}

.plate__inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 clamp(0.9rem, 3vw, 2rem);
}

.plate__top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem 1.5rem;
}

.plate__identity { min-width: 0; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 0.55rem;
}

.station-name {
  font-family: var(--sans);
  font-weight: 700;
  font-stretch: 118%;
  font-size: clamp(1.85rem, 5.6vw, 3.35rem);
  line-height: 0.98;
  letter-spacing: 0.005em;
  text-transform: uppercase;
  margin: 0;
  overflow-wrap: break-word;
}

.station-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0.7rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.55rem;
}

.station-meta span:not(:last-child)::after {
  content: "·";
  margin-left: 0.55rem;
  color: var(--text-faint);
}

/* Status dot: the colour says the essential, the text confirms it. */

.beacon {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.8rem 0.42rem 0.62rem;
  border: 1px solid var(--edge-strong);
  border-radius: 100px;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  white-space: nowrap;
}

.beacon__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.beacon[data-state="up"] {
  color: var(--live);
  background: var(--live-soft);
  border-color: color-mix(in srgb, var(--live) 40%, transparent);
}

.beacon[data-state="up"] .beacon__dot { animation: breathe 2.8s ease-in-out infinite; }

.beacon[data-state="down"] {
  color: var(--down);
  background: var(--down-soft);
  border-color: color-mix(in srgb, var(--down) 40%, transparent);
}

.beacon[data-state="unknown"] { color: var(--text-faint); }

@keyframes breathe {
  0%, 100% { opacity: 1;   box-shadow: 0 0 0 0 currentColor; }
  50%      { opacity: 0.5; box-shadow: 0 0 0 4px transparent; }
}

.plate__status-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55rem;
}

.status-note {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: right;
  margin: 0;
}

/* -- Reception ribbon: the signature element ------------------------------ */

.ribbon {
  margin: clamp(1.4rem, 3.5vw, 2.2rem) 0 0;
  padding-bottom: 1.4rem;
}

.ribbon__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.ribbon__legend {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  display: flex;
  gap: 0.9rem;
}

.ribbon__key {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
}

.ribbon__swatch {
  width: 8px;
  height: 8px;
  flex: none;
}

.ribbon__swatch--direct  { background: var(--signal); }
.ribbon__swatch--relayed { background: color-mix(in srgb, var(--signal) 42%, transparent); }

.ribbon__plot {
  display: block;
  width: 100%;
  height: 118px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
}

.ribbon__empty {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-faint);
  border: 1px dashed var(--edge-strong);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
}

/* -- Counters ------------------------------------------------------------- */

.counters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  border-top: 1px solid var(--edge);
  border-left: 1px solid var(--edge);
  margin-top: clamp(1.5rem, 4vw, 2.4rem);
}

.counter {
  border-right: 1px solid var(--edge);
  border-bottom: 1px solid var(--edge);
  padding: 0.85rem 0.95rem 0.9rem;
  background: var(--surface);
}

.counter__value {
  font-family: var(--mono);
  font-size: clamp(1.35rem, 3.4vw, 1.85rem);
  font-weight: 600;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  display: block;
}

.counter__label {
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-top: 0.35rem;
  display: block;
}

/* -- Section grid --------------------------------------------------------- */

.layout {
  display: grid;
  gap: clamp(1.4rem, 3vw, 2.2rem);
  margin-top: clamp(1.6rem, 4vw, 2.6rem);
  align-items: start;
}

/* Two columns of comparable height: the log and the nodes on the left,
   the messages and the map on the right. Below 900 px, the stack follows
   the natural reading order. */
.column {
  display: grid;
  gap: clamp(1.4rem, 3vw, 2.2rem);
  align-content: start;
  min-width: 0;
}

@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .layout > .panel--wide { grid-column: 1 / -1; }
}

.panel {
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.75rem 0.95rem;
  border-bottom: 1px solid var(--edge);
  background: var(--surface-hi);
}

.panel__title {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0;
}

.panel__hint {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--text-faint);
}

.panel__body { padding: 0.5rem 0.6rem 0.7rem; }
.panel__body--flush { padding: 0; }

.empty {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-faint);
  padding: 1.6rem 1rem;
  text-align: center;
}

/* -- Listening log -------------------------------------------------------- */

.log {
  display: flex;
  flex-direction: column;
  max-height: 34rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: var(--edge-strong); border-radius: 4px; }

.log__row {
  display: grid;
  grid-template-columns: 4.9rem minmax(0, 1fr) 5.2rem 4.4rem 4.6rem;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.95rem;
  border-bottom: 1px solid var(--edge);
  font-family: var(--mono);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.log__row:last-child { border-bottom: none; }

.log__time  { color: var(--text-faint); white-space: nowrap; }
.log__name  { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log__snr   { color: var(--signal); text-align: right; }
.log__rssi  { color: var(--text-dim); text-align: right; }
.log__blank { color: var(--text-faint); }

.tag {
  font-size: 0.62rem;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  border: 1px solid var(--edge-strong);
  border-radius: 2px;
  padding: 0.08rem 0.3rem;
  justify-self: start;
  white-space: nowrap;
}

.hops {
  text-align: right;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.hops[data-direct="true"] { color: var(--live); }

.log__row--new { animation: arrive 1.6s ease-out; }

@keyframes arrive {
  0%   { background: var(--signal-soft); }
  100% { background: transparent; }
}

/* -- Nodes ---------------------------------------------------------------- */

.nodes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  background: var(--surface);
  margin: 0 -1px -1px 0;
}

.node {
  border-right: 1px solid var(--edge);
  border-bottom: 1px solid var(--edge);
  padding: 0.72rem 0.85rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.node__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.3rem 0.5rem;
  flex-wrap: wrap;
}

.node__name {
  font-weight: 600;
  font-size: 0.95rem;
  overflow-wrap: break-word;
  min-width: 0;
}

.node__seen {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-faint);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.node__seen[data-active="true"] { color: var(--live); }

.node__seen::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.node__hw {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node__figures {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.5rem;
  margin-top: 0.15rem;
}

.node__figures b { color: var(--signal); font-weight: 600; }

.node__figures span:not(:last-child)::after {
  content: "·";
  margin-left: 0.5rem;
  color: var(--text-faint);
}

.node__id {
  font-family: var(--mono);
  font-size: 0.64rem;
  color: var(--text-faint);
}

.node--local {
  box-shadow: inset 3px 0 0 var(--signal);
}

.node__locate {
  align-self: flex-start;
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--edge-strong);
  border-radius: 2px;
  padding: 0.22rem 0.45rem;
  cursor: pointer;
}

.node__locate:hover { color: var(--signal); border-color: var(--signal); }

/* Leaflet paints its popup white by default, which the dark theme cannot
   live with: the whole box is repainted from the page's own tokens. */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface-hi);
  color: var(--text);
  border: 1px solid var(--edge-strong);
  border-radius: var(--radius);
  box-shadow: none;
}

.leaflet-popup-content { margin: 0.55rem 0.7rem; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-faint); }

.map-popup {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.map-popup strong {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

/* -- Public messages ------------------------------------------------------ */

.messages {
  display: flex;
  flex-direction: column;
  max-height: 34rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--edge-strong); border-radius: 4px; }

.message {
  padding: 0.7rem 0.95rem 0.8rem;
  border-bottom: 1px solid var(--edge);
}

.message:last-child { border-bottom: none; }

.message__meta {
  font-family: var(--mono);
  font-size: 0.67rem;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.5rem;
  margin-bottom: 0.28rem;
}

.message__from { color: var(--signal); }

.message__text {
  margin: 0;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

/* -- Map ------------------------------------------------------------------ */

.map {
  height: 300px;
  width: 100%;
  background: var(--surface-hi);
}

.map__note {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--text-faint);
  padding: 0.55rem 0.95rem;
  border-top: 1px solid var(--edge);
}

.leaflet-container {
  font-family: var(--mono);
  font-size: 0.72rem;
  background: var(--surface-hi);
}

/* The OSM tiles are designed for a light background: we mute them in the
   dark theme rather than leave a white rectangle in the middle of the page. */
:root:not([data-theme="light"]) .leaflet-tile-pane {
  filter: grayscale(0.4) brightness(0.62) contrast(1.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .leaflet-tile-pane { filter: none; }
}

:root[data-theme="dark"] .leaflet-tile-pane {
  filter: grayscale(0.4) brightness(0.62) contrast(1.08);
}

.map-pin {
  display: block;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--signal);
  border: 2px solid var(--bg-plate);
  box-shadow: 0 0 0 3px var(--signal-soft);
}

.map-pin--remote { background: var(--text-dim); }

/* -- Technical record ----------------------------------------------------- */

.specs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  background: var(--surface);
  margin: 0 -1px -1px 0;
}

.spec {
  border-right: 1px solid var(--edge);
  border-bottom: 1px solid var(--edge);
  padding: 0.6rem 0.85rem 0.65rem;
}

.spec__label {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: block;
}

.spec__value {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  margin-top: 0.2rem;
  display: block;
  overflow-wrap: break-word;
  line-height: 1.35;
}

/* -- Footer --------------------------------------------------------------- */

.footer {
  margin-top: 2.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--edge);
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.2rem;
  justify-content: space-between;
  align-items: center;
}

.theme-toggle {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--edge-strong);
  border-radius: 2px;
  padding: 0.28rem 0.6rem;
  cursor: pointer;
}

.theme-toggle:hover { color: var(--text); border-color: var(--text-faint); }

/* -- Sign-in page --------------------------------------------------------- */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login { width: 100%; max-width: 27rem; }

.login__plate {
  background: var(--bg-plate);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 2rem 1.7rem 1.8rem;
}

.login__title { font-size: clamp(1.5rem, 6vw, 2.1rem); margin-bottom: 0.9rem; }

.login__note {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--text-dim);
  margin: 0 0 1.3rem;
}

.login__error {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--down);
  background: var(--down-soft);
  border-left: 2px solid var(--down);
  padding: 0.55rem 0.7rem;
  margin: 0 0 1.1rem;
}

.login__form { display: flex; flex-direction: column; gap: 0.9rem; }

.login .field { display: flex; flex-direction: column; gap: 0.35rem; }

.login .field__label {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.login__input {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--edge-strong);
  border-radius: 2px;
  padding: 0.6rem 0.7rem;
  width: 100%;
}

.login__input:focus { outline: 2px solid var(--signal); outline-offset: 1px; }

.login__submit {
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--signal);
  border: 1px solid var(--signal);
  border-radius: 2px;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
}

.login__submit:hover { filter: brightness(1.08); }

/* Sign-out sits in the footer and borrows the theme toggle's shape. */
.footer__logout { margin-left: auto; }

/* -- Real-time stream state ----------------------------------------------- */

.stream-state {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.stream-state::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.stream-state[data-live="true"] { color: var(--live); }

/* -- Responsive ----------------------------------------------------------- */

@media (max-width: 560px) {
  .log__row {
    grid-template-columns: 4.4rem minmax(0, 1fr) 4.7rem;
    grid-template-areas:
      "time name snr"
      ".    tag  .";
    row-gap: 0.1rem;
  }
  .log__time { grid-area: time; }
  .log__name { grid-area: name; }
  .log__snr  { grid-area: snr; }
  .log__row .tag { grid-area: tag; }
  .log__rssi { display: none; }
  .plate__status-side { align-items: flex-start; }
  .status-note { text-align: left; }
  .ribbon__plot { height: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
