:root {
  --bg: #f7f5ef;
  --card: #ffffff;
  --ink: #2b2a26;
  --muted: #8a857a;
  --line: #e7e3d8;
  --accent: #c8743a;
  --accent-ink: #ffffff;
  --danger: #c0473b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 6px 18px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; }

/* ---------- Login ---------- */
.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-emoji { font-size: 44px; }
.login-card h1 { margin: 6px 0 2px; font-size: 1.5rem; }
.login-card input {
  width: 100%;
  margin: 18px 0 12px;
  padding: 14px;
  font-size: 1.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf6;
}
.login-card button {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- App shell ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(247, 245, 239, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 8px;
}
.brand { font-weight: 700; font-size: 1.15rem; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  padding: 6px;
}
.danger-link { color: var(--danger); }

/* ---------- Toolbar (search + groups) ---------- */
.toolbar {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 14px 10px;
}
.search-wrap { margin-bottom: 8px; }
.search {
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
}
.search::placeholder { color: var(--muted); }

.group-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.group-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  flex: 1;
  min-width: 0;
}
.group-bar::-webkit-scrollbar { display: none; }
.group-tools {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.group-tools .link-btn { font-size: 0.82rem; padding: 4px 4px; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.9rem;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.chip-count {
  font-size: 0.72rem;
  background: var(--bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}
.chip.active .chip-count {
  background: rgba(255, 255, 255, 0.25);
  color: var(--accent-ink);
}
.chip-add { color: var(--accent); border-style: dashed; }

/* Group chips inside the editor sheet */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.chip-row:empty { display: none; }

.feed {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px calc(100px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 18vh;
  padding: 0 30px;
}

/* ---------- Note card ---------- */
.note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.note-body { white-space: pre-wrap; word-break: break-word; }
.note-body.empty-body { display: none; }

.note-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.note-photos img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: #eee;
}

.note-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.note-date { font-size: 0.78rem; color: var(--muted); }
.note-tag {
  font-size: 0.72rem;
  color: var(--accent);
  background: rgba(200, 116, 58, 0.1);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}
.note-tools {
  display: flex;
  flex-shrink: 0;
}
.note-tools button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 6px 8px;
}
.note-tools .del { color: var(--danger); }

/* ---------- Move-to-group picker ---------- */
.move-list {
  display: flex;
  flex-direction: column;
  margin-top: 4px;
  max-height: 60vh;
  overflow-y: auto;
}
.move-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 6px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  text-align: left;
}
.move-item:last-child { border-bottom: none; }
.move-item.checked { color: var(--accent); font-weight: 600; }
.move-check { color: var(--accent); font-weight: 700; }
.move-add { color: var(--accent); }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(200, 116, 58, 0.45);
  z-index: 6;
}

/* ---------- Sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
}
.sheet-card {
  width: 100%;
  max-width: 640px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 600;
}
#noteBody {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  background: #fbfaf6;
  resize: vertical;
  min-height: 96px;
}
.thumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.thumb-row:empty { display: none; }
.thumb {
  position: relative;
  width: 72px;
  height: 72px;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}
.thumb .x {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  line-height: 22px;
  padding: 0;
}
.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}
.photo-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-weight: 600;
  padding: 10px 4px;
}
.primary {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 1rem;
}
.primary:disabled { opacity: 0.5; }

/* ---------- Viewer ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.92);
  display: grid;
  place-items: center;
  padding: 16px;
}
.viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
