:root {
  --purple: #6D40C4;
  --purple-dark: #57339d;
  --purple-light: #f4effc;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f3f4f6;
  --green: #059669;
  --red: #dc2626;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Poppins', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 90px; /* room for sticky action bar */
}
.wrap { max-width: 680px; margin: 0 auto; padding: 12px; }

header.app {
  background: var(--purple);
  color: #fff;
  padding: 14px 16px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
header.app h1 { margin: 0; font-size: 18px; font-weight: 600; }
header.app .powered { font-size: 11px; color: #e4d9f7; white-space: nowrap; }
header.app .powered a { color: #fff; font-weight: 600; text-decoration: none; }

.card {
  background: #fff; border-radius: 14px; padding: 16px;
  margin: 12px 0; box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card h2 {
  margin: 0 0 12px; font-size: 16px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--line); padding-bottom: 8px;
}
.badge {
  background: var(--purple-light); color: var(--purple);
  font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px;
}

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font-size: 16px; /* 16px prevents iOS zoom */
  font-family: inherit; color: var(--ink);
  border: 1px solid #d1d5db; border-radius: 10px;
  padding: 11px 12px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--purple); border-color: var(--purple); }
textarea { min-height: 72px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .row2.stack-sm { grid-template-columns: 1fr; } }

button {
  font-family: inherit; font-size: 15px; font-weight: 600;
  border: none; border-radius: 10px; padding: 12px 16px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--purple); color: #fff; width: 100%; }
.btn-primary:active { background: var(--purple-dark); }
.btn-secondary { background: #e5e7eb; color: var(--ink); width: 100%; }
.btn-ghost { background: transparent; color: var(--purple); padding: 8px; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { font-size: 13px; padding: 8px 12px; }
button:disabled { opacity: .5; }

.search-box { position: relative; }
.search-results {
  position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  margin-top: 4px; max-height: 260px; overflow-y: auto;
  box-shadow: 0 8px 20px rgba(0,0,0,.12);
}
.search-results div { padding: 12px; border-bottom: 1px solid var(--bg); font-size: 15px; }
.search-results div:active { background: var(--purple-light); }
.search-results .co { color: var(--muted); font-size: 13px; }

.list-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: 10px 12px; border-radius: 10px; margin-top: 8px; font-size: 14px;
}
.list-item.member { background: #eef4ff; }
.list-item.guest { background: #ecfdf5; }
.list-item.promise { background: var(--purple-light); }
.list-item .meta { color: var(--muted); font-size: 12.5px; }
.list-item .acts { display: flex; gap: 4px; flex-shrink: 0; }
.list-item .acts button { padding: 6px 8px; font-size: 15px; background: transparent; }
.tag { font-size: 11px; font-weight: 600; color: var(--purple); }

.actionbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: #fff; border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; max-width: 680px; margin: 0 auto;
}
.actionbar .btn-primary { flex: 2; }
.actionbar .btn-secondary { flex: 1; }

.modal {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: rgba(31,41,55,.55); align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; }
.modal-content {
  background: #fff; width: 100%; max-width: 680px;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
}
@media (min-width: 700px) {
  .modal { align-items: center; }
  .modal-content { border-radius: 18px; }
}
.modal-content h3 { margin: 0 0 12px; font-size: 17px; }
pre.report {
  white-space: pre-wrap; background: var(--bg); border-radius: 10px;
  padding: 12px; font-size: 13px; font-family: inherit; max-height: 45vh; overflow-y: auto;
}
.btnrow { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btnrow button { flex: 1; min-width: 120px; }

.notice { border-radius: 10px; padding: 12px; font-size: 14px; margin-top: 10px; }
.notice.ok { background: #ecfdf5; color: #065f46; }
.notice.err { background: #fef2f2; color: #991b1b; }
.hidden { display: none !important; }

/* directory table */
table.dir { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.dir th, table.dir td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.dir a { color: var(--purple); text-decoration: none; word-break: break-all; }

/* ---- admin ---- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; }
.tabs button { background: #e5e7eb; color: var(--ink); font-size: 13.5px; padding: 9px 14px; white-space: nowrap; }
.tabs button.active { background: var(--purple); color: #fff; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.stat { background: #fff; border-radius: 12px; padding: 12px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stat .n { font-size: 22px; font-weight: 700; color: var(--purple); }
.stat .l { font-size: 11.5px; color: var(--muted); }
table.adm { width: 100%; border-collapse: collapse; font-size: 13.5px; background: #fff; border-radius: 12px; overflow: hidden; }
table.adm th { background: var(--purple-light); color: var(--purple); text-align: left; padding: 9px 8px; font-size: 12px; }
table.adm td { padding: 9px 8px; border-bottom: 1px solid var(--bg); vertical-align: top; }
.scroll-x { overflow-x: auto; }
