:root {
  --bg: #faf7f5;
  --card: #ffffff;
  --text: #2a1f2d;
  --muted: #6d6070;
  --line: #e8e0e6;
  --field: #ffffff;
  --brand: #7a2e6b;
  --brand-dark: #5e2152;
  --brand-soft: #f5e9f2;
  --on-brand: #ffffff;
  --blue: #1d4f91;
  --blue-soft: #e8f0fb;
  --ok: #1f7a4d;
  --ok-soft: #e6f4ec;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --err: #b3261e;
  --err-soft: #fdecea;
  --shadow: 0 1px 3px rgba(42, 31, 45, 0.06), 0 8px 24px rgba(42, 31, 45, 0.05);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17121a;
    --card: #221b26;
    --text: #f1eaf2;
    --muted: #b3a6b6;
    --line: #3a2f3f;
    --field: #1b151f;
    --brand: #d98bc8;
    --brand-dark: #e8a9da;
    --brand-soft: #3a2437;
    --on-brand: #2a1026;
    --blue: #9cc0f0;
    --blue-soft: #1f2b3d;
    --ok: #7fd1a4;
    --ok-soft: #1b3226;
    --warn: #f0bd6a;
    --warn-soft: #3a2d17;
    --err: #ff8a80;
    --err-soft: #3d1c1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.wrap.wide { max-width: 900px; }

/* Brand header */
header.brand { text-align: center; margin-bottom: 20px; }
.logo {
  width: 56px; height: 56px; margin: 0 auto 10px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--brand); color: var(--on-brand);
  font-size: 28px;
}
header.brand h1 { margin: 0; font-size: clamp(1.6rem, 6vw, 2rem); color: var(--brand); letter-spacing: -0.02em; line-height: 1.2; }
header.brand h1 span { font-weight: 500; color: var(--muted); }
header.brand p { margin: 6px 0 0; color: var(--muted); }

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

/* Privacy notice */
.notice {
  background: var(--brand-soft);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.94rem;
  margin-bottom: 22px;
}
.notice summary {
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  font-weight: 600;
  min-height: 28px;
}
.notice summary::-webkit-details-marker { display: none; }
.notice summary::after { content: "▾"; margin-left: auto; color: var(--brand); transition: transform .2s; }
.notice[open] summary::after { transform: rotate(180deg); }
.notice ul { margin: 10px 0 2px; padding-left: 20px; }
.notice li { margin: 4px 0; }

/* Form */
.field { margin-top: 22px; border: 0; padding: 0; min-width: 0; }
form > .field:first-child { margin-top: 0; }
.field-label, legend { display: block; font-weight: 600; margin: 0 0 10px; padding: 0; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.88rem; }

textarea, input[type="password"], input[type="text"], input[type="search"], select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  transition: border-color .15s;
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--brand); }
textarea { min-height: 150px; resize: none; overflow: hidden; line-height: 1.5; }

/* Tap-to-choose options */
.options { display: grid; gap: 10px; }
.options.two { grid-template-columns: 1fr 1fr; }
.options.cats { grid-template-columns: 1fr 1fr; }
@media (min-width: 480px) { .options.cats { grid-template-columns: repeat(3, 1fr); } }

.option { position: relative; display: block; cursor: pointer; }
.option input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.option > span {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px;
  padding: 10px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  text-align: center;
  font-weight: 500;
  line-height: 1.25;
  transition: border-color .15s, background .15s, transform .1s;
}
.option small { display: block; font-size: 0.78rem; color: var(--muted); font-weight: 400; }
.option .emoji { font-size: 1.3rem; line-height: 1; }
.options.cats .option .emoji { font-size: 1.5rem; margin-bottom: 2px; }
.option > input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.option > input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.option:active > span { transform: scale(0.98); }
.options.cats .option > span { flex-direction: column; gap: 2px; min-height: 64px; font-size: 0.92rem; }

.count { text-align: right; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.count.near { color: var(--warn); }

/* Buttons */
button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  min-height: 44px;
  background: var(--brand);
  color: var(--on-brand);
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: 0.6; cursor: default; }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button.full { width: 100%; margin-top: 22px; min-height: 54px; font-size: 1.05rem; }
button.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--line); padding: 8px 14px; }
button.ghost:hover { background: var(--brand-soft); }
button.danger { background: transparent; color: var(--err); padding: 8px 12px; }
button.danger:hover { background: var(--err-soft); }

.spinner {
  display: inline-block; width: 18px; height: 18px; vertical-align: -3px; margin-right: 8px;
  border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  display: none;
  color: var(--err); background: var(--err-soft);
  border-radius: 10px; padding: 10px 12px;
  font-size: 0.92rem; margin-top: 14px;
}
.error.show { display: block; }

.offline {
  background: var(--warn-soft); color: var(--warn);
  border-radius: 10px; padding: 10px 12px; font-size: 0.9rem; margin-bottom: 14px; text-align: center;
}

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* Thank-you */
.thanks { text-align: center; padding: 32px 22px; }
.thanks h2 { color: var(--brand); margin: 16px 0 8px; }
.thanks p { color: var(--muted); margin: 0 0 22px; }
.check { width: 72px; height: 72px; margin: 0 auto; }
.check circle { fill: var(--ok-soft); }
.check path { fill: none; stroke: var(--ok); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .5s .15s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

footer { text-align: center; font-size: 0.84rem; color: var(--muted); margin-top: 22px; padding: 0 8px; }

/* ---------- Admin ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 1.35rem; color: var(--brand); line-height: 1.2; }
.topbar h1 small { display: block; font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.topbar .btns { display: flex; gap: 8px; flex-shrink: 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card); color: var(--text);
  border: 1.5px solid var(--line); border-radius: 14px;
  padding: 12px 14px; text-align: left; font-weight: 400;
  box-shadow: var(--shadow);
}
.stat:hover { background: var(--card); border-color: var(--brand); }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: 0.82rem; color: var(--muted); }
.stat.active { border-color: var(--brand); background: var(--brand-soft); }
.stat.s-new b { color: var(--brand); }
.stat.s-seen b { color: var(--warn); }
.stat.s-resolved b { color: var(--ok); }

.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.filters select { padding-right: 32px; }

.item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.item.new { border-left: 4px solid var(--brand); }
.meta { display: flex; gap: 6px 8px; flex-wrap: wrap; align-items: center; font-size: 0.84rem; color: var(--muted); margin-bottom: 8px; }
.tag { padding: 2px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.tag.suggestion { background: var(--blue-soft); color: var(--blue); }
.msg { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 14px; font-size: 1rem; }
.actions { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.segmented { display: inline-flex; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 3px; }
.segmented button {
  background: transparent; color: var(--muted);
  min-height: 38px; padding: 6px 12px; border-radius: 9px; font-size: 0.9rem; font-weight: 500;
}
.segmented button:hover { background: transparent; color: var(--text); }
.segmented button[aria-pressed="true"].new { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.segmented button[aria-pressed="true"].seen { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.segmented button[aria-pressed="true"].resolved { background: var(--ok-soft); color: var(--ok); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 2.2rem; display: block; margin-bottom: 8px; }

.skeleton { height: 120px; border-radius: 14px; margin-bottom: 12px; background: linear-gradient(90deg, var(--card), var(--line), var(--card)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.pw { position: relative; }
.pw input { padding-right: 70px; }
.pw button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); min-height: 36px; padding: 4px 10px; background: transparent; color: var(--brand); font-size: 0.88rem; }
.pw button:hover { background: var(--brand-soft); }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-size: 0.92rem; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 600px) {
  .card { padding: 18px; }
  .topbar h1 { font-size: 1.15rem; }
  .topbar .btns button { padding: 8px 10px; font-size: 0.9rem; }
  .stats { gap: 6px; }
  .stat { padding: 10px 8px; text-align: center; border-radius: 12px; }
  .stat b { font-size: 1.3rem; }
  .stat span { font-size: 0.74rem; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  .item { padding: 14px; }
  .actions { flex-wrap: nowrap; gap: 6px; }
  .segmented { display: flex; flex: 1; min-width: 0; }
  .segmented button { flex: 1; padding: 6px 4px; font-size: 0.86rem; }
  .actions .danger { padding: 8px; font-size: 0.9rem; flex-shrink: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .check path { stroke-dashoffset: 0; }
}
