/* The parent dashboard: built for a phone held in one hand. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --line: #dde2ee;
  --text: #141a2b;
  --muted: #5d6781;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefe;
  --ok: #128a55;
  --ok-soft: #dcf5e9;
  --warn: #9a6200;
  --warn-soft: #fff1d1;
  --danger: #c7322b;
  --danger-soft: #fde8e6;
  --shadow: 0 1px 2px rgba(20, 26, 43, 0.06), 0 4px 14px rgba(20, 26, 43, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1220;
    --surface: #161c2e;
    --line: #2a3350;
    --text: #edf0f8;
    --muted: #9aa4c0;
    --accent: #6ea8ff;
    --accent-ink: #06122b;
    --accent-soft: #1c2a4d;
    --ok: #4bd9a0;
    --ok-soft: #12382b;
    --warn: #ffc457;
    --warn-soft: #3d2e0d;
    --danger: #ff7b73;
    --danger-soft: #45191a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; margin-bottom: 8px; }
p { margin: 0; }
a { color: var(--accent); }

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

button, .button, input, select { font: inherit; }

button, .button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, .button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 650; }
.danger-text { color: var(--danger); }
.ghost { background: transparent; }
.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 6px 4px;
  min-height: 36px;
  font-weight: 600;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="time"], input:not([type]), select {
  width: 100%;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
label { font-size: 0.88rem; color: var(--muted); font-weight: 600; }
.hint { font-size: 0.85rem; color: var(--muted); }
.error { color: var(--danger); font-size: 0.92rem; }
.notice { color: var(--ok); font-size: 0.92rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.stack { display: grid; gap: 8px; }
.stack > label { margin-top: 6px; }
.stack > .primary { margin-top: 8px; }
.field { display: grid; gap: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.row.buttons { margin-top: 8px; grid-template-columns: 1fr auto; align-items: center; }
#custom .row.buttons { grid-template-columns: 1fr 1fr; }

/* Honeypot: off screen for people, present for scripts that fill in every field. */
.hp { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* ----- signed out ----- */

.auth { max-width: 420px; margin: 0 auto; padding: 40px 16px 32px; display: grid; gap: 16px; }
.brand { font-size: 1.9rem; letter-spacing: -0.01em; }
.lede { color: var(--muted); }
.links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.foot { color: var(--muted); font-size: 0.9rem; text-align: center; }

/* ----- signed in ----- */

.top {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.25rem; flex: 1; }
.conn { font-size: 0.8rem; color: var(--warn); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.conn.on { color: var(--ok); }

.sections { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; display: grid; gap: 24px; }
.sections > section { display: grid; gap: 10px; }
.head { display: flex; align-items: center; justify-content: space-between; }
.inline { margin-right: 8px; }
#target-sec { grid-template-columns: auto 1fr; align-items: center; }

.setup { border-color: var(--accent); background: var(--accent-soft); gap: 10px; }
.setup .primary { justify-self: start; }
.url {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.95rem;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
  user-select: all;
}

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

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 650; overflow-wrap: anywhere; }
.item .sub { color: var(--muted); font-size: 0.88rem; margin-top: 2px; overflow-wrap: anywhere; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex: none; }
.item.off .main { opacity: 0.55; }
.item.ringing { border-color: var(--danger); background: var(--danger-soft); }
.item.ringing .state { color: var(--danger); font-weight: 650; }
.empty { color: var(--muted); font-size: 0.92rem; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 12px; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
  vertical-align: 2px;
  white-space: nowrap;
}
.badge.on { background: var(--ok-soft); color: var(--ok); }
.chip {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  vertical-align: 2px;
}

.history.acknowledged { border-left: 4px solid var(--ok); }
.history.disarmed { border-left: 4px solid var(--accent); }
.history.silenced { border-left: 4px solid var(--warn); }
.history.missed { border-left: 4px solid var(--danger); }

/* ----- quick reminders ----- */

.presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.preset {
  display: grid;
  gap: 2px;
  justify-items: start;
  justify-content: start;
  align-content: center;
  text-align: left;
  padding: 14px;
  min-height: 72px;
  border-radius: 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
}
.preset:active { transform: scale(0.98); }
.preset-title { font-weight: 700; font-size: 1.02rem; overflow-wrap: anywhere; }
.preset-sub { font-size: 0.85rem; opacity: 0.85; }
.presets.editing .preset { background: var(--surface); color: var(--text); border-style: dashed; border-color: var(--accent); }
.preset.add { color: var(--accent); }

/* ----- on/off switch ----- */

.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.track { width: 44px; height: 26px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.15s; }
.track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ----- day picker ----- */

.days { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.days legend { font-size: 0.88rem; color: var(--muted); font-weight: 600; padding: 0; margin-bottom: 6px; }
.day { position: relative; }
.day input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.day span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 40px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
}
.day input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.day input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ----- dialog ----- */

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(calc(100% - 24px), 520px);
  max-height: calc(100% - 24px);
  background: var(--bg);
  color: var(--text);
}
dialog::backdrop { background: rgba(8, 12, 24, 0.55); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
.dialog-body { padding: 16px; display: grid; gap: 22px; }
.dialog-body > section { display: grid; gap: 8px; }

/* ----- toast ----- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  max-width: calc(100% - 32px);
  text-align: center;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

@media (min-width: 560px) {
  .presets { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 420px) {
  .item { flex-wrap: wrap; }
  .item .actions { width: 100%; justify-content: flex-start; }
  .switch + .main { flex-basis: calc(100% - 60px); }
}
