/* MyPets — mobile-first, warm earth palette:
   brown #54433a · sage #cfcb90 · mauve #7f7378 · cream #efe1d0 · terracotta #cc7f50
   Two themes on <html data-theme="...">: dark (brown, default) and light (sage). */
:root, [data-theme="dark"] {
  --bg: #322822;       /* deep brown, darkened from the palette for contrast */
  --bg2: #3d312a;      /* top/tab bars, inputs */
  --card: #54433a;     /* palette brown — cards */
  --line: #6f5d54;
  --text: #efe1d0;     /* palette cream */
  --muted: #b5a294;
  --accent: #cc7f50;   /* palette terracotta — primary actions, selection */
  --accent2: #de9463;
  --on-accent: #322822;/* text on terracotta: deep brown reads best */
  --hl: #cfcb90;       /* palette sage — links, icons, today marker */
  --danger: #b85744;
  --flash-bg: #48482c;      --flash-text: #ddd8a4;
  --flash-err-bg: #4f2f26;  --flash-err-text: #eac4b4;
  --bar-color: #3d312a;     /* synced to the browser theme-color meta by app.js */
  --radius: 14px;
}

[data-theme="light"] {
  --bg: #cfcb90;       /* palette sage — main background */
  --bg2: #c1bc7c;
  --card: #e5e1b8;
  --line: #a49e63;
  --text: #453930;
  --muted: #6e6354;
  --accent: #b06030;   /* deepened terracotta so cream text reads on it */
  --accent2: #cc7f50;
  --on-accent: #f8efe3;
  --hl: #5c5720;       /* dark olive links on sage */
  --danger: #9c4230;
  --flash-bg: #b6c47c;      --flash-text: #39471b;
  --flash-err-bg: #e0b2a2;  --flash-err-text: #6b2517;
  --bar-color: #c1bc7c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* keep the hidden attr authoritative over display rules */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 76px; /* room for the tab bar */
}
a { color: var(--hl); text-decoration: none; }
h1 { font-size: 1.4rem; margin: 14px 0 10px; }
h2 { font-size: 1.1rem; margin: 22px 0 8px; color: var(--muted); }
main { padding: 0 14px; max-width: 640px; margin: 0 auto; }

/* Top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 1.3rem; font-weight: 700; color: var(--text); font-family: Georgia, serif; }
.brand.big { font-size: 2rem; display: block; text-align: center; margin-bottom: 14px; }
.brand .paw { vertical-align: super; }
.brand .paw svg.icon { width: .55em; height: .55em; color: var(--accent2); }
.topnav a { margin-left: 14px; color: var(--muted); }
.topnav .iconbtn { margin-left: 14px; padding: 0; vertical-align: middle; }
/* Theme toggle shows the theme you'd switch TO. */
[data-theme="light"] .theme-sun { display: none; }
:root:not([data-theme="light"]) .theme-moon { display: none; }

/* Lucide sprite icons inherit text color via stroke: currentColor. */
svg.icon, svg.ico, svg.chev { width: 22px; height: 22px; vertical-align: -5px; flex-shrink: 0; }
h1 svg.icon { width: 24px; height: 24px; color: var(--hl); }
.attachment svg.icon, .attach-add svg.icon { width: 15px; height: 15px; vertical-align: -3px; }

/* Bottom tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--bg2); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 8px 0 6px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem;
}
.tabbar a svg.ico { width: 24px; height: 24px; }
.tabbar a.on { color: var(--text); background: var(--card); border-radius: 18px 18px 0 0; }

/* Flash + empty states */
.flash {
  margin: 10px 14px 0; padding: 10px 14px; border-radius: var(--radius);
  background: var(--flash-bg); color: var(--flash-text);
}
.flash.error { background: var(--flash-err-bg); color: var(--flash-err-text); }
.empty { text-align: center; padding: 40px 0; color: var(--muted); }

/* Pet chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 2px; }
.chip {
  padding: 7px 16px; border-radius: 999px; background: var(--card);
  color: var(--text); white-space: nowrap; border: 1px solid var(--line);
}
.chip.on { background: var(--accent); border-color: var(--accent2); color: var(--on-accent); }
.chip.add { color: var(--muted); }
.filters { display: flex; gap: 8px; margin: 10px 0; }

/* Cards / lists */
.petgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.petcard {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text);
}
.petcard img, .petavatar {
  width: 84px; height: 84px; border-radius: 50%; object-fit: cover;
  background: var(--bg2); display: flex; align-items: center; justify-content: center;
  font-size: 2rem; color: var(--muted);
}
.petcard.add { border: 1px dashed var(--line); background: transparent; }
.petavatar svg.icon { width: 42%; height: 42%; }
.thumb svg.icon { width: 22px; height: 22px; }

.list { list-style: none; margin: 8px 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius); margin-bottom: 8px; padding: 12px 14px;
}
.list li a { color: var(--text); display: flex; flex-direction: column; flex: 1; gap: 2px; }
.list li a strong { display: block; }
.list .thumb {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center; background: var(--bg2);
}
.list p { margin: 4px 0; color: var(--text); }

.catlist { list-style: none; margin: 12px 0; padding: 0; }
.catlist a {
  display: flex; align-items: center; gap: 14px; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 10px;
}
.catlist svg.ico { width: 26px; height: 26px; color: var(--hl); }
.catlist svg.chev { margin-left: auto; color: var(--muted); }
.badge {
  background: var(--accent); color: var(--on-accent);
  border-radius: 999px; padding: 2px 9px; font-size: .75rem;
}
.badge.off { background: var(--danger); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 11px 12px; font-size: 1rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
details { background: var(--card); border-radius: var(--radius); padding: 12px; }
details summary { cursor: pointer; color: var(--muted); }
details .stack, details label { margin-top: 10px; }
.addbox { margin: 18px 0; background: transparent; padding: 0; }
.addbox summary { list-style: none; display: inline-block; }
.addbox summary::-webkit-details-marker { display: none; }

/* Buttons */
.btn {
  display: inline-block; padding: 10px 18px; border-radius: 999px;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  font-size: .95rem; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent2); color: var(--on-accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-accent); }
.iconbtn { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.actions.center { justify-content: center; }
.fab {
  position: fixed; right: 18px; bottom: 86px; width: 56px; height: 56px;
  background: var(--accent); color: var(--on-accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.8rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.backlink { display: inline-block; margin-top: 12px; color: var(--muted); }
.attachment { display: inline-block; margin: 3px 0; font-size: .85rem; }
.attrow { display: inline-flex; align-items: center; gap: 2px; margin-right: 10px; }
.attach-add { background: transparent; padding: 0; margin-top: 4px; font-size: .85rem; }
.att-rename { background: transparent; padding: 0; display: inline-block; }
.att-rename summary { color: var(--muted); cursor: pointer; padding: 0 4px; }
.namebox:empty { display: none; }
.memberactions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.attach-add summary { color: var(--hl); }
.attachform { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.attachform input[type="file"] { width: auto; flex: 1; min-width: 200px; }

/* Pet profile */
.pethead { text-align: center; margin-top: 16px; }
.petphoto { width: 130px; height: 130px; border-radius: 50%; object-fit: cover; margin: 0 auto; }
div.petphoto { display: flex; font-size: 3rem; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; background: var(--card); border-radius: var(--radius); padding: 14px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

/* Calendar */
.calhead { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 12px 0; }
.calgrid .dow { text-align: center; color: var(--muted); font-size: .75rem; padding: 6px 0; }
.calgrid .day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--text); position: relative;
}
.calgrid .day.today { color: var(--hl); font-weight: 700; }
.calgrid .day.sel { background: var(--accent); color: var(--on-accent); }
.calgrid .day.has::after {
  content: ""; position: absolute; bottom: 5px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--accent2);
}

/* Auth pages */
.authpage { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.authcard { width: 100%; max-width: 380px; background: var(--card); border-radius: 18px; padding: 26px; }
.authcard form { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); font-size: .85rem; }
.version { text-align: center; margin: 26px 0 10px; }
.tokenbox { display: flex; gap: 8px; margin-bottom: 10px; }
