/* =================================================================
   TMS BUG REPORTER — floating button + one-screen report form
   Self-contained (no page CSS-var or icon-font dependency). Class prefix:
   tmsbug-, so nothing here can collide with a host's own chrome
   (developer/tests/e2e/css_bleed_guard.cjs).

   THE BUTTON IS RED, AND THAT IS DELIBERATE. It was TMS blue, on the
   reasoning that the reporter should wear the host's palette. It should
   not: this is the same control WSOL puts in the same corner — a white
   Font Awesome `bug` on a red circle — and someone who uses both
   products should not have to learn it twice. Red also does what blue
   could not, which is stop reading as one more piece of app chrome in a
   shell where every other accent is #1a5fb4. #EF4444 / #DC2626 are
   WSOL's own two values, not a near miss.

   THREE UI STATES, and the button is the same OBJECT in each — one red
   circle, one bug — differing only in how big the target is and what it
   has to clear. They are selected by `data-ui` on the element, written
   by assets/bug-reporter.js, never by a bare media query: the phone
   answer depends on whether the phone SHELL is mounted and on how tall
   its action bar currently is, which no media query can see.

     data-ui="pc"      a pointer. 44px — WSOL's size.
     data-ui="tablet"  the desktop layout under a thumb. A 52px touch
                       target; nothing else changes.
     data-ui="mobile"  the phone shell. 48px, lifted clear of #m-actbar
                       by --tmsbug-dock (measured, because that bar is
                       one row or two depending on the screen) and the
                       safe area.

   IT IS ON SCREEN IN ALL THREE, WHATEVER ELSE IS UP. A sheet, the
   drawer or an open window no longer takes it away: the moment worth
   reporting is usually one of those moments, and the button that says
   so was disappearing into it.
   ================================================================= */

/* The measured height of whatever the shell has pinned to the bottom edge.
   0 on every surface that has nothing there. */
:root { --tmsbug-dock: 0px; }

/* ---- Floating button: a bug on a red circle ---- */
.tmsbug-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;          /* a circle at every size and in every state */
  border: none;
  background: #EF4444;
  color: #fff;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
  z-index: 2147483000;
  display: none;               /* revealed by JS once signed in */
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, background .2s ease, box-shadow .2s ease, opacity .15s ease;
}
.tmsbug-fab.tmsbug-show { display: inline-flex; }
.tmsbug-fab svg { width: 21px; height: 21px; flex: none; display: block; fill: currentColor; }
.tmsbug-fab:hover { background: #DC2626; transform: scale(1.1); box-shadow: 0 4px 12px rgba(239, 68, 68, .4); }
.tmsbug-fab:active { transform: scale(.95); }
.tmsbug-fab:focus-visible { outline: 3px solid #FCA5A5; outline-offset: 2px; }

/* A guest's report would look filed and reach nobody, so a guest gets no
   button. `role-guest` is set on <html> by assets/tms-shell.js, which means
   this still holds if the session is re-gated after the reveal. */
html.role-guest .tmsbug-fab { display: none !important; }

/* Someone reading the page should not have to work around the reporter. */
@media print { .tmsbug-fab, .tmsbug-modal { display: none !important; } }

/* ---- pc: WSOL's 44px circle, unchanged ---- */
.tmsbug-fab[data-ui="pc"] { width: 44px; height: 44px; }

/* ---- tablet: the desktop layout, but a thumb is pressing it ---- */
.tmsbug-fab[data-ui="tablet"] { width: 52px; height: 52px; right: 20px; bottom: 20px; }
.tmsbug-fab[data-ui="tablet"] svg { width: 24px; height: 24px; }

/* ---- mobile: above the shell's own bottom furniture ----
   WSOL's phone rule too: 48px, off the right edge, and slightly translucent at
   rest so it reads as an overlay rather than as part of the module under it. */
.tmsbug-fab[data-ui="mobile"] {
  width: 48px; height: 48px;
  right: 12px;
  bottom: calc(var(--tmsbug-dock, 0px) + 14px + env(safe-area-inset-bottom, 0px));
  opacity: .9;
}
.tmsbug-fab[data-ui="mobile"] svg { width: 22px; height: 22px; }
.tmsbug-fab[data-ui="mobile"]:active { opacity: 1; }

/* Off screen for THIS MODULE'S OWN FORM, and nothing else — a press that can
   do nothing, under an overlay this file put there. It once covered the host's
   sheets, drawer and dialogs too; assets/bug-reporter.js records why that is
   gone. JS toggles the class off a <body> observer.

   AFTER the three state blocks, and that placement is load-bearing:
   `.tmsbug-fab.tmsbug-obscured` and `.tmsbug-fab[data-ui="mobile"]` have the
   same specificity (0,2,0), so whichever is written last wins the `opacity`.
   Written above them, this rule lost — the class went on and the button stayed
   at .92 on top of the open drawer, which is the one place it must not be.
   `visibility` is carried too: no state rule sets it, so it holds whatever the
   cascade does with the rest. */
.tmsbug-fab.tmsbug-obscured {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(.9);
}

@media (prefers-reduced-motion: reduce) {
  .tmsbug-fab { transition: none; }
  .tmsbug-fab:hover, .tmsbug-fab:active { transform: none; }
}

/* ---- Overlay ---- */
.tmsbug-modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 22, 34, .5);
  z-index: 2147483001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.tmsbug-modal.tmsbug-hidden { display: none; }

/* ---- Card ---- */
.tmsbug-card {
  background: #fff;
  color: #14181f;
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(20, 25, 35, .3);
  overflow: hidden;
  animation: tmsbug-in .2s ease-out;
}
@keyframes tmsbug-in {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* tablet: same card, larger type and targets — it is being filled in by hand. */
.tmsbug-modal[data-ui="tablet"] .tmsbug-card { max-width: 540px; }
.tmsbug-modal[data-ui="tablet"] .tmsbug-textarea { font-size: 15.5px; }
.tmsbug-modal[data-ui="tablet"] .tmsbug-prio button { padding: 12px 4px; font-size: 13px; }
.tmsbug-modal[data-ui="tablet"] .tmsbug-submit { padding: 13px 24px; font-size: 15px; }
.tmsbug-modal[data-ui="tablet"] .tmsbug-back { padding: 12px 18px; font-size: 14px; }

/* mobile: a sheet off the bottom edge, next to the hand — the same shape the
   phone shell gives every other transient surface (assets/mobile.css #m-sheet). */
.tmsbug-modal[data-ui="mobile"] { align-items: flex-end; padding: 0; }
.tmsbug-modal[data-ui="mobile"] .tmsbug-card {
  max-width: 100%;
  border-radius: 18px 18px 0 0;
  max-height: 92vh; max-height: 92dvh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation-name: tmsbug-up;
}
@keyframes tmsbug-up {
  from { opacity: .4; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Header ----
   Red, following the button. Not a restyle for its own sake: the header carries
   THE SAME bug glyph as the button that opened it, and a red control opening a
   blue-headed dialog with a red-context icon in it reads as a mismatch rather
   than as one surface. WSOL's is #EF4444 for the same reason. The form's own
   controls below — focus rings, Send, the spinner — stay TMS blue, because those
   are the app's action colour and this is a TMS dialog. */
.tmsbug-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px;
  background: #EF4444;
  color: #fff;
}
.tmsbug-head h3 { margin: 0; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tmsbug-head h3 svg { width: 18px; height: 18px; fill: currentColor; }
.tmsbug-x { background: none; border: none; color: #fff; font-size: 26px; line-height: 1; cursor: pointer; opacity: .85;
  padding: 0 4px; min-width: 34px; min-height: 34px; }
.tmsbug-x:hover { opacity: 1; }

/* ---- Body ---- */
.tmsbug-body { padding: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tmsbug-step.tmsbug-hidden { display: none; }

/* The line that says the screen is already safe. It is the whole reason the
   form can be one screen: nothing the reporter does from here can spoil the
   capture, so there is nothing left to ask them before they start typing. */
.tmsbug-snap {
  display: flex; align-items: flex-start; gap: 9px;
  background: #eef4fd; border-left: 4px solid #1769d6; border-radius: 6px;
  padding: 10px 12px; margin-bottom: 14px; font-size: 12.5px; line-height: 1.5; color: #14406f;
}
.tmsbug-snap svg { width: 16px; height: 16px; flex: none; margin-top: 2px; fill: #1769d6; }
#tmsbug-snapwhat { color: #33507a; }

.tmsbug-label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: #5b6472; margin: 0 0 6px; }
.tmsbug-textarea {
  width: 100%; box-sizing: border-box; padding: 10px 12px;
  border: 2px solid #e6e8ec; border-radius: 8px; font-size: 14px; font-family: inherit;
  background: #fff; color: #14181f; resize: vertical; margin-bottom: 14px;
  transition: border-color .15s;
}
.tmsbug-textarea:focus { outline: none; border-color: #1769d6; }

.tmsbug-prio { display: flex; gap: 6px; margin-bottom: 16px; }
.tmsbug-prio button {
  flex: 1; padding: 9px 4px; border: 2px solid #e6e8ec; border-radius: 6px;
  background: #fff; color: #14181f; font-size: 12px; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: all .15s;
}
.tmsbug-prio button:hover { border-color: #9aa3b2; }
.tmsbug-prio button.tmsbug-active[data-prio="low"]      { background: #22c55e; border-color: #22c55e; color: #fff; }
.tmsbug-prio button.tmsbug-active[data-prio="normal"]   { background: #eab308; border-color: #eab308; color: #fff; }
.tmsbug-prio button.tmsbug-active[data-prio="high"]     { background: #f97316; border-color: #f97316; color: #fff; }
.tmsbug-prio button.tmsbug-active[data-prio="critical"] { background: #dc2626; border-color: #dc2626; color: #fff; }

.tmsbug-disclose { font-size: 11.5px; color: #5b6472; line-height: 1.5; margin: 0 0 14px; }

.tmsbug-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tmsbug-back {
  padding: 10px 15px; border: none; border-radius: 6px; background: #f0f2f6; color: #5b6472;
  font-size: 13px; font-family: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.tmsbug-back:hover { background: #e6e8ec; }
.tmsbug-submit {
  padding: 11px 20px; border: none; border-radius: 7px; background: #1769d6; color: #fff;
  font-size: 14px; font-weight: 700; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.tmsbug-submit:hover { background: #1257b3; }
.tmsbug-submit:disabled { opacity: .6; cursor: default; }

/* On a phone the two actions are the full width of the thumb, Send on top —
   the same order every confirm sheet in the shell uses. */
.tmsbug-modal[data-ui="mobile"] .tmsbug-actions { flex-direction: column-reverse; align-items: stretch; }
.tmsbug-modal[data-ui="mobile"] .tmsbug-actions button { justify-content: center; min-height: 46px; }
.tmsbug-modal[data-ui="mobile"] .tmsbug-prio { flex-wrap: wrap; }
.tmsbug-modal[data-ui="mobile"] .tmsbug-prio button { flex: 1 1 45%; min-height: 44px; }
.tmsbug-modal[data-ui="mobile"] .tmsbug-textarea { font-size: 16px; }   /* 16px: iOS zooms below it */

.tmsbug-center { text-align: center; padding: 26px 0; color: #5b6472; }
.tmsbug-center .tmsbug-spin { width: 34px; height: 34px; margin: 0 auto 12px; border: 3px solid #dfe3ea; border-top-color: #1769d6; border-radius: 50%; animation: tmsbug-rot .8s linear infinite; }
@keyframes tmsbug-rot { to { transform: rotate(360deg); } }
.tmsbug-center .tmsbug-ok { width: 44px; height: 44px; margin: 0 auto 10px; display: block; fill: #22c55e; }
.tmsbug-center h4 { margin: 0 0 6px; font-size: 16px; color: #14181f; }
.tmsbug-center p { margin: 4px 0; font-size: 13px; }
.tmsbug-center .tmsbug-submit { margin-top: 16px; }
/* "Open in dev server" (bug-reporter.js): beside Close, for an admin with a dev server. */
.tmsbug-center .tmsbug-back { margin-top: 16px; margin-right: 6px; }
.tmsbug-center .tmsbug-back.tmsbug-hidden { display: none; }
.tmsbug-muted { color: #5b6472; font-size: 12px; }

.tmsbug-err { color: #c0392b; font-size: 13px; margin: 0 0 10px; min-height: 1em; }

/* ---- Dark mode ---- */
@media (prefers-color-scheme: dark) {
  .tmsbug-card { background: #1a1f28; color: #e7eaf0; }
  .tmsbug-textarea, .tmsbug-prio button { background: #232a34; color: #e7eaf0; border-color: #333c48; }
  .tmsbug-back { background: #2a313c; color: #b7c0ce; }
  .tmsbug-back:hover { background: #333c48; }
  .tmsbug-snap { background: rgba(23,105,214,.14); color: #a9c8f2; border-left-color: #4a90e2; }
  .tmsbug-snap svg { fill: #6ea8ef; }
  #tmsbug-snapwhat { color: #8fb3e0; }
  .tmsbug-center h4 { color: #e7eaf0; }
}
