/* Dictation: the microphone beside every free-text field (see dictation.js).

   Linked by every page that loads dictation.js -- the portal, the intake application and its status
   page, and ER Documents -- which do not share a stylesheet, so these rules carry their own colours
   instead of leaning on one page's variables. Nothing here applies until dictation.js has found
   speech recognition in this browser and marked the page `.can-dictate`; in Firefox the page is
   exactly as it was. */

.can-dictate .dictate {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.can-dictate .dictate--area { align-items: flex-start; }
.can-dictate .dictate--inline { display: inline-flex; vertical-align: baseline; max-width: 100%; }
.can-dictate .dictate > .dictate__field { min-width: 0; flex: 0 1 auto; }

/* The button overlaps the field's right edge, and the field leaves room so no word hides under it. */
@media screen {
  .can-dictate .dictate > .dictate__field { padding-right: 2.5rem !important; }
  .can-dictate .dictate--compact > .dictate__field { padding-right: 1.7rem !important; }
}

.dictate__mic {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  margin-left: -2.3rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  opacity: 0.72;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.dictate--area > .dictate__mic { margin-top: 0.3rem; }
.dictate--compact > .dictate__mic { width: 1.4rem; height: 1.4rem; margin-left: -1.55rem; }
.dictate--compact > .dictate__mic svg { width: 14px; height: 14px; }
.dictate__mic:hover { opacity: 1; background: rgba(127, 127, 127, 0.16); }
.dictate__mic:focus-visible { opacity: 1; outline: 2px solid #9d7818; outline-offset: 1px; }
.dictate__mic svg { display: block; pointer-events: none; }

/* A field that cannot be typed into right now has nothing to dictate into. */
.dictate:has(> .dictate__field:disabled) > .dictate__mic,
.dictate:has(> .dictate__field[readonly]) > .dictate__mic { display: none; }

/* On a touch screen the button keeps a 44px target, whatever size it is drawn at. */
@media (any-pointer: coarse) {
  .dictate__mic::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
  }
  .dictate__mic { opacity: 0.85; }
}

/* Listening: solid red with a pulsing dot, so it is plain from across a kitchen which field is live. */
.dictate__mic.is-listening { opacity: 1; background: #b3261e; color: #fff; }
.dictate__mic.is-listening:hover { background: #8f1d17; }
.dictate__dot {
  position: absolute;
  top: 0.1rem;
  right: 0.1rem;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #e5483d;
  box-shadow: 0 0 0 2px #fff;
  display: none;
}
.dictate__mic.is-listening .dictate__dot { display: block; animation: dictate-pulse 1.1s ease-in-out infinite; }
.dictate.is-listening > .dictate__field { box-shadow: 0 0 0 2px rgba(179, 38, 30, 0.35); }

@keyframes dictate-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.45); opacity: 0.55; }
}

/* A rich-text editor (ER Documents): the microphone sits in the page margin -- at the top right of
   the document body, staying in view as a long document scrolls, and level with a page header or
   footer (dictation.js measures where). The dock takes no height, so the
   page lays out exactly as before. */
.dictate-dock { position: relative; height: 0; z-index: 3; }
.dictate-dock--sticky { position: sticky; top: 0.5rem; }
.dictate-dock > .dictate__mic { position: absolute; top: 0; right: -2.45rem; margin: 0; background: #fff; color: #1f4e79; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); opacity: 1; }
.dictate-dock > .dictate__mic.is-listening { background: #b3261e; color: #fff; }

/* What dictation is doing, on one line near the foot of the screen (or of the open dialog). */
.dictate-status {
  position: fixed;
  left: 50%;
  bottom: calc(var(--navbar-h, 0px) + 1rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 2147483000;
  width: max-content;
  max-width: min(36rem, calc(100vw - 1.5rem));
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  background: #1c2230;
  color: #fff;
  font: 500 0.9rem/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  overflow-wrap: anywhere;
}
.dictate-status--live::before {
  content: "";
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.5rem;
  border-radius: 50%;
  background: #e5483d;
  vertical-align: 0.05rem;
  animation: dictate-pulse 1.1s ease-in-out infinite;
}
.dictate-status--error { background: #8f1d17; }
/* On a phone the foot of a sheet is where Save is, so the line moves to the top of the screen. */
@media (max-width: 640px) {
  .dictate-status { bottom: auto; top: calc(0.6rem + env(safe-area-inset-top, 0px)); }
}
.dictate-status[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .dictate__mic.is-listening .dictate__dot, .dictate-status--live::before { animation: none; }
}

@media print {
  .dictate__mic, .dictate-dock, .dictate-status { display: none !important; }
}
