/* Hamrah Build 537 — language, bidi, and typography layer. */

:root {
  --font-ui-fa: var(--g114-interface-font, "Vazirmatn", "Estedad", "Peyda", Tahoma, "Segoe UI", sans-serif);
  --font-ui-en: var(--g114-interface-font, "Hamrah Roboto", Roboto, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif);
  --font-message-en: var(--g114-message-font, "Hamrah Roboto", Roboto, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif);
  --font-ui-mixed: var(--font-message-en), var(--font-ui-fa), "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
}

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="ltr"] body {
  direction: ltr !important;
}

html[lang="en"] body,
html[lang="en"] body[data-font-family="modern"],
html[lang="en"] body[data-font-family="readable"],
html[lang="en"] body[data-font-family="classic"],
html[lang="en"] button,
html[lang="en"] input,
html[lang="en"] textarea,
html[lang="en"] select {
  font-family: var(--font-ui-en) !important;
  letter-spacing: normal;
}

html[lang="en"] :where(
  .message-text,
  .row-sub,
  .reply-preview,
  .forwarded-from,
  .attachment-file,
  .pc-profile-bio,
  .pc-link-value,
  .saved-message-text,
  [data-user-content]
) {
  font-family: var(--font-ui-mixed);
}

:where(
  .message-text,
  .row-sub,
  .reply-preview,
  .forwarded-from,
  .attachment-file,
  .pc-profile-bio,
  .pc-link-value,
  .saved-message-text,
  [data-user-content]
) {
  unicode-bidi: plaintext;
  overflow-wrap: anywhere;
  text-align: start;
}

#messageInput,
#chatSearch,
#messageSearchInput,
#contactSearch,
#profileBio,
#profileMood,
#channelName {
  unicode-bidi: plaintext;
  text-align: start;
}

/* Surfaces that historically forced RTL now inherit the selected UI language. */
html[dir="ltr"] :where(
  .g9-call-layer,
  .g9-call-bar,
  .g119a-layer,
  .g119a-minibar,
  .g119a-call-invite,
  .g119a-top-actions,
  .g114-layout,
  .g114d3-shell,
  .g11x-shell,
  .p2p-modal,
  .p2p-field input,
  .saved-messages-layer,
  .saved-messages-sheet,
  .voice-core-player,
  .voice-core-recording,
  .pc-profile-layer,
  .pc-private-layer,
  .group-profile-layer,
  .hamrah-r5d-gallery .g113-album-chips,
  .g119b-image-viewer .viewer-toolbar,
  .capability-list,
  .console-note,
  .profile-birthday-input[readonly],
  .ui-studio-phone,
  .g114-shell,
  .g114d3-studio,
  .g114-studio
) {
  direction: ltr !important;
}

html[dir="ltr"] :where(
  .g114-nav button,
  .g114-option-grid button,
  .g114-preset-grid > button,
  .g8-category-card,
  .g8-page-header,
  .plain-row,
  .setting-row,
  .action-row,
  .list-row,
  .sheet-title,
  .profile-settings-row
) {
  text-align: start;
}

/* Back controls are semantic; ordinary media/control icons are never mirrored. */
html[dir="ltr"] :where(
  #backFromChat,
  .g8-page-back,
  .pc-back,
  .g114-back,
  .g114d3-back,
  [data-nav-action="back"]
) svg {
  transform: scaleX(-1);
}

html[dir="ltr"] .studio-back {
  transform: none;
}

html[dir="rtl"] .studio-back {
  transform: rotate(180deg);
}

/* Preserve sender/receiver geometry regardless of application direction. */
.message,
.message.mine,
.studio-message,
.studio-message.sent {
  direction: inherit;
}

/* Language settings use the existing selected-row vocabulary. */
.g8-language-intro {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--line));
  border-radius: 18px;
  background: color-mix(in srgb, var(--primary) 6%, var(--surface));
}

.g8-language-intro > span {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}

.g8-language-intro b,
.g8-language-intro small {
  display: block;
}

.g8-language-intro b {
  font-size: .78rem;
}

.g8-language-intro small {
  margin-top: 4px;
  color: var(--muted);
  font-size: .6rem;
  line-height: 1.65;
}

.g8-language-list {
  display: grid;
  gap: 9px;
}

.g8-language-row {
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--text);
  background: var(--surface);
  text-align: start;
}

.g8-language-row:hover {
  border-color: color-mix(in srgb, var(--primary) 42%, var(--line));
  background: color-mix(in srgb, var(--primary) 4%, var(--surface));
}

.g8-language-row.selected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 9%, var(--surface));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 10%, transparent);
}

.g8-language-row b,
.g8-language-row small {
  display: block;
}

.g8-language-row b {
  font-size: .76rem;
}

.g8-language-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: .57rem;
}

.g8-language-check {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  color: transparent;
  background: var(--surface-2);
}

.g8-language-row.selected .g8-language-check {
  border-color: var(--primary);
  color: #fff;
  background: var(--primary);
}

.g8-language-check svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.5;
}

.g8-language-native[lang="fa"] {
  font-family: var(--font-ui-fa) !important;
}

.g8-language-native[lang="en"] {
  font-family: var(--font-ui-en) !important;
}

@media (prefers-reduced-motion: reduce) {
  .g8-language-row {
    transition: none;
  }
}
/* I18N + Android Settings + Super Admin Physical QA Hotfix R1
   English owns application direction; user-generated content keeps plaintext bidi. */
html[lang="en"][dir="ltr"] :where(
  .app,.app > .topbar,.app > .view,.view,.settings-view,.profile-view,
  #chatsView,#settingsView,#profileView,#callsView,#adminView,#chatScreen,
  .chat-screen,.chat-header,.chat-tools,.bottom-nav,.sheet,.sheet-title,.modal,.drawer,
  .g8-settings-shell,.g8-settings-home,.g8-settings-pages,.g8-settings-page,
  .g11x-admin-center,.g11x-shell,.g11x-sidebar,.g11x-workspace,.g11x-content,.g11x-section,
  .g11x-modal,.g11x-drawer,.g11x-drawer-body,
  .g114-shell,.g114-layout,.g114d3-studio,.g114d3-shell,.g114d3-workspace,
  .g114d3-nav,.g114d3-panel,.g114d3-preview-wrap
){direction:ltr!important}

html[lang="en"][dir="ltr"][data-hamrah-desktop="windows"] :where(
  [class^="hdw-"],[class*=" hdw-"],[class^="desktop-"],[class*=" desktop-"],
  .app,.app > .topbar,.app > .view,#chatsView,#settingsView,#profileView,#callsView,
  #adminView,#chatScreen,.chat-screen,.g8-settings-shell,.g11x-shell,.g114d3-shell
){direction:ltr!important}

html[lang="en"][dir="ltr"] :where(
  .topbar-copy,.settings-intro,.settings-title,.setting-copy,.g8-settings-hero,
  .g8-category-card,.g8-page-header,.g8-settings-section,.g8-search-results button,
  .plain-row,.setting-row,.font-setting,.action-row,.list-row,.profile-settings-row,
  .g11x-brand,.g11x-nav button,.g11x-page-meta,.g11x-section-head,.g11x-command-card,
  .g11x-alert,.g11x-person,.g11x-admin-row,.g11x-community-card,
  .g11x-command-results button,.g11x-drawer-title,.g11x-inspector-hero,.g11x-field,
  .g114d3-nav button,.g114d3-panel
){text-align:start!important}

html[lang="en"][dir="ltr"] .room-unread{margin-right:0!important;margin-left:auto!important}
html[lang="en"][dir="ltr"] .room-local-menu{margin-left:0!important;margin-right:5px!important}
html[lang="en"][dir="ltr"] .g11x-top-actions{margin-right:0!important;margin-left:auto!important}

@media(min-width:761px){
  html[lang="en"][dir="ltr"] .g11x-sidebar{
    border-left:0!important;border-right:1px solid var(--g11x-line)!important
  }
  html[lang="en"][dir="ltr"] .g11x-drawer{
    inset:0 auto 0 0!important;border-left:0!important;
    border-right:1px solid var(--g11x-line)!important;
    transform:translateX(-104%)!important;
    box-shadow:24px 0 70px rgba(0,0,0,.28)!important
  }
  html[lang="en"][dir="ltr"] .g11x-drawer-layer.visible .g11x-drawer{transform:none!important}
  html[lang="en"][dir="ltr"] .g114d3-nav{
    border-left:0!important;border-right:1px solid var(--line)!important
  }
  html[lang="en"][dir="ltr"] .g114d3-preview-wrap{
    border-right:0!important;border-left:1px solid var(--line)!important
  }
}

html[lang="en"] :where(
  .message-text,.reply-preview,.forwarded-from,.attachment-file,.pc-profile-bio,
  .pc-link-value,.saved-message-text,[data-user-content]
){unicode-bidi:plaintext;text-align:start}

html:not([data-hamrah-desktop="windows"]) #settingsView [data-g8-category="language"]{
  display:grid!important;visibility:visible!important;opacity:1!important
}
html:not([data-hamrah-desktop="windows"]) #settingsView .g8-settings-search,
html:not([data-hamrah-desktop="windows"]) #settingsView #g8SettingsSearch{
  pointer-events:auto!important;touch-action:manipulation!important
}
/* English First-Class LTR Architecture R2 — shared semantic surfaces */
html[lang="en"][dir="ltr"] :where(
  #settingsView,#profileView,#contactsView,#callsView,#adminView,
  .g8-settings-shell,.g8-settings-home,.g8-settings-pages,.g8-settings-page,
  .g11x-admin-center,.g11x-shell,.g11x-sidebar,.g11x-workspace,.g11x-content,
  .g11x-section,.g11x-modal,.g11x-drawer,.g114d3-shell,.g114d3-workspace,
  .g114d3-nav,.g114d3-panel,.g114d3-preview-wrap
) {
  direction:ltr!important;
}

html[lang="en"][dir="ltr"] :where(
  .g8-category-card,.g8-page-header,.g8-settings-section,.g8-search-results button,
  .g8-language-row,.g11x-nav button,.g11x-command-card,.g11x-alert,.g11x-person,
  .g11x-admin-row,.g11x-community-card,.g11x-field,.g11x-inspector-hero,
  .g114d3-nav button,.g114d3-panel
) {
  text-align:start!important;
}

/* RTL back chevrons become natural LTR chevrons. */
html[lang="en"][dir="ltr"] :where(.g8-page-back,.g8-category-card) svg[data-icon="back"],
html[lang="en"][dir="ltr"] .g8-page-back svg {
  transform:scaleX(-1);
  transform-origin:center;
}

/* Android / narrow-screen English remains touch-native and LTR. */
@media(max-width:899px) {
  html[lang="en"][dir="ltr"] #settingsView .g8-settings-shell,
  html[lang="en"][dir="ltr"] #settingsView .g8-settings-home,
  html[lang="en"][dir="ltr"] #settingsView .g8-settings-pages,
  html[lang="en"][dir="ltr"] #adminView .g11x-admin-center {
    direction:ltr!important;
    text-align:start;
  }

  html[lang="en"][dir="ltr"] #settingsView .g8-category-card {
    grid-template-columns:42px minmax(0,1fr) 20px;
  }

  html[lang="en"][dir="ltr"] #settingsView .g8-settings-search input,
  html[lang="en"][dir="ltr"] #adminView :is(input,textarea,select) {
    direction:ltr!important;
    text-align:left!important;
  }
}
