:root {
  --title-bar-height: 3rem;
  --unassigned-width: 16rem;
  --ink: #1d2021;
  --paper: #fbf9f4;
  --line: #d9d2c5;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#title-bar {
  height: var(--title-bar-height);
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

#title-bar h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  align-self: center;
}

/* The tab strip sits between the title bar and the workspace, so every tab is
   one click away and the one being shown carries its controls. */
#tab-strip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
  overflow-x: auto;
}

#tab-list {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.15rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--paper);
  white-space: nowrap;
}

.tab.viewing {
  border-color: #8a8070;
  background: #fff;
  box-shadow: 0 1px 2px rgb(29 32 33 / 0.08);
}

.tab-name {
  font: inherit;
  padding: 0.15rem 0.25rem;
  border: 0;
  color: var(--ink);
  background: none;
  cursor: pointer;
}

/* The current tab is the real arrangement, so the strip says which one it is. */
.tab.is-current .tab-name {
  font-weight: 600;
}

.current-marker {
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6b6357;
}

/* The tab's actions live behind ⋯ so the strip stays a strip of names. The
   menu itself is placed against the window by the page, because the strip
   scrolls sideways and would otherwise clip it. */
.tab-controls-toggle {
  font: inherit;
  line-height: 1;
  padding: 0.15rem 0.3rem;
  border: 0;
  border-radius: 0.2rem;
  color: #6b6357;
  background: none;
  cursor: pointer;
}

.tab-controls-toggle:hover,
.tab-controls-toggle[aria-expanded="true"] {
  color: var(--ink);
  background: #f1ece1;
}

/* display: flex would otherwise beat the hidden attribute's display: none. */
.tab-controls-menu[hidden] {
  display: none;
}

.tab-controls-menu {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 9rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: #fff;
  box-shadow: 0 4px 14px rgb(29 32 33 / 0.18);
}

.tab-control {
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  text-align: left;
  padding: 0.4rem 0.5rem;
  border: 0;
  border-radius: 0.2rem;
  color: var(--ink);
  background: none;
  cursor: pointer;
}

.tab-control:hover:not(:disabled) {
  background: #f1ece1;
}

.tab-control:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tab-rename {
  font: inherit;
  width: 10rem;
  padding: 0.15rem 0.25rem;
  border: 1px solid var(--line);
  border-radius: 0.2rem;
}

#new-tab {
  flex: none;
  font: inherit;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--paper);
  cursor: pointer;
}

#new-tab:hover {
  background: #f1ece1;
}

#workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

#unassigned {
  width: var(--unassigned-width);
  flex: none;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: #fff;
  overflow-y: auto;
}

/* The heading sits under the Add person button and directly over the names,
   with a rule under it, so it reads as the label of the list below it. */
#unassigned h2 {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b6357;
  margin: 0 0 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
}

#unassigned-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--paper);
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
  /* Every gesture on the canvas is the page's own: a drag pans, a pinch
     zooms, so the browser must neither scroll nor select anything itself. */
  touch-action: none;
  user-select: none;
  cursor: grab;
}

#canvas.panning {
  cursor: grabbing;
}

/* A meeting is not the background, so pressing it does not offer to pan; its
   title bar and its chips keep the grab cursor of their own drags. */
.meeting {
  cursor: auto;
}

/* The single transformed container: pan and zoom change the two custom
   properties below, nothing else. */
#canvas-transform {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  transform: translate(var(--pan-x, 0px), var(--pan-y, 0px)) scale(var(--zoom, 1));
}

/* The view controls: a small cluster in the corner, outside the transformed
   container so they stay put while the canvas moves under them. */
#canvas-controls {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 10;
  display: flex;
  gap: 0.25rem;
}

#canvas-controls button {
  font: inherit;
  line-height: 1;
  min-width: 2rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 2px rgb(29 32 33 / 0.12);
}

#canvas-controls button:hover {
  background: #f1ece1;
}

#add-meeting,
#auto-arrange {
  align-self: center;
  font: inherit;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--paper);
  cursor: pointer;
}

/* The first of the pair is what pushes both to the far end of the bar. */
#add-meeting {
  margin-left: auto;
}

#add-meeting:hover,
#auto-arrange:hover {
  background: #f1ece1;
}

/* A home meeting is a free-floating box; --x and --y are its shared position
   in canvas coordinates, written by the drag and saved through the API. */
.meeting {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(var(--x, 0px), var(--y, 0px));
  width: 17rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: #fff;
  box-shadow: 0 1px 2px rgb(29 32 33 / 0.08);
}

.meeting.dragging {
  box-shadow: 0 6px 16px rgb(29 32 33 / 0.18);
}

.meeting-title-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
  border-radius: 0.4rem 0.4rem 0 0;
  background: #f5f1e8;
  cursor: grab;
  /* The browser must not scroll or select while a finger drags the box. */
  touch-action: none;
  user-select: none;
}

.meeting.dragging .meeting-title-bar {
  cursor: grabbing;
}

.meeting-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: none;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  color: #6b6357;
  background: #fff;
}

.meeting-settings {
  flex: none;
  border: 0;
  padding: 0 0.1rem;
  font-size: 0.9rem;
  line-height: 1;
  color: #6b6357;
  background: none;
  cursor: pointer;
}

/* What a meeting says before it is opened: how many people it involves, and
   the first words of its notes. */
.meeting-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--line);
  background: #fdfcf9;
}

.involved-count {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #4a443b;
}

.also-count {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: #6b6357;
}

.meeting-notes {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: #6b6357;
}

.host-section,
.member-section {
  padding: 0.5rem;
}

/* The host section is the meeting's home, so it is tinted apart from the
   members below it rather than told apart by its heading alone. */
.host-section {
  background: #f7f3ea;
}

.member-section {
  border-top: 1px dashed var(--line);
}

.host-section h3,
.member-section h3 {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b6357;
  margin: 0 0 0.35rem;
}

/* How many homes host the meeting, beside the word Hosts. */
.host-count {
  display: inline-block;
  min-width: 1.15rem;
  padding: 0 0.3rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
  color: #4a443b;
  background: #e7dfcf;
  border-radius: 0.6rem;
}

.people {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 1.5rem;
}

#meeting-dialog {
  width: min(26rem, 90vw);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 1rem;
  color: var(--ink);
  background: #fff;
}

#meeting-dialog::backdrop {
  background: rgb(29 32 33 / 0.3);
}

#meeting-dialog h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

#meeting-dialog label {
  display: block;
  font-size: 0.8rem;
  color: #6b6357;
  margin: 0.75rem 0 0.25rem;
}

#meeting-dialog select,
#meeting-dialog textarea {
  width: 100%;
  font: inherit;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--paper);
}

#meeting-dialog menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0 0;
  padding: 0;
}

#meeting-dialog menu .spacer {
  flex: 1;
}

#meeting-dialog button {
  font: inherit;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--paper);
  cursor: pointer;
}

#meeting-dialog button.danger {
  color: #8f2f2f;
  border-color: #e0c3c3;
}

/* The sign-out control sits at the far end of the title bar, after the
   Add meeting button, which is the one that pushes the pair to that end. */
#logout {
  margin: 0 0 0 0.5rem;
  align-self: center;
}

#logout button {
  font: inherit;
  color: #6b6357;
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  cursor: pointer;
}

#logout button:hover {
  color: var(--ink);
  border-color: #b8ae9d;
}

/* The login page is the one screen shown before any data loads. */
.login-page {
  display: block;
  overflow: auto;
}

#login {
  max-width: 22rem;
  margin: 12vh auto;
  padding: 1.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

#login h1 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}

.login-intro {
  margin: 0 0 1.25rem;
  color: #6b6357;
}

.login-error {
  margin: 0 0 1rem;
  padding: 0.6rem 0.75rem;
  border-radius: 4px;
  color: #7b241c;
  background: #fdecea;
}

#login label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b6357;
}

#login input {
  width: 100%;
  font: inherit;
  padding: 0.45rem 0.6rem;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
}

#login input:focus {
  outline: 2px solid #8a7f6b;
  outline-offset: 1px;
}

#login button {
  font: inherit;
  width: 100%;
  padding: 0.5rem;
  color: var(--paper);
  background: var(--ink);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#login button:hover {
  background: #33393b;
}

#add-person {
  width: 100%;
  margin-bottom: 1.25rem;
  padding: 0.35rem;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 0.4rem;
  cursor: pointer;
}

#add-person:hover {
  border-style: solid;
}

#unassigned-list li + li {
  margin-top: 0.35rem;
}

.chip {
  display: block;
  width: 100%;
  padding: 0.3rem 0.5rem;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  cursor: pointer;
}

.chip:hover {
  background: var(--paper);
}

/* Somebody whose home meeting is elsewhere: drawn faintly so the eye reads the
   meeting's own people first, and marked "also" so faintness alone is never
   what has to be noticed. */
.chip.ghost {
  border-style: dashed;
  background: transparent;
  color: #6b6357;
}

.also-marker {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6b6357;
  border: 1px dashed var(--line);
  border-radius: 0.6rem;
  padding: 0 0.35rem;
  vertical-align: 0.05rem;
}

.also-remove {
  float: right;
  padding: 0 0.15rem;
  line-height: 1.2;
  color: #6b6357;
}

.also-remove:hover {
  color: #a03b2f;
}

.child-marker {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6b6357;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0 0.35rem;
  vertical-align: 0.05rem;
}

#person-dialog {
  min-width: 18rem;
  padding: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

#person-dialog h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

#person-dialog label {
  display: block;
  margin-bottom: 0.6rem;
  color: #6b6357;
}

#person-dialog label.checkbox {
  color: var(--ink);
}

#person-dialog input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.3rem 0.4rem;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
}

#person-error {
  margin: 0 0 0.6rem;
  color: #a03b2f;
}

#person-dialog menu {
  display: flex;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
}

#person-dialog menu button {
  font: inherit;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: #fff;
  cursor: pointer;
}

#person-dialog #person-save {
  margin-left: auto;
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

#person-dialog #person-delete {
  color: #a03b2f;
}

/* A chip or a family box is dragged as one unit. While it moves it follows the
   pointer through --drag-x and --drag-y and stops answering hit tests, so the
   drop target underneath it can be found. */
.draggable {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.draggable .chip {
  cursor: grab;
}

.draggable.dragging {
  position: relative;
  z-index: 5;
  transform: translate(var(--drag-x, 0px), var(--drag-y, 0px));
  pointer-events: none;
  opacity: 0.9;
  box-shadow: 0 6px 16px rgb(29 32 33 / 0.18);
}

/* An Alt-drag with a mouse, or a drag begun with a long press on a touch
   screen, adds an also-attends link instead of moving anybody, so it is drawn
   as the ghost chip it is about to become. */
.draggable.linking {
  opacity: 0.6;
}

/* The Unassigned panel or the section a drop would land in. */
.drop-target {
  outline: 2px dashed #6b6357;
  outline-offset: -2px;
  background: #f5f1e8;
}

/* A family is drawn as one rounded box around its members; the chips inside
   stay separate buttons. Each family has its own hue, written on the box by
   the page, so a family reads as one group at a glance and the same family is
   the same colour wherever it sits. The band down the side carries the colour
   at full strength; the fill stays pale so the names on it keep their
   contrast. */
.family {
  padding: 0.3rem;
  border: 1px solid hsl(var(--family-hue, 40) 42% 62%);
  border-left: 6px solid hsl(var(--family-hue, 40) 52% 34%);
  border-radius: 0.6rem;
  background: hsl(var(--family-hue, 40) 60% 87%);
}

.family .chip + .chip {
  margin-top: 0.3rem;
}

#person-family {
  margin-bottom: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
}

#person-family h3 {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b6357;
  margin: 0 0 0.4rem;
}

#family-members,
#family-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

#family-members li + li,
#family-results li + li {
  margin-top: 0.3rem;
}

#family-none {
  margin: 0;
  color: #6b6357;
}

#family-unlink {
  margin-top: 0.4rem;
  padding: 0.2rem 0.6rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  cursor: pointer;
}

#family-results {
  margin-top: 0.3rem;
}

#person-also-attends {
  margin-bottom: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
}

#person-also-attends h3 {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b6357;
  margin: 0 0 0.4rem;
}

#also-attends-list,
#also-attends-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

#also-attends-list li + li,
#also-attends-results li + li {
  margin-top: 0.3rem;
}

#also-attends-none {
  margin: 0;
  color: #6b6357;
}

#also-attends-results {
  margin-top: 0.3rem;
}

.also-attends-remove {
  padding: 0.1rem 0.5rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  cursor: pointer;
}
