/* Dark by default: this gets used at night, in a car, one-handed. Light is
   there for daylight, where a dark screen behind glare is worse. */
:root {
  color-scheme: dark light;

  --bg: #0d0f12;
  --surface: #171a1f;
  --surface-hi: #1f232a;
  --line: #282d35;
  --text: #eef1f5;
  --muted: #969ea9;
  --accent: #f0b429;
  --ok: #3ecf8e;
  --bad: #f2555a;

  --radius: 20px;
  --tap: 0.06s;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-hi: #f0f2f5;
    --line: #e0e3e8;
    --text: #14171c;
    --muted: #6b747f;
    --accent: #b8770a;
    --ok: #12855a;
    --bad: #cf2b31;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  /* No accidental pull-to-refresh or double-tap zoom while jabbing at a
     button through a car window. */
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 460px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px
    max(16px, env(safe-area-inset-bottom));
}

.screen[hidden] {
  display: none;
}

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

.login {
  margin: auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 4px;
  color: var(--accent);
}

.login-mark svg {
  width: 100%;
  height: 100%;
}

.login h1 {
  margin: 0 0 10px;
  text-align: center;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

.field input {
  height: 52px;
  padding: 0 14px;
  font-size: 17px; /* 16px+ so iOS does not zoom the page on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
}

.login-error {
  margin: 0;
  font-size: 14px;
  color: var(--bad);
}

.login-error[hidden] {
  display: none;
}

.login-submit {
  height: 52px;
  margin-top: 4px;
  font: inherit;
  font-weight: 600;
  font-size: 17px;
  color: #12140f;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.login-submit:disabled {
  opacity: 0.55;
}

/* ----------------------------------------------------------- top bar ----- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
}

.link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.link-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.link[data-state="online"] .link-dot {
  background: var(--ok);
}

.link[data-state="offline"] .link-dot {
  background: var(--bad);
}

.link[data-state="offline"] {
  color: var(--bad);
}

.signout {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 6px;
  cursor: pointer;
}

/* ------------------------------------------------------------- gates ----- */

.gates {
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* A real gap, so a thumb aiming at one gate cannot clip the other. */
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.gate {
  flex: 1;
  min-height: 150px;
  /* Past this the card is just empty space; the extra room is better spent
     on breathing gap between the two. */
  max-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  font: inherit;
  color: var(--text);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    transform var(--tap) ease-out,
    background 0.15s,
    border-color 0.15s;
}

.gate:active:not(:disabled) {
  transform: scale(0.985);
  background: var(--surface-hi);
}

.gate:disabled {
  cursor: default;
}

.gate-icon {
  width: 60px;
  height: 60px;
  color: var(--muted);
  transition: color 0.15s;
}

.gate-name {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.gate-status {
  font-size: 13px;
  color: var(--muted);
  min-height: 1.45em;
}

/* Sending → sent → back to rest. Colour carries the state so it reads at a
   glance without having to parse the label. */
.gate[data-state="sending"] .gate-icon {
  color: var(--accent);
}

.gate[data-state="sending"] .gate-status {
  color: var(--accent);
}

.gate[data-state="sent"] {
  border-color: var(--ok);
}

.gate[data-state="sent"] .gate-icon,
.gate[data-state="sent"] .gate-status {
  color: var(--ok);
}

.gate[data-state="failed"] {
  border-color: var(--bad);
}

.gate[data-state="failed"] .gate-icon,
.gate[data-state="failed"] .gate-status {
  color: var(--bad);
}

/* Controller unreachable: still tappable (the state may be stale), but say so. */
.gate[data-offline="1"] {
  opacity: 0.6;
}

@media (prefers-reduced-motion: reduce) {
  .gate {
    transition: none;
  }
}

/* ------------------------------------------------------------ recent ----- */

.recent {
  padding-top: 20px;
}

.recent h2 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.activity {
  list-style: none;
  margin: 0;
  padding: 0;
  /* Capped so the gate buttons never get squeezed off a small screen. */
  max-height: 132px;
  overflow-y: auto;
}

.activity li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.activity li:last-child {
  border-bottom: 0;
}

.activity .who {
  color: var(--text);
  font-weight: 500;
}

.activity .when {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  flex: none;
}

.activity li[data-result="offline"] .what,
.activity li[data-result="timeout"] .what,
.activity li[data-result="failed"] .what {
  color: var(--bad);
}

.empty {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.empty[hidden] {
  display: none;
}
