/* WATranslate v4.5 — Admin branding/settings */

.login-brand-group,
.desktop-brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.login-brand-logo {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  object-fit: contain;
  border-radius: 12px;
}

.desktop-brand-logo {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  object-fit: contain;
  border-radius: 8px;
}

.desktop-brand-group .brand-block {
  min-width: 0;
}

.mobile-brand-logo {
  display: none;
}

.settings-modal-card {
  max-width: 590px;
}

.branding-settings-form {
  display: grid;
  gap: 18px;
}

.settings-field {
  display: grid;
  gap: 7px;
}

.settings-field > label,
.settings-image-field label {
  color: #e9edef;
  font-size: 14px;
  font-weight: 700;
}

.settings-field small {
  display: block;
  color: #9fb0b8;
  font-size: 12px;
  line-height: 1.4;
}

#scriptNameInput {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  outline: 0;
  background: #111b21;
  color: #e9edef;
  font: inherit;
  font-size: 15px;
}

#scriptNameInput:focus {
  border-color: #00a884;
}

.branding-preview-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  align-items: center;
  gap: 13px;
}

.branding-preview {
  display: flex;
  width: 76px;
  height: 76px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 12px;
  background: #111b21;
}

.branding-preview img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.icon-preview-box {
  border-radius: 18px;
}

.settings-image-field input[type="file"] {
  box-sizing: border-box;
  width: 100%;
  color: #cbd5d9;
  font-size: 13px;
}

.settings-image-field input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 8px 11px;
  border: 0;
  border-radius: 8px;
  background: #2a3942;
  color: #e9edef;
  cursor: pointer;
}

.branding-icon-note {
  margin: -2px 0 0;
  color: #d7b36a;
  font-size: 12px;
  line-height: 1.4;
}

.branding-settings-status {
  min-height: 18px;
  color: #9fb0b8;
  font-size: 13px;
}

.branding-settings-status.success {
  color: #74d7b7;
}

.branding-settings-status.error {
  color: #ff9696;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.settings-actions button {
  min-height: 42px;
  padding: 9px 15px;
}

@media (max-width: 760px) {
  .mobile-title-block {
    align-items: center;
    flex-direction: row;
    gap: 9px;
  }

  .mobile-title-text {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
  }

  .mobile-title-text > span,
  .mobile-title-text > strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-brand-logo {
    display: block;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    object-fit: contain;
    border-radius: 9px;
  }

  .settings-modal-card {
    max-height: min(86dvh, 720px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .branding-preview-row {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .branding-preview {
    width: 64px;
    height: 64px;
  }

  .settings-actions {
    position: sticky;
    bottom: -24px;
    margin: 4px -22px -22px;
    padding:
      12px 22px calc(12px + env(safe-area-inset-bottom));
    background: #202c33;
    border-top: 1px solid rgba(255,255,255,.07);
  }

  .settings-actions button:first-child {
    flex: 1;
  }
}


/* v4.5.2 — Login screen hierarchy
   Logo on top, language selector at the bottom.
*/

.login-card {
  text-align: left;
}

.login-brand-top {
  display: grid;
  justify-items: center;
  margin-bottom: 18px;
  text-align: center;
}

.login-brand-top .login-brand-logo {
  width: 82px;
  height: 82px;
  margin: 0 0 12px;
  flex: none;
  border-radius: 17px;
  object-fit: contain;
}

.login-brand-top h1 {
  margin: 0 0 4px;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}

.login-brand-top #loginSubtitle {
  margin: 0;
  color: #8696a0;
  text-align: center;
}

.login-language-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.07);
}

.login-language-footer label {
  color: #8696a0;
  font-size: 12px;
  line-height: 1.25;
}

.login-language-footer .login-language-select {
  width: 132px;
  max-width: 132px;
  height: 38px;
  padding: 0 9px;
  border-radius: 8px;
}

#scriptNameInput,
#loginSubtitleInput {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  outline: 0;
  background: #111b21;
  color: #e9edef;
  font: inherit;
  font-size: 15px;
}

#scriptNameInput:focus,
#loginSubtitleInput:focus {
  border-color: #00a884;
}

@media (max-width: 760px) {
  .login-brand-top .login-brand-logo {
    width: 86px;
    height: 86px;
    border-radius: 19px;
  }

  .login-language-footer {
    grid-template-columns: 1fr auto;
  }

  .login-language-footer .login-language-select {
    width: 126px;
    max-width: 126px;
  }
}

@media (max-width: 360px) {
  .login-language-footer {
    grid-template-columns: 1fr;
  }

  .login-language-footer .login-language-select {
    width: 100%;
    max-width: none;
  }
}


/* v4.7.2 — Separate Web Logo / Mobile Logo */

/*
 * Desktop login:
 * show Web logo only.
 */
.login-mobile-brand-logo {
  display: none;
}

/*
 * Desktop header:
 * Web logo + text group.
 */
@media (min-width: 761px) {
  .desktop-brand-group {
    display: flex;
  }

  .mobile-title-block {
    /* The existing mobile CSS also hides this, but keep the branding rule explicit. */
    display: none;
  }
}

/*
 * Mobile/PWA:
 * Hide the ENTIRE desktop branding wrapper.
 *
 * Previous versions only hid .desktop-brand-block, leaving
 * .desktopBrandLogo visible beside .mobileBrandLogo and causing the
 * two-icon problem shown on iPhone.
 */
@media (max-width: 760px) {
  .desktop-brand-group {
    display: none !important;
  }

  .login-web-brand-logo {
    display: none !important;
  }

  .login-mobile-brand-logo {
    display: block;
  }

  /*
   * Only the dedicated Mobile logo is rendered in the mobile header.
   */
  #mobileBrandLogo {
    display: block;
  }
}


/* v4.7.3 — Recommended image-size guidance */
.settings-field small.image-size-recommendation {
  margin-top: 3px;
  padding: 7px 9px;
  border-left: 3px solid #00a884;
  border-radius: 5px;
  background: rgba(0, 168, 132, .08);
  color: #b9d8cf;
  font-size: 11.5px;
  line-height: 1.4;
}

@media (max-width: 760px) {
  .settings-field small.image-size-recommendation {
    font-size: 11px;
  }
}


/* v4.7.4 — Settings modal scrolling + always-visible Save controls */

/*
 * The Settings content can now be taller than the viewport because it contains:
 * - application name
 * - login subtitle
 * - web logo
 * - mobile logo
 * - app icon/favicon
 * - image-size guidance
 * - notification settings
 *
 * Make the modal itself scrollable on BOTH desktop and mobile.
 */
.settings-modal-card {
  box-sizing: border-box;
  width: min(590px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/*
 * Keep Save / Cancel visible while the administrator scrolls through Settings.
 */
.settings-actions {
  position: sticky;
  z-index: 20;
  bottom: -24px;
  margin: 6px -22px -22px;
  padding: 13px 22px 14px;
  background: #202c33;
  border-top: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 -10px 20px rgba(17,27,33,.92);
}

/*
 * Save is the primary action and should remain obvious.
 */
#settingsSaveButton {
  min-width: 150px;
}

/*
 * Give the form enough final spacing so the sticky footer never covers
 * notification/status text while scrolling.
 */
.branding-settings-form {
  padding-bottom: 2px;
}

/*
 * Firefox: make it clear that the Settings pane is scrollable.
 */
.settings-modal-card {
  scrollbar-width: thin;
  scrollbar-color: #53656f #202c33;
}

.settings-modal-card::-webkit-scrollbar {
  width: 8px;
}

.settings-modal-card::-webkit-scrollbar-track {
  background: #202c33;
}

.settings-modal-card::-webkit-scrollbar-thumb {
  background: #53656f;
  border-radius: 999px;
}

@media (max-width: 760px) {
  .settings-modal-card {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }

  /*
   * Override the older mobile-only values so desktop and mobile use the same
   * reliable sticky footer behavior.
   */
  .settings-actions {
    bottom: -24px;
    margin: 6px -22px -22px;
    padding:
      12px
      22px
      calc(12px + env(safe-area-inset-bottom));
  }

  #settingsSaveButton {
    flex: 1;
    min-width: 0;
  }
}


/* ============================================================
   v4.8.1 — Reliable Settings scrolling architecture
   ============================================================

   OLD:
   The entire modal card scrolled and the Save footer was sticky inside it.

   NEW:
   - Modal card itself never scrolls.
   - Header remains fixed.
   - .settings-scroll-body is the ONLY scrolling region.
   - Save / Cancel footer is a normal fixed flex child at the bottom.
*/

.settings-modal-card {
  display: flex;
  flex-direction: column;

  width: min(590px, calc(100vw - 40px));
  height: min(820px, calc(100dvh - 40px));
  max-height: calc(100dvh - 40px);

  overflow: hidden !important;
}

/* Settings title never scrolls away. */
.settings-modal-card > #settingsTitle {
  flex: 0 0 auto;
  margin-bottom: 14px;
}

/*
 * The form fills the remaining modal height.
 * min-height: 0 is essential so the child scroll container is allowed
 * to shrink instead of forcing the modal beyond the viewport.
 */
.branding-settings-form {
  display: flex !important;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  gap: 0 !important;
  padding-bottom: 0 !important;
}

/* Only this section scrolls. */
.settings-scroll-body {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  gap: 18px;

  overflow-y: auto;
  overflow-x: hidden;

  padding: 0 8px 14px 0;

  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;

  scrollbar-width: thin;
  scrollbar-color: #53656f #202c33;
}

.settings-scroll-body::-webkit-scrollbar {
  width: 8px;
}

.settings-scroll-body::-webkit-scrollbar-track {
  background: #202c33;
}

.settings-scroll-body::-webkit-scrollbar-thumb {
  background: #53656f;
  border-radius: 999px;
}

/*
 * Footer no longer uses position:sticky.
 * It is outside the scroll body, so it is naturally always visible.
 */
.settings-actions {
  position: static !important;
  z-index: auto !important;

  flex: 0 0 auto;

  margin: 0 -22px -22px !important;
  padding: 13px 22px 14px !important;

  background: #202c33;
  border-top: 1px solid rgba(255,255,255,.09);
  box-shadow: 0 -10px 22px rgba(17,27,33,.92);

  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#settingsSaveButton {
  min-width: 150px;
}

/*
 * Close control remains attached to the modal card, not to the scroll body.
 */
.settings-modal-card > .app-modal-close {
  z-index: 30;
}

@media (max-width: 760px) {
  .settings-modal-card {
    width: 100%;
    height: calc(
      100dvh
      - 24px
      - env(safe-area-inset-top)
      - env(safe-area-inset-bottom)
    );
    max-height: calc(
      100dvh
      - 24px
      - env(safe-area-inset-top)
      - env(safe-area-inset-bottom)
    );
  }

  .settings-scroll-body {
    padding-right: 4px;
    padding-bottom: 12px;
  }

  .settings-actions {
    margin: 0 -22px -24px !important;
    padding:
      12px
      22px
      calc(12px + env(safe-area-inset-bottom))
      !important;
  }

  #settingsSaveButton {
    flex: 1;
    min-width: 0;
  }
}

/*
 * Fallback for browsers that do not understand dynamic viewport units.
 */
@supports not (height: 100dvh) {
  .settings-modal-card {
    height: min(820px, calc(100vh - 40px));
    max-height: calc(100vh - 40px);
  }

  @media (max-width: 760px) {
    .settings-modal-card {
      height: calc(100vh - 24px);
      max-height: calc(100vh - 24px);
    }
  }
}


/* v4.8.4 — Visible application release version */

.app-version {
  display: block;
  color: #667781;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: .01em;
  white-space: nowrap;
}

.login-app-version {
  margin-top: 6px;
  text-align: center;
}

.desktop-app-version {
  margin-top: 1px;
}

.mobile-app-version {
  margin-top: 1px;
  font-size: 10px;
}

@media (max-width: 760px) {
  .mobile-title-text {
    line-height: 1.05;
  }

  .mobile-title-text .mobile-app-version {
    overflow: visible;
    text-overflow: clip;
  }
}


/* ============================================================
   v4.8.5 — Application version moved to footer
   ============================================================ */

.app-version-footer {
  flex: 0 0 auto;
  color: #667781;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: .01em;
  text-align: center;
  white-space: nowrap;
}

/* Login: version is the final item in the login card. */
.login-version-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.05);
}

/*
 * Sidebar structure:
 * ensure the chat list is the flexible/scrollable middle region and the
 * application version remains at the physical bottom of the sidebar.
 */
.inbox .sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.inbox .sidebar .contact-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-version-footer {
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,.05);
  background: #111b21;
}

/*
 * Old v4.8.4 header-version selectors are no longer rendered.
 * Keep this defensive rule in case stale HTML survives a browser cache.
 */
.login-app-version,
.desktop-app-version,
.mobile-app-version {
  display: none !important;
}

@media (max-width: 760px) {
  .sidebar-version-footer {
    padding-top: 7px;
    padding-bottom: calc(7px + env(safe-area-inset-bottom));
    font-size: 10px;
  }
}


/* ============================================================
   v4.8.6 — Version centered on the entire screen
   ============================================================ */

/*
 * The release number is now independent of the login card and sidebar.
 * It is fixed to the horizontal center of the whole viewport.
 */
.global-app-version-footer {
  position: fixed;
  z-index: 1100;

  left: 50%;
  bottom: calc(8px + env(safe-area-inset-bottom));

  transform: translateX(-50%);

  padding: 3px 8px;

  color: #667781;
  background: rgba(11, 20, 26, .72);
  border-radius: 6px;

  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: .01em;

  text-align: center;
  white-space: nowrap;

  pointer-events: none;
  user-select: none;

  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

/*
 * Old footer locations are no longer rendered. Defensive hide for stale cache.
 */
.login-version-footer,
.sidebar-version-footer,
.login-app-version,
.desktop-app-version,
.mobile-app-version {
  display: none !important;
}

@media (max-width: 760px) {
  .global-app-version-footer {
    bottom: calc(6px + env(safe-area-inset-bottom));
    font-size: 10px;
    padding: 2px 7px;
  }
}


/* ============================================================
   v4.8.8 — Admin automatic logout / session timeout
   ============================================================ */

.settings-security-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 11px;
  background: rgba(17,27,33,.52);
}

.settings-security-section > h3 {
  margin: 0;
  color: #e9edef;
  font-size: 15px;
}

#sessionTimeoutSelect {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 9px 34px 9px 11px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  outline: 0;
  background: #111b21;
  color: #e9edef;
  font: inherit;
  font-size: 15px;
}

#sessionTimeoutSelect:focus {
  border-color: #00a884;
}
