:root {
  --paper: #F2F4EF;
  --card: #FFFFFF;
  --ink: #262E27;
  --ink-soft: #697065;
  --blue: #4C5FD5;
  --coral: #FF6F61;
  --line: rgba(105, 112, 101, 0.18);
  --radius: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.loading { color: var(--ink-soft); text-align: center; margin-top: 40vh; }

/* ---------- home ---------- */
.home { padding: 28px 20px 24px; }
.home h1 { font-size: 26px; font-weight: 600; margin: 0; }
.home .sub { font-size: 14px; color: var(--ink-soft); margin: 2px 0 16px; }
.empty { color: var(--ink-soft); font-size: 13px; margin: 0 0 16px; line-height: 1.45; }
.cal-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: var(--card); border-radius: var(--radius);
  padding: 12px 8px 12px 14px; margin-bottom: 10px;
}
.avatar {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700;
}
.avatar.sm { width: 22px; height: 22px; font-size: 11px; }
.cal-row .text { flex: 1; min-width: 0; }
.cal-row .label { font-weight: 600; font-size: 15px; }
.cal-row .meta { font-size: 11px; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex: none;
}
.icon-btn:hover { background: rgba(38, 46, 39, 0.06); }
.icon-btn svg { width: 22px; height: 22px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 50px; border-radius: 10px; font-weight: 600; font-size: 15px;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.outline { border: 1.5px solid var(--line); color: var(--blue); background: transparent; }
.btn.danger { background: rgba(255, 111, 97, 0.1); color: var(--coral); height: 46px; font-size: 14px; }
.btn.small { height: 46px; font-size: 14px; }
.btn + .btn { margin-top: 10px; }
.install-tip {
  margin-top: 22px; padding: 14px; background: var(--card); border-radius: var(--radius);
  font-size: 13px; color: var(--ink-soft); line-height: 1.45;
}
.install-tip p { margin: 0 0 10px; }
.install-tip b { color: var(--ink); }
.install-tip .row { display: flex; align-items: center; gap: 6px; }
.install-tip .btn { width: auto; height: 40px; padding: 0 20px; }
.link-btn { padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 13px; color: var(--ink-soft); }
.link-btn:hover { background: rgba(38, 46, 39, 0.06); }

/* ---------- calendar header ---------- */
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 8px 10px 8px; gap: 6px;
}
.cal-head .left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cal-head .back { margin-left: 4px; }
.pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 999px; padding: 8px 12px;
  font-size: 13px; font-weight: 600; min-width: 0;
}
.pill .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 11px; color: var(--ink-soft); padding: 8px 10px; gap: 6px; flex: none; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.toggle { display: flex; justify-content: center; gap: 8px; padding: 0 16px 8px; }
.toggle button {
  padding: 7px 18px; border-radius: 20px; background: var(--card);
  color: var(--ink-soft); font-size: 12px; font-weight: 600;
}
.toggle button.on { background: var(--blue); color: #fff; }

/* ---------- month ---------- */
.month-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 6px 18px;
}
.month-head h2 { font-size: 22px; font-weight: 600; margin: 0; }
.month-head .nav { display: flex; }
.today-btn { font-size: 12px; font-weight: 600; color: var(--blue); padding: 0 10px; height: 44px; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); padding: 0 12px; }
.weekdays span { text-align: center; font-size: 11px; font-weight: 700; color: var(--ink-soft); }
.grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px;
  padding: 12px; touch-action: pan-y;
}
.day {
  position: relative; aspect-ratio: 0.85; background: var(--card);
  border-radius: 10px; overflow: hidden; text-align: left;
}
.day.out { opacity: 0.45; }
@media (hover: hover) { .day:hover { box-shadow: inset 0 0 0 1.5px rgba(76, 95, 213, 0.35); } }
.day .num {
  position: absolute; top: 5px; left: 5px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.day.today .num { background: var(--blue); color: #fff; }
.day .notes-ind { position: absolute; top: 6px; right: 6px; width: 22%; opacity: 0.45; }
.bars {
  position: absolute; left: 4px; right: 4px; bottom: 5px;
  display: flex; flex-direction: column; gap: 3px;
}
.bar { height: 7px; }
.more { font-size: 8px; font-weight: 700; color: var(--ink-soft); text-align: center; line-height: 1; }

/* ---------- agenda ---------- */
.agenda { padding: 0 16px 24px; }
.agenda h3 {
  font-size: 13px; font-weight: 700; color: var(--ink-soft);
  margin: 14px 0 6px; cursor: pointer;
}
.agenda-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border-radius: 10px; padding: 10px; margin-bottom: 8px;
}
.agenda-item .t { flex: 1; min-width: 0; }
.agenda-item .title { font-weight: 700; font-size: 14px; }
.agenda-item .notes { font-size: 12px; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agenda-item .time { font-size: 12px; font-weight: 600; flex: none; }

/* ---------- overlays: sheets and dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(20, 24, 21, 0.38);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s ease-out;
}
.overlay.dialog-wrap { align-items: center; padding: 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
  animation: rise 0.18s ease-out;
}
@media (min-width: 640px) {
  .overlay:not(.dialog-wrap) { align-items: center; padding: 20px; }
  .sheet { border-radius: 22px; }
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 0 12px; position: sticky; top: -10px; background: var(--paper); z-index: 1;
}
.sheet-head h2 { font-size: 18px; font-weight: 600; margin: 0; }
.sheet-head .actions { display: flex; }
.dialog {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 22px;
  padding: 22px 22px 12px; animation: rise 0.18s ease-out;
}
.dialog h2 { font-size: 20px; font-weight: 600; margin: 0 0 12px; }
.dialog p { font-size: 13px; color: var(--ink-soft); margin: 0 0 12px; line-height: 1.45; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 8px; }
.text-btn { padding: 12px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--blue); }
.text-btn:hover { background: rgba(76, 95, 213, 0.08); }
.text-btn.danger { color: var(--coral); }
.field {
  display: block; width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--card); padding: 12px 14px; font-size: 16px; margin-bottom: 8px;
  outline: none;
}
.field:focus { border-color: var(--blue); }
textarea.field { resize: vertical; min-height: 70px; }
.caps { font-size: 11px; font-weight: 700; color: var(--ink-soft); letter-spacing: 0.02em; margin: 0 0 6px; }
.divider { height: 1px; background: var(--line); margin: 22px 0; }
.code-row {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: var(--card); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px;
}
.code-row .code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 16px; font-weight: 700; }
.code-row .copy { font-size: 11px; font-weight: 700; color: var(--ink-soft); }

/* ---------- day sheet ---------- */
.form-card { background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 14px; }
.form-card .editing { font-size: 11px; color: var(--ink-soft); margin: 0 0 8px; }
.span-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--paper); border-radius: 10px; padding: 8px 12px; margin: 2px 0 10px;
}
.span-row .caps { font-size: 10px; margin: 0; }
.span-row .val { font-size: 12px; }
.stepper { display: flex; align-items: center; }
.stepper button {
  width: 34px; height: 34px; border-radius: 50%; background: var(--card);
  color: var(--blue); font-weight: 700; font-size: 18px;
}
.stepper span { min-width: 36px; text-align: center; font-weight: 700; font-size: 14px; }
.entry {
  border-radius: 12px; padding: 12px; margin-bottom: 10px; cursor: pointer;
}
.entry .top { display: flex; justify-content: space-between; align-items: center; }
.entry .author { font-size: 12px; font-weight: 700; opacity: 0.75; }
.entry .right { display: flex; align-items: center; gap: 2px; }
.entry .time { font-size: 11px; font-weight: 600; opacity: 0.65; }
.entry .del { width: 32px; height: 32px; opacity: 0.5; }
.entry .del svg { width: 17px; height: 17px; }
.entry .title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.entry .title svg { width: 12px; opacity: 0.55; }
.entry .span { font-size: 11px; font-weight: 600; opacity: 0.6; margin-top: 1px; }
.entry .notes { font-size: 13px; opacity: 0.78; margin-top: 2px; white-space: pre-wrap; }
.entry .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.45); border-radius: 8px; padding: 7px 10px;
  font-size: 12px; font-weight: 600; opacity: 0.9;
}
.chip svg { width: 16px; height: 16px; }
.chip.muted { opacity: 0.6; cursor: default; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; font-size: 13px; font-weight: 600;
  padding: 10px 16px; border-radius: 999px; transition: all 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- notes & checklists ---------- */
.sheet.tall { min-height: 70vh; min-height: 70dvh; max-height: 94vh; max-height: 94dvh; }
.notes-date { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.notes-title { font-size: 21px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.note-card { background: var(--card); border-radius: var(--radius); padding: 14px 14px 12px 16px; margin-bottom: 10px; }
.note-top { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.type-pill {
  flex: none; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 6px;
  background: rgba(105, 112, 101, 0.1);
  background: color-mix(in srgb, currentColor 12%, transparent);
}
.note-heading-wrap { flex: 1; min-width: 0; }
.note-heading { display: block; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-ctl { display: flex; align-items: center; flex: none; }
.note-ctl .del { width: 34px; height: 34px; color: var(--ink-soft); }
.note-ctl .del svg { width: 18px; height: 18px; }
.text-btn.small { font-size: 12px; padding: 8px 10px; }
.author-line { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--ink-soft); margin-top: 2px; }
.author-line .dot { width: 8px; height: 8px; }
.note-body { font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; border-radius: 8px; margin: -4px; padding: 4px; }
.note-body:hover { background: rgba(38, 46, 39, 0.04); }
.note-body.placeholder { color: var(--ink-soft); font-size: 12px; }
.field.compact { padding: 9px 12px; font-size: 15px; margin-bottom: 0; }
.field-error { color: var(--coral); font-size: 12px; margin: -4px 0 8px; }

.items { display: flex; flex-direction: column; gap: 2px; }
.item {
  display: flex; align-items: center; gap: 4px; background: var(--card); border-radius: 8px;
  padding: 3px 0; transition: transform 0.15s ease;
}
.item.dragging { transition: none; position: relative; z-index: 2; box-shadow: 0 6px 18px rgba(38, 46, 39, 0.18); }
.handle {
  flex: none; width: 28px; height: 36px; display: grid; place-items: center;
  color: var(--ink-soft); opacity: 0.6; cursor: grab; touch-action: none;
}
.handle svg { width: 10px; height: 16px; }
.handle.off { cursor: default; }
.item.dragging .handle { cursor: grabbing; }
.check { flex: none; width: 20px; height: 20px; margin: 0 6px 0 2px; accent-color: var(--blue); cursor: pointer; }
.item-text { flex: 1; min-width: 0; font-size: 14px; padding: 6px 4px; cursor: pointer; overflow-wrap: anywhere; }
.item.done .item-text > div:first-child { text-decoration: line-through; color: var(--ink-soft); }
.item .by { font-size: 10px; color: var(--ink-soft); margin-top: 1px; }
.claim {
  flex: none; display: flex; align-items: center; gap: 4px;
  background: var(--paper); color: var(--ink-soft); border-radius: 20px;
  padding: 6px 10px; font-size: 11px; font-weight: 600; max-width: 40%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.claim.on { background: rgba(76, 95, 213, 0.15); color: var(--blue); }
.claim.locked { cursor: default; }
.claim .x { font-size: 13px; font-weight: 700; }
.add-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.add-row .field { flex: 1; }
.add-item-row { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.add-item-row .field { flex: 1; }
.add-item-row .icon-btn { width: 36px; height: 36px; color: var(--ink-soft); }
.add-item-row .icon-btn svg { width: 16px; height: 16px; }
.dialog .toggle button { background: var(--paper); }
.dialog .toggle button.on { background: var(--blue); color: #fff; }
.dialog { max-height: 90vh; max-height: 90dvh; overflow-y: auto; }
