:root {
  --radius: 14px;
}

/* Color themes — selected in Settings and stored per account. */
:root,
[data-theme="sage"] {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #24312b;
  --muted: #6e7a73;
  --line: #e3ded2;
  --accent: #3e6b57;
  --accent-ink: #ffffff;
  --accent-soft: #e4efe7;
  --highlight: #c97b4a;
  --highlight-soft: #f6e3d5;
  --danger: #a33a3a;
  --danger-soft: #fdecec;
  --success-soft: #e8f3ef;
  --success-border: #cfe5dc;
  --success-ink: #215c4b;
  --surface-2: #fbfaf8;
  --field-bg: #ffffff;
}

[data-theme="sunset"] {
  --bg: #fbf3ee;
  --card: #fffbf8;
  --ink: #2e2320;
  --muted: #7a6a63;
  --line: #eadcd3;
  --accent: #a94a36;
  --accent-ink: #ffffff;
  --accent-soft: #f7e1d8;
  --highlight: #e0a458;
  --highlight-soft: #fbebd3;
  --danger: #9c2f2f;
  --danger-soft: #fdecec;
  --success-soft: #eaf3ec;
  --success-border: #d3e5d8;
  --success-ink: #2e5b42;
  --surface-2: #fdf7f3;
  --field-bg: #ffffff;
}

[data-theme="ocean"] {
  --bg: #f1f5f6;
  --card: #ffffff;
  --ink: #17272e;
  --muted: #5f7480;
  --line: #dce6e9;
  --accent: #1f5f74;
  --accent-ink: #ffffff;
  --accent-soft: #dceef2;
  --highlight: #d9a441;
  --highlight-soft: #f7ebcb;
  --danger: #a33a3a;
  --danger-soft: #fdecec;
  --success-soft: #eaf3ec;
  --success-border: #d3e5d8;
  --success-ink: #2e5b42;
  --surface-2: #f7fafb;
  --field-bg: #ffffff;
}

[data-theme="lavender"] {
  --bg: #f5f2f8;
  --card: #ffffff;
  --ink: #2a2433;
  --muted: #6f6579;
  --line: #e4ddeb;
  --accent: #6b5b95;
  --accent-ink: #ffffff;
  --accent-soft: #eae4f2;
  --highlight: #7c9a72;
  --highlight-soft: #e7efe2;
  --danger: #a33a3a;
  --danger-soft: #fdecec;
  --success-soft: #eaf3ec;
  --success-border: #d3e5d8;
  --success-ink: #2e5b42;
  --surface-2: #faf8fc;
  --field-bg: #ffffff;
}

[data-theme="maple"] {
  --bg: #f6f2ea;
  --card: #fffdf9;
  --ink: #2b2720;
  --muted: #736b5c;
  --line: #e6decf;
  --accent: #566b3a;
  --accent-ink: #ffffff;
  --accent-soft: #e8eedd;
  --highlight: #b4633a;
  --highlight-soft: #f5e2d6;
  --danger: #9c2f2f;
  --danger-soft: #fdecec;
  --success-soft: #eaf3ec;
  --success-border: #d3e5d8;
  --success-ink: #2e5b42;
  --surface-2: #fbf8f2;
  --field-bg: #ffffff;
}

[data-theme="graphite"] {
  color-scheme: dark;
  --bg: #121816;
  --card: #1b2421;
  --ink: #e8efea;
  --muted: #9aa8a1;
  --line: #2c3a35;
  --accent: #6fb79a;
  --accent-ink: #10201a;
  --accent-soft: #203a31;
  --highlight: #e0a458;
  --highlight-soft: #3a2f1e;
  --danger: #e58b8b;
  --danger-soft: #3a1f1f;
  --success-soft: #1f3a2e;
  --success-border: #2c4a3c;
  --success-ink: #bfe6d4;
  --surface-2: #202b27;
  --field-bg: #1b2421;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand { font-weight: 700; font-size: 18px; color: var(--ink); }

.chips { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }

.chip {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
}

.chip-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.me { display: flex; align-items: center; gap: 12px; margin-left: auto; font-size: 14px; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.narrow { max-width: 420px; margin-left: auto; margin-right: auto; }

h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 12px; }

.eyebrow { margin: 0 0 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.error { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 10px 12px; }

.flash {
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  color: var(--success-ink);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  word-break: break-word;
}

label { display: block; margin: 0 0 14px; font-size: 14px; color: var(--muted); }
input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:disabled { background: var(--surface-2); color: var(--muted); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  color: var(--ink);
  padding: 9px 14px;
}
button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  padding: 11px 16px;
  font-weight: 600;
}
.button { display: inline-block; padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); }
button.small, .small-button { padding: 6px 10px; font-size: 13px; }
button.danger { color: var(--danger); }

.button.primary:hover, button.primary:hover { text-decoration: none; opacity: .92; }

.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.row:first-child { border-top: 0; }

.person { display: flex; align-items: center; gap: 12px; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline { display: inline-flex; gap: 6px; align-items: center; }
.inline select { width: auto; margin: 0; padding: 6px 8px; }

/* Theme picker */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 10px 0 16px; }
.theme-option {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; cursor: pointer; background: var(--field-bg); color: var(--ink);
  font-size: 14px;
}
.theme-option:hover { border-color: var(--accent); }
.theme-option.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.theme-option input[type="radio"] { display: inline-block; width: auto; margin: 0; accent-color: var(--accent); }
.theme-swatch { width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.theme-swatch.sage { background: linear-gradient(135deg, #f4f1ea 0 45%, #3e6b57 45% 72%, #c97b4a 72% 100%); }
.theme-swatch.sunset { background: linear-gradient(135deg, #fbf3ee 0 45%, #a94a36 45% 72%, #e0a458 72% 100%); }
.theme-swatch.ocean { background: linear-gradient(135deg, #f1f5f6 0 45%, #1f5f74 45% 72%, #d9a441 72% 100%); }
.theme-swatch.lavender { background: linear-gradient(135deg, #f5f2f8 0 45%, #6b5b95 45% 72%, #7c9a72 72% 100%); }
.theme-swatch.maple { background: linear-gradient(135deg, #f6f2ea 0 45%, #566b3a 45% 72%, #b4633a 72% 100%); }
.theme-swatch.graphite { background: linear-gradient(135deg, #121816 0 45%, #6fb79a 45% 72%, #e0a458 72% 100%); }

.invite-form { display: grid; grid-template-columns: 1fr 180px auto; gap: 12px; align-items: end; }
.invite-form label { margin: 0; }
@media (max-width: 640px) {
  .invite-form { grid-template-columns: 1fr; }
  .wrap { padding: 16px 12px 48px; }
  h1 { font-size: 22px; }
  .me { margin-left: 0; }
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.family-card { display: block; }
.family-card h2 { margin: 6px 0 4px; }
.family-card:hover { border-color: var(--accent); text-decoration: none; }

.muted-card { background: var(--surface-2); }

/* Calendar */
.home-actions { margin: -4px 0 16px; }
.split { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.month-nav { display: flex; gap: 8px; margin-bottom: 10px; }
.month { width: 100%; border-collapse: collapse; table-layout: fixed; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.month th { font-size: 12px; color: var(--muted); text-align: left; padding: 8px; border-bottom: 1px solid var(--line); font-weight: 600; }
.month td { vertical-align: top; height: 92px; padding: 6px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.month td:first-child { border-left: 0; }
.month td.other { background: var(--surface-2); color: var(--muted); }
.month td.today { background: var(--accent-soft); }
.daynum { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.occ { display: block; font-size: 12px; line-height: 1.25; margin: 2px 0; padding: 2px 4px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.occ.allday { background: var(--highlight-soft); color: var(--highlight); }
.occ-time { font-weight: 600; margin-right: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .row2 { grid-template-columns: 1fr; } .month td { height: 74px; padding: 4px; } .occ { font-size: 11px; } }
textarea { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; color: var(--ink); background: var(--field-bg); border: 1px solid var(--line); border-radius: 10px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
.event-footer { margin-top: 16px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* Sub navigation */
.subnav { display: flex; gap: 14px; padding: 8px 20px; background: var(--card); border-bottom: 1px solid var(--line); font-size: 14px; overflow-x: auto; }
.subnav a { color: var(--muted); white-space: nowrap; }
.subnav a:hover { color: var(--accent); text-decoration: none; }

/* Today */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.today-card { display: block; }
.today-card:hover { border-color: var(--accent); text-decoration: none; }
.today-card h2 { display: flex; align-items: center; gap: 8px; }
.total { font-size: 26px; font-weight: 700; margin: 4px 0 8px; }
.badge-hot { background: var(--accent); color: #fff; }

/* Chat */
.chat { padding: 14px; }
.messages { max-height: 55vh; overflow-y: auto; padding: 4px 2px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.msg-head { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.msg-head strong { color: var(--ink); }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 12px; }
.chat-form textarea { margin: 0; flex: 1; }
.wish-form { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }

/* Chat: full-height layout so the input stays above the keyboard and the
   last messages remain visible while typing. */
body.chat-page {
  height: 100vh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.chat-page .top,
body.chat-page .subnav { flex: none; }
body.chat-page .wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  padding: 8px 12px 0;
}
body.chat-page .page-head { display: none; }
body.chat-page .flash { flex: none; }
body.chat-page .chat {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 10px;
  border-radius: 14px 14px 0 0;
}
body.chat-page .messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}
body.chat-page .chat-form {
  flex: none;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
body.chat-page .chat-form textarea { max-height: 30vh; }
