/*
 * FamilyOnGuard — shared shell.
 *
 * Design rules, all downstream of the product:
 *   - Dark by default. This app is opened at night, in the street, and a white
 *     screen lights up the face of someone who may not want to be seen.
 *   - One thing on screen at a time. During an alert the person cannot read.
 *   - Nothing essential requires looking: the button is found by feel (it is
 *     the whole lower half), confirmation is a vibration.
 *   - Touch targets ≥ 56px, text ≥ 17px. Cold hands, moving, adrenaline.
 *   - Safe areas everywhere: this runs full-bleed inside a Capacitor shell.
 */

:root {
  color-scheme: dark;

  --bg: #0b0e14;
  --bg-raised: #141925;
  --bg-input: #1b2231;
  --line: #262f42;

  --text: #eef2f8;
  --text-dim: #93a0b8;

  --accent: #4d8dff;       /* calm, not alarming: most screens are not an alert */
  --danger: #ff3b30;       /* the button, and only things that are the alert */
  --danger-deep: #c1121f;
  --ok: #2fbf71;
  --warn: #ffb020;

  --radius: 16px;
  --pad: 20px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/*
 * `hidden` must win.
 *
 * The attribute hides an element through the browser's own stylesheet, which
 * ANY class rule outranks — and `.btn { display: flex }` did exactly that. So
 * "Appeler le 17" stayed on screen during an alert that had found somebody,
 * and the cancel button would have stayed after a responder took it, offering
 * an action that could only be refused. Every `el.hidden = true` in this
 * codebase depends on this one line.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

/* Text is content, not a control: nothing is selectable except what the user
   may need to copy (a code, a link). */
body { user-select: none; }
.selectable, input, textarea { user-select: text; }

[dir="rtl"] .ltr, .ltr { direction: ltr; unicode-bidi: isolate; }

/* --- app frame ------------------------------------------------------------ */

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  min-height: 0;
}

.screen {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--pad) calc(var(--pad) + var(--safe-bottom));
}
.screen.is-on { display: flex; }

.head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 10px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg) 70%, transparent);
  z-index: 5;
}
.head h1 { font-size: 22px; font-weight: 650; margin: 0; flex: 1; }
.head .back {
  background: none; border: 0; color: var(--text-dim);
  font-size: 26px; line-height: 1; padding: 8px; margin: -8px; cursor: pointer;
}

h2 { font-size: 17px; font-weight: 600; margin: 24px 0 10px; color: var(--text-dim); }
p.lede { color: var(--text-dim); margin: 0 0 20px; }
.hint { color: var(--text-dim); font-size: 14px; margin: 6px 0 0; }

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

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 56px; padding: 0 20px;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff;
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--bg-raised); color: var(--text); }
.btn.line { background: none; border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--ok); }
.btn + .btn { margin-top: 10px; }
.btn.small { min-height: 44px; font-size: 15px; width: auto; padding: 0 16px; }

label { display: block; font-size: 14px; color: var(--text-dim); margin: 16px 0 6px; }

input[type="text"], input[type="tel"], input[type="number"], select, textarea {
  width: 100%; min-height: 56px; padding: 0 16px;
  background: var(--bg-input); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); font: inherit;
}
textarea { padding: 14px 16px; min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* A masked PIN, without being a password field — see ui.js pinField(). */
.pin-input {
  -webkit-text-security: disc;
  text-security: disc;
}

/* A code field: big, spaced, always left-to-right. */
.code-input {
  text-align: center; font-size: 28px; letter-spacing: .4em;
  font-variant-numeric: tabular-nums; direction: ltr;
}

.check { display: flex; gap: 12px; align-items: flex-start; margin: 16px 0; }
.check input { width: 26px; height: 26px; margin: 0; flex: none; accent-color: var(--accent); }
.check span { font-size: 15px; }

/* --- cards, rows ---------------------------------------------------------- */

.card {
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.row .sub { color: var(--text-dim); font-size: 14px; }
.row + .row { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--bg-input); color: var(--text-dim); font-size: 13px; font-weight: 600;
}
.pill.ok { background: rgba(47,191,113,.16); color: var(--ok); }
.pill.warn { background: rgba(255,176,32,.16); color: var(--warn); }
.pill.danger { background: rgba(255,59,48,.16); color: var(--danger); }

/* --- feedback ------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + var(--safe-bottom));
  max-width: min(92vw, 420px); padding: 14px 18px;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  z-index: 50; font-size: 15px;
}
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; z-index: 40;
}
.sheet {
  width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--bg-raised); border-radius: 22px 22px 0 0;
  padding: 22px var(--pad) calc(28px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}
.sheet h2 { margin-top: 0; color: var(--text); font-size: 20px; }

/* --- language chips ------------------------------------------------------- */

.langs { display: flex; gap: 8px; justify-content: center; padding: 18px 0 4px; }
.lang-chip {
  background: none; border: 1px solid var(--line); color: var(--text-dim);
  border-radius: 999px; padding: 8px 16px; font: inherit; font-size: 14px; cursor: pointer;
}
.lang-chip.is-on { border-color: var(--accent); color: var(--text); }

/* --- tab bar -------------------------------------------------------------- */

.tabs {
  display: flex; border-top: 1px solid var(--line); background: var(--bg-raised);
  padding-bottom: var(--safe-bottom);
}
.tabs button {
  flex: 1; background: none; border: 0; color: var(--text-dim);
  padding: 12px 4px; font: inherit; font-size: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.tabs button.is-on { color: var(--accent); }
.tabs .ic { font-size: 22px; line-height: 1; }

/* --- map ------------------------------------------------------------------ */

.map { width: 100%; height: 260px; border-radius: var(--radius); overflow: hidden; background: var(--bg-input); }
.map-big { flex: 1; min-height: 200px; border-radius: var(--radius); overflow: hidden; background: var(--bg-input); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* --- readiness ------------------------------------------------------------ */

.ready-row { border-color: var(--warn); }
.ready-ok { color: var(--ok); font-size: 14px; padding: 4px 0 10px; }
