/* Redesign, om-ai workstream.
   Tokens, the layout system and the type atoms live in redesign.css; this file is the
   only stylesheet the om-ai pages own. See docs/redesign-workstreams.md.

   The chat panel (hand-off ~/artifacts/om-redesign-v1/om-ai-chat-v1): a slide-over on
   the AI field over whatever page the person is on, with the page's banner and tab bar
   still showing. Sizes are the hand-off's points. Every rule here is presentation: the
   launch-token flow, the transcript and the widget's behaviour are unchanged.

   Three states the CSS reads off the markup the controller builds or moves:
     [data-placeholder="false"]     the answer has text, so the bubble is the cream card
     .om-ai-widget--open            the panel is open: the launcher hides, the wash shows
     .om-ai-widget--history-open    previous chats replace the conversation and question box */

/* ---------- the panel ---------- */

/* Chrome the panel has to clear: the banner above (48 at sm, 56 at lg — the values
   redesign.css assumes for a tab page) and the tab bar below (128). They sit on the
   root because both the wash behind the panel and the panel itself need them. */
.om-ai-widget {
  --rd-om-ai-banner: 3rem;
  --rd-om-ai-bar: 0px;
}
@media (min-width: 1024px) {
  .om-ai-widget { --rd-om-ai-banner: 3.5rem; }
}
.om-ai-widget--web-bottom-bar { --rd-om-ai-bar: 8rem; }
.om-ai-widget--no-bottom-bar { --rd-om-ai-bar: 0px; }
.om-ai-widget--no-top-bar { --rd-om-ai-banner: 0px; }
/* Turbo Native draws the bars outside the web view */
.om-ai-widget--native {
  --rd-om-ai-banner: 0px;
  --rd-om-ai-bar: 0px;
}

/* The page behind the panel, dimmed; the banner and tab bar stay clear of it. */
.rd-om-ai__wash {
  position: fixed;
  top: var(--rd-om-ai-banner);
  bottom: var(--rd-om-ai-bar);
  left: 0;
  right: 0;
  display: none;
  background: rgba(40, 26, 18, 0.34);
  pointer-events: none;
}
.om-ai-widget--open .rd-om-ai__wash { display: block; }

.om-ai-widget-panel.rd-om-ai__panel {
  position: fixed;
  top: calc(var(--rd-om-ai-banner) + 12px);
  bottom: calc(var(--rd-om-ai-bar) + 14px);
  left: 12px;
  right: 12px;
  /* the hand-off keeps the 12pt margins and lets the panel grow in height; on a wide
     screen it stays a phone-width panel over the app's phone-width column */
  max-width: 430px;
  margin-inline: auto;
  border: 0;
  border-radius: 30px;
  overflow: hidden;
  color: #fff;
  box-shadow: 0 20px 40px -18px rgba(30, 18, 10, 0.6);
}

/* ---------- header ---------- */

.rd-om-ai__head {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 96px;
}

.rd-om-ai__round {
  position: absolute;
  top: 16px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
}
.rd-om-ai__round--menu { left: 16px; }
.rd-om-ai__round--close { right: 16px; }

.rd-om-ai__brand {
  position: absolute;
  top: 20px;
  left: 72px;
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0.3em;
  line-height: 1.4;
  text-transform: uppercase;
}

.rd-om-ai__title {
  position: absolute;
  top: 38px;
  left: 72px;
  font-family: var(--rd-serif);
  font-style: italic;
  font-weight: 300;
  /* 33 at the hand-off's 390 wide canvas, so the line never wraps on a narrower phone */
  font-size: clamp(27px, 8.46vw, 33px);
  line-height: 1;
  white-space: nowrap;
}

/* ---------- conversation ---------- */

.rd-om-ai__thread {
  position: absolute;
  top: 96px;
  bottom: 84px;
  left: 0;
  right: 0;
  padding: 6px 16px 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* messages fade out as they scroll under the header and above the question box */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 22px), transparent 100%);
}

.rd-om-ai__hint {
  margin: 14px 8px 0;
  font-size: 17px;
  font-weight: 300;
  line-height: 1.5;
  text-wrap: pretty;
}

.rd-om-ai__messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 22px;
}
.rd-om-ai__messages:empty { display: none; }

.rd-om-ai__message {
  display: flex;
  width: 100%;
}
.rd-om-ai__message[data-role="user"] { justify-content: flex-end; }
.rd-om-ai__message[data-role="assistant"] { justify-content: flex-start; }

/* the person's question: right-aligned, 78% at most, one small corner */
.om-ai-widget-bubble.om-ai-widget-bubble--user {
  max-width: 78%;
  padding: 13px 20px;
  border-radius: 24px 24px 6px 24px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
  color: #fff;
}
.om-ai-widget-user-content {
  font-size: 17px;
  font-weight: 400;
  line-height: 1.35;
}

/* the answer: a cream card that grows as it is written, 26 short of the right edge.
   While the answer is still empty the bubble is not a card at all — the three dots
   sit on the field. (Where :has() is unavailable the dots simply sit in an empty
   card; the answer itself always renders as the card, which is the part that has to
   be readable.) */
.om-ai-widget-bubble.om-ai-widget-bubble--assistant {
  width: calc(100% - 26px);
  max-width: none;
  margin-right: 26px;
  padding: 20px 22px 22px;
  border: 0;
  border-radius: 24px;
  background: var(--rd-sheet);
  box-shadow: none;
  color: var(--rd-ink-reading);
}
@supports selector(:has(*)) {
  .om-ai-widget-bubble.om-ai-widget-bubble--assistant:not(:has(.om-ai-widget-markdown[data-placeholder="false"])) {
    padding: 0;
    border-radius: 0;
    background: none;
  }
}
/* an answer that directly follows the question gets the one small corner */
.rd-om-ai__message[data-role="user"] + .rd-om-ai__message .om-ai-widget-bubble--assistant {
  border-top-left-radius: 6px;
}

.om-ai-widget-markdown {
  font-family: var(--rd-serif);
  font-size: 20px;
  font-weight: 400;
  line-height: 1.42;
  color: var(--rd-ink-reading);
}

/* three dots while the answer is being written */
.om-ai-widget-thinking {
  display: inline-flex;
  align-items: center;
  margin: 18px 0 0 10px;
}
.om-ai-widget-thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.om-ai-widget-thinking-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 10px 2px rgba(255, 240, 220, 0.7);
}
.om-ai-widget-thinking-dot:nth-child(2) { opacity: 0.6; }
.om-ai-widget-thinking-dot:nth-child(3) { opacity: 0.3; }

/* end of an answer: a hairline, then Copy, Helpful and Not helpful */
.om-ai-widget-message-actions {
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(160, 106, 46, 0.25);
}
.om-ai-widget-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--rd-accent);
  box-shadow: inset 0 0 0 1px var(--rd-accent-underline);
  cursor: pointer;
}
.om-ai-widget-action-button:not(.is-active):hover { background: rgba(160, 106, 46, 0.08); }
.om-ai-widget-action-button.is-active {
  background: var(--rd-accent);
  color: var(--rd-sheet);
}
.om-ai-widget-action-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.rd-om-ai__action-icon {
  width: 19px;
  height: 19px;
}

/* ---------- question box ---------- */

.rd-om-ai__ask {
  position: absolute;
  bottom: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 7px 0 22px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.85);
}
.rd-om-ai__ask:focus-within { box-shadow: inset 0 0 0 1px #fff; }

/* The app's own field styling is `#frontend [type='text'] { … }` — id + attribute, so a
   lone class here lost: the typed text came out charcoal in Encode Sans, with the global
   border, radius and shadow, and the placeholder in gray-300. Matching its specificity
   (id + two classes) is the only way to win without an !important. */
#frontend .om-ai-widget .rd-om-ai__input,
#frontend .om-ai-widget .rd-om-ai__input:focus,
#frontend .om-ai-widget .rd-om-ai__input:hover {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #fff;
  caret-color: #fff;
  font-family: var(--rd-sans);
  font-size: 16px;
  font-weight: 300;
  outline: none;
  -webkit-text-fill-color: #fff;
}
#frontend .om-ai-widget .rd-om-ai__input::placeholder {
  color: rgba(255, 255, 255, 0.85);
  opacity: 1;
  -webkit-text-fill-color: rgba(255, 255, 255, 0.85);
}

.rd-om-ai__send {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #4d4350;
  cursor: pointer;
}
.rd-om-ai__send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ---------- previous chats ---------- */

/* The drawer is the panel body on the field: no sheet of its own, and the thread and
   question box are hidden underneath while it is open (the hand-off hides the question
   box on this screen). */
.om-ai-widget--history-open .rd-om-ai__thread,
.om-ai-widget--history-open .rd-om-ai__ask {
  visibility: hidden;
}

.om-ai-widget-history-backdrop.rd-om-ai__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: transparent;
}

.om-ai-widget-history-drawer.rd-om-ai__history {
  position: absolute;
  top: 96px;
  bottom: 0;
  left: 0;
  right: 0;
  width: auto;
  max-width: none;
  padding: 22px 32px 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow-y: auto;
}

.rd-om-ai__history-label {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.rd-om-ai__new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  height: 50px;
  margin-top: 16px;
  border: 0;
  border-radius: 30px;
  background: #fff;
  color: #4d4350;
  font-family: var(--rd-sans);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
}
.rd-om-ai__new-chat-plus {
  font-size: 15px;
  line-height: 1;
}

.rd-om-ai__history-empty {
  margin-top: 20px;
  font-family: var(--rd-serif);
  font-style: italic;
  font-size: 19px;
  line-height: 1.3;
  text-wrap: balance;
}

.rd-om-ai__history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}
.rd-om-ai__history-list:empty { display: none; }

.om-ai-widget-history-item {
  width: 100%;
  padding: 14px 18px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  color: #fff;
  text-align: left;
  overflow: hidden;
  cursor: pointer;
}
.om-ai-widget-history-item.is-active {
  background: rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.rd-om-ai__history-title {
  font-family: var(--rd-sans);
  font-size: 15px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- launcher, while the panel is open ---------- */

/* The panel is the only surface while it is open, and its header holds the one close
   button; the floating launcher steps out of the way and comes back on close. */
.om-ai-widget-launcher {
  transition: opacity 200ms ease, visibility 200ms;
}
.om-ai-widget--open .om-ai-widget-launcher {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------- focus ---------- */

.rd-om-ai__round:focus-visible,
.rd-om-ai__send:focus-visible,
.rd-om-ai__new-chat:focus-visible,
.om-ai-widget-history-item:focus-visible,
.om-ai-widget-action-button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.72);
  outline-offset: 2px;
}

/* ---------- hover and active states ----------
   The hand-off draws five static states, so these are derived from the same tones:
   a translucent fill lifts, a press darkens it and nudges in. Every control gets a
   focus-visible ring at the end of this file. */
.rd-om-ai__round:hover,
.om-ai-widget-action-button:hover:not(:disabled),
.rd-om-ai__send:hover:not(:disabled) {
  transform: translateY(-1px);
}
.rd-om-ai__round:active { background: rgba(255, 255, 255, 0.26); transform: none; }
.rd-om-ai__send:hover:not(:disabled) { background: #fff; box-shadow: 0 2px 10px rgba(30, 18, 10, 0.35); }
.rd-om-ai__send:active:not(:disabled) { transform: none; background: rgba(255, 255, 255, 0.9); }
.rd-om-ai__new-chat:hover { background: #fff; box-shadow: 0 2px 10px rgba(30, 18, 10, 0.25); }
.rd-om-ai__new-chat:active { transform: none; background: rgba(255, 255, 255, 0.88); }
.om-ai-widget-history-item:hover { background: rgba(255, 255, 255, 0.2); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45); }
.om-ai-widget-history-item:active { background: rgba(255, 255, 255, 0.28); transform: none; }
.om-ai-widget-action-button:active:not(:disabled) { background: rgba(160, 106, 46, 0.16); transform: none; }
@media (prefers-reduced-motion: reduce) {
  .rd-om-ai__round:hover,
  .om-ai-widget-action-button:hover:not(:disabled),
  .rd-om-ai__send:hover:not(:disabled) { transform: none; }
}

/* ---------- the launcher, in the redesign's palette ----------
   Was the old peach-800 rust (#BE5325) with eggshell-100 text — the one red left on every
   page. It is now the package's paper: the bone field, the ink glyph, a hairline and a soft
   shadow. That reads on the bone pages (where it looks like a paper control) and on the dusk
   fields (OM AI panel, partner slides) where anything darker sank into the gradient.
   `#frontend` is deliberate: the button carries Tailwind utilities (bg-peach-800, text-eggshell-100,
   shadow-…, hover:bg-peach-900) and an id beats them without !important. */
#frontend .om-ai-widget .om-ai-widget-launcher-button {
  background-color: var(--rd-bone);
  color: var(--rd-ink);
  box-shadow: 0 0 0 1px rgba(51, 45, 43, 0.2), 0 10px 24px rgba(51, 45, 43, 0.18);
}
#frontend .om-ai-widget .om-ai-widget-launcher-button:hover {
  background-color: var(--rd-bone);
  box-shadow: 0 0 0 1px rgba(51, 45, 43, 0.28), 0 16px 30px rgba(51, 45, 43, 0.22);
}
#frontend .om-ai-widget .om-ai-widget-launcher-button:active {
  transform: scale(0.97);
  box-shadow: 0 0 0 1px rgba(51, 45, 43, 0.24), 0 6px 14px rgba(51, 45, 43, 0.2);
}
#frontend .om-ai-widget .om-ai-widget-launcher-button:focus-visible {
  outline: 2px solid var(--rd-ink);
  outline-offset: 3px;
  --tw-ring-shadow: 0 0 #0000;
  --tw-ring-offset-shadow: 0 0 #0000;
}
.om-ai-widget-launcher-icon {
  background-color: rgba(51, 45, 43, 0.08);
}
.om-ai-widget-launcher.is-collapsed .om-ai-widget-launcher-icon {
  background-color: transparent;
}
.om-ai-widget-launcher-label small,
.om-ai-widget-launcher-label span {
  color: var(--rd-ink);
}
.om-ai-widget-launcher-label small {
  color: var(--rd-ink-muted);
}
@media (prefers-reduced-motion: reduce) {
  #frontend .om-ai-widget .om-ai-widget-launcher-button:active { transform: none; }
}
