/* Visual direction: a plumbing instrument panel, not a dashboard.
   Deep-water ground, one cyan for anything that represents moving water,
   brass for the mechanical controls, red reserved strictly for alarm. */

@import url("https://fonts.googleapis.com/css2?family=Archivo:wght@400;500;600;800&display=swap");

:root {
  --deep: #0e2430;
  --panel: #143241;
  --rule: #214a5c;
  --flow: #56c7d6;
  --brass: #d9a441;
  --alarm: #e2574a;
  --paper: #e6eff1;
  --muted: #8fabb6;

  --step: 1.5rem;
  --radius: 3px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--deep);
  color: var(--paper);
  font-family: Archivo, system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 460px;
  margin: 0 auto;
  padding: var(--step) 1.25rem 4rem;
}

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

/* ---------- header ---------- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
}

.masthead h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.timestamp {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- the hero: valve state ---------- */

.state {
  padding: 2.25rem 0 1.25rem;
}

.state-line {
  margin: 0;
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.02;
}

.state-note {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.state.is-off .state-line {
  color: var(--brass);
}

.state.is-unknown .state-line {
  color: var(--muted);
}

/* The channel fills only while water is actually moving, so a glance at
   the page answers "is anything running right now". */
.channel {
  position: relative;
  height: 10px;
  margin-top: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.channel-fill {
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent,
    var(--flow) 35%,
    var(--flow) 65%,
    transparent
  );
  opacity: 0;
}

.channel.is-flowing .channel-fill {
  opacity: 0.9;
  animation: run 1.6s linear infinite;
}

@keyframes run {
  to {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .channel.is-flowing .channel-fill {
    animation: none;
    transform: none;
    opacity: 0.55;
  }
}

/* ---------- readouts ---------- */

.readouts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.readout {
  padding: 1rem 0.75rem;
  text-align: center;
}

.readout + .readout {
  border-left: 1px solid var(--rule);
}

.readout .value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.readout .unit {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.15rem;
}

.readout .name {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- stale + error banners ---------- */

.banner {
  margin: 1.25rem 0 0;
  padding: 0.75rem 0.9rem;
  border-left: 3px solid var(--alarm);
  background: var(--panel);
  font-size: 0.88rem;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.banner[hidden] {
  display: none;
}

/* When data cannot be trusted, the whole readout drains of colour rather
   than quietly showing old numbers as if they were current. */
.draining .state-line,
.draining .readout .value {
  color: var(--muted);
}

.draining .channel.is-flowing .channel-fill {
  animation: none;
  opacity: 0.2;
}

/* ---------- sections ---------- */

section {
  margin-top: 2.25rem;
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--paper);
}

/* ---------- controls ---------- */

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--paper);
  font: inherit;
  font-weight: 500;
  padding: 0.7rem 0.4rem;
  cursor: pointer;
}

.segmented button + button {
  border-left: 1px solid var(--rule);
}

.segmented button[aria-pressed="true"] {
  background: var(--flow);
  color: var(--deep);
  font-weight: 600;
}

.segmented button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.sleep-options {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sleep-options[hidden] {
  display: none;
}

.chip {
  appearance: none;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: transparent;
  color: var(--paper);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

.chip:hover:not(:disabled) {
  border-color: var(--flow);
}

button.action {
  display: block;
  width: 100%;
  appearance: none;
  font: inherit;
  font-weight: 600;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  background: transparent;
  color: var(--brass);
  border: 1px solid var(--brass);
}

button.action + button.action {
  margin-top: 0.6rem;
}

button.action.secondary {
  color: var(--paper);
  border-color: var(--rule);
}

button.action.armed {
  background: var(--alarm);
  border-color: var(--alarm);
  color: #fff;
}

button.action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button:focus-visible,
.chip:focus-visible,
input:focus-visible {
  outline: 2px solid var(--flow);
  outline-offset: 2px;
}

.confirm-note {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  color: var(--brass);
}

.confirm-note[hidden] {
  display: none;
}

/* ---------- chart ---------- */

.range {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.chart-frame {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 0.5rem;
}

.chart-frame svg {
  display: block;
  width: 100%;
  height: 160px;
}

.chart-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2.5rem 0.5rem;
  text-align: center;
}

.chart-legend {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 2px;
  vertical-align: middle;
  margin-right: 0.35rem;
}

/* ---------- lists ---------- */

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entries li {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.88rem;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
}

.entries li:first-child {
  border-top: 1px solid var(--rule);
}

.entries time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 0.82rem;
}

.entries .empty {
  color: var(--muted);
  border: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  max-width: 90vw;
}

.toast[hidden] {
  display: none;
}

.toast.bad {
  border-color: var(--alarm);
}

/* ---------- sign in ---------- */

.signin {
  max-width: 340px;
  margin: 22vh auto 0;
  padding: 0 1.25rem;
}

.signin h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

.signin p {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
}

.signin input {
  width: 100%;
  font: inherit;
  padding: 0.75rem;
  color: var(--paper);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

.signin button {
  width: 100%;
  font: inherit;
  font-weight: 600;
  padding: 0.75rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--flow);
  color: var(--deep);
  cursor: pointer;
}

.signin .error {
  color: var(--alarm);
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
}

.footnote {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.78rem;
}

/* ---------- google sign-in ---------- */

.signin .google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.75rem;
  background: var(--paper);
  color: #1f1f1f;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
}

.signin .google:hover {
  opacity: 0.92;
}

.signin .divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.1rem 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.signin .divider::before,
.signin .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.admin-input {
  width: 100%;
  font: inherit;
  padding: 0.75rem;
  color: var(--paper);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.entries li small {
  font-size: 0.78rem;
}

/* ---------- paused protection ---------- */

.pause {
  border: 1px solid var(--brass);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.pause[hidden] {
  display: none;
}

.pause-line {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--brass);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.pause-note {
  margin: 0.35rem 0 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
}
