:root {
  --bg: #FBF3E9;
  --surface: #FFFFFF;
  --text: #2E2A26;
  --muted: #8A8378;
  --border: #EADFCF;
  --primary: #C1673E;
  --primary-dark: #A34F2E;
  --request: #D97706;
  --available: #4C8C6B;
  --accepted: #6B8CAE;
  --danger: #B4544A;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { margin: 0; }
p { margin: 0 0 .5rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* ---------- Onboarding ---------- */
#screen-onboarding {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.onboard-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
.onboard-card h1 { font-size: 1.6rem; color: var(--primary-dark); margin-bottom: .4rem; }
.lead { color: var(--muted); margin-bottom: 1.25rem; }
.field-label { font-weight: 600; font-size: .85rem; margin: 1rem 0 .4rem; color: var(--text); }

input[type="text"], input[type="date"], input[type="time"], textarea {
  width: 100%;
  padding: .65rem .8rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
textarea { resize: vertical; }

.swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.swatch-grid button {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  font-size: 1.3rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  cursor: pointer;
}
.swatch-grid button.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(193,103,62,.25);
}
.swatch-grid button[data-color] { background: var(--sw-color, var(--bg)); }

.btn-primary {
  width: 100%;
  margin-top: 1.5rem;
  padding: .85rem;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary:not(:disabled):active { background: var(--primary-dark); }

.btn-secondary {
  padding: .6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--primary-dark);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-danger-link {
  margin-top: 1.5rem;
  background: none;
  border: none;
  color: var(--danger);
  text-decoration: underline;
  cursor: pointer;
  font-size: .9rem;
  padding: 0;
}

/* ---------- Main ---------- */
#screen-main { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.3rem; color: var(--primary-dark); }
.me-chip {
  display: flex; align-items: center; gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .3rem .8rem .3rem .3rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  font-size: .9rem;
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

#feed-wrap { flex: 1; padding: .5rem 1rem 6rem; max-width: 640px; width: 100%; margin: 0 auto; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }

.date-heading {
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 1.4rem 0 .5rem;
}
.date-heading:first-child { margin-top: .8rem; }

.entry-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: .9rem 1rem;
  margin-bottom: .6rem;
  display: flex;
  gap: .75rem;
}
.entry-card.poll-yes { border-color: var(--available); }
.entry-card.poll-no { border-color: var(--danger); }
.entry-card .avatar { width: 38px; height: 38px; font-size: 1.2rem; }
.entry-body { flex: 1; min-width: 0; }
.entry-top { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.entry-name { font-weight: 700; }
.entry-time { color: var(--muted); font-size: .88rem; }
.entry-badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  padding: .15rem .55rem;
  border-radius: 999px;
  margin-top: .3rem;
}
.entry-badge.request { background: color-mix(in srgb, var(--request) 16%, white); color: var(--request); }
.entry-badge.available { background: color-mix(in srgb, var(--available) 16%, white); color: var(--available); }
.entry-badge.accepted { background: color-mix(in srgb, var(--accepted) 18%, white); color: var(--accepted); }
.entry-note { margin-top: .4rem; font-size: .92rem; }
.entry-actions { margin-top: .6rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.entry-actions button {
  border: none;
  border-radius: 10px;
  padding: .45rem .8rem;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-accept { background: var(--available); color: #fff; }
.btn-undo { background: var(--bg); color: var(--text); border: 1px solid var(--border) !important; }
.btn-delete { background: var(--bg); color: var(--danger); border: 1px solid var(--border) !important; }
.accepted-line { font-size: .85rem; color: var(--accepted); margin-top: .4rem; font-weight: 600; }

.poll-summary { font-size: .82rem; color: var(--muted); margin-top: .5rem; }
.btn-kan, .btn-kan-ikke { background: var(--bg); color: var(--text); border: 1px solid var(--border) !important; }
.btn-kan.active { background: var(--available); border-color: var(--available) !important; color: #fff; }
.btn-kan-ikke.active { background: var(--danger); border-color: var(--danger) !important; color: #fff; }

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  width: 58px; height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(163,79,46,.4);
  cursor: pointer;
  z-index: 6;
}

/* ---------- Overlay sheets (compose / settings) ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.icon-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); }

.type-toggle { display: flex; gap: .5rem; margin-top: 1rem; }
.type-btn {
  flex: 1;
  padding: .7rem .5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
}
.type-btn.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, white); }

.checkbox-row { display: flex; align-items: center; gap: .5rem; margin-top: 1rem; font-weight: 600; font-size: .92rem; }
.checkbox-row input { width: 18px; height: 18px; }

.time-fields { display: flex; gap: .75rem; margin-top: .5rem; }
.time-fields > div { flex: 1; }

.code-row { display: flex; gap: .5rem; align-items: center; }
.code-row input { flex: 1; }
.code-pill {
  flex: 1;
  font-weight: 700;
  letter-spacing: .03em;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: .6rem .8rem;
  text-align: center;
}

.following-list { list-style: none; margin: .5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.following-list li {
  display: flex; align-items: center; gap: .6rem;
  background: var(--bg);
  border-radius: 12px;
  padding: .4rem .6rem;
}
.following-list .avatar { width: 30px; height: 30px; font-size: 1rem; }
.following-list .fname { flex: 1; font-weight: 600; }
.unfollow-x { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: .2rem .4rem; }

hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0 0; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: .6rem 1.1rem;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 20;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
