/* Sidebar tree: Remotekiddy stations, eggs, per-target chats, and the
   laid-egg modal. Layout of the panel itself lives in style.css.

   Every surface is bordered and square. The group headers carry a picture
   behind their left edge (the art from version 0), fading out along a diagonal.
   The fade is a dither baked into the picture by `make art` — see
   internal/artgen — not a mask, because a mask would blend it into flat grey. */

/* The panel is a column of rows, and every row's height is a share of one number: an
   accordion head is six times it, a machine and the button that starts a chat five, a chat
   four, and the foot at the bottom five. One number, so that "shorter" means the same thing
   everywhere in the panel — including in the squares in the foot, which are as tall as the
   row they stand in and as wide as they are tall. */
#sidebar {
  --row: 10px;
}

.tree {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* The accordions butt up against each other and against the panel edges:
     one stack, not floating cards. The only lines are the separators. Nothing is
     indented: every row in the panel starts at the same left edge, so the stack
     reads as one list and the nesting is the target it is under. */
  padding: 0;
}

.group {
  border-top: 1px solid var(--border);
}

/* ── group headers ─────────────────────────────────────────────────────── */

.group-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  /* the art occupies the left band; the label starts clear of it and the fade
     runs on underneath for the rest of the header */
  padding: 0 10px 0 62px;
  min-height: calc(var(--row) * 6);
  border: 0;
  background: var(--panel-2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  text-align: left;
  overflow: hidden;
}

.group-head:hover {
  background: var(--hover);
}

/* group-art is the picture: left side, behind the text. Each one is baked at
   its own on-screen size by `make art`, and shown at that size here — a 1-bit
   dither only stays a dither while nothing scales it. */
.group-head .group-art {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 112px;
  background-repeat: no-repeat;
  pointer-events: none;
}

.group-head > :not(.group-art) {
  position: relative;
  z-index: 1;
}

/* A nest for the nest's own chats, a hen for the stations, an egg for the eggs.
   Each is 1:1 with its baked pixels and pinned to whole-pixel offsets, so the
   pattern lands on the screen grid exactly as it was rendered. The offsets centre
   each picture in the head it sits in — the head is one row tall, whatever that is. */
.group[data-group="ask"] .group-art {
  background-image: url("/art/nest-44.png");
  background-position: 16px 8px;
  background-size: 44px 44px;
  image-rendering: pixelated;
}

.group[data-group="remote"] .group-art {
  background-image: url("/art/chicken-54.png");
  background-position: 8px 3px;
  background-size: 54px 54px;
  /* Never smoothed: at a device pixel ratio of 2 the pattern has to come out
     as 2x2 blocks rather than as the grey blur it replaced. */
  image-rendering: pixelated;
}

.group[data-group="eggs"] .group-art {
  background-image: url("/art/egg-38.png");
  background-position: 16px 11px;
  background-size: 38px 38px;
  image-rendering: pixelated;
}

.group-head .group-name {
  flex: 0 0 auto;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

/* ── icons ────────────────────────────────────────────────────────────── */

/* Phosphor, drawn at the size of the words it sits beside. It fills with
   currentColor, so an icon is the colour of the line it is in, and nothing here
   sets one. */
.icon {
  flex: none;
  display: block;
}

/* The arrow's place is at least as wide as the arrow, whether or not there is an arrow in it: a
   row that cannot be unfolded is given the place and not the arrow — an arrow that does nothing
   is a promise the row cannot keep — so a place that closed up when the arrow was away would
   slide the badge in front of it out past the badges on the rows that have one, and the column
   of badges down the panel would be a column of badges and gaps. `min-width` rather than `width`
   because it does both jobs: it holds the place open when there is nothing in it, and it is the
   floor a flex item cannot be shrunk past when the row is too narrow for its name. The number is
   the arrow's own size, drawn in sidebar.js. */
.chev {
  display: inline-block;
  min-width: 13px;
  color: var(--muted-2);
  transition: transform 140ms ease;
}

.chev.open {
  transform: rotate(90deg);
}

.collapsed .group-body {
  display: none;
}

/* The things a group holds are one stack rather than a pile of cards: no gaps
   between them, no side borders, and each row's bottom line is the next row's top
   line. A note or a box to paste into is not a row, and insets itself.

   flow-root is here for the button that starts a chat: a child's bottom margin
   otherwise collapses out of a body with no bottom border, and the gap the button
   keeps under itself is drawn in the *parent's* colour instead of the body's — so
   under a machine it vanished into the row and under Ask it did not, which is two
   panels' worth of rule for one button. Containing the body's children keeps the
   gap inside it, in the body's own colour, wherever the body is. */
.group-body {
  display: flow-root;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* ── targets ───────────────────────────────────────────────────────────── */

.target {
  /* Only a bottom line: the row above provides the one above this, so a stack of
     targets is a stack of single lines rather than of doubled ones. */
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

/* A machine — an egg or a station — is indented from the panel's edge, and the chats that run on
   it are indented twice as far: what belongs to something sits under it. The right inset stays
   what it was, so a long name still ends where it always did. */
.target-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0 8px 0 20px;
  min-height: calc(var(--row) * 5);
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.target-head:hover {
  background: var(--hover);
}

/* The light: green for a machine that is up, red for one that is not, and gray for an egg
   nobody has started yet — waiting is not working and not broken. It is a mark and not a
   surface, like the shadows on the picture, so it is one of the round things in the panel. */
.light {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted-2);
}

.light.ok {
  background: var(--ok);
}

.light.bad {
  background: var(--err);
}

/* The badge an egg wears: a person in a circle, blue for an account with root and gray for
   one without. Round like the light, for the same reason — it is a mark, not a surface — and
   its icon is the colour of the panel, so the circle it sits in is the colour that means
   something. */
.priv {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--muted-2);
  color: var(--bg);
}

/* An account with root wears the blue, and its picture is light rather than the dark the gray
   circle's is: the blue is dark enough that a dark icon on it is hard to read. */
.priv.admin {
  background: var(--admin);
  color: var(--text);
}

.target-name {
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The words of a name, inside the box that holds the name: the box takes the rest of the row so
   the badge and the arrow stay at the far end, and the words take no more room than they need, so
   that a press on the row is a press on the row and only a press on the words is a press on the
   name. A name that can be renamed is a text cursor and nothing else: it does not underline
   itself on a hover and it does not change colour, because the name on a row is the name whether
   or not it can be changed. */
.target-text.renamable {
  cursor: text;
}

/* The field a name becomes is the name: the same place, the same type at the same size, no box
   around it, no line under it, and the row's own background — so what changes when somebody
   clicks a name is that the name can be typed in, and nothing else at all. */
.rename-field {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1rem;
  outline: none;
  appearance: none;
}

.target-badge {
  border: 1px solid var(--border-2);
  padding: 0 6px;
  font-size: 0.8rem;
  font-family: var(--mono);
  color: var(--muted);
}

.target-badge.ok {
  color: var(--ok);
  border-color: rgba(87, 180, 115, 0.45);
}


.target-body {
  display: flow-root;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* A chat's row: a picture, a name, and the line under it. */
.chat-item {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  text-align: left;
  padding: 0 8px 0 25px;
  min-height: calc(var(--row) * 4);
  border: 0;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.2;
}

.chat-item:hover {
  background: var(--hover);
  color: var(--text);
}

.chat-item.active {
  color: var(--text);
  border-left: 3px solid var(--accent);
  background: var(--panel-3);
}

/* The icon is the first thing in the row and the name takes what is left, so a
   long name shortens rather than pushing the icon off the edge. */
.chat-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A name that is not the chat's last one: the model names a chat after the first answer and
   again after the second, and the italics say which of the two this is. */
.chat-title.provisional {
  font-style: italic;
}
/* The row that starts a chat, or an egg: the one thing in a body that is not a row in the
   stack. It insets itself — ten pixels on each side and fifteen under it — it is five
   --row tall, and its picture and its words are centred rather than ranged left. It
   carries its own border and background, because it is a button rather than another chat
   in the list. */
.chat-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  /* A button is as wide as its words unless it is told otherwise, so it is told: what is
     left of the width after the twenty pixels it keeps clear, ten on each side. */
  width: calc(100% - 20px);
  margin: 10px 10px 15px 10px;
  padding: 0;
  min-height: calc(var(--row) * 5);
  border: 1px solid var(--border-2);
  background: var(--panel-3);
  color: var(--muted-2);
  font-size: 1rem;
  line-height: 1.2;
}

.chat-new:hover {
  color: var(--text);
  border-color: var(--accent-dim);
  background: var(--hover);
}

/* A note is not a row: it insets itself and has no line of its own. */
.chat-empty {
  color: var(--muted-2);
  font-size: 0.8rem;
  padding: 6px 8px 8px;
  line-height: 1.45;
}

.hint {
  color: var(--muted-2);
  font-size: 0.8rem;
  line-height: 1.45;
  padding: 6px 8px;
}

.hint.error {
  color: var(--err);
  white-space: pre-wrap;
  border: 1px solid rgba(217, 87, 78, 0.4);
  background: rgba(217, 87, 78, 0.06);
  margin: 6px 8px;
}

.hint.error:empty {
  display: none;
}

/* A box to paste into is not a row and does not pretend to be one, but it is not
   inset either: it is the width of the panel, edge to edge, and the stack runs
   through it. A margin here is a gap between two rows, which is the one thing the
   panel is not allowed to have. */
.paste-box {
  display: block;
  /* A hole in the panel rather than a row in the stack, so it runs the width of the
     panel: nothing is indented now, so there is nothing to back out through. */
  width: 100%;
  margin: 0;
  /* No drag handle in the corner: the box is the width of the panel and the height it
     needs, and a blob is pasted into it rather than written in it. A grip that is only
     ever a way to make the panel look broken is not a control. */
  resize: none;
  /* Blacker than the panel behind it, so the box is a hole to fill in rather than
     another surface to press. */
  background: var(--bg);
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  /* A terminal font, and the same one the codes and the model ids use. Every part
     of the stack is something a machine wrote, so the box agrees with them. */
  font-family: var(--mono);
  font-size: 1rem;
  padding: 8px;
}

.paste-box::placeholder {
  color: var(--muted-2);
}

.paste-box:focus {
  outline: none;
  border-bottom-color: var(--accent-dim);
}


/* ── the foot ───────────────────────────────────────────────────────────── */

/* Who is logged in, and the account's own two buttons plus the one that opens the second
   panel. The row is as tall as the buttons in it and the buttons are squares of that height,
   so they are flush with the panel's bottom edge and with each other. Nothing draws it apart
   from the tree above it — no line, no colour of its own — so it is the last row of the same
   stack the tree is rather than a toolbar sitting under it, and the row's height is not
   written out here either: it is the squares, which is one number rather than two to keep in
   step. The username is the rest of the width, cut with an ellipsis rather than wrapped,
   because a row does not grow. */
.sb-foot {
  display: flex;
  align-items: stretch;
  flex: 0 0 auto;
}

.sb-who {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  /* Twenty pixels clear of the panel's edge on the left: the name is a label for the
     pictures beside it, so it sits in from the rows above rather than flush with them. */
  padding: 0 8px 0 20px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A square with its picture in the middle, and the height of the row: five shares of the
   panel's row. Nothing is drawn around it — the panel's own colour behind the picture is the
   whole of what it looks like at rest, which is what a row of buttons and a name should look
   like — so what marks a button out is pointing at it. */
.sb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--row) * 5);
  height: calc(var(--row) * 5);
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: none;
}

.sb-btn:hover {
  background: var(--hover);
  color: var(--text);
}

/* A button that cannot be pressed does not light up under the pointer. The notepad is dead
   until a chat is open, and a square that brightens and then does nothing is a lie about what
   is there — so the hover is put back, the way the button that starts a chat puts its own
   hover back when it is disabled. */
.sb-btn:disabled {
  color: var(--muted-2);
  cursor: default;
}

.sb-btn:disabled:hover {
  background: none;
  color: var(--muted-2);
}

/* The settings page is an admin's, and the `hidden` attribute says so. Nothing else in the
   panel is hidden by an attribute, so this is where it is said out loud: a display of our
   own would otherwise paint over the browser's. */
.sb-btn[hidden] {
  display: none;
}

/* ── modal ─────────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  z-index: 60;
}

.modal.hidden {
  display: none;
}

.modal-box {
  width: min(92vw, 440px);
  /* The laid-egg dialog is an egg taller than most dialogs, and a short window must be
     able to scroll it rather than cut the button off the bottom. */
  max-height: calc(100dvh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border-2);
  padding: 20px;
}

.modal-box h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
  letter-spacing: 0.2px;
}

/* The cells are the button, and the square they cover is the whole of it: the pointer, the
   focus ring, the hover and the press. The egg around them is the picture the hatch page
   draws, and pointing at a picture does nothing. */
#egg-slots {
  cursor: copy;
  outline: none;
}

#egg-slots:focus-visible .slot {
  border-color: var(--accent-dim);
}

/* The square is the target and the cells are what says so: pointing anywhere inside it — at a
   cell, or at the gap between two — takes every cell's border to the accent, the colour the
   hatch page puts on the cell the next character goes in. The borders only: the code inside
   them is still the code, and repainting it on a hover would be the picture answering for the
   press rather than the control it is. */
#egg-slots:hover .slot {
  border-color: var(--accent);
}

/* A click is a copy, and the cells are what says so, the way the hatch page says a code was
   taken: every cell at once, in the accent, and then a fade of 0.3s back to what it was.
   Only the `from` is written, so what it fades back to is whatever the cell was going to be
   anyway — a filled cell's own text colour — rather than a second copy of it kept here to
   fall out of step with the first. */
@keyframes egg-copied {
  from {
    border-color: var(--accent);
    color: var(--accent);
  }
}

#egg-slots.copied .slot {
  animation: egg-copied 0.3s ease-out;
}

.modal-box input {
  width: 100%;
  margin-bottom: 0;
  padding: 9px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1rem;
}

.modal-box input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* The button that closes the laid-egg dialog is the whole of the way out of it, so it fills
   its row — and the gap above it is what separates it from the egg, rather than a line or a
   label. */
#egg-close {
  width: 100%;
  margin-top: 20px;
}

/* A target that cannot take a new chat says so by refusing to be pressed. */
.chat-new:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-new:disabled:hover {
  color: var(--muted-2);
  border-color: var(--border-2);
  background: var(--panel-3);
}

/* ── the right-click menu ──────────────────────────────────────────────── */

/* Drawn at the pointer, over everything, and the one thing in the panel that is
   as wide as its longest line rather than as wide as the panel.

   It is one surface and its items are not boxes on it: the border around the menu is the
   only border, an item with one of its own would be a border inside a border, and there is
   no padding, so a highlighted item reaches the menu's edge instead of floating in a frame
   of background. */
.menu {
  position: fixed;
  z-index: 30;
  min-width: 168px;
  padding: 0;
  border: 1px solid var(--border-2);
  background: var(--panel);
}

/* The one element in the app whose display is a grid of its own: hidden has to
   win over it, or a closed menu would sit there empty and swallow clicks. */
.menu[hidden] {
  display: none;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  /* The eight pixels are what the border used to be: the item's height is the same as it
     was, and none of it is a box. */
  padding: 8px 10px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}

.menu-item:hover,
.menu-item.on {
  background: var(--hover);
}

.menu-item:disabled {
  color: var(--muted-2);
  cursor: default;
}

.menu-item:disabled:hover {
  background: none;
}

/* A menu is a list of things that can be done, and nothing on it is red: the panel's
   error colour is for a machine that is down, not for a thing somebody chose to open. */
.menu-sep {
  height: 1px;
  margin: 3px 0;
  background: var(--border);
}

/* ── the front door ────────────────────────────────────────────────────── */

/* Shown instead of the app, over everything, until somebody has logged in. It is not
   a modal: there is nothing behind it to go back to. */
.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-color: var(--bg);
}

/* The nest, behind the form: 1.5x its source and lifted 30% of its own height, so it
   sits above the middle of the page rather than dead behind the box. */
.gate::before {
  content: "";
  position: absolute;
  top: 66%;
  left: 50%;
  width: 525px;
  height: 525px;
  transform: translate(-50%, -80%);
  background-image: url("/art/nest-login.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 525px 525px;
  image-rendering: pixelated;
}

.gate[hidden] {
  display: none;
}

.gate-box {
  position: relative;
  z-index: 1;
  width: min(92vw, 320px);
  border: 1px solid var(--border-2);
  background: var(--panel);
  padding: 18px;
}

.gate-form {
  display: flex;
  flex-direction: column;
}

/* The two fields share one edge: each keeps its whole border and the next is pulled
   up by a pixel over it, so there is one line rather than two. The focused field is
   lifted above its neighbour, which is what keeps its accent border on top of that
   shared line instead of under it. */
.gate-form .gate-input {
  position: relative;
  margin-top: -1px;
  border-bottom: 1px solid var(--border);
}

.gate-form .gate-input:first-of-type {
  margin-top: 0;
}

/* All four sides of the focused field take the accent, and this rule has to be the one that says
   so: the shorthand above re-adds the bottom border, and it is exactly as specific as the plain
   `.gate-input:focus` that colours the rest — so source order decides, and without this the field
   came out with three accent sides and a grey one along the line it shares with the password.
   The lift is the other half: it is what keeps that accent line above the neighbour's top border,
   which is drawn on the same pixel. */
.gate-form .gate-input:focus {
  z-index: 1;
  border-color: var(--accent-dim);
}

/* The gap between the fields and the button is what says the button is not a third
   field: the stack of inputs ends and the way in begins. */
.gate-form .btn {
  margin-top: 14px;
  width: 100%;
}

/* A login the nest would not take: the fields and the way in take the red, the colour the hatch
   page's cells take for a code the nest would not take, and they fade back out of it in the same
   0.42s. It is an animation rather than a class to take off again, so the flash is the whole of
   the form's answer and there is no clock here to keep in step with. Only the `from` is written:
   what it fades back to is whatever the cell was going to be anyway. */
@keyframes gate-bad {
  from {
    border-color: var(--err);
    color: var(--err);
  }
}

.gate-form.bad .gate-input,
.gate-form.bad .btn {
  animation: gate-bad 0.42s ease-out;
}

.gate-error {
  color: var(--err);
  font-size: 0.8rem;
  padding-top: 8px;
  min-height: 14px;
}


/* The phone's door: Hydra's QR code filling the box, and the same login's four digits under it
   in the cells an egg code is drawn in. The code is dark on light, as a phone's camera wants it,
   so it keeps the white it was drawn on inside the box's own border. */
.gate-phone {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gate-qr {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border-2);
  background: #fff;
  image-rendering: pixelated;
}

.gate-qr[hidden] {
  display: none;
}

.gate-slots {
  grid-template-columns: repeat(4, 56px);
  grid-template-rows: 56px;
  margin-top: 14px;
}

.gate-slots.bad .slot {
  animation: gate-bad 0.42s ease-out;
}
