body {
  margin: 0;
  height: 100vh;
  position: relative;
  /* The sidebar is the only thing that scrolls. Without this the page itself
     can scroll past the map and show a strip of nothing underneath it. */
  overflow: hidden;
}

#map {
  width: 100vw;
  height: 100vh;
}

#sidebar {
  position: absolute;
  top: 0;
  right: 0;
  /* 15% leaves a tablet like the iPad mini with a column too narrow for the
     route dates, so it never goes below what those need */
  width: max(15%, 260px);
  height: 100vh;
  background: rgb(248 249 250 / 60%);
  border-left: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  font-family:
    San Francisco,
    sans-serif;
}

/* Trailing room inside the scrolled content: padding on #sidebar itself is at
   the end of the scroll box, so the last tag would still sit against the edge */
/* The only thing that scrolls */
#tags-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Reaching the end of the list must not hand the scroll to the page */
  overscroll-behavior: contain;
  padding: 14px 16px 28px;
}

#sidebar.hidden {
  display: none;
}

/* Outside the scrolling area rather than floating above it, so no row ever
   passes behind it and it can stay as see-through as the sidebar itself */
#sidebar-top {
  flex: none;
  padding: 14px 16px;
  /* Anchors the logout button without pushing the heading off centre */
  position: relative;
}

/* Small and in the corner: it is used once a session, not every visit */
#logout {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  display: flex;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: none;
  color: #555;
  cursor: pointer;
}

#logout:hover {
  background: rgb(255 255 255 / 70%);
  border-color: rgb(0 0 0 / 12%);
  color: #b00020;
}

#logout:focus-visible {
  outline: 2px solid #2f6fed;
  outline-offset: 2px;
}

.logout-icon {
  width: 16px;
  height: 16px;
}

/* Read out by screen readers, never drawn */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#sidebar h2 {
  margin: 0;
  text-align: center;
}

/* The heading doubles as the reset control. Nobody hovers a title to find out
   it is clickable, so it has to look like a control while sitting still. */
#show-all {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  padding: 4px 16px;
  border: 1px solid rgb(0 0 0 / 12%);
  border-radius: 20px;
  background: rgb(255 255 255 / 70%);
  color: inherit;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

#show-all:hover {
  background: #fff;
  border-color: rgb(0 0 0 / 28%);
}

.show-all-icon {
  width: 15px;
  height: 15px;
  opacity: 0.55;
}

#show-all:hover .show-all-icon {
  opacity: 0.9;
}

#show-all:focus-visible {
  outline: 2px solid #2f6fed;
  outline-offset: 2px;
}

/* The collapsed row is one line: the name gives up its space first, so the
   battery and the age stay put instead of wrapping onto a second line */
.tag-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  /* Keeps the overflow measurable, and hides whatever is still too long at the
     smallest size the text is allowed to reach */
  overflow: hidden;
}

/* Nothing gives way on its own: the row is measured and the text scaled down
   as a whole instead */
.tag-head > * {
  flex: none;
}

.tag-name,
.tag-time {
  white-space: nowrap;
}

.tag-row {
  padding: 12px 16px;
  font-size: 16px;
  border-radius: 20px;
  margin-bottom: 12px;
}

/* The row tint is 20% alpha, which squashes the difference between two tag
   colours to the point of invisibility. This carries the colour at full
   strength so the list is actually readable. */
/* The emoji is painted in the tag's colour: hiding the glyph and drawing a
   shadow with no blur or offset leaves its silhouette in whatever colour the
   shadow is. The blurred white behind it keeps the shape legible over the map. */
.tag-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  font-size: 31px;
  line-height: 1;
  /* Recoloured rather than filled in, so the emoji keeps its own shading:
     strip its colour, tint it sepia, then rotate that onto the tag's hue.
     drop-shadow runs last, so its white halo is not tinted with everything else. */
  filter: grayscale(1) sepia(1) hue-rotate(calc(var(--hue) * 1deg - 40deg))
    saturate(3) drop-shadow(0 0 2px #fff)
    drop-shadow(0 1px 1px rgb(0 0 0 / 30%));
}

.tag-emoji-row {
  display: inline-flex;
  width: 24px;
  height: 24px;
  font-size: 19px;
  /* Centred against the name rather than nudged by a fixed offset, which only
     lines up at one font size */
  vertical-align: middle;
  /* No halo needed against the sidebar */
  filter: grayscale(1) sepia(1) hue-rotate(calc(var(--hue) * 1deg - 40deg))
    saturate(3);
}

.tag-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  vertical-align: -2px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 20%);
}

.battery-icon {
  width: 22px;
  height: 10px;
  vertical-align: middle;
}

.tag-time {
  font-style: italic;
  color: #888;
}

.tag-schedules {
  font-size: 14px;
  text-align: center;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition:
    max-height 0.5s ease,
    opacity 0.5s ease;
}

.tag-schedules.visible {
  padding-top: 5%;
  max-height: 800px;
  opacity: 1;
}

/* One schedule, one line. nowrap is what makes the line overflow rather than
   wrap, which is how the fitting code detects that it has to shrink. */
.tag-schedule {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
}

.schedule-pin {
  border: 0;
  background: none;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.65;
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
}

.schedule-pin:hover {
  opacity: 1;
}

.schedule-pin.active {
  opacity: 1;
  transform: scale(1.25);
}

.schedule-pin:focus-visible {
  outline: 2px solid #2f6fed;
  outline-offset: 2px;
  border-radius: 4px;
}

.tag-schedules a {
  text-decoration: none;
}

.tag-schedules:empty {
  display: none;
}

#login-page {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(255 255 255 / 80%);
  z-index: 3000;
  font-family:
    San Francisco,
    sans-serif;
}

.login-form {
  width: min(360px, 92vw);
  display: grid;
  gap: 10px;
  padding: 24px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
}

/* Decorative: the heading beside it already names the app, so it is alt="" */
.login-logo {
  justify-self: center;
  /* The artwork sits inside a taller transparent canvas, so the lock itself
     comes out around 110px */
  height: 160px;
  width: auto;
  margin-bottom: 10px;
}

.login-form p {
  margin: 0;
}

.login-form input {
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.login-form button {
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: #2f6fed;
  color: #fff;
  cursor: pointer;
}

.login-error {
  min-height: 20px;
  color: #b00020;
}

.tag-route {
  container-type: inline-size;
  display: grid;
  gap: 6px;
  padding-top: 10px;
  margin-top: 8px;
  border-top: 1px solid rgb(0 0 0 / 10%);
  text-align: left;
  font-size: 13px;
}

.tag-route-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #555;
}

.tag-route label {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 6px;
  color: #555;
}

.tag-route input[type="date"] {
  box-sizing: border-box;
  width: 100%;
  /* Date inputs have a wide intrinsic size, Safari's especially, which would
     otherwise push them out of the sidebar instead of shrinking */
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}

/* Too narrow for the label beside the date: put it above instead */
@container (max-width: 200px) {
  .tag-route label {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

.tag-route-buttons {
  display: flex;
  gap: 6px;
}

.tag-route button {
  flex: 1;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: #2f6fed;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.tag-route .route-clear {
  background: #e5e7eb;
  color: #374151;
}

.route-status {
  min-height: 16px;
  color: #666;
  font-style: italic;
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(255 255 255 / 80%);
  font-family:
    San Francisco,
    sans-serif;
}

#loading.hidden {
  display: none;
}

.loading-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #fff;
  color: #222;
  box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #ddd;
  border-top-color: #2f6fed;
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}
