/* Safe Guard of Africa — field-instrument styling for smart safety glasses.
   Red, green and white: red for the name, main actions and emergencies; green for
   connections, headings and anything live; white surfaces. */
@font-face {
  font-family: "Archivo";
  src: url("/static/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  color-scheme: light;
  --signal: #d7141a;
  --signal-deep: #9e0b10;
  --signal-wash: #fde9e9;
  --black: #10231a;
  --text: #45564c;
  --green: #1f7a4a;
  --green-deep: #165c37;
  --green-wash: #e6f3ea;
  --paper: #ffffff;
  --mist: #eef4f0;
  --rule: #d5e3da;
  --leaf: #1f7a4a;
  --gutter: clamp(16px, 4vw, 40px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--black);
  font: 400 16px/1.5 "Archivo", system-ui, sans-serif;
  font-stretch: 100%;
}
[hidden] { display: none !important; }
h2 { margin: 0 0 12px; font-size: 15px; font-weight: 700; line-height: 1.3; color: var(--green-deep); }
p { margin: 0; }
.fine { color: var(--text); font-size: 14px; line-height: 1.45; }
.strong { font-weight: 700; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }

/* ---------- Masthead ---------- */
.masthead { background: var(--paper); }
.masthead-inner {
  max-width: 1280px; margin: 0 auto; padding: 18px var(--gutter) 0;
  display: flex; align-items: center; gap: 20px;
}
.identity { display: flex; align-items: center; gap: 12px; color: var(--signal); text-decoration: none; margin-right: auto; }
.logo { width: 50px; height: auto; display: block; }
.wordmark {
  font-stretch: 125%; font-weight: 850; font-size: 17px; line-height: 1;
  text-transform: uppercase; letter-spacing: .01em;
}
.live { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text); }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: #b5c4ba; }
.live.on { color: var(--black); }
.live.on .dot { background: var(--leaf); box-shadow: 0 0 0 0 rgba(19, 138, 62, .5); animation: beacon 2s infinite; }
.live.alarm { color: var(--signal); }
.live.alarm .dot { background: var(--signal); }
@keyframes beacon { 70% { box-shadow: 0 0 0 8px rgba(19, 138, 62, 0); } 100% { box-shadow: 0 0 0 0 rgba(19, 138, 62, 0); } }
.account { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--text); }

/* The heartbeat trace: flat when the camera is off, beats with each hand seen, red while SOS is held. */
.pulse { display: block; width: 100%; height: 46px; margin-top: 10px; }
.pulse polyline { fill: none; stroke: #c3d3c9; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.pulse.live polyline { stroke: var(--green); }
.pulse.alarm polyline { stroke: var(--signal); stroke-width: 2.5; }

.tabs {
  max-width: 1280px; margin: 0 auto; padding: 0 var(--gutter);
  display: flex; gap: 6px; border-bottom: 1px solid var(--rule); padding-bottom: 10px;
}
.tabs button {
  border: 0; background: none; padding: 9px 18px; border-radius: 6px; cursor: pointer;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--text);
}
.tabs button:hover { color: var(--green-deep); background: var(--green-wash); }
.tabs button[aria-selected="true"] { color: #fff; background: var(--green); }

/* ---------- Page ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 28px var(--gutter) 48px; }

/* Live view */
.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 44px; align-items: start; }
.viewfinder {
  position: relative; background: #0d1f15; border-radius: 6px; overflow: hidden;
  aspect-ratio: 4 / 3; max-height: 64vh; display: grid; place-items: center;
}
.viewfinder img { width: 100%; height: 100%; object-fit: contain; display: block; }
.video-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; color: #c9cdd2; font-size: 15px; }
.camera-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; padding: 14px 0 0; }
.camera-status { color: var(--text); font-size: 14px; flex: 1 1 260px; }
.camera-actions { display: flex; gap: 10px; }

.readout { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--rule); }
.gesture {
  font-stretch: 125%; font-weight: 800; font-size: clamp(44px, 7.5vw, 88px);
  line-height: .95; letter-spacing: -.02em; margin-bottom: 18px; overflow-wrap: anywhere;
}
.gesture.idle { color: #b1c2b7; }
.meter { height: 4px; background: var(--mist); border-radius: 2px; overflow: hidden; margin-bottom: 10px; max-width: 520px; }
.meter span { display: block; height: 100%; width: 0; background: var(--green); transition: width .15s linear; }
.readout .fine + .fine { margin-top: 2px; }
.response {
  margin: 22px 0 8px; padding: 2px 0 2px 16px; border-left: 4px solid var(--signal);
  font-size: clamp(18px, 2.2vw, 22px); line-height: 1.35; font-weight: 500; max-width: 60ch;
}

/* Side column */
.side { display: grid; gap: 0; }
.side > section { padding: 26px 0; border-top: 1px solid var(--rule); }
.side > section:first-child { padding-top: 0; border-top: 0; }

.sos-status { font-size: 14px; color: var(--text); min-height: 2.9em; }
.sos-meter { height: 6px; background: var(--signal-wash); border-radius: 3px; overflow: hidden; margin: 12px 0 16px; }
.sos-meter span { display: block; height: 100%; width: 0; background: var(--signal); transition: width .1s linear; }
.sos-button {
  width: 100%; min-height: 150px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--signal); color: #fff; font: inherit;
  display: grid; place-content: center; gap: 4px; text-align: center;
  box-shadow: 0 6px 0 var(--signal-deep);
  transform: translateY(0); transition: transform .06s, box-shadow .06s;
}
.sos-button:hover { background: #c71218; }
.sos-button:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--signal-deep); }
.sos-word { font-stretch: 125%; font-weight: 900; font-size: 58px; line-height: 1; letter-spacing: .06em; }
.sos-sub { font-size: 14px; font-weight: 500; opacity: .92; }

.voice .fine { margin: 8px 0 10px; }

/* Switch */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 600; font-size: 15px; margin: 4px 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  flex: none; width: 42px; height: 24px; border-radius: 12px; background: #c3d3c9; position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform .15s;
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--signal); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .4; }

/* Robot (hidden unless enabled) */
.telemetry { white-space: pre-line; font-size: 14px; margin: 4px 0; }
.bot .fine { margin: 6px 0; }
.power { display: grid; gap: 6px; margin: 14px 0; font-size: 14px; }
.power input { width: 100%; accent-color: var(--green); }
.dpad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: ". up ." "left stop right" ". down ."; gap: 8px; margin-bottom: 8px; }
.dpad .up { grid-area: up; } .dpad .left { grid-area: left; } .dpad .right { grid-area: right; }
.dpad .down { grid-area: down; } .dpad .stopbtn { grid-area: stop; border-color: var(--signal); color: var(--signal); }
.drive { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.drive.active { background: var(--green); color: #fff; }

/* ---------- Buttons ---------- */
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 6px; cursor: pointer; text-decoration: none;
  font: inherit; font-size: 15px; font-weight: 650; line-height: 1.2;
  background: var(--paper); color: var(--green-deep); border: 1.5px solid var(--green);
}
.btn:hover { background: var(--green-wash); }
.btn.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn.primary:hover { background: #bb1117; border-color: #bb1117; }
.btn.dark { background: var(--green); color: #fff; }
.btn.dark:hover { background: var(--green-deep); }
.btn:disabled { background: var(--paper); color: #a6b3ab; border-color: #d3ddd6; cursor: not-allowed; }
.link {
  border: 0; background: none; padding: 0; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  color: var(--green-deep); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px;
}
.link:hover { color: var(--signal); }

/* ---------- Settings ---------- */
.settings { max-width: 720px; }
.settings form { display: block; }
fieldset { border: 0; border-top: 1px solid var(--rule); margin: 0; padding: 26px 0 30px; min-width: 0; }
fieldset:first-child { border-top: 0; padding-top: 0; }
legend { float: left; width: 100%; padding: 0; margin-bottom: 16px; font-stretch: 112%; font-weight: 750; font-size: 19px; color: var(--green-deep); }
legend + * { clear: left; }
.field { display: grid; gap: 6px; margin: 0 0 18px; }
.field > span { font-size: 14px; font-weight: 600; }
.field small, small.fine { display: block; color: var(--text); font-size: 13px; line-height: 1.4; }
input, select {
  font: inherit; font-size: 15px; color: var(--black); background: var(--paper);
  border: 1.5px solid #c3d3c9; border-radius: 6px; padding: 9px 12px; min-height: 44px; width: 100%; min-width: 0;
}
input:hover, select:hover { border-color: #8fa99a; }
input:focus, select:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(215, 20, 26, .18); }
fieldset .switch { margin-bottom: 18px; }
.field-title { font-size: 14px; font-weight: 600; margin: 6px 0 12px; }
fieldset .switch + .indent { margin: -12px 0 16px 54px; }
.indent { margin-left: 54px; }
.contacts { list-style: none; margin: 0 0 14px; padding: 0; border-top: 1px solid var(--rule); }
.contacts li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.contacts .who { flex: 1; min-width: 0; }
.contacts .who strong { display: block; font-weight: 650; overflow-wrap: anywhere; }
.contacts .who span { color: var(--text); font-size: 14px; }
.contacts .empty { color: var(--text); font-size: 14px; }
.contact-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0 12px; align-items: end; }
.contact-add .field { margin-bottom: 12px; }
.contact-add .btn { margin-bottom: 12px; }
@media (max-width: 600px) { .contact-add { grid-template-columns: 1fr; } }
fieldset > .fine { margin-top: 4px; }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.messages .field { grid-template-columns: 130px 1fr; align-items: center; gap: 14px; margin-bottom: 10px; }
.save-bar {
  position: sticky; bottom: 0; background: var(--paper); border-top: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 0 calc(14px + env(safe-area-inset-bottom));
}

/* ---------- Activity ---------- */
.activity-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.activity-head h2 { margin: 0; font-stretch: 112%; font-weight: 750; font-size: 19px; }
.log {
  margin: 0 0 12px; padding: 16px 18px; background: var(--mist); border-radius: 6px; color: var(--black);
  height: 60vh; min-height: 240px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 520px); background: var(--green-deep); color: #fff; padding: 12px 18px; border-radius: 6px;
  font-size: 15px; z-index: 10;
}
.toast.bad { background: var(--signal); }

/* ---------- Sign in ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; text-align: center; }
.login .logo { width: 104px; margin: 0 auto 14px; }
.login .wordmark { display: block; font-size: 24px; }
.login .pulse { height: 40px; margin: 16px 0 22px; }
.login form { text-align: left; }
.login .btn { width: 100%; margin-top: 6px; }
.error { color: var(--signal-deep); background: var(--signal-wash); border-radius: 6px; padding: 10px 12px; margin: 0 0 12px; font-size: 14px; }

/* ---------- Small screens ---------- */
@media (max-width: 960px) {
  .live-grid { grid-template-columns: 1fr; gap: 32px; }
  .side > section:first-child { padding-top: 26px; border-top: 1px solid var(--rule); }
}
@media (max-width: 600px) {
  .masthead-inner { flex-wrap: wrap; gap: 10px 16px; padding-top: 14px; }
  .logo { width: 42px; }
  .wordmark { font-size: 15px; }
  .live { order: 3; width: 100%; }
  .tabs { gap: 22px; }
  .page { padding-top: 20px; }
  .camera-actions { width: 100%; }
  .camera-actions .btn { flex: 1; }
  .sos-button { min-height: 128px; }
  .trio { grid-template-columns: 1fr; }
  .messages .field { grid-template-columns: 1fr; gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
