:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #dcd8d2;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-hover: #255a4c;
  --focus: #3b82f6;
  --error-bg: #fdecec;
  --error-text: #8a1c1c;
  --ok-bg: #e8f5ee;
  --ok-text: #1d5e3d;
  --info-bg: #eef3fb;
  --info-text: #1f3f73;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1e2227;
    --text: #e8eaed;
    --muted: #a3aab3;
    --border: #343a42;
    --accent: #5fb39b;
    --accent-text: #0e1a16;
    --accent-hover: #74c4ad;
    --error-bg: #3a1d1d;
    --error-text: #f4b4b4;
    --ok-bg: #18332a;
    --ok-text: #a6e0c3;
    --info-bg: #1b2a40;
    --info-text: #b7cdf0;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

.site-header {
  padding: 16px;
  text-align: center;
}
.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  align-self: flex-start;
}
.card.wide { max-width: 720px; }

h1 { font-size: 1.5rem; margin: 0 0 4px; }
.lead { color: var(--muted); margin: 0 0 20px; }

form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 0.95rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }

input, textarea, select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button {
  font: inherit;
  font-weight: 600;
  padding: 11px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.6; cursor: progress; }
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover:not(:disabled) { background: var(--bg); }

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

.links {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: space-between;
  font-size: 0.95rem;
}

.message {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--info-bg);
  color: var(--info-text);
}
form + .message { margin-top: 14px; }
.message[data-kind="error"] { background: var(--error-bg); color: var(--error-text); }
.message[data-kind="ok"]    { background: var(--ok-bg);    color: var(--ok-text); }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

textarea { resize: vertical; min-height: 96px; }

/* Links styled as buttons */
a.button, label.button {
  display: inline-block;
  font-weight: 600;
  padding: 11px 16px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}
a.button:hover, label.button:hover { background: var(--accent-hover); }
label.button.secondary, a.button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
label.button.secondary:hover, a.button.secondary:hover { background: var(--bg); }
label.button:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

button.danger {
  background: transparent;
  color: var(--error-text);
  border: 1px solid currentColor;
}
button.danger:hover:not(:disabled) { background: var(--error-bg); }

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

/* Dashboard: pet list */
.pet-list {
  list-style: none;
  padding: 0;
  margin: 20px 0;
  display: grid;
  gap: 10px;
}
.pet-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.pet-card:hover { background: var(--bg); }
.pet-card strong { display: block; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 0.9rem; }
.empty { color: var(--muted); margin: 20px 0; }

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--muted);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.large { width: 96px; height: 96px; font-size: 2rem; }

/* Pet form */
.field {
  display: grid;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.field-label { font-weight: 600; font-size: 0.95rem; display: grid; gap: 6px; }
label.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
}
label.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.photo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tags */
h2 { font-size: 1.2rem; margin: 0 0 8px; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 28px 0 20px; }
.code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 600;
  letter-spacing: 0.06em;
}
input.code-input { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.1em; text-transform: uppercase; }
.tag-list { list-style: none; padding: 0; margin: 12px 0 20px; display: grid; gap: 10px; }
.tag-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tag-row > div:first-child { display: grid; gap: 2px; }
.tag-row.lost { opacity: 0.6; }
.tag-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tag-actions select { width: auto; padding: 6px 8px; }
button.small { padding: 6px 10px; font-size: 0.9rem; }

/* Public tag page */
.pet-hero { text-align: center; display: grid; justify-items: center; gap: 4px; margin-bottom: 16px; }
.avatar.xlarge { width: 160px; height: 160px; font-size: 3rem; margin-bottom: 8px; }
.pet-notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.found-box {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
}
.owner-bar {
  margin: -8px 0 16px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 0.9rem;
}
.setup-code { margin-top: 16px; }

[hidden] { display: none !important; }
