/* Mobile-first: base styles target phones; wider screens only get more breathing room. */
:root {
  --bg: #f6f6f4;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --card: #ffffff;
  --line: #deded9;
  --accent: #2f5d50;
  --accent-fg: #ffffff;
  --error: #a3261f;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #ececea;
    --muted: #a0a09a;
    --card: #222220;
    --line: #3a3a37;
    --accent: #7fb8a6;
    --accent-fg: #10201b;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main { padding: 16px; max-width: 640px; margin: 0 auto; }

h1 { font-size: 1.4rem; margin: 0; overflow-wrap: anywhere; }

/* Login screen */
.login { padding-top: 12vh; }
.login h1 { text-align: center; margin-bottom: 24px; font-size: 1.8rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

label { display: block; font-weight: 600; margin: 0 0 6px; }

input {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 1.1rem; /* >= 16px stops iOS from zooming in on focus */
  padding: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}

input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  cursor: pointer;
  min-height: 44px; /* comfortable touch target */
}

button[type="submit"]:not(.link) {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

button.link {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 0 4px;
  text-decoration: underline;
}

.error {
  color: var(--error);
  margin: 0 0 16px;
  font-weight: 600;
}

/* Page list */
.bar {
  position: sticky;
  top: 0;
  display: flex;
  flex-wrap: wrap; /* long names wrap onto a second line instead of overflowing a narrow screen */
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.bar form { display: flex; align-items: center; gap: 8px; margin: 0; }
.who { color: var(--muted); font-size: 0.95rem; min-width: 0; overflow-wrap: anywhere; }
/* On the page list the User's name is the link to changing their Login code: a full touch target. */
a.who { color: var(--accent); text-decoration: underline; padding: 10px 0; }

.pages { list-style: none; margin: 0; padding: 0; }
.pages li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
  position: relative;
}
/* The whole entry is the touch target for opening the Page. */
.pages .title {
  display: block;
  padding: 14px 16px 2px;
  color: var(--fg);
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.pages .title::after { content: ""; position: absolute; inset: 0; }
.pages .meta { display: block; padding: 0 16px 14px; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }

a.button {
  display: block;
  padding: 12px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  min-height: 44px;
}

.empty { color: var(--muted); text-align: center; margin-top: 15vh; }
.empty a { color: var(--accent); }

/* The filter box above the page list: the field takes the row, its button sits beside it. */
.filter { display: flex; gap: 8px; margin: 0 0 12px; }
.filter input { flex: 1; min-width: 0; margin: 0; }

.nav { color: var(--accent); font-weight: 600; text-decoration: none; padding: 10px 0; }
.bar h1 { margin-right: auto; }

/* Users screen (Admins only) */
main > .card { margin-bottom: 16px; }
.notice { border-color: var(--accent); }
.notice p { margin: 0 0 8px; }
.code {
  display: block;
  font: 700 2.2rem/1.2 ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: 0.2em;
  margin: 4px 0 8px;
  user-select: all;
}
.hint { color: var(--muted); font-size: 0.95rem; }

.users { list-style: none; margin: 0; padding: 0; }
.users li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
}
.users .name { font-weight: 600; margin-right: 6px; overflow-wrap: anywhere; }
.tag {
  display: inline-block;
  font-size: 0.8rem;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  margin-right: 4px;
}
.tag.warn { color: var(--error); border-color: var(--error); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.actions form { margin: 0; }

button[type="submit"].secondary,
a.secondary {
  display: inline-flex;
  align-items: center;
  width: auto;
  min-height: 44px;
  padding: 8px 14px;
  background: none;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}
a.danger { color: var(--error); font-weight: 600; padding: 10px 6px; }
button[type="submit"].danger { background: var(--error); color: var(--card); margin-bottom: 12px; }

/* Editor: the title, then a text area filling the rest of the screen. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.status { color: var(--muted); font-size: 0.9rem; margin-right: auto; }
.status[data-state="offline"],
.status[data-state="refused"] { color: var(--error); font-weight: 600; }
.presence { color: var(--muted); font-size: 0.9rem; margin: 0 0 8px; overflow-wrap: anywhere; }
.presence[hidden] { display: none; }
/* Below the text area: deleting the Page, out of the way of typing. */
.page-actions { margin: 16px 0 0; text-align: right; }

/* A Page in the Trash, as an Admin looks at it: read-only, its line breaks kept. */
.page-preview {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.trash { list-style: none; margin: 0; padding: 0; }
.trash li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
}
.trash .title { display: block; padding: 6px 0; font-weight: 600; color: var(--fg); text-decoration: none; overflow-wrap: anywhere; }
.trash .meta { display: block; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
main.editor {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 66px);
  min-height: calc(100dvh - 66px);
  padding-bottom: 8px;
}
.page-title { font-size: 1.3rem; font-weight: 600; margin-bottom: 10px; }
.page-body {
  display: block;
  flex: 1;
  width: 100%;
  min-height: 60vh;
  font: inherit;
  font-size: 1.05rem; /* >= 16px stops iOS from zooming in on focus */
  line-height: 1.5;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  resize: vertical;
}
.page-body:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.page-title[readonly], .page-body[readonly] { color: var(--muted); }

@media (min-width: 700px) {
  main { padding: 32px 16px; }
}
