/* Walk On Water — Bibles to Send
   Brand colours pulled from https://www.walknonwater.org.nz/ theme stylesheet:
   aqua #79FFFF, teal #5dbebe, ink #101010/#1E1E1E, warm neutrals, plus the
   site's own light-green/light-red alert tints reused for done/duplicate rows. */

:root {
  --wow-aqua: #79ffff;
  --wow-aqua-deep: #3d8f8f;
  --wow-teal: #5dbebe;
  --wow-teal-dark: #3a8f8f;
  --wow-ink: #1e1e1e;
  --wow-ink-soft: #454545;
  --wow-gold: #fbbd00;

  --bg: #f7fbfb;
  --bg-elevated: #ffffff;
  --bg-muted: #eef5f5;
  --text: var(--wow-ink);
  --text-muted: #5c6666;
  --border: #dbe6e6;
  --border-strong: #b9cccc;

  --accent: var(--wow-teal-dark);
  --accent-contrast: #ffffff;
  --accent-hover: #2f7373;
  --accent-soft: #e3fbfb;
  --focus-ring: #2f9d9d;

  --done-bg: #d4edda;
  --done-border: #b7dfc0;
  --dup-bg: #f8d7da;
  --dup-border: #f0aeb4;
  --dup-text: #8a1c26;
  --muted-badge-bg: #ebebec;
  --muted-badge-text: #5c6666;

  --danger: #c0392b;
  --shadow: 0 4px 18px rgba(16, 16, 16, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 16, 16, 0.18);
  --radius: 10px;
  --radius-sm: 6px;

  --font: "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10191a;
    --bg-elevated: #172224;
    --bg-muted: #1c2a2c;
    --text: #eef6f6;
    --text-muted: #a3b6b6;
    --border: #2a3b3d;
    --border-strong: #3a4f52;

    --accent: var(--wow-aqua);
    --accent-contrast: #0a1a1a;
    --accent-hover: #93ffff;
    --accent-soft: #163235;
    --focus-ring: var(--wow-aqua);

    --done-bg: #163a26;
    --done-border: #1f5636;
    --dup-bg: #4a1c22;
    --dup-border: #6b2a31;
    --dup-text: #ff9aa4;
    --muted-badge-bg: #26383a;
    --muted-badge-text: #a3b6b6;

    --danger: #ff6b5e;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }

  /* the source logo is near-black on transparent; invert so it reads on dark cards/headers */
  .auth-logo, .app-brand img {
    filter: invert(1) brightness(1.6);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

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

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  border-color: var(--dup-border);
  color: var(--danger);
}
.btn-danger:hover { background: var(--dup-bg); }

.btn-ghost {
  border-color: transparent;
  background: transparent;
}
.btn-ghost:hover { background: var(--bg-muted); border-color: var(--border); }

.btn-sm { padding: 4px 9px; font-size: 12.5px; }

/* ---------- Login page ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 0%, var(--accent-soft), transparent 55%), var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px 26px;
  text-align: center;
}

.auth-logo {
  height: 52px;
  width: auto;
  margin-bottom: 14px;
}

.auth-card h1 {
  font-size: 19px;
  margin: 0 0 4px;
}

.auth-card p.subtitle {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0 0 22px;
}

.auth-field {
  text-align: left;
  margin-bottom: 16px;
}

.auth-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.auth-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}

.auth-field input.code-input {
  letter-spacing: 0.4em;
  font-size: 22px;
  text-align: center;
  font-family: var(--font-mono);
}

.auth-submit {
  width: 100%;
  justify-content: center;
  padding: 10px 14px;
  font-size: 14.5px;
  margin-top: 4px;
}

.auth-msg {
  font-size: 13px;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  margin: 4px 0 16px;
  text-align: left;
}
.auth-msg.info { background: var(--accent-soft); color: var(--accent-hover); }
.auth-msg.error { background: var(--dup-bg); color: var(--dup-text); }
.auth-msg[hidden] { display: none; }

.auth-links {
  margin-top: 14px;
  font-size: 13px;
}
.auth-links button {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  padding: 0;
  text-decoration: underline;
}

.auth-footer {
  margin-top: 22px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
}
.app-brand img { height: 30px; width: auto; }
.app-brand .app-name-sub { color: var(--text-muted); font-weight: 600; font-size: 12.5px; display: block; }

.view-switch {
  display: flex;
  gap: 4px;
  background: var(--bg-muted);
  border-radius: 999px;
  padding: 3px;
  margin-left: auto;
}
.view-switch button {
  border: none;
  background: transparent;
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.view-switch button.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

.pending-badge {
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}
.view-switch button:not(.active) .pending-badge {
  background: var(--muted-badge-bg);
  color: var(--muted-badge-text);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 53px;
  z-index: 20;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
.field input, .field select {
  padding: 6px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
.field.search { flex: 1 1 200px; min-width: 160px; }
.field.search input { width: 100%; }

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
  align-items: flex-end;
}

.selection-count {
  font-size: 12.5px;
  color: var(--text-muted);
  align-self: center;
  padding: 0 4px;
}

/* ---------- Table ---------- */
.table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0 18px 18px;
}

.status-line {
  padding: 10px 18px 0;
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

table.entries {
  border-collapse: collapse;
  width: 100%;
  min-width: 1100px;
  font-size: 13px;
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  overflow: hidden;
}

table.entries thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-muted);
  border-bottom: 2px solid var(--border-strong);
  text-align: left;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  white-space: nowrap;
}

table.entries td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

table.entries td.wrap-cell { white-space: normal; }

table.entries tbody tr:nth-child(even) { background: var(--bg-muted); }
table.entries tbody tr:hover { background: var(--accent-soft); cursor: pointer; }

table.entries tbody tr.done { background: var(--done-bg) !important; }
table.entries tbody tr.done:hover { filter: brightness(0.97); }

table.entries tbody tr.dup-row { box-shadow: inset 3px 0 0 var(--danger); }

table.entries td.checkbox-cell, table.entries th.checkbox-cell {
  width: 32px;
  text-align: center;
  white-space: nowrap;
}

table.entries td.checkbox-cell { cursor: default; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  font-family: var(--font);
  white-space: nowrap;
}
.badge-dup { background: var(--dup-bg); color: var(--dup-text); border: 1px solid var(--dup-border); }
.badge-muted { background: var(--muted-badge-bg); color: var(--muted-badge-text); font-weight: 700; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.load-more-row {
  display: flex;
  justify-content: center;
  padding: 16px;
}
.load-more-row[hidden] { display: none; }

/* ---------- Drawer ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 20, 0.4);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(430px, 100vw);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 { font-size: 15px; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.drawer-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

.field-list { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 13px; margin-bottom: 18px; }
.field-list dt { color: var(--text-muted); font-weight: 700; font-size: 11.5px; text-transform: uppercase; align-self: start; padding-top: 1px; }
.field-list dd { margin: 0; word-break: break-word; }

.drawer-message {
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 18px;
}

.drawer-section h3 {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0 0 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.match-list { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.match-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.match-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.match-item .match-done { color: var(--done-border); font-weight: 800; font-size: 11px; }
.match-empty { color: var(--text-muted); font-size: 12.5px; font-style: italic; margin: 0 0 4px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--muted-badge-bg);
  color: var(--muted-badge-text);
}
.status-pill.is-done { background: var(--done-bg); color: #1c6b34; }

/* ---------- Modal (Users) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 20, 20, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.modal.open { opacity: 1; pointer-events: auto; }
.modal-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.user-row .user-email { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.user-row .user-admin-tag {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--accent-hover);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 999px;
}

.user-add-form {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.user-add-form input[type="text"], .user-add-form input[type="email"] {
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  flex: 1 1 130px;
  min-width: 0;
}
.user-add-form label.inline-check {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  white-space: nowrap;
}

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--wow-ink);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.15s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .app-header { padding: 8px 12px; gap: 10px; }
  .app-brand .app-name-sub { display: none; }
  .toolbar { padding: 8px 12px; top: 49px; }
  .table-wrap { padding: 0 0 12px; }
  table.entries { border-radius: 0; }
  .header-user span.user-email-text { display: none; }
  .drawer { width: 100vw; }
  .toolbar-actions { width: 100%; justify-content: flex-start; }
  .field.search { flex-basis: 100%; }
}
