/* Deliberately echoes the Family Link dark UI this monitor watches, so the two
   do not feel like unrelated tools when you flip between them on a phone. */
:root {
  --bg: #0e0e10;
  --card: #1b1b1e;
  --card-2: #242427;
  --line: #303034;
  --text: #e6e6e8;
  --muted: #9d9da4;
  --blue: #8ab4f8;
  --blue-solid: #1a73e8;
  --green: #66d19e;
  --red: #f28b82;
  --amber: #fdd663;
  --radius: 18px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute only sets `display: none` at user-agent priority, so
   any class here that sets `display` (.gate, .modal) silently overrides it and
   leaves the element on screen. The whole UI is toggled with `hidden`, so this
   rule is load-bearing, not defensive. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); }
.spacer { flex: 1; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 20px 20px 8px; max-width: 780px; margin: 0 auto;
}
main {
  max-width: 780px; margin: 0 auto;
  padding: 8px 16px calc(48px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
details.card > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "▾"; color: var(--muted); }
details.card[open] > summary::after { content: "▴"; }
details.card > summary + * { margin-top: 16px; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 620px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- status ---------- */
.status-main { display: flex; gap: 16px; align-items: center; }
.verdict {
  flex: 0 0 auto; min-width: 108px; text-align: center;
  padding: 14px 16px; border-radius: 14px; font-weight: 700; font-size: 15px;
  background: var(--card-2); color: var(--muted); letter-spacing: .3px;
}
.verdict.ok    { background: rgba(102, 209, 158, .14); color: var(--green); }
.verdict.alert { background: rgba(242, 139, 130, .16); color: var(--red); }
.verdict.error { background: rgba(253, 214, 99, .14);  color: var(--amber); }
.status-reason { font-weight: 600; }
.status-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.next-run { margin-top: 12px; }

/* ---------- controls ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: filter .15s, opacity .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.25); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--blue-solid); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 13px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=time], input[type=number], input:not([type]), textarea {
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font: inherit; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
textarea { resize: vertical; }

.checks { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.check input { accent-color: var(--blue-solid); width: 17px; height: 17px; }

/* toggle switch */
.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.slider {
  width: 42px; height: 24px; border-radius: 999px; background: #46464b;
  position: relative; transition: background .18s; flex: none;
}
.slider::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform .18s;
}
.switch input:checked + .slider { background: var(--blue-solid); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--blue); outline-offset: 2px; }
.switch-label { font-size: 14px; }

.days { display: flex; gap: 8px; }
.day {
  flex: 1 1 0; min-width: 0; height: 42px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card-2); color: var(--muted);
  font-weight: 600; font-size: 13px;
}
.day[aria-pressed="true"] { background: var(--blue-solid); border-color: transparent; color: #fff; }

.pill {
  font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 999px;
  background: var(--card-2); color: var(--muted);
}
.pill.warn { background: rgba(253, 214, 99, .15); color: var(--amber); }
.pill.live { background: rgba(102, 209, 158, .15); color: var(--green); }

.saved { color: var(--green); font-size: 13px; margin-right: auto; }

/* ---------- history ---------- */
.history { display: flex; flex-direction: column; }
.hrow {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.hrow:first-child { border-top: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--green); }
.dot.alert { background: var(--red); }
.dot.error { background: var(--amber); }
.hrow .h-main { flex: 1; min-width: 0; }
.hrow .h-reason { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hrow img { width: 64px; height: 44px; object-fit: cover; object-position: top; border-radius: 7px; border: 1px solid var(--line); cursor: zoom-in; }
.called { color: var(--blue); }

.logs {
  max-height: 320px; overflow: auto; margin: 0;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); white-space: pre-wrap; word-break: break-word;
}

/* ---------- gate ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.gate-card { width: 100%; max-width: 380px; }
.gate-title { margin-bottom: 4px; }
.gate-card .btn { width: 100%; margin-top: 6px; }
.gate-card .field { margin-top: 18px; }

/* ---------- remote browser ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .8);
  display: grid; place-items: center; padding: 16px; z-index: 50;
}
.modal-inner {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; width: min(1320px, 100%); max-width: 100%; max-height: 96dvh;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.modal-head .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }
.modal-foot { margin: 0; }
/* The frame sizes itself from the image's own 1280x900, capped by both the
   window width and the remaining modal height. Fixing an aspect-ratio here
   instead made the box derive its width from its height, which overflowed the
   viewport and clipped the modal's own header off both edges. */
.screen-wrap {
  position: relative; background: #000; border-radius: 10px; overflow: hidden;
  outline: none; display: grid; place-items: center; min-height: 220px;
}
.screen-wrap:focus-visible { outline: 2px solid var(--blue); }
#screen {
  display: block; user-select: none;
  max-width: 100%; max-height: min(72dvh, 900px);
  width: auto; height: auto;
}
.screen-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); background: #000; text-align: center; padding: 20px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 20px; border-radius: 999px; z-index: 100; max-width: 90vw;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast.bad { border-color: var(--red); color: var(--red); }
.toast.good { border-color: var(--green); color: var(--green); }
