/* Keep the mailbox and the public pages anchored to the same physical edges
   when the interface language changes. Reading direction belongs to the text. */
html:is([lang="ar"], [lang="he"], [lang="ur"]) body {
  direction: ltr;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :where(
  :is(h1, h2, h3, h4, h5, h6, p, figcaption, legend, dt, dd, blockquote):not(:has(button, input, svg, md-icon, [role="button"])),
  li:not(:has(ul, ol, div, button, input)),
  label:not(:has(input, select, button, svg)),
  :is(button, a, span, strong, small, th, td, option):not(:has(*)),
  .posta-reader-label, .md-tooltip
):not(:where(.msg-body, .msg-body *, [contenteditable], [contenteditable] *, [dir], body [dir="ltr"] *, [aria-hidden="true"], .material-icons, md-icon, .sg-counter-badge)) {
  direction: rtl;
  unicode-bidi: isolate;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :where(input[type="text"], input[type="search"], input:not([type]), textarea):not([dir]) {
  direction: rtl;
  unicode-bidi: plaintext;
  text-align: start;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :is(
  input[type="email"], input[type="url"], input[type="tel"], input[type="number"],
  input[type="password"], input[inputmode="email"], input[inputmode="numeric"],
  input[autocomplete="username"], input[autocomplete="one-time-code"], input[name="code"],
  input[dir="ltr"], code, pre, kbd, .member-code, .msg-email, a[href^="mailto:"], .material-icons, md-icon
):not(:where(.msg-body *, [contenteditable] *)) {
  direction: ltr;
  unicode-bidi: isolate;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :where(.brand, .brand span, .brand b, .pi-tabs, .pi-choices, .posta-header,
  .md-toolbar-tools, #detailView md-card-actions, #mailEditor md-toolbar, .credential-field, .pu-bar, .pu-chooser) {
  direction: ltr;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :where(.login-card, .registration-card, .hero-copy, .story-copy,
  .mp-option, .legal-layout article, .sg-item-name, .pi-tabs > button) {
  min-inline-size: 0;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :where(.pi-dialog, .pi-tabs) {
  max-inline-size: 100%;
  box-sizing: border-box;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :is(.pi-tabs button[data-tab="all"], .posta-reminder-count, .su-compact-picker) {
  margin-left: auto;
  margin-right: 0;
}
html:is([lang="ar"], [lang="he"], [lang="ur"]) .su-task-heading {
  margin-left: 0;
  margin-right: auto;
}
html:is([lang="ar"], [lang="he"], [lang="ur"]) .posta-search-hint {
  left: 4px;
  right: auto;
}
html:is([lang="ar"], [lang="he"], [lang="ur"]) .view-list .md-toolbar-tools .sg-folder-name {
  text-align: left;
  unicode-bidi: plaintext;
}

html:is([lang="ar"], [lang="he"], [lang="ur"]) :is(.art, .stage-art) { transform: none; }
html:is([lang="ar"], [lang="he"], [lang="ur"]) .login-card .brand { min-inline-size: 9.44em; }
html:is([lang="ar"], [lang="he"], [lang="ur"]) .section-heading .choices {
  inline-size: min(16rem, 100%);
  flex: none;
  justify-content: space-between;
}
@media (max-width: 780px) {
  html:is([lang="ar"], [lang="he"], [lang="ur"]) .section-heading .choices { inline-size: min(14.125rem, 100%); }
}
@media (max-width: 700px) {
  html:is([lang="ar"], [lang="he"], [lang="ur"]) .login-card .brand { min-inline-size: 9.28em; }
}
@media (min-width: 741px) {
  html:is([lang="ar"], [lang="he"], [lang="ur"]) .sky::after { background: linear-gradient(90deg, #0b0e27df, #17182a11 65%); }
}
html:is([lang="ar"], [lang="he"], [lang="ur"]) .story-tab[aria-selected="true"] { box-shadow: inset 3px 0 var(--story-accent); }
@media (max-width: 740px) {
  html:is([lang="ar"], [lang="he"], [lang="ur"]) .story-tab[aria-selected="true"] { box-shadow: none; }
}

/* webmail UI Material supplies an explicit [dir=rtl] transform for the left
   drawer. It must still enter and leave through the same edge as in Turkish. */
html:is([lang="ar"], [lang="he"], [lang="ur"]).posta-mail md-sidenav.md-sidenav-left {
  left: 0;
  right: auto;
  direction: ltr;
}
/* A folder row contains the icon, the display name and an optional count.
   Keep their order independent of the writing direction of the name. */
html:is([lang="ar"], [lang="he"], [lang="ur"]) md-sidenav .sg-mailbox-list-item p.sg-item-name {
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
}
html:is([lang="ar"], [lang="he"], [lang="ur"]) md-sidenav .sg-item-name .mc-folder-label {
  direction: rtl;
  unicode-bidi: isolate;
  text-align: left;
}
html:is([lang="ar"], [lang="he"], [lang="ur"]) md-sidenav .sg-item-name .sg-counter-badge {
  direction: ltr;
  unicode-bidi: isolate;
  flex-shrink: 0;
}
html:is([lang="ar"], [lang="he"], [lang="ur"]).posta-mail md-sidenav.md-sidenav-left.md-closed:not(.md-locked-open) {
  transform: translate3d(-100%, 0, 0);
}

.posta-language-footer { display:flex; justify-content:center; padding:1rem; }
.posta-language-footer .language-menu { display:flex; align-items:center; gap:.55rem; margin:0; font:inherit; }
.posta-language-footer select { max-inline-size:100%; padding:.35rem .55rem; border:1px solid currentColor; border-radius:.4rem; font:inherit; }
