/* Admin web page, stage 1 (docs/WEB_ADMIN_PLAN.md 3.2). The apps' own colours, copied from the Android app's
   ui/theme/Color.kt (a test checks they still match: docker/auth-server/test/web-page-scan.test.js), light and dark by
   the system setting. The system font, so no font files. A side bar from 900 px wide; a top bar, cards and bottom
   sheets on a phone. Every control is at least 44 px tall, with a visible focus ring. */

/* --- Colours (Color.kt) --- */
:root {
  color-scheme: light dark;
  --bg: #FAF8F5;
  --surface: #F2EEE8;
  --surface-hover: #E3DCCE;
  --text: #2B2B28;
  --muted: #6B6B66;
  --accent: #1A4D4A;
  --accent-hover: #123A38;
  --border: #C9C0AC;
  --on-accent: #FAF8F5;
  --accent-container: #D9E6E4;
  --on-accent-container: #123A38;
  --error: #B3413A;
  --backdrop: rgba(20, 22, 20, 0.45);
  /* The edge of a text or password field: the muted text colour, at least 3:1 against the card or box behind it
     (WCAG 1.4.11; the Color.kt border colour is too faint for that, so it is kept for cards and dividers only). */
  --input-border: var(--muted);
  --radius: 16px;
  --radius-small: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1D1B;
    --surface: #242724;
    --surface-hover: #2E312D;
    --text: #F2EFE9;
    --muted: #9A9E96;
    --accent: #2DD4C4;
    --accent-hover: #45E0D1;
    --border: #33362F;
    --on-accent: #07302C;
    --accent-container: #223B37;
    --on-accent-container: #BEEEE6;
    --error: #E0847B;
    --backdrop: rgba(0, 0, 0, 0.6);
  }
}

/* --- Base --- */
* { box-sizing: border-box; }

/* The hidden attribute must win over the display rules below. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: anywhere;
}

h1, h2, h3, p { margin: 0; }

a { color: var(--accent); }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Headings reached by keyboard or screen reader after moving to a screen show no ring (they are not controls). */
h1[tabindex]:focus, .sheet-title:focus { outline: none; }

/* A row that is a link fills its card, and the card clips what sticks out (rounded corners), so its ring is drawn
   inside it. */
.row-link:focus-visible { outline-offset: -3px; }

.strong { font-weight: 600; }

.hint, .row-detail, .loaded-at {
  font-size: 14px;
  color: var(--muted);
}

.form-error {
  color: var(--error);
  font-size: 14px;
}

.form-error:empty, .enrol-message:empty { display: none; }

/* --- Buttons --- */
.btn {
  min-height: 44px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-small);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: transparent; color: var(--accent); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }

.btn-danger { background: transparent; color: var(--error); border-color: var(--error); }
.btn-danger:hover:not(:disabled) { background: var(--surface-hover); }

.btn-text, .btn-text-danger {
  background: transparent;
  padding: 8px 10px;
  font-weight: 500;
}
.btn-text { color: var(--accent); }
.btn-text-danger { color: var(--error); }
.btn-text:hover:not(:disabled), .btn-text-danger:hover:not(:disabled) { background: var(--surface-hover); }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button-row-start { justify-content: flex-start; }

/* --- Forms --- */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field label, .field-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.field-group {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-small);
}

.input:disabled { opacity: 0.6; }

/* A temporary password for someone else: masked on screen, but not a password field to the browser, so a password
   manager never offers to save it under this site (L3). */
.masked { -webkit-text-security: disc; }

select.input { appearance: auto; }

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 4px 0;
  cursor: pointer;
}

.check-row input {
  width: 20px;
  height: 20px;
  flex: none;
  margin: 0;
  accent-color: var(--accent);
}

.check-row.is-disabled { cursor: default; opacity: 0.75; }

.check-text {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.pick-list {
  display: flex;
  flex-direction: column;
  max-height: 46vh;
  overflow-y: auto;
  /* Room for the check boxes' focus rings: a list that scrolls clips what sticks out of it. */
  padding: 0 8px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.pick-list > .check-row + .check-row { border-top: 1px solid var(--border); }

/* --- People, tags and animals --- */
.person {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
  min-width: 0;
}

.person-name, bdi { unicode-bidi: isolate; }
.person-name { font-weight: 600; }

.person-username {
  font-size: 14px;
  color: var(--muted);
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  background: var(--surface-hover);
  color: var(--text); /* the muted colour is under 4.5:1 on this background */
}
.tag-accent { background: var(--accent-container); color: var(--on-accent-container); }
.tag-error { background: transparent; color: var(--error); border: 1px solid var(--error); }

/* The apps' animal pictures (iPhone ChatAvatar): an emoji on its own colour. */
.animal {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.86);
  line-height: 1;
}
.animal-sm { width: 28px; height: 28px; font-size: 14px; }
.animal-md { width: 36px; height: 36px; font-size: 18px; }
.animal-lg { width: 46px; height: 46px; font-size: 22px; }
.animal-shark { background: #1565C0; }
.animal-fox { background: #D84315; }
.animal-bear { background: #5D4037; }
.animal-owl { background: #6A1B9A; }
.animal-wolf { background: #37474F; }
.animal-eagle { background: #8D6E63; }
.animal-turtle { background: #2E7D32; }
.animal-deer { background: #8D6E63; }
.animal-boar { background: #4E342E; }
.animal-beaver { background: #6D4C41; }
.animal-bee { background: #F9A825; }
.animal-bat { background: #283593; }

.animal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.animal-option {
  min-height: 96px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  cursor: pointer;
}
.animal-option:hover:not(:disabled) { background: var(--surface-hover); }
.animal-option.is-selected { border: 2px solid var(--accent); background: var(--accent-container); color: var(--on-accent-container); }
.animal-option-taken { font-size: 12px; color: var(--error); overflow-wrap: anywhere; }
.animal-option.is-selected .animal-option-taken { color: var(--on-accent-container); }

/* --- Sign-in --- */
.signin-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.signin-card {
  width: 100%;
  max-width: 420px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.signin-status:empty { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1, .brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.brand-large h1 { font-size: 22px; }

.enrol-details summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.enrol-details[open] > .hint { margin-bottom: 12px; }

.enrol { display: flex; flex-direction: column; gap: 12px; }

/* --- The frame --- */
.app { min-height: 100vh; }

.sidebar { display: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
}

.nav { display: flex; }

/* On a phone the five screens sit in a row that scrolls sideways on its own, never the page. (The row clips what
   sticks out of it, so it leaves room above and beside for the focus rings.) */
.nav-top {
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 6px 12px 8px;
}

.nav-link {
  flex: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: var(--radius-small);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.nav-link:hover { background: var(--surface-hover); }
.nav-link[aria-current="page"] { background: var(--accent-container); color: var(--on-accent-container); font-weight: 700; }

.main {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 96px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
  }
  .topbar { display: none; }
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 16px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  .nav-side { flex-direction: column; gap: 2px; }
  .main { padding: 32px 32px 96px; }
}

.session-side {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
}
.session-limit { color: var(--muted); }

/* --- Screens --- */
.screen-header { display: flex; flex-direction: column; gap: 6px; }

.back-link {
  align-self: flex-start;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  text-decoration: none;
}

.screen-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.screen-title { font-size: 26px; line-height: 1.25; }

.screen-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.screen-hint { color: var(--muted); font-size: 15px; }
.screen-hint.is-error { color: var(--error); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 6px;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.count { font-size: 13px; font-weight: 700; color: var(--accent); }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 56px;
}

.card > .row + .row, .card > .row + .row-link, .card > .row-link + .row, .card > .row-link + .row-link,
.card > .card-title-row + .row, .card > .check-row + .check-row { border-top: 1px solid var(--border); }
.card > .card-title-row + .row { border-top: 0; }

.card > .check-row { padding: 4px 16px; }

.row-column { flex-direction: column; align-items: stretch; }

.row > .form { flex: 1; }

.row-link { color: inherit; text-decoration: none; }
/* The page's own background, not --surface-hover: the muted details stay over 4.5:1 under the mouse. */
.row-link:hover { background: var(--bg); }

.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
}

.row-detail.is-error { color: var(--error); }

.row-detail-only { color: var(--muted); font-size: 14px; display: block; }

.row-value { color: var(--muted); font-size: 15px; }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 4px 0 0 -10px;
}

/* A person with buttons under their name: the picture stays level with the name. */
.person-row { align-items: flex-start; }
.person-row > .animal { margin-top: 2px; }

.row-empty { color: var(--muted); display: block; }

.row-error { flex-direction: column; align-items: flex-start; }

.chevron { font-size: 24px; color: var(--muted); line-height: 1; }

.save-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.plain-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

.choice-group { display: flex; flex-direction: column; }

/* --- Sheets: a bottom sheet on a phone, a centred card on a wider screen --- */
dialog.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}

dialog.sheet::backdrop { background: var(--backdrop); }

@media (min-width: 600px) {
  dialog.sheet {
    max-width: 540px;
    margin: auto;
    border-radius: 20px;
    border: 1px solid var(--border);
  }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 20px;
  min-height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.sheet-title { font-size: 18px; line-height: 1.3; }

.sheet-body {
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.sheet-actions .btn { min-width: 120px; }

@media (max-width: 599px) {
  .sheet-actions .btn { flex: 1; }
}

/* The one-time temporary password: large, in a typewriter font so look-alike letters stay apart. */
.password-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-small);
  background: var(--surface-hover);
}

.password-value {
  flex: 1;
  font: 600 24px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  user-select: all;
  -webkit-user-select: all;
  overflow-wrap: anywhere;
}

.password-value:empty { display: none; }

.password-hidden { flex: 1; color: var(--text); }

/* --- The session banner and toasts --- */
.session-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--accent-container);
  color: var(--on-accent-container);
  border: 1px solid var(--border);
}

/* While a box is open the banner sits at the bottom of the box (app.js placeBanner): the rest of the page cannot be
   used then. It stays in sight there while the box scrolls. */
dialog.sheet > .session-banner {
  position: sticky;
  left: auto;
  right: auto;
  bottom: 0;
  max-width: none;
  margin: 0;
  border-radius: 0;
  border-width: 1px 0 0;
}

.countdown { font-weight: 700; font-variant-numeric: tabular-nums; }

.toast-stack {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast-stack > div { display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* Above the session banner while it shows. */
body.has-banner .toast-stack { bottom: 140px; }

.toast {
  max-width: 560px;
  padding: 10px 16px;
  border-radius: var(--radius-small);
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
}

.toast-error { background: var(--error); color: var(--bg); }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 160ms ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}
