:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --line: #e4e2dc;
  --line-soft: #efede8;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --navy: #1d3557;
  --red: #c8102e;
  --accent: var(--navy);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.06);
  --hour: 56px;
  --gutter: 46px;
  --topbar: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 700; }
.muted { color: var(--muted); }
.error { color: var(--red); font-size: 14px; margin: 4px 0 0; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar);
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  background: var(--navy); color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .flag { font-size: 28px; }
.brand h1 { font-size: 18px; line-height: 1.1; letter-spacing: .2px; }
.brand .sub { font-size: 12px; opacity: .8; white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tabs button {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 0; color: rgba(255,255,255,.75);
  padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
.tabs button:hover { background: rgba(255,255,255,.1); color: #fff; }
.tabs button.active { background: rgba(255,255,255,.16); color: #fff; }
.tabs .ico { font-size: 15px; }
.me { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.me-label { opacity: .75; }
.me-btn {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2);
  color: #fff; border-radius: 999px; padding: 4px 12px 4px 4px; font-weight: 600;
}
.me-btn:hover { background: rgba(255,255,255,.2); }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--c, #888); color: #fff; font-size: 12px; font-weight: 700;
  flex: none; letter-spacing: .3px;
}
.avatar.sm { width: 20px; height: 20px; font-size: 10px; }

/* ---------- Main ---------- */
main { max-width: 1400px; margin: 0 auto; padding: 16px 20px 40px; }
.view-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.view-head h2 { font-size: 20px; }
.view-head .spacer { flex: 1; }
.hint { font-size: 13px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 14px;
  white-space: nowrap;
}
.btn:hover { background: #faf9f6; border-color: #cfcdc6; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #16294a; }
.btn.danger { color: var(--red); border-color: #f2c4cb; background: #fff5f6; }
.btn.danger:hover { background: #fde8eb; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 6px 9px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: 13px; }

/* ---------- Schedule ---------- */
.day-tabs {
  display: none; gap: 6px; margin: 0 -10px 12px; padding: 8px 10px;
  position: sticky; top: var(--topbar); z-index: 6; background: var(--bg);
}
.day-tabs button {
  flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 4px; font-weight: 600; font-size: 13px; line-height: 1.2;
}
.day-tabs button small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.day-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.day-tabs button.active small { color: rgba(255,255,255,.75); }

.calendar {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: clip;
}
.cal-head {
  display: grid; grid-template-columns: var(--gutter) repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
  position: sticky; top: var(--topbar); background: #fff; z-index: 5;
}
.cal-head .day-head {
  padding: 10px 8px; text-align: center; border-left: 1px solid var(--line-soft);
}
.cal-head .day-head b { display: block; font-size: 15px; }
.cal-head .day-head small { color: var(--muted); font-size: 12px; }
.cal-body {
  display: grid; grid-template-columns: var(--gutter) repeat(4, 1fr);
  overflow-x: hidden;
}
.gutter { position: relative; }
.gutter .h {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.day-col {
  position: relative; border-left: 1px solid var(--line-soft);
  background-image:
    linear-gradient(to bottom, var(--line-soft) 1px, transparent 1px),
    linear-gradient(to bottom, transparent calc(var(--hour) / 2 - 1px), #f6f5f1 calc(var(--hour) / 2 - 1px), #f6f5f1 calc(var(--hour) / 2), transparent calc(var(--hour) / 2));
  background-size: 100% var(--hour), 100% var(--hour);
  cursor: cell;
}
.day-col:hover { background-color: #fbfaf7; }

.ev {
  position: absolute; left: 0; right: 0; overflow: hidden;
  padding: 4px 6px 4px 8px; border-radius: 7px;
  background: color-mix(in srgb, var(--c, #888) 16%, #fff);
  border-left: 4px solid var(--c, #888);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c, #888) 20%, transparent);
  font-size: 12px; line-height: 1.25; cursor: pointer; user-select: none;
  transition: transform .08s, box-shadow .08s;
}
.ev:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.12), inset 0 0 0 1px color-mix(in srgb, var(--c, #888) 35%, transparent); z-index: 3; }
.ev .t { font-weight: 700; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .m { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .who { display: flex; gap: 2px; margin-top: 3px; flex-wrap: wrap; }
.ev .who .avatar { width: 16px; height: 16px; font-size: 8px; }
.ev.short { padding-top: 2px; padding-bottom: 2px; }
.ev.short .who, .ev.short .m { display: none; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); display: inline-block; }

/* ---------- Wishlist ---------- */
.people-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.people-filter button {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 4px 12px 4px 4px; font-weight: 600; font-size: 13px;
}
.people-filter button.active { background: var(--text); color: #fff; border-color: var(--text); }
.people-filter button.all { padding-left: 12px; }

.wish-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.wish-col {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 140px;
  border-top: 4px solid var(--c);
}
.wish-col header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.wish-col header b { flex: 1; font-size: 15px; }
.wish-col header .count { color: var(--muted); font-size: 12px; font-weight: 500; }
.wish-col ul { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.wish-col .empty { padding: 14px 12px; color: var(--muted); font-size: 13px; text-align: center; }
.wish {
  border: 1px solid var(--line-soft); border-radius: 9px; padding: 8px 10px; background: #fff;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: start;
}
.wish:hover { border-color: var(--line); background: #fdfcfa; }
.wish .main { cursor: pointer; min-width: 0; }
.wish .title { font-weight: 600; font-size: 14px; }
.wish .meta { color: var(--muted); font-size: 12px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.wish .meta a { color: var(--accent); text-decoration: none; }
.wish .meta a:hover { text-decoration: underline; }
.wish .tools { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.wish .vote, .wish .sched {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 3px 9px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.wish .vote.on { background: #fff3cd; border-color: #f0d27a; }
.wish .vote:hover, .wish .sched:hover { border-color: #bbb; }
.wish .sched.on { background: color-mix(in srgb, var(--accent) 10%, #fff); border-color: color-mix(in srgb, var(--accent) 35%, #fff); color: var(--accent); }
.wish .voters { grid-column: 1 / -1; display: flex; gap: 2px; }
.wish .voters .avatar { width: 16px; height: 16px; font-size: 8px; }
.wish.scheduled .title::before { content: "✓ "; color: #2a9d8f; }

/* ---------- Info ---------- */
.info-wrap { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 8px; }
.card ul { margin: 0; padding-left: 18px; font-size: 14px; }
.card li { margin: 4px 0; }
.info-text {
  width: 100%; min-height: 420px; resize: vertical;
  border: 0; outline: 0; padding: 0; font-size: 15px; line-height: 1.55;
  font-family: inherit; background: transparent;
}
.save-state { font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 13px; }
.stats div { background: #faf9f6; border-radius: 8px; padding: 8px 10px; }
.stats b { display: block; font-size: 20px; }

/* ---------- Dialogs ---------- */
.dlg {
  border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 24px));
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
}
.dlg.small { width: min(400px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(20, 25, 40, .5); backdrop-filter: blur(2px); }
.dlg form, .dlg > h2, .dlg > p, .dlg > .who-grid { padding: 0 20px; }
.dlg form { padding: 20px; }
.dlg > h2 { padding-top: 20px; }
.dlg > .who-grid { padding-bottom: 20px; }
.dlg h2 { font-size: 18px; margin-bottom: 4px; }
.dlg p.muted { margin: 0 0 12px; font-size: 14px; }
.dlg label, .dlg .field { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 12px; }
.dlg .field-label { display: block; margin-bottom: 6px; }
.dlg input, .dlg select, .dlg textarea {
  display: block; width: 100%; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
  background: #fff; font-size: 15px; font-weight: 400; color: var(--text);
}
.dlg input:focus, .dlg select:focus, .dlg textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, #fff); border-color: var(--accent); }
.dlg .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg .actions { display: flex; gap: 8px; margin-top: 20px; align-items: center; }
.dlg .actions .spacer { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px 3px 3px;
  cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text); background: #fff;
}
.chips label:has(input:checked) { background: color-mix(in srgb, var(--c) 14%, #fff); border-color: var(--c); }
.chips input { position: absolute; opacity: 0; width: 0; height: 0; margin: 0; }
.chip-tools { margin-top: 6px; font-size: 13px; font-weight: 400; }
.who-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.who-grid button {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 10px;
  font-weight: 600; font-size: 15px;
}
.who-grid button:hover { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, #fff); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  max-width: calc(100vw - 32px);
}
.toast.err { background: var(--red); }

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
  :root { --hour: 60px; --gutter: 42px; --topbar: 54px; }
  .topbar { padding: 0 12px; gap: 12px; }
  .brand .flag { font-size: 24px; }
  .brand h1 { font-size: 16px; }
  .brand .sub { font-size: 11px; }
  .me-label { display: none; }
  .me-btn { padding-right: 8px; font-size: 12px; }
  .me-btn #me-name { max-width: 70px; overflow: hidden; text-overflow: ellipsis; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0;
    background: #fff; border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; z-index: 20;
  }
  .tabs button { flex-direction: column; gap: 2px; color: var(--muted); padding: 4px 16px; font-size: 11px; }
  .tabs button.active { background: transparent; color: var(--accent); }
  .tabs button:hover { background: transparent; }
  .tabs .ico { font-size: 20px; }
  main { padding: 12px 10px calc(80px + env(safe-area-inset-bottom)); }
  .view-head h2 { font-size: 18px; }
  .day-tabs { display: flex; }
  .cal-head { display: none; }
  .cal-head, .cal-body { grid-template-columns: var(--gutter) 1fr; }
  .day-col:not(.active) { display: none; }
  .hint { display: none; }
  .people-filter { flex-wrap: nowrap; overflow-x: auto; margin: 0 -10px 12px; padding: 0 10px 4px; scrollbar-width: none; }
  .people-filter button { flex: none; }
  .wish-grid { grid-template-columns: 1fr; }
  .wish-col { min-height: 0; }
  .wish-col.hide { display: none; }
  .info-wrap { grid-template-columns: 1fr; }
  .info-text { min-height: 300px; }
  .dlg { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 14px 14px 0 0; }
  .dlg .row { grid-template-columns: 1fr 1fr; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .legend { display: none; }
}
@media (min-width: 768px) and (max-width: 1100px) {
  .wish-grid { grid-template-columns: repeat(2, 1fr); }
}
