/* Rukoo in the browser (src/web/index.html, web-shell.js). Loaded after styles.css, which draws everything; these rules
   only change what a browser page needs differently from the desktop window. Every rule is scoped under
   html[data-platform='web'] or the web shell's own classes, so nothing here reaches the Electron window. */

/* ---------- the page ---------- */

/* The dynamic viewport: with interactive-widget=resizes-content the page shrinks above a phone's on-screen keyboard,
   so the composer at the bottom of the conversation stays in view. */
html[data-platform='web'],
html[data-platform='web'] body {
  height: 100dvh;
}
html[data-platform='web'] {
  --web-top: env(safe-area-inset-top, 0px);
}
/* The title bar's height: the desktop's 40px, and 48px on a phone, around its 44px Back and Settings. */
html[data-platform='web'] body {
  --web-bar: 40px;
}
html[data-platform='web'] body.web-phone {
  --web-bar: 48px;
}

/* No window buttons to make room for (styles.css reserves about 150px on Windows and Linux), and nothing to drag. */
html[data-platform='web'] .titlebar {
  -webkit-app-region: no-drag;
  height: calc(var(--web-bar) + var(--web-top));
  padding-top: var(--web-top);
  padding-right: calc(8px + env(safe-area-inset-right, 0px));
}
html[data-platform='web'] #app,
html[data-platform='web'] .page {
  top: calc(var(--web-bar) + var(--web-top));
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
}
/* The image viewer starts under the title bar too (styles.css puts it under the desktop's 40px), so the bar, which
   stays above every scrim, leaves its Close, Open and Download alone on a phone's 48px bar and below a notch. */
html[data-platform='web'] .scrim.ch-viewer {
  top: calc(var(--web-bar) + var(--web-top));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

/* The state that stands in for chat while it isn't there (web-shell.js gate): the chat pane's empty state. */
.web-gate {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  --text-3: var(--ch-text-3);
}
.web-gate .ch-empty > svg {
  width: 44px;
  height: 44px;
}

/* A file in the composer's tray that failed says why in full, over more lines: the desktop shows the rest in a tooltip,
   which a touch screen doesn't have, and the browser's reasons say what to do (chat.errors.webFileUnreadable). Retry
   gets a line of its own under the reason, in line with the text, so a long label (Dutch Opnieuw proberen) leaves the
   reason its width. A picture that failed becomes such a card too, with the picture where the file's icon is. */
html[data-platform='web'] .ch-tray-item.is-file.is-failed,
html[data-platform='web'] .ch-tray-item.is-image.is-failed {
  flex-wrap: wrap;
  row-gap: 0;
  height: auto;
  min-height: 52px;
}
html[data-platform='web'] .ch-tray-item.is-failed .ch-tray-sub {
  white-space: normal;
}
html[data-platform='web'] .ch-tray-item.is-file.is-failed .ch-file-text,
html[data-platform='web'] .ch-tray-item.is-image.is-failed .ch-tray-sub {
  flex: 1 1 calc(100% - 50px);
}
html[data-platform='web'] .ch-tray-item.is-failed .ch-tray-retry {
  margin-left: 50px;
}
html[data-platform='web'] .ch-tray-item.is-image.is-failed {
  display: flex;
  align-items: center;
  column-gap: 10px;
  width: 248px;
  max-width: 100%;
  padding: 6px 30px 6px 6px;
}
html[data-platform='web'] .ch-tray-item.is-image.is-failed .ch-tray-thumb {
  position: relative;
  inset: auto;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
}
html[data-platform='web'] .ch-tray-item.is-image.is-failed .ch-tray-sub {
  display: block;
  min-width: 0;
}
html[data-platform='web'] .ch-tray-item.is-image.is-failed .ch-tray-retry {
  position: static;
  transform: none;
  min-height: 24px;
  padding: 2px 4px;
  border-radius: 6px;
  background: none;
  box-shadow: none;
}
html[data-platform='web'] .ch-tray-item.is-image.is-failed .ch-tray-x {
  top: 50%;
  right: 6px;
  margin-top: -10px;
}
/* A file uploading: the page learns how much went only once the server answers (chat-rich.js unmeasured), so the bar
   runs full length with a light moving along it, as the loading bar's shimmer does. */
html[data-platform='web'] .ch-tray-item.is-unmeasured .ch-tray-bar i {
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: shimmer 1s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  html[data-platform='web'] .ch-tray-item.is-unmeasured .ch-tray-bar i {
    animation: none;
    background: color-mix(in srgb, var(--accent) 50%, transparent);
  }
}

/* ---------- title bar: Back and Settings on a phone ---------- */

.web-back {
  display: none;
  align-items: center;
  gap: 2px;
  height: 44px;
  margin-left: 4px;
  padding: 0 12px 0 6px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 120ms ease;
}
.web-back:hover {
  background: var(--hover);
}
.web-back:active {
  background: var(--active);
}
.web-back svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.7;
  flex: none;
}
/* A thread over the conversation has its own Back in its header, which leads to the conversation. */
body.web-can-back:not(:has(.page, .chat[data-thread='open'])) .web-back {
  display: inline-flex;
}
body.web-can-back:not(:has(.page, .chat[data-thread='open'])) .titlebar-brand {
  display: none;
}
.web-bar-settings {
  display: none;
}
body.web-phone .web-bar-settings {
  display: inline-grid;
}

/* ---------- a phone: the list or the conversation ---------- */

body.web-phone .titlebar-brand {
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
}
.web-shell.web-phone .sidebar {
  width: 100%;
  padding: 4px 16px calc(8px + env(safe-area-inset-bottom, 0px));
}
.web-shell.web-phone[data-pane='main'] .sidebar,
.web-shell.web-phone[data-pane='list'] .workspace {
  display: none;
}
.web-shell.web-phone .workspace {
  border-left: 0;
  border-top-left-radius: 0;
}
/* The gear and the rail button are the desktop's; a phone has Settings in the title bar and no rail. */
body.web-phone .web-foot-settings,
body.web-phone .web-foot-collapse {
  display: none;
}
.web-shell.web-phone .ch-compose,
.web-shell.web-phone .ch-thread-compose {
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}
/* Notices go above the composer, or the list's status line, instead of over it: web-shell.js (placeToast) measures the
   one that shows into --web-toast-bottom, and leaves it unset where neither shows. */
body.web-phone .toast {
  bottom: var(--web-toast-bottom, calc(24px + env(safe-area-inset-bottom, 0px)));
  max-width: calc(100vw - 32px);
}
/* A notice's button (Undo, a chat alert's Open) keeps its size; an invisible area around it, half of what it lacks of
   44px on each side, makes the touch target 44px. */
body.web-phone .toast button {
  position: relative;
}
body.web-phone .toast button::after {
  content: '';
  position: absolute;
  inset: min(0px, calc((100% - 44px) / 2));
}
body.web-phone .dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}

/* Touch targets of at least 44 by 44px (WCAG 2.5.5, Apple's guideline). The plus beside Channels and Direct messages
   shows without a hover, which a touch screen doesn't have; negative margins keep the headings as tall as they were. */
body.web-phone .nav-item,
body.web-phone .sync-status,
body.web-phone .compose-btn,
body.web-phone .btn,
body.web-phone .btn.sm,
body.web-phone .tbtn,
body.web-phone .dialog .buttons button {
  height: 44px;
}
body.web-phone .icon-btn,
body.web-phone .icon-btn.sm,
body.web-phone .icon-btn.xs,
body.web-phone .ch-tool {
  width: 44px;
  height: 44px;
}
body.web-phone .nav-section .icon-btn {
  opacity: 1;
  margin: -14px -10px -14px 0;
}
body.web-phone .menu button {
  min-height: 44px;
}
body.web-phone .radio-row,
body.web-phone .ch-new-row,
body.web-phone .ch-browse-row,
body.web-phone .ch-person,
body.web-phone .ch-suggest [role='option'] {
  min-height: 44px;
}
/* The account forms' code step (email-code.js): Send a new code, and Email me a code under a locked account's error. */
body.web-phone .code-step .code-actions .link-btn,
body.web-phone .error .code-offer {
  min-height: 44px;
}
body.web-phone .ch-send {
  width: 44px;
  height: 44px;
  border-radius: 10px;
}
/* The composer's Mention, Attach, Emoji and Formatting, a file card's Download and the viewer's buttons: 44px round
   buttons, as Send. */
body.web-phone .ch-tb,
body.web-phone .ch-file-dl {
  width: 44px;
  height: 44px;
}
body.web-phone .ch-box-tools {
  margin-left: -10px;
}
/* Reactions keep their pill, a little taller; an invisible area makes each one 44px high, and the gap between the
   rows of a wrapped list keeps their areas apart. */
body.web-phone .ch-reacts {
  gap: 8px 6px;
}
body.web-phone .ch-react,
body.web-phone .ch-react-add {
  position: relative;
  height: 32px;
  min-width: 44px;
  justify-content: center;
}
body.web-phone .ch-react::after,
body.web-phone .ch-react-add::after {
  content: '';
  position: absolute;
  inset: -6px 0;
}
/* A touch screen has no hover: a staged file's remove button and a link card's always show, with a 44px area around
   their small circles. */
body.web-phone .ch-tray-x,
body.web-phone .ch-card-x {
  opacity: 1;
}
body.web-phone .ch-tray-x::after,
body.web-phone .ch-card-x::after {
  content: '';
  position: absolute;
  inset: -12px;
}
body.web-phone .ch-tray-retry,
body.web-phone .ch-tray-item.is-image.is-failed .ch-tray-retry {
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
}
/* A failed file or picture takes the whole row, and its Retry line is 44px high (above). */
body.web-phone .ch-tray-item.is-file.is-failed,
body.web-phone .ch-tray-item.is-image.is-failed {
  width: 100%;
}
/* A picture smaller than a fingertip keeps its own size, with an invisible area around it that makes the tap target
   44px each way (as the banner's action below). The tile lets that area out; the picture keeps its round corners. */
body.web-phone .ch-media.is-n1 .ch-img {
  overflow: visible;
  /* What overflow: hidden gave it: no taller than the picture for the placeholder icon inside. */
  min-height: 0;
}
body.web-phone .ch-media.is-n1 .ch-img img {
  border-radius: inherit;
}
body.web-phone .ch-media.is-n1 .ch-img::before {
  content: '';
  position: absolute;
  inset: min(0px, calc((100% - 44px) / 2));
}
/* The emoji picker: as wide as the screen allows, with a 44px search field, skin tones and group tabs, and as many
   44px cells to a row as fit (chat-rich.js reads that count for the arrow keys). */
body.web-phone .ch-emoji {
  width: calc(100vw - 16px);
}
body.web-phone .ch-emoji-search {
  height: 44px;
}
body.web-phone .ch-emoji-tone,
body.web-phone .ch-emoji-tone-opt,
body.web-phone .ch-emoji-tab {
  width: 44px;
  height: 44px;
}
body.web-phone .ch-emoji-cells {
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
}
body.web-phone .ch-jump {
  height: 44px;
  padding: 0 16px 0 12px;
}
body.web-phone .ch-jump.is-up:not([hidden]) + .ch-jump.is-thread {
  top: 60px;
}
/* The banner's action (Try now, Start over: a 24px .link-btn, chat-view.js setBanner) keeps its size, so the strip
   and its text stay where they are. An invisible area around it, half of what it lacks of 44px on each side, makes
   the touch target 44px; it reaches 6px past the 32px strip above and below. */
body.web-phone .ch-banner [data-ch-banner] {
  position: relative;
}
body.web-phone .ch-banner [data-ch-banner]::after {
  content: '';
  position: absolute;
  inset: min(0px, calc((100% - 44px) / 2));
}
body.web-phone .form input[type='text'],
body.web-phone .form input[type='email'],
body.web-phone .form input[type='password'],
body.web-phone .form-input,
body.web-phone .form .inline,
body.web-phone .ch-browse-open {
  min-height: 44px;
}
body.web-phone .ch-search {
  height: 44px;
}
/* 16px text in fields keeps mobile browsers from zooming in when one takes the focus. */
body.web-phone .form input[type='text'],
body.web-phone .form input[type='email'],
body.web-phone .form input[type='password'],
body.web-phone .form textarea,
body.web-phone .form-input,
body.web-phone .ch-search,
body.web-phone .ch-emoji-search,
body.web-phone .ch-input {
  font-size: 16px;
}
body.web-phone .page-scroll {
  padding: 4px 16px calc(32px + env(safe-area-inset-bottom, 0px));
}
body.web-phone .page-bar {
  padding: 6px 8px;
}
body.web-phone .tbtn {
  min-width: 44px;
  justify-content: center;
}
/* The thread summary under a message keeps its 24px in the log; its touch area reaches 44px above and below without
   moving the rows. */
body.web-phone .ch-replies {
  position: relative;
}
body.web-phone .ch-replies::after {
  content: '';
  position: absolute;
  inset: -10px 0;
}
/* A touch screen keeps :hover on whatever was tapped last, so on a phone the sidebar's rows and the buttons don't keep
   that grey after the finger is gone. The open conversation keeps its own. */
@media (hover: none) {
  body.web-phone .nav-item:not(.active):hover,
  body.web-phone .account-switch:hover,
  body.web-phone .sync-status:hover,
  body.web-phone .icon-btn:not(.on):hover,
  body.web-phone .web-back:hover {
    background: transparent;
  }
}

/* A browser too old for the app (web-shell.js gate 'old'): nothing in Settings works there either. After the phone's
   rules, which show the title bar's Settings. */
body.web-old .web-foot-settings,
body.web-old .web-bar-settings {
  display: none;
}

/* ---------- the Rukoo apps: which to get, in order (web-shell.js renderApps, web-apps.js) ---------- */

/* The notice sits above the shell, on the title bar's canvas, and the shell takes the height that is left. */
html[data-platform='web'] #app {
  display: flex;
  flex-direction: column;
}
html[data-platform='web'] #app > .web-shell {
  flex: 1;
  min-height: 0;
  height: auto;
}
.web-apps-slot {
  flex: none;
  padding: 0 8px 8px;
}
.web-apps-slot[hidden] {
  display: none;
}
/* At most a little under half the window's height, and never so tall that chat's header, a few lines and the composer
   lose their room (about 260px): on a short window the steps scroll under the title and its close button. */
.web-apps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(45dvh, calc(100dvh - 260px));
  padding: 12px 8px 8px 16px;
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  animation: web-apps-in 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes web-apps-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .web-apps {
    animation: none;
  }
}
.web-apps-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.web-apps-text {
  flex: 1;
  min-width: 0;
}
.web-apps-title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  text-wrap: balance;
}
.web-apps-intro {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
  text-wrap: pretty;
}
.web-apps-close {
  width: 28px;
  height: 28px;
  margin-top: -4px;
}
.web-apps-close svg {
  width: 16px;
  height: 16px;
}
.web-apps-steps {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 20px;
  margin: 0;
  /* Room for the focus ring of the last links, which the scrolling would cut off. */
  padding: 0 8px 4px 0;
  list-style: none;
}
.web-apps-step {
  display: flex;
  gap: 10px;
  min-width: 0;
}
.web-apps-n {
  display: grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 9999px;
  background: var(--chip);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.web-apps-step-text {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding-top: 2px;
}
.web-apps-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 500;
  color: var(--text);
}
.web-apps-ic {
  display: inline-grid;
  flex: none;
  color: var(--text-3);
}
.web-apps-ic svg {
  width: 15px;
  height: 15px;
}
.web-apps-desc {
  font-size: 12px;
  color: var(--text-2);
  text-wrap: pretty;
}
.web-apps-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0 8px;
  margin: 2px 0 0 -4px;
}
/* .link-btn is drawn for buttons; as a link it drops the browser's underline until it is pointed at. */
.web-apps-link {
  min-height: 24px;
  text-decoration: none;
  cursor: pointer;
}
.web-apps-link:hover {
  text-decoration: underline;
}
.web-apps-link svg {
  width: 14px;
  height: 14px;
}
.web-apps-link.quiet {
  color: var(--text-2);
}
.web-apps-link:focus-visible,
.web-apps-close:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
/* Narrower than three columns hold: one step under the other. */
@media (max-width: 900px) {
  .web-apps-steps {
    grid-template-columns: minmax(0, 1fr);
  }
}
/* A phone: 44px targets, without the notice growing by as much: a link's extra height reaches 10px into the line
   above and below it. Links that wrap get 20px between their lines, so no two targets overlap, and the steps keep 10px
   at their end, so the last link's target isn't cut off where they scroll. */
/* Under it, a phone's list keeps the workspace, New message, the Channels heading and its first row whole (about
   300px with the title bar). */
body.web-phone .web-apps {
  max-height: min(45dvh, calc(100dvh - 300px));
  padding: 12px 4px 2px 14px;
}
/* 10px for the last link's target and 3px more for its focus ring. */
body.web-phone .web-apps-steps {
  padding-bottom: 13px;
}
body.web-phone .web-apps-close {
  width: 44px;
  height: 44px;
  margin: -12px -2px -8px 0;
}
body.web-phone .web-apps-link {
  min-height: 44px;
  margin-block: -10px;
}
body.web-phone .web-apps-links {
  row-gap: 20px;
  margin-top: 0;
}
body.web-phone .web-apps-desc {
  font-size: 13px;
}
/* The numbers show the order and each step says what its app is for, so a phone, where the notice pushes the list
   down, leaves out the sentence under the title. */
body.web-phone .web-apps-intro {
  display: none;
}
/* A narrow window under 480px tall, such as a phone turned sideways, has no room for the notice and chat together,
   since there its steps stand one under the other: it waits until the window is taller again. A wide window, where
   they stand side by side, keeps it down to 400px. */
@media (max-height: 479.98px) and (max-width: 900px), (max-height: 399.98px) {
  .web-apps-slot {
    display: none;
  }
}
/* While a phone's on-screen keyboard is up for the composer, the conversation needs the room. */
body.web-phone.web-typing .web-apps-slot {
  display: none;
}
